Comments (2)
Thanks for the bug report!
So the counterexamples produced by your input contain a specific storage prestate, if you just try to execute them without first setting up the correct storage prestate, you won't trigger a counterexample.
Setting up a storage prestate is currently pretty clunky (should be a lot easier once #227 is merged), but I could do it as follows using your testing harness:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import {Test} from "forge-std/Test.sol";
interface IToken {
function mint(address, uint256) external;
function transfer(address, uint256) external;
function balanceOf(address) external view returns (uint256);
}
/// @author philogy <https://github.com/philogy>
contract METH_WETHVerification is Test {
function testMain(address _addr1, address _addr2, uint256 _amount1, uint256 _amount2) public {
require(_amount1 >= _amount2);
IToken token;
bytes memory tokenCode =
hex"606b8060093d393df3583560e01c8063a9059cbb1461002a57806370a0823114610047576340c10f19146100515760006000fd5b335460243581811161005e57600435805482909303335591019055005b600435545952593df35b6004358054602435019055005b63f4d678b83d526004601cfd";
assembly {
token := create(0, add(tokenCode, 0x20), mload(tokenCode))
}
emit log_named_address("this: ", address(this));
// -- prepare storage prestate --
vm.store(address(token), bytes32(uint(0x0)), 0xc41f9400030ace5d0babe3b93bd6041fbbd4060900ffe7ff1b78d6f4fdd74149);
vm.store(address(token), bytes32(uint(0x4000000000)), 0xb20293c000018103400000000000000000000000000000000000000000000004);
token.mint(_addr1, _amount1);
vm.prank(_addr1);
token.transfer(_addr2, _amount2);
uint256 bal1 = token.balanceOf(_addr1);
uint256 bal2 = token.balanceOf(_addr2);
_assertNoOverflow(bal1, bal2);
assert(bal1 + bal2 == _amount1);
}
function _assertNoOverflow(uint256 x, uint256 y) internal {
assert(type(uint256).max - x >= y);
}
// -- verify that the hevm generated cex is valid
function testCex() public {
(bool res, bytes memory data) = address(this).call(hex"7e6f0d300000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000098984142001000b000042886cd1cfbe04523f9ffff02000200072c1f4308caec1aa0dbbe90200000000000000000000000000000000000000000000000000000");
assertFalse(res);
assertEq0(abi.encodeWithSignature("Panic(uint256)", 0x1), data);
}
}
Note the calls to vm.prank
that I inserted into testMain
. I had to modify the address given in the hevm counterexample, I believe that this is due to differences in the address that METH_WETHVerification
is instantiated at between foundry and hevm. I couldn't find the right set of cli flags to either to get this to match.
If you want to get a counterexample that doesn't require setting up a specific storage prestate, you can run hevm with the flag --storage-model InitialS
, and it will assume that storage is empty at the start of execution (as opposed to the default where storage is held to be completely symbolic at the start of execution). This gives me back valid counterexamples that depend on calldata only.
None of the generated counterexamples trigger the second assert
(regarding the sum of the two balances), if you have an example of a valid input that does trigger this assertion that is not discovered by hevm I would be very happy to know about it.
from hevm.
Thanks for the explanation, didn't know about / understand storage presets. --storage-model InitialS
works like a charm, surprised it's not the default, although it makes sense that the storage would be symbolic as that's required to find certain vulnerabilities.
Not sure what you mean concerning the issue/difference between the forge and hevm addresses? Do you mean the address that's shown in the counterexample?
from hevm.
Related Issues (20)
- bug: "No discrepancies found" for simple test-case for `hevm symbolic` HOT 4
- bug: `hevm equivalence` does not use provided function signature HOT 1
- bug: `hevm equivalence` falsely reports "Not equivalent" HOT 4
- feat: allow passing in the source file as a parameter HOT 2
- Incorrect simplification
- `hevm symbolic` reports an incorrect counterexample/false negative HOT 1
- Investigate soundness of symbolic execution against remote state
- Decompose Storage HOT 1
- [Bug-Candidate]: Prank uses wrong account when sending ether to payable function HOT 1
- Change in pretty printing breaks dapptools integration tests
- Bug: `prank` underflows balance if sending too much ETH in `msg.value` HOT 2
- Incorrect Return Value Compared to Geth HOT 3
- feat: document/support Foundry-compatible `--match` options
- hevm does not support deal cheatcode
- hevm does not work when solidity file produces non-expected json format HOT 2
- CI Failing on Windows HOT 2
- Hevm exec (and others) errors when there is no `/out/` directory HOT 1
- Cheatcodes are missing from traces
- Function calls from MAINNET Addresses fail HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hevm.