Skip to content

Commit

Permalink
fix: honor pranks during contract creation (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Daejun Park <daejunpark@gmail.com>
  • Loading branch information
karmacoma-eth and daejunpark committed Jul 22, 2023
1 parent 50ebba8 commit d7e3a4e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ def create(
#
calldata=[],
callvalue=value,
caller=ex.this,
caller=caller,
this=new_addr,
#
pc=0,
Expand Down
8 changes: 8 additions & 0 deletions tests/expected/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions tests/test/Prank.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
// }
}

0 comments on commit d7e3a4e

Please sign in to comment.