-
Notifications
You must be signed in to change notification settings - Fork 12
Fixed expectRevert being applied to calls to cheatcodes #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bc81b81
f65dbbb
262c27c
6ade197
9f5601b
5fe872b
09c01aa
91bd109
b9ee616
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -559,18 +559,6 @@ function expectRevert(bytes4 msg) external; | |
function expectRevert(bytes calldata msg) external; | ||
``` | ||
|
||
All cheat code calls which take place while `expectRevert` is active are ignored. | ||
|
||
```k | ||
rule [cheatcode.call.ignoreCalls]: | ||
<k> #cheatcode_call _ _ => .K ... </k> | ||
<expectedRevert> | ||
<isRevertExpected> true </isRevertExpected> | ||
... | ||
</expectedRevert> | ||
[priority(35)] | ||
``` | ||
|
||
We use the `#next[OP]` to identify OpCodes that can revert and insert a `#checkRevert` production used to examine the end of each call/create in KEVM. | ||
The check will be inserted only if the current depth is the same as the depth at which the `expectRevert` cheat code was used. | ||
WThe `#checkRevert` will be used to compare the status code of the execution and the output of the call against the expect reason provided. | ||
|
@@ -579,23 +567,37 @@ WThe `#checkRevert` will be used to compare the status code of the execution and | |
rule [foundry.set.expectrevert.1]: | ||
<k> #next [ _OP:CallOp ] ~> (.K => #checkRevert ~> #updateRevertOutput RETSTART RETWIDTH) ~> #execute ... </k> | ||
<callDepth> CD </callDepth> | ||
<wordStack> _ : _ : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack> | ||
<wordStack> _ : ACCTTO : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack> | ||
<expectedRevert> | ||
<isRevertExpected> true </isRevertExpected> | ||
<expectedDepth> CD </expectedDepth> | ||
... | ||
</expectedRevert> | ||
requires ACCTTO =/=Int #address(FoundryCheat) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this check also have to be added to the rule There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it's possible/likely to delegate a call to the cheatcode address? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into this and wrote two tests, one for The assertion at the end fails for function testDelegatecallCheatcodeReverts() external {
(bool success, ) = VM_ADDRESS.delegatecall(
abi.encodeWithSignature("roll(uint256)", 1337)
);
assertTrue(success);
assertEq(block.number, 1337);
}
function testStaticcallcallCheatcode() external view {
(bool success, ) = VM_ADDRESS.staticcall(
abi.encodeWithSignature("roll(uint256)", 1337)
);
assertTrue(success);
assertEq(block.number, 1337);
} So maybe it's worth adding the rule to cover @palinatolmach what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it sounds good! Let's add a rule for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do it! function testIncrementAsNotOwner_2() public {
vm.expectRevert(Unauthorized.selector);
(bool success, ) = VM_ADDRESS.delegatecall(
abi.encodeWithSignature("roll(uint256)", 1337)
);
upOnly.increment();
} And this test is passing when it shouldn't, since the function does not revert as expected. On the other hand, the following test fails: function testIncrementAsNotOwner_3() public {
vm.expectRevert(Unauthorized.selector);
(bool success, ) = VM_ADDRESS.delegatecall(
abi.encodeWithSignature("roll(uint256)", 1337)
);
vm.prank(address(0));
upOnly.increment();
} It seems that |
||
[priority(32)] | ||
|
||
rule [foundry.set.expectrevert.2]: | ||
<k> #next [ _OP:CallSixOp ] ~> (.K => #checkRevert ~> #updateRevertOutput RETSTART RETWIDTH) ~> #execute ... </k> | ||
<callDepth> CD </callDepth> | ||
<wordStack> _ : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack> | ||
<wordStack> _ : ACCTTO : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack> | ||
<expectedRevert> | ||
<isRevertExpected> true </isRevertExpected> | ||
<expectedDepth> CD </expectedDepth> | ||
... | ||
</expectedRevert> | ||
requires ACCTTO =/=Int #address(FoundryCheat) | ||
[priority(32)] | ||
|
||
rule [foundry.clear.expectrevert]: | ||
<k> #next [ DELEGATECALL ] ~> (.K => #clearExpectRevert) ~> #execute ... </k> | ||
<callDepth> CD </callDepth> | ||
<wordStack> _ : ACCTTO : _ : _ : _ : _ : _ : _WS </wordStack> | ||
<expectedRevert> | ||
<isRevertExpected> true </isRevertExpected> | ||
<expectedDepth> CD </expectedDepth> | ||
... | ||
</expectedRevert> | ||
requires ACCTTO ==Int #address(FoundryCheat) | ||
[priority(32)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anvacaru and @palinatolmach, I added this rule, and now Kontrol mimics the same behavior as Foundry for the |
||
|
||
rule [foundry.set.expectrevert.3]: | ||
|
Uh oh!
There was an error while loading. Please reload this page.