From 7bfa87ad76e39f7a046b20a7342e1e4c8239ddce Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 9 Sep 2024 10:38:28 +0200 Subject: [PATCH 1/3] Add support custom errors in require --- .../core/declarations/solidity_variables.py | 1 + .../require-error.sol-0.8.27-compact.zip | Bin 0 -> 3685 bytes .../require-error.sol-0.8.27-compact.json | 5 +++++ .../solc_parsing/test_data/require-error.sol | 20 ++++++++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 tests/e2e/solc_parsing/test_data/compile/require-error.sol-0.8.27-compact.zip create mode 100644 tests/e2e/solc_parsing/test_data/expected/require-error.sol-0.8.27-compact.json create mode 100644 tests/e2e/solc_parsing/test_data/require-error.sol diff --git a/slither/core/declarations/solidity_variables.py b/slither/core/declarations/solidity_variables.py index 8094ab7c3..ce8477ab2 100644 --- a/slither/core/declarations/solidity_variables.py +++ b/slither/core/declarations/solidity_variables.py @@ -50,6 +50,7 @@ "assert(bool)": [], "require(bool)": [], "require(bool,string)": [], + "require(bool,error)": [], # Solidity 0.8.26 via-ir and Solidity >= 0.8.27 "revert()": [], "revert(string)": [], "revert ": [], diff --git a/tests/e2e/solc_parsing/test_data/compile/require-error.sol-0.8.27-compact.zip b/tests/e2e/solc_parsing/test_data/compile/require-error.sol-0.8.27-compact.zip new file mode 100644 index 0000000000000000000000000000000000000000..63aa223b37ffa0e9d4e552aa106161a54fd79272 GIT binary patch literal 3685 zcma*qNS&gfvLkXaqJ=Kw>bOQ4%6u(jfvvq*J;(M%QRb zLEig$zdzUYob%y)Isd>Tf0I+WXfad@J0B#HOa)jIR z+QQ*(a6S(=7YkcocQ?4Fg%#Y!!O`26&&k8hl^72nU$Rb5*Cv5qh6+=OsH6wTDLZed9m^LUE0zdzi|(mhYQg8hsY>BAS^%_3m)e3)ux|7|2<7lz`U;iK}FCvfhF z>ucWyu34!{tMOA>V2p;d_y<(SRc8~HO+zQ_OVkb>cL{5{C58Ly6;ZY}xb2=M}b0~CtUC>aJc(}>10Zw5q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?oV)EOrl}%tqwE;)a}^QRBxV&T@OI}Z){bAn^1Urmt;~_KC!vE^4 z;pt&XzBSGT&y!dmF&jZXo0Z6?9T^M}n74KH{Jf>zq+8=gb?VZWvh%ZK_KVeweh_Vr zWhM{IA#QGga3=5$x*|5F`=%eokYUI5tULIe*jA*yL4w(`;`9Fi7ya=`fM{nyth1)V zZ8j6+h5cspkeKPNxN?0l>%7k$jlAHEAqz%NMvqliEu;O{Vs4;JpWD0HgcYna7Ywh0FQbNk3XPxr?jHTqcyGCzF<244NdUnG2k{Oxf-eNYeIG|w+R zOTne%ub3FAD4HYoIglt3uXXO?b9)OKTHLu1w&v=t(!dWldDA~a*rJ`k=W+k$yK}f| zo*BDGdD}652&3+GTucEN?f$^E|AWD-c2~lV5s%cV0jefpmxaYS!{R`6B7cLqS;TE~ zu{qI)hPA{BCOnX)?fyRM{rNCh@Au!h9AP%w>6=)g?g+Ls9NL>{u}D85lnf=xvcLf- zo98N9;->2_)<3SUUs}&Jrz`m5xXDfDn;y$MqB_19<~LF3=vc|QvhcAQ&=Z-5TM=PA qEj1vHEbf2T-@gF-{{#d7GyjtXwbbwl{&NQYTit*6?q5s-0RIOy0rV&U literal 0 HcmV?d00001 diff --git a/tests/e2e/solc_parsing/test_data/expected/require-error.sol-0.8.27-compact.json b/tests/e2e/solc_parsing/test_data/expected/require-error.sol-0.8.27-compact.json new file mode 100644 index 000000000..3c3089c04 --- /dev/null +++ b/tests/e2e/solc_parsing/test_data/expected/require-error.sol-0.8.27-compact.json @@ -0,0 +1,5 @@ +{ + "TestToken": { + "transferWithRequireError(address,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n2->3;\n3[label=\"Node Type: EXPRESSION 3\n\"];\n}\n" + } +} \ No newline at end of file diff --git a/tests/e2e/solc_parsing/test_data/require-error.sol b/tests/e2e/solc_parsing/test_data/require-error.sol new file mode 100644 index 000000000..97c8ecac4 --- /dev/null +++ b/tests/e2e/solc_parsing/test_data/require-error.sol @@ -0,0 +1,20 @@ +pragma solidity 0.8.27; + +/// Insufficient balance for transfer. Needed `required` but only +/// `available` available. +/// @param available balance available. +/// @param required requested amount to transfer. +error InsufficientBalance(uint256 available, uint256 required); + +contract TestToken { + mapping(address => uint) balance; + function transferWithRequireError(address to, uint256 amount) public { + require( + balance[msg.sender] >= amount, + InsufficientBalance(balance[msg.sender], amount) + ); + balance[msg.sender] -= amount; + balance[to] += amount; + } + // ... +} From 5d55bc5752070f28330acafe890100b48b59aff0 Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 9 Sep 2024 10:44:29 +0200 Subject: [PATCH 2/3] Add test --- tests/e2e/solc_parsing/test_ast_parsing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/solc_parsing/test_ast_parsing.py b/tests/e2e/solc_parsing/test_ast_parsing.py index ca3872f8c..6ec7b6fbd 100644 --- a/tests/e2e/solc_parsing/test_ast_parsing.py +++ b/tests/e2e/solc_parsing/test_ast_parsing.py @@ -475,6 +475,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]: Test("solidity-0.8.24.sol", ["0.8.24"], solc_args="--evm-version cancun"), Test("scope/inherited_function_scope.sol", ["0.8.24"]), Test("using_for_global_user_defined_operator_1.sol", ["0.8.24"]), + Test("require-error.sol", ["0.8.27"]), ] # create the output folder if needed try: From 109c31adcf0b31f4a45c1ce63ab97db63496844e Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 11 Sep 2024 14:01:59 +0200 Subject: [PATCH 3/3] Add require with error --- slither/core/cfg/node.py | 3 ++- slither/printers/summary/require_calls.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/slither/core/cfg/node.py b/slither/core/cfg/node.py index 87d0e16a2..f600d0f43 100644 --- a/slither/core/cfg/node.py +++ b/slither/core/cfg/node.py @@ -529,7 +529,8 @@ def contains_require_or_assert(self) -> bool: bool: True if the node has a require or assert call """ return any( - c.name in ["require(bool)", "require(bool,string)", "assert(bool)"] + c.name + in ["require(bool)", "require(bool,string)", "require(bool,error)", "assert(bool)"] for c in self.internal_calls ) diff --git a/slither/printers/summary/require_calls.py b/slither/printers/summary/require_calls.py index 7823de160..ae79e9ed6 100644 --- a/slither/printers/summary/require_calls.py +++ b/slither/printers/summary/require_calls.py @@ -11,6 +11,7 @@ SolidityFunction("assert(bool)"), SolidityFunction("require(bool)"), SolidityFunction("require(bool,string)"), + SolidityFunction("require(bool,error)"), ]