do not convert IRs with arguments to state var read (#1230)

* do not convert IRs with arguments to state var read
pull/1300/head
alpharush 2 years ago committed by GitHub
parent 8bead9347c
commit 2e341aee9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      scripts/ci_test_truffle.sh
  2. 2
      slither/core/children/child_node.py
  3. 6
      slither/slithir/convert.py
  4. BIN
      tests/ast-parsing/compile/free_functions/libraries_from_free.sol-0.8.12-compact.zip
  5. BIN
      tests/ast-parsing/compile/free_functions/library_constant_function_collision.sol-0.8.12-compact.zip
  6. BIN
      tests/ast-parsing/compile/free_functions/new_operator.sol-0.8.12-compact.zip
  7. 9
      tests/ast-parsing/expected/free_functions/libraries_from_free.sol-0.8.12-compact.json
  8. 9
      tests/ast-parsing/expected/free_functions/library_constant_function_collision.sol-0.8.12-compact.json
  9. 6
      tests/ast-parsing/expected/free_functions/new_operator.sol-0.8.12-compact.json
  10. 18
      tests/ast-parsing/free_functions/libraries_from_free.sol
  11. 14
      tests/ast-parsing/free_functions/library_constant_function_collision.sol
  12. 13
      tests/ast-parsing/free_functions/new_operator.sol
  13. 3
      tests/test_ast_parsing.py

@ -15,7 +15,7 @@ npm install -g truffle
truffle unbox metacoin
slither .
if [ $? -eq 9 ]
if [ $? -eq 6 ]
then
exit 0
fi

@ -28,4 +28,4 @@ class ChildNode:
@property
def compilation_unit(self) -> "SlitherCompilationUnit":
return self.contract.compilation_unit
return self.node.compilation_unit

@ -1385,7 +1385,11 @@ def convert_type_library_call(ir: HighLevelCall, lib_contract: Contract):
if len(candidates) == 1:
func = candidates[0]
if func is None:
# We can discard if there are arguments here because libraries only support constant variables
# And constant variables cannot have non-value type
# i.e. "uint[2] constant arr = [1,2];" is not possible in Solidity
# If this were to change, the following condition might be broken
if func is None and not ir.arguments:
# TODO: handle collision with multiple state variables/functions
func = lib_contract.get_state_variable_from_name(ir.function_name)
if func is None and candidates:

@ -0,0 +1,9 @@
{
"L": {
"pub()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n",
"inter()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n"
},
"C": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n"
}
}

@ -0,0 +1,9 @@
{
"ExtendedMath": {},
"IERC20": {
"decimals()": "digraph{\n}\n"
},
"A": {
"test(address)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n}\n"
}
}

@ -0,0 +1,6 @@
{
"C": {},
"D": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n"
}
}

@ -0,0 +1,18 @@
library L {
function pub() public pure returns (uint) {
return 7;
}
function inter() internal pure returns (uint) {
return 8;
}
}
function fu() pure returns (uint, uint) {
return (L.pub(), L.inter());
}
contract C {
function f() public pure returns (uint, uint) {
return fu();
}
}

@ -0,0 +1,14 @@
library ExtendedMath {
uint256 constant decimals = 18;
}
interface IERC20 {
function decimals() external view returns (uint8);
}
contract A {
using ExtendedMath for *;
function test(address x) public {
uint8 decimals = IERC20(address(x)).decimals();
}
}

@ -0,0 +1,13 @@
contract C {
uint public x = 2;
}
function test() returns (uint) {
return (new C()).x();
}
contract D {
function f() public returns (uint) {
return test();
}
}

@ -408,6 +408,9 @@ ALL_TESTS = [
# 0.8.9 crashes on our testcase
Test("user_defined_types.sol", ["0.8.8"] + make_version(8, 10, 12)),
Test("bytes_call.sol", ["0.8.12"]),
Test("free_functions/libraries_from_free.sol", ["0.8.12"]),
Test("free_functions/new_operator.sol", ["0.8.12"]),
Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]),
]
# create the output folder if needed
try:

Loading…
Cancel
Save