handle tmp call to library's custom error (#1267)

* handle tmp call to library's custom error
pull/1300/head
alpharush 2 years ago committed by GitHub
parent 98e6d8c13e
commit 167b4c0394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      slither/core/cfg/node.py
  2. 18
      slither/slithir/convert.py
  3. 4
      slither/solc_parsing/slither_compilation_unit_solc.py
  4. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.10-compact.zip
  5. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.11-compact.zip
  6. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.12-compact.zip
  7. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.4-compact.zip
  8. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.5-compact.zip
  9. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.6-compact.zip
  10. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.7-compact.zip
  11. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.8-compact.zip
  12. BIN
      tests/ast-parsing/compile/custom_error_with_state_variable.sol-0.8.9-compact.zip
  13. 11
      tests/ast-parsing/custom_error_with_state_variable.sol
  14. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.10-compact.json
  15. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.11-compact.json
  16. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.12-compact.json
  17. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.4-compact.json
  18. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.5-compact.json
  19. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.6-compact.json
  20. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.7-compact.json
  21. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.8-compact.json
  22. 5
      tests/ast-parsing/expected/custom_error_with_state_variable.sol-0.8.9-compact.json

@ -39,12 +39,11 @@ from slither.slithir.variables import (
TupleVariable,
)
from slither.all_exceptions import SlitherException
from slither.core.declarations import Contract
from slither.core.declarations import Contract, Function
from slither.core.expressions.expression import Expression
if TYPE_CHECKING:
from slither.core.declarations import Function
from slither.slithir.variables.variable import SlithIRVariable
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.utils.type_helpers import (
@ -917,6 +916,7 @@ class Node(SourceMapping, ChildFunction): # pylint: disable=too-many-public-met
)
elif isinstance(ir, LibraryCall):
assert isinstance(ir.destination, Contract)
assert isinstance(ir.function, Function)
self._high_level_calls.append((ir.destination, ir.function))
self._library_calls.append((ir.destination, ir.function))

@ -817,12 +817,28 @@ def extract_tmp_call(ins: TmpCall, contract: Optional[Contract]): # pylint: dis
# lib L { event E()}
# ...
# emit L.E();
if str(ins.ori.variable_right) in [f.name for f in ins.ori.variable_left.events]:
if str(ins.ori.variable_right) in ins.ori.variable_left.events_as_dict:
eventcall = EventCall(ins.ori.variable_right)
eventcall.set_expression(ins.expression)
eventcall.call_id = ins.call_id
return eventcall
# lib Lib { error Error()} ... revert Lib.Error()
if str(ins.ori.variable_right) in ins.ori.variable_left.custom_errors_as_dict:
custom_error = ins.ori.variable_left.custom_errors_as_dict[
str(ins.ori.variable_right)
]
assert isinstance(
custom_error,
CustomError,
)
sol_function = SolidityCustomRevert(custom_error)
solidity_call = SolidityCall(
sol_function, ins.nbr_arguments, ins.lvalue, ins.type_call
)
solidity_call.set_expression(ins.expression)
return solidity_call
libcall = LibraryCall(
ins.ori.variable_left,
ins.ori.variable_right,

@ -679,12 +679,12 @@ Please rename it, this name is reserved for Slither's internals"""
for func in contract.functions + contract.modifiers:
try:
func.generate_slithir_and_analyze()
except AttributeError:
except AttributeError as e:
# This can happens for example if there is a call to an interface
# And the interface is redefined due to contract's name reuse
# But the available version misses some functions
self._underlying_contract_to_parser[contract].log_incorrect_parsing(
f"Impossible to generate IR for {contract.name}.{func.name}"
f"Impossible to generate IR for {contract.name}.{func.name}:\n {e}"
)
contract.convert_expression_to_slithir_ssa()

@ -9,5 +9,14 @@ error ErrorWithParam(uint256 value);
uint256 constant ONE = 1;
uint256 constant TWO = ONE + 1;
function foo() pure { revert ErrorWithParam(0); }
contract Bar { }
library CustomErrors {
error LibraryError();
}
contract Bar {
function baz() external {
revert CustomErrors.LibraryError();
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}

@ -1,3 +1,6 @@
{
"Bar": {}
"CustomErrors": {},
"Bar": {
"baz()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}
Loading…
Cancel
Save