Skip to content

Commit

Permalink
feat[lang]!: change the signature of block.prevrandao (#3879)
Browse files Browse the repository at this point in the history
`block.prevrandao` is an opcode alias for `difficulty`. however, it
returns a bytes object at the evm level (cf. for instance py-evm returns
the value of `block.mixhash`). this commit changes the signature of
`block.prevrandao` to be more consistent with the VM semantics.

also update PR title regex per conventional commit specification - add
optional `!` which indicates a breaking change
  • Loading branch information
charles-cooper authored Mar 23, 2024
1 parent b557e19 commit e48ff32
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
subjectPatternError: |
Starts with uppercase letter: '{subject}'
(Full PR title: '{title}')
headerPattern: '^(\w*)(?:\[([\w$.\-*/ ]*)\])?: (.*)$'
# type[scope]<optional !>: subject
# use [] instead of () for aesthetics
headerPattern: '^(\w*)(?:\[([\w$.\-*/ ]*)\])?!?: (.*)$'
validateSingleCommit: true
validateSingleCommitMatchesPrTitle: true
4 changes: 2 additions & 2 deletions docs/constants-and-vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Name Type Value
==================== ================ =========================================================
``block.coinbase`` ``address`` Current block miner's address
``block.difficulty`` ``uint256`` Current block difficulty
``block.prevrandao`` ``uint256`` Current randomness beacon provided by the beacon chain
``block.prevrandao`` ``bytes32`` Current randomness beacon provided by the beacon chain
``block.number`` ``uint256`` Current block number
``block.prevhash`` ``bytes32`` Equivalent to ``blockhash(block.number - 1)``
``block.timestamp`` ``uint256`` Current block epoch timestamp
Expand All @@ -31,7 +31,7 @@ Name Type Value

.. note::

``block.prevrandao`` is an alias for ``block.difficulty``. Since ``block.difficulty`` is considered deprecated according to `EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>`_ after "The Merge" (Paris hard fork), we recommend using ``block.prevrandao``.
``block.prevrandao`` is an alias for the ``block.difficulty`` opcode. Since ``block.difficulty`` is considered deprecated according to `EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>`_ after "The Merge" (Paris hard fork), we recommend using ``block.prevrandao``.

.. note::

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def foo():
"""
@external
def foo():
x: uint256 = block.prevrandao + 185
x: bytes32 = block.prevrandao
if tx.origin == self:
y: Bytes[35] = concat(block.prevhash, b"dog")
""",
Expand Down
2 changes: 1 addition & 1 deletion vyper/codegen/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def parse_Attribute(self):
warning = "tried to use block.prevrandao in pre-Paris "
warning += "environment! Suggest using block.difficulty instead."
vyper_warn(warning, self.expr)
return IRnode.from_list(["prevrandao"], typ=UINT256_T)
return IRnode.from_list(["prevrandao"], typ=BYTES32_T)
elif key == "block.difficulty":
if version_check(begin="paris"):
warning = "tried to use block.difficulty in post-Paris "
Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _Block(_EnvType):
_type_members = {
"coinbase": AddressT(),
"difficulty": UINT256_T,
"prevrandao": UINT256_T,
"prevrandao": BYTES32_T,
"number": UINT256_T,
"gaslimit": UINT256_T,
"basefee": UINT256_T,
Expand Down

0 comments on commit e48ff32

Please sign in to comment.