-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2589 from crytic/dev-event-selector-ir
Fix IR conversion when an Event selector is accessed
- Loading branch information
Showing
6 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
interface I{ | ||
function testFunction(uint a) external ; | ||
} | ||
|
||
contract A{ | ||
function testFunction() public{} | ||
} | ||
|
||
contract Test{ | ||
event TestEvent(); | ||
struct St{ | ||
uint a; | ||
} | ||
error TestError(); | ||
|
||
function testFunction(uint a) public {} | ||
|
||
|
||
function testFunctionStructure(St memory s) public {} | ||
|
||
function returnEvent() public returns (bytes32){ | ||
return TestEvent.selector; | ||
} | ||
|
||
function returnError() public returns (bytes4){ | ||
return TestError.selector; | ||
} | ||
|
||
|
||
function returnFunctionFromContract() public returns (bytes4){ | ||
return I.testFunction.selector; | ||
} | ||
|
||
|
||
function returnFunction() public returns (bytes4){ | ||
return this.testFunction.selector; | ||
} | ||
|
||
function returnFunctionWithStructure() public returns (bytes4){ | ||
return this.testFunctionStructure.selector; | ||
} | ||
|
||
function returnFunctionThroughLocaLVar() public returns(bytes4){ | ||
A a; | ||
return a.testFunction.selector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
from slither import Slither | ||
from slither.slithir.operations import Assignment | ||
from slither.slithir.variables import Constant | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
|
||
|
||
func_to_results = { | ||
"returnEvent()": "16700440330922901039223184000601971290390760458944929668086539975128325467771", | ||
"returnError()": "224292994", | ||
"returnFunctionFromContract()": "890000139", | ||
"returnFunction()": "890000139", | ||
"returnFunctionWithStructure()": "1430834845", | ||
"returnFunctionThroughLocaLVar()": "3781905051", | ||
} | ||
|
||
|
||
def test_enum_max_min(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.19") | ||
slither = Slither(Path(TEST_DATA_DIR, "selector.sol").as_posix(), solc=solc_path) | ||
|
||
contract = slither.get_contract_from_name("Test")[0] | ||
|
||
for func_name, value in func_to_results.items(): | ||
f = contract.get_function_from_signature(func_name) | ||
assignment = f.slithir_operations[0] | ||
assert ( | ||
isinstance(assignment, Assignment) | ||
and isinstance(assignment.rvalue, Constant) | ||
and assignment.rvalue.value == value | ||
) |