Skip to content

Commit e48ff32

Browse files
feat[lang]!: change the signature of block.prevrandao (#3879)
`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
1 parent b557e19 commit e48ff32

5 files changed

Lines changed: 8 additions & 6 deletions

File tree

.github/workflows/pull-request.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
subjectPatternError: |
5050
Starts with uppercase letter: '{subject}'
5151
(Full PR title: '{title}')
52-
headerPattern: '^(\w*)(?:\[([\w$.\-*/ ]*)\])?: (.*)$'
52+
# type[scope]<optional !>: subject
53+
# use [] instead of () for aesthetics
54+
headerPattern: '^(\w*)(?:\[([\w$.\-*/ ]*)\])?!?: (.*)$'
5355
validateSingleCommit: true
5456
validateSingleCommitMatchesPrTitle: true

docs/constants-and-vars.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Name Type Value
1616
==================== ================ =========================================================
1717
``block.coinbase`` ``address`` Current block miner's address
1818
``block.difficulty`` ``uint256`` Current block difficulty
19-
``block.prevrandao`` ``uint256`` Current randomness beacon provided by the beacon chain
19+
``block.prevrandao`` ``bytes32`` Current randomness beacon provided by the beacon chain
2020
``block.number`` ``uint256`` Current block number
2121
``block.prevhash`` ``bytes32`` Equivalent to ``blockhash(block.number - 1)``
2222
``block.timestamp`` ``uint256`` Current block epoch timestamp
@@ -31,7 +31,7 @@ Name Type Value
3131

3232
.. note::
3333

34-
``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``.
34+
``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``.
3535

3636
.. note::
3737

tests/functional/syntax/test_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def foo():
138138
"""
139139
@external
140140
def foo():
141-
x: uint256 = block.prevrandao + 185
141+
x: bytes32 = block.prevrandao
142142
if tx.origin == self:
143143
y: Bytes[35] = concat(block.prevhash, b"dog")
144144
""",

vyper/codegen/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def parse_Attribute(self):
270270
warning = "tried to use block.prevrandao in pre-Paris "
271271
warning += "environment! Suggest using block.difficulty instead."
272272
vyper_warn(warning, self.expr)
273-
return IRnode.from_list(["prevrandao"], typ=UINT256_T)
273+
return IRnode.from_list(["prevrandao"], typ=BYTES32_T)
274274
elif key == "block.difficulty":
275275
if version_check(begin="paris"):
276276
warning = "tried to use block.difficulty in post-Paris "

vyper/semantics/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class _Block(_EnvType):
1919
_type_members = {
2020
"coinbase": AddressT(),
2121
"difficulty": UINT256_T,
22-
"prevrandao": UINT256_T,
22+
"prevrandao": BYTES32_T,
2323
"number": UINT256_T,
2424
"gaslimit": UINT256_T,
2525
"basefee": UINT256_T,

0 commit comments

Comments
 (0)