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

add support for prevrando (solc 0.8.18) #1946

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ For each new detector, at least one regression tests must be present.
> - To run tests for a specific test case, run `pytest tests/e2e/solc_parsing/test_ast_parsing.py -k user_defined_value_type` (the filename is the argument).
> - To run tests for a specific version, run `pytest tests/e2e/solc_parsing/test_ast_parsing.py -k 0.8.12`.
> - To run tests for a specific compiler json format, run `pytest tests/e2e/solc_parsing/test_ast_parsing.py -k legacy` (can be legacy or compact).
> - The IDs of tests can be inspected using ``pytest tests/e2e/solc_parsing/test_ast_parsing.py --collect-only`.
> - The IDs of tests can be inspected using `pytest tests/e2e/solc_parsing/test_ast_parsing.py --collect-only`.

### Synchronization with crytic-compile

Expand Down
4 changes: 3 additions & 1 deletion slither/core/declarations/solidity_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"block.basefee": "uint",
"block.coinbase": "address",
"block.difficulty": "uint256",
"block.prevrandao": "uint256",
"block.gaslimit": "uint256",
"block.number": "uint256",
"block.timestamp": "uint256",
"block.blockhash": "uint256", # alias for blockhash. It's a call
"block.blockhash": "bytes32", # alias for blockhash. It's a call
"block.chainid": "uint256",
"msg.data": "bytes",
"msg.gas": "uint256",
Expand Down Expand Up @@ -60,6 +61,7 @@
"log2(bytes32,bytes32,bytes32)": [],
"log3(bytes32,bytes32,bytes32,bytes32)": [],
"blockhash(uint256)": ["bytes32"],
"prevrandao()": ["uint256"],
# the following need a special handling
# as they are recognized as a SolidityVariableComposed
# and converted to a SolidityFunction by SlithIR
Expand Down
3 changes: 3 additions & 0 deletions slither/solc_parsing/yul/evm_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"TIMESTAMP",
"NUMBER",
"DIFFICULTY",
"PREVRANDAO",
"GASLIMIT",
"CHAINID",
"SELFBALANCE",
Expand Down Expand Up @@ -168,6 +169,7 @@
)
] + yul_funcs

# "identifier": [input_count, output_count]
function_args = {
"byte": [2, 1],
"addmod": [3, 1],
Expand Down Expand Up @@ -221,6 +223,7 @@
"timestamp": [0, 1],
"number": [0, 1],
"difficulty": [0, 1],
"prevrandao": [0, 1],
"gaslimit": [0, 1],
}

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/solc_parsing/test_ast_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]:
Test("units_and_global_variables-0.8.0.sol", VERSIONS_08),
Test("units_and_global_variables-0.8.4.sol", make_version(8, 4, 6)),
Test("units_and_global_variables-0.8.7.sol", make_version(8, 7, 9)),
Test("global_variables-0.8.18.sol", make_version(8, 18, 18)),
Test(
"push-all.sol",
ALL_VERSIONS,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"C": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n",
"g()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}
11 changes: 11 additions & 0 deletions tests/e2e/solc_parsing/test_data/global_variables-0.8.18.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract C {
function f() public view returns (uint256) {
return block.prevrandao;
}

function g() public view returns (uint256 ret) {
assembly {
ret := prevrandao()
}
}
}