From 705994ef6569431f13cb8470935de77a2c71598b Mon Sep 17 00:00:00 2001 From: karmacoma Date: Fri, 21 Jul 2023 16:25:36 -0700 Subject: [PATCH] fix: honor pranks during contract creation Fixes https://github.com/a16z/halmos/issues/116 --- src/halmos/sevm.py | 2 +- tests/expected/all.json | 8 ++++++++ tests/test/Prank.t.sol | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/halmos/sevm.py b/src/halmos/sevm.py index f44d80e7..2e733e75 100644 --- a/src/halmos/sevm.py +++ b/src/halmos/sevm.py @@ -1752,7 +1752,7 @@ def create( # calldata=[], callvalue=value, - caller=ex.this, + caller=caller, this=new_addr, # pc=0, diff --git a/tests/expected/all.json b/tests/expected/all.json index f9d95c64..e80c94f9 100644 --- a/tests/expected/all.json +++ b/tests/expected/all.json @@ -689,6 +689,14 @@ "time": null, "num_bounded_loops": null }, + { + "name": "checkPrankConstructor(address)", + "exitcode": 0, + "num_models": 0, + "num_paths": null, + "time": null, + "num_bounded_loops": null + }, { "name": "checkPrankExternal(address)", "exitcode": 0, diff --git a/tests/test/Prank.t.sol b/tests/test/Prank.t.sol index 8fe8f1b9..b086ac8e 100644 --- a/tests/test/Prank.t.sol +++ b/tests/test/Prank.t.sol @@ -17,6 +17,14 @@ contract Target { } } +contract ConstructorRecorder { + address public caller; + + constructor() { + caller = msg.sender; + } +} + contract Ext is Test { function prank(address user) public { vm.prank(user); @@ -131,4 +139,17 @@ contract PrankTest is Test { target.recordCaller(); assert(target.caller() == address(this)); } + + function checkPrankConstructor(address user) public { + vm.prank(user); + ConstructorRecorder recorder = new ConstructorRecorder(); + assert(recorder.caller() == user); + } + + // TODO: uncomment when we add CREATE2 support + // function checkPrankConstructorCreate2(address user, bytes32 salt) public { + // vm.prank(user); + // ConstructorRecorder recorder = new ConstructorRecorder{salt:salt}(); + // assert(recorder.caller() == user); + // } }