Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[lang]: disallow blockhash in pure functions #3157

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
90747ef
add blockhash to local validation
tserg Nov 24, 2022
393dfed
add test
tserg Nov 24, 2022
3d303c7
fix mypy lint
tserg Nov 24, 2022
439bb78
use StateMutability
tserg Nov 27, 2022
5fadb3b
fix lint
tserg Nov 27, 2022
d976d3f
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Nov 28, 2022
aa82067
fix merge conflict
tserg Nov 28, 2022
cccd707
fix import
tserg Nov 28, 2022
6f193e4
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg May 18, 2023
a0e80ad
clean up imports
tserg May 18, 2023
b3e4b62
undo blank line
tserg May 18, 2023
79e1674
filter for nonpure builtins from namespace
tserg May 18, 2023
f6f2e91
fetch all call nodes
tserg May 18, 2023
a5b1924
clean up
tserg May 18, 2023
b754a1b
undo blank line
tserg May 18, 2023
eff8438
add interface test
tserg May 18, 2023
035a91b
fix lint
tserg May 18, 2023
9410901
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Feb 21, 2024
f6c95b2
revert merge conflict
tserg Feb 21, 2024
19baa5d
some fixes
tserg Feb 21, 2024
a33c7a8
move raw_call check to fetch_call_return
tserg Mar 8, 2024
bf26d2e
fix lint
tserg Mar 8, 2024
7ae3018
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Mar 8, 2024
c3f2bf6
fix test
tserg Mar 8, 2024
3931761
modify tests
tserg Mar 19, 2024
1895549
add default value
tserg Mar 19, 2024
9e52ecc
Merge branch 'master' into fix/blockhash
charles-cooper Mar 25, 2024
dad2c46
apply bts suggestion
tserg Mar 26, 2024
ebfe003
revert raw call changes
tserg Mar 26, 2024
4709936
fix lint
tserg Mar 26, 2024
e2e9864
Merge branch 'fix/blockhash' of https://github.com/tserg/vyper into f…
tserg Mar 26, 2024
b1517b7
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Mar 27, 2024
d9e32c7
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Oct 11, 2024
8610908
add blobhash
tserg Oct 11, 2024
36d6ddb
Merge branch 'master' of https://github.com/vyperlang/vyper into fix/…
tserg Oct 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/parser/features/decorators/test_pure.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,17 @@ def foo() -> uint256:
),
FunctionDeclarationException,
)


def test_invalid_builtin(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
"""
@external
@pure
def foo(x: uint256)-> bytes32:
return blockhash(x)
"""
),
StateAccessViolation,
)
4 changes: 4 additions & 0 deletions vyper/semantics/validation/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def __init__(
]
node_list.extend(standalone_self) # type: ignore

# Add references to builtin functions reading from the chain's state
builtin_fns = fn_node.get_descendants(vy_ast.Name, {"id": "blockhash"})
node_list.extend(builtin_fns) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add builtin function calls to the list of nodes to check. Or should the check for builtin functions be performed elsewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh for some reason i thought the mutability check was performed under visit_Call. i guess this solution is ok for now; i want to get in #2974 first though


for node in node_list:
t = node._metadata.get("type")
if isinstance(t, ContractFunction) and t.mutability == StateMutability.PURE:
Expand Down