From 0c27b000aa6d1ffd88439078af4086ee0cd12542 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Mon, 5 Jun 2023 09:22:27 -0500 Subject: [PATCH] add support for prevrando (solc 0.8.18) --- CONTRIBUTING.md | 2 +- slither/core/declarations/solidity_variables.py | 4 +++- slither/solc_parsing/yul/evm_functions.py | 3 +++ tests/e2e/solc_parsing/test_ast_parsing.py | 1 + ...lobal_variables-0.8.18.sol-0.8.18-compact.zip | Bin 0 -> 2023 bytes ...obal_variables-0.8.18.sol-0.8.18-compact.json | 6 ++++++ .../test_data/global_variables-0.8.18.sol | 11 +++++++++++ 7 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/solc_parsing/test_data/compile/global_variables-0.8.18.sol-0.8.18-compact.zip create mode 100644 tests/e2e/solc_parsing/test_data/expected/global_variables-0.8.18.sol-0.8.18-compact.json create mode 100644 tests/e2e/solc_parsing/test_data/global_variables-0.8.18.sol diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d1a9497f1..c00fda8aad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/slither/core/declarations/solidity_variables.py b/slither/core/declarations/solidity_variables.py index 552cf9e7f5..f6a0f08390 100644 --- a/slither/core/declarations/solidity_variables.py +++ b/slither/core/declarations/solidity_variables.py @@ -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", @@ -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 diff --git a/slither/solc_parsing/yul/evm_functions.py b/slither/solc_parsing/yul/evm_functions.py index dfb52a2448..28ea70e933 100644 --- a/slither/solc_parsing/yul/evm_functions.py +++ b/slither/solc_parsing/yul/evm_functions.py @@ -51,6 +51,7 @@ "TIMESTAMP", "NUMBER", "DIFFICULTY", + "PREVRANDAO", "GASLIMIT", "CHAINID", "SELFBALANCE", @@ -168,6 +169,7 @@ ) ] + yul_funcs +# "identifier": [input_count, output_count] function_args = { "byte": [2, 1], "addmod": [3, 1], @@ -221,6 +223,7 @@ "timestamp": [0, 1], "number": [0, 1], "difficulty": [0, 1], + "prevrandao": [0, 1], "gaslimit": [0, 1], } diff --git a/tests/e2e/solc_parsing/test_ast_parsing.py b/tests/e2e/solc_parsing/test_ast_parsing.py index a561343ded..316f2cc382 100644 --- a/tests/e2e/solc_parsing/test_ast_parsing.py +++ b/tests/e2e/solc_parsing/test_ast_parsing.py @@ -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, diff --git a/tests/e2e/solc_parsing/test_data/compile/global_variables-0.8.18.sol-0.8.18-compact.zip b/tests/e2e/solc_parsing/test_data/compile/global_variables-0.8.18.sol-0.8.18-compact.zip new file mode 100644 index 0000000000000000000000000000000000000000..04dde0da9c01b3b5d61bed184e30c285e572dcdd GIT binary patch literal 2023 zcmb8wX&}=N0|)TmHb-TKa>TIY$dxk;WgCAL!rVfHEk_t8k!0nXE1L)*=fs~mQYngM z2uUqD|BhUV_qT3X>BoU*#)5@iApwf*vWXe?QYMHI;wy3OjdMbYv>Z>Dkr+TYY)y<) zAk3sKpyNePyfpvVb}eGHa>5v`q12ajpHwS;^jMNqUftu7ddNoas;#2#7Y(5^jMTTxyUTEcEN+Es#yzL4wJppOt-=qZ$3zdOOa`L6Yc5*c1?V* zLBc|XbaRS3Xirw9NbF2ouyokFw5pW+nkSU?aR(~Acv3|g2=6m+!q6b3i1?a8tV=RZ zE%erv%eYa&!e;EeY5vKwQ~{mdLDXL82V2%S+4MGeVOA!k{sm~+E-pLDjAQ+9-SG(d zK(^|I>U}%=_#}V(cVk}*&CAz}dfy%Hoj%pV8877Y!7SG&G!oiv*Dc-3@nSzR@*9=k zHhpWLFj(;oD{gu_Hj?x!x5 zuURqDb6Sn)nnoaD?l;a|XgcP`*Bon;?OC*I7_W9PX(Sd?jS@Rhf4HUZgs7K^hhFq>7Rqk`rpOB*nw!pU zMCrKJdJ2>ZyDwl=DqqG%V0wI5;i6$`L#9)19B}dVXXILroN0J^YFU)e3x?0v2c0^W zxgdyx*4R>7#7Xta#b0c?NFZ}q5@W3j?Kt^MXnlaLmiF^5_0ED!_w!6f{(jx_gRHgu zY`s07izK%en`PG0;0VflZ~3i%fh|~SYJ`3$-GyNo>y)~g-5S788>8pwGuB`p1_8-4 z@7~-xlCZ*c!P+_FN=?=5ha;f0GZkTWqkG8ZVqEQkJni531=1m7h)_{`3w3n#q5C(d z;v@qDL~U$A{ozgQ z`(*~NjvVYdXf3xPn>JezeM`@nXp)`b?5vbKLt|{Q35GTe_k+fK!}hNV(@!snq|Wb{ z?AXn`#TmY`n9BDIrh^-}33~lsvxj`SHI=>UYZ=4!#dCE{p0nPUjnUPGsC}m?Ui&ii zw*Dy!iMeOBd%TqU9bQB$f8jXYVbYrT%ro%lg!zwPXVr{<ump%om zej+p!arKaqBqHQy(R&dEUA2lOm;n-WR*!3L{W*S0?*j(B!~YPRVsxedvYwW95sL>8 zC-+nBE*d=&Al}wm4CYVFI6tZ+&#q1T?3$25T(LfJZS%|bCriy+P1k=7eF)8YVW~Ce zi?}W{V8kGOFYguuxq3WL98~DT7EiFQxwkom#?NQJX>tF#RkVgG>$8kBq<}cr83RK% zskZmu(?n^?3D&M~j~Tke=XbRVNQKXXx4p05G%-geiyPy-j0~5d3e9b!(pM8c;U$IX zk8@G~2!ey=>cAz*AuNj+-Aw-`n1z!=?%P)(R`4q2b{J32%5kRHMoE=*^E!-D@-QUu zx5x+63&QI>tVSl9Q;}_;B+1Wncd}UPTYJnUoUhIllmP~`1_)HwN2=6unZZ1z%X|^? zVs2;y@e_DLkr-P+(F5^oxgT+Zuewxyue3Mq1}61w5KlMx_2g#f`~eDF47*)02Q@md z_43V75y9WS>f&5(qFhIfI^Me<#H`KJ5^rm*mayCrhZM}#ox1cP@8<=qHQ}&~K9q8_ zCMq&akR`BK2@5xgVmza;pr4qpW5Q>jtcA9mJBmeYrayAGDVd=;Z}eET&8|>dqR*}x zOH@l^TMO(YF$CAR(()_keKWh_@*BI3W89G6@;Z>~c~(R4EBL2kP9A8%%Ek(`Uo)F` z$~o^r@+(h$c}Hp7ooiRyRWxx?PXVwtl1;\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" + } +} \ No newline at end of file diff --git a/tests/e2e/solc_parsing/test_data/global_variables-0.8.18.sol b/tests/e2e/solc_parsing/test_data/global_variables-0.8.18.sol new file mode 100644 index 0000000000..f21ae5d8f6 --- /dev/null +++ b/tests/e2e/solc_parsing/test_data/global_variables-0.8.18.sol @@ -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() + } + } +} \ No newline at end of file