Skip to content

Commit

Permalink
feat[lang]: change the signature of block.prevrandao
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.
  • Loading branch information
charles-cooper committed Mar 21, 2024
1 parent e589278 commit b5340a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
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 @@ -273,7 +273,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 b5340a8

Please sign in to comment.