-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
REVM cheatcodes #841
REVM cheatcodes #841
Conversation
Side note, I highly recommend enabling the new Github PR file tree if you are part of the feature preview 😄 |
|
||
// Handle expected reverts | ||
if let Some(expected_revert) = &self.expected_revert { | ||
if data.subroutine.depth() <= expected_revert.depth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depth check is needed to replicate a specific behavior we have on master now, see this test: https://github.com/onbjerg/foundry-test/blob/7909fe8db74ca13fd86cc501fbbb53baaaec5db8/src/cheats/ExpectRevert.t.sol#L79-L84
The reason this was handled in Sputnik without recording the depth
is because we wrapped the entirety of call_inner
Ok(Bytes::new()) | ||
} | ||
HEVMCalls::Store(inner) => { | ||
// TODO: Does this increase gas usage? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still haven't figured this out, will ping Dragan unless one of you know - whenever we want to change something about an account (nonce, storage, balance, ...) we need to call load_account
first in the subroutine and it does a bunch of stuff. As far as I could tell there is no gas recording in there, it just returns some info about whether the account/slot/whatever was hot or cold, which I assume the rest of the REVM impl uses to account for gas.
Generally, though, there are some major issues with the current REVM port in terms of gas accounting, which I will address in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good - maybe @draganrakita can share some context here for anyone following the PR
Also @gakonst I considered adding
I noted both of these as drafts in the project for now Tried rebasing a couple of times but it was a huge pain on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice - so far so good! Hyped. Agree with your assessment of rebasing after we also merge the forked provider
Ok(Bytes::new()) | ||
} | ||
HEVMCalls::Store(inner) => { | ||
// TODO: Does this increase gas usage? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good - maybe @draganrakita can share some context here for anyone following the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
.or_else(|| expect::apply(self, data, &decoded)) | ||
.or_else(|| fuzz::apply(data, &decoded)) | ||
.or_else(|| ext::apply(self.ffi, &decoded)) | ||
.ok_or_else(|| "Cheatcode was unhandled. This is a bug.".to_string().encode())? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know the efficiency loss here by repeatedly trying & failing until we match? i.e. 5 match statements vs 1 match statement? I don't imagine its that bad but just curious if thats a concern here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspect that is not gonna be too expensive
094b805
to
c70272b
Compare
Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752
c70272b
to
387272e
Compare
5840f47
to
0602292
Compare
Addressed the outstanding items. I moved to static dispatch in 2dd2eb7 with a helper macro, so I'd like some extra eyes on that. I really liked the dynamic dispatch approach but all the research I could find seemed to suggest that it was much slower than static dispatch In terms of Rust tests, most of them seem to compile stuff and then run some tests based on that (even in |
Solmate, this PR:
Solmate, master:
(Prebuilt, no traces or logs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
data.subroutine.load_account(who, data.db); | ||
let balance = data.subroutine.account(inner.0).info.balance; | ||
|
||
// TODO: We should probably upstream a `set_balance` function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, should be simple
// Decode the log | ||
let (offset, len) = | ||
(try_or_return!(interpreter.stack().peek(0)), try_or_return!(interpreter.stack().peek(1))); | ||
let data = if len.is_zero() { | ||
Vec::new() | ||
} else { | ||
interpreter.memory.get_slice(as_usize_or_return!(offset), as_usize_or_return!(len)).to_vec() | ||
}; | ||
|
||
let n = n as usize; | ||
let mut topics = Vec::with_capacity(n); | ||
for i in 0..n { | ||
let mut topic = H256::zero(); | ||
try_or_return!(interpreter.stack.peek(2 + i)).to_big_endian(topic.as_bytes_mut()); | ||
topics.push(topic); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be moved to a helper function, for getting the events from an interpreter?
.or_else(|| expect::apply(self, data, &decoded)) | ||
.or_else(|| fuzz::apply(data, &decoded)) | ||
.or_else(|| ext::apply(self.ffi, &decoded)) | ||
.ok_or_else(|| "Cheatcode was unhandled. This is a bug.".to_string().encode())? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspect that is not gonna be too expensive
opcode::SSTORE => { | ||
let key = try_or_continue!(interpreter.stack().peek(0)); | ||
|
||
// An SSTORE does an SLOAD internally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exactly correct (I know I said something like that) @brockelmore how exactly should we be thinking about this for the record
cheat code?
@@ -96,9 +96,9 @@ where | |||
) -> (Return, Gas, Bytes) { | |||
if call.contract == *HARDHAT_CONSOLE_ADDRESS { | |||
let (status, reason) = self.hardhat_log(call.input.to_vec()); | |||
(status, Gas::new(0), reason) | |||
(status, Gas::new(call.gas_limit), reason) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@draganrakita it seems like Gas::new
now needs to be providing the full gas limit per call, vs gas used
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy
* Simple REVM test runner (#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (#789) * REVM cheatcodes (#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes #902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (#956) Ports #903 * REVM: FFI cheatcode updates (#955) * feat: only strip 0x in ffi output if present Ports #904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (#962) * Cross-crate testdata (#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes #959 * REVM fuzz dictionary (#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(config): add caching settings * feat: add none option * feat: add foundry data dir * feat: add storage map support * bump ethers * chore(clippy): make clippy happy * refactor: diskmap * feat: add rpc caching support * feat: add no storage cache option * refactor: rename cnfig value * docs: more storage caching docs * fix: with config builder function * refactor: address review Co-authored-by: Bjerg <[email protected]> Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Oliver Nordbjerg <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]>
* Simple REVM test runner (#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (#789) * REVM cheatcodes (#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes #902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (#956) Ports #903 * REVM: FFI cheatcode updates (#955) * feat: only strip 0x in ffi output if present Ports #904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (#962) * Cross-crate testdata (#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes #959 * REVM fuzz dictionary (#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(cli): Refactor cli/cmd over forge and cast (#1009) * ⚙️ refactor cli * 🧪 refactor casts * REVM: Support cheatcodes in `setUp` (#997) * fix: support cheatcodes in `setUp` * fix: subtract stipend without panic * chore: rename test * fix: set tx gas price to block basefee * fix: use `CALLER` for `is_success` check * chore: remove duplicate clap attribute * fix: set chain id correctly in fork mode * fix: separate evm block env from execution env * chore: clippy * refactor: block override without `block_env` fn * test: explain why git clone failed * test: disable maple-labs/loan * refactor: make addresses statics instead of lazies * docs: fix console address comment * refactor: make `DUMMY_CREATE_ADDRESS` a static * chore: minor nits * refactor: move inspector state collection * fix: report correct fuzz failure case (#1017) * fix: report correct fuzz failure case * docs: improve some docs in fuzzer * feat: add support for storage caching (#1006) * Simple REVM test runner (#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (#789) * REVM cheatcodes (#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes #752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes #902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (#956) Ports #903 * REVM: FFI cheatcode updates (#955) * feat: only strip 0x in ffi output if present Ports #904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (#962) * Cross-crate testdata (#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes #959 * REVM fuzz dictionary (#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(config): add caching settings * feat: add none option * feat: add foundry data dir * feat: add storage map support * bump ethers * chore(clippy): make clippy happy * refactor: diskmap * feat: add rpc caching support * feat: add no storage cache option * refactor: rename cnfig value * docs: more storage caching docs * fix: with config builder function * refactor: address review Co-authored-by: Bjerg <[email protected]> Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Oliver Nordbjerg <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> * fix: default to 80m gas * fix(evm): gracefully shutdown backendhandler (#1021) * feat(evm/cache): improve json file caching (#1025) * feat(cache): proper json cache * refactor: use new db types * chore(clippy): make clippy happy * bump revm * docs: some docs * refactor: extend Fork type * remove diskmap types * test: refactor tests * remove sharedmemcache * add tests * more tracing * chore(clippy): make clippy happy * release: 0.2.0 Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: abigger87 <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
* Simple REVM test runner (foundry-rs#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (foundry-rs#789) * REVM cheatcodes (foundry-rs#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes foundry-rs#752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (foundry-rs#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (foundry-rs#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (foundry-rs#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes foundry-rs#902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (foundry-rs#956) Ports foundry-rs#903 * REVM: FFI cheatcode updates (foundry-rs#955) * feat: only strip 0x in ffi output if present Ports foundry-rs#904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (foundry-rs#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (foundry-rs#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (foundry-rs#962) * Cross-crate testdata (foundry-rs#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (foundry-rs#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (foundry-rs#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes foundry-rs#959 * REVM fuzz dictionary (foundry-rs#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(cli): Refactor cli/cmd over forge and cast (foundry-rs#1009) * ⚙️ refactor cli * 🧪 refactor casts * REVM: Support cheatcodes in `setUp` (foundry-rs#997) * fix: support cheatcodes in `setUp` * fix: subtract stipend without panic * chore: rename test * fix: set tx gas price to block basefee * fix: use `CALLER` for `is_success` check * chore: remove duplicate clap attribute * fix: set chain id correctly in fork mode * fix: separate evm block env from execution env * chore: clippy * refactor: block override without `block_env` fn * test: explain why git clone failed * test: disable maple-labs/loan * refactor: make addresses statics instead of lazies * docs: fix console address comment * refactor: make `DUMMY_CREATE_ADDRESS` a static * chore: minor nits * refactor: move inspector state collection * fix: report correct fuzz failure case (foundry-rs#1017) * fix: report correct fuzz failure case * docs: improve some docs in fuzzer * feat: add support for storage caching (foundry-rs#1006) * Simple REVM test runner (foundry-rs#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (foundry-rs#789) * REVM cheatcodes (foundry-rs#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes foundry-rs#752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (foundry-rs#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (foundry-rs#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (foundry-rs#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes foundry-rs#902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (foundry-rs#956) Ports foundry-rs#903 * REVM: FFI cheatcode updates (foundry-rs#955) * feat: only strip 0x in ffi output if present Ports foundry-rs#904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (foundry-rs#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (foundry-rs#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (foundry-rs#962) * Cross-crate testdata (foundry-rs#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (foundry-rs#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (foundry-rs#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes foundry-rs#959 * REVM fuzz dictionary (foundry-rs#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(config): add caching settings * feat: add none option * feat: add foundry data dir * feat: add storage map support * bump ethers * chore(clippy): make clippy happy * refactor: diskmap * feat: add rpc caching support * feat: add no storage cache option * refactor: rename cnfig value * docs: more storage caching docs * fix: with config builder function * refactor: address review Co-authored-by: Bjerg <[email protected]> Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Oliver Nordbjerg <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> * fix: default to 80m gas * fix(evm): gracefully shutdown backendhandler (foundry-rs#1021) * feat(evm/cache): improve json file caching (foundry-rs#1025) * feat(cache): proper json cache * refactor: use new db types * chore(clippy): make clippy happy * bump revm * docs: some docs * refactor: extend Fork type * remove diskmap types * test: refactor tests * remove sharedmemcache * add tests * more tracing * chore(clippy): make clippy happy * release: 0.2.0 Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: abigger87 <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
* Simple REVM test runner (foundry-rs#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (foundry-rs#789) * REVM cheatcodes (foundry-rs#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes foundry-rs#752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (foundry-rs#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (foundry-rs#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (foundry-rs#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes foundry-rs#902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (foundry-rs#956) Ports foundry-rs#903 * REVM: FFI cheatcode updates (foundry-rs#955) * feat: only strip 0x in ffi output if present Ports foundry-rs#904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (foundry-rs#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (foundry-rs#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (foundry-rs#962) * Cross-crate testdata (foundry-rs#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (foundry-rs#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (foundry-rs#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes foundry-rs#959 * REVM fuzz dictionary (foundry-rs#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(cli): Refactor cli/cmd over forge and cast (foundry-rs#1009) * ⚙️ refactor cli * 🧪 refactor casts * REVM: Support cheatcodes in `setUp` (foundry-rs#997) * fix: support cheatcodes in `setUp` * fix: subtract stipend without panic * chore: rename test * fix: set tx gas price to block basefee * fix: use `CALLER` for `is_success` check * chore: remove duplicate clap attribute * fix: set chain id correctly in fork mode * fix: separate evm block env from execution env * chore: clippy * refactor: block override without `block_env` fn * test: explain why git clone failed * test: disable maple-labs/loan * refactor: make addresses statics instead of lazies * docs: fix console address comment * refactor: make `DUMMY_CREATE_ADDRESS` a static * chore: minor nits * refactor: move inspector state collection * fix: report correct fuzz failure case (foundry-rs#1017) * fix: report correct fuzz failure case * docs: improve some docs in fuzzer * feat: add support for storage caching (foundry-rs#1006) * Simple REVM test runner (foundry-rs#788) * refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm chore: renuke `evm-adapters` * REVM fuzzer (foundry-rs#789) * REVM cheatcodes (foundry-rs#841) * feat: add `InspectorStack` Adds `InspectorStack`, an inspector that calls a stack of other inspectors sequentially. Closes foundry-rs#752 * feat: port cheatcodes to revm * feat: port `expectCall` cheatcode * feat: extract labels from cheatcode inspector * feat: port `expectEmit` cheatcode * refactor: move log decoding into `forge` crate * chore: remove unused evm patch * test: re-enable debug logs test * fix: record reads on `SSTORE` ops * refactor: rename `record` to `start_record` * docs: clarify why `DUMMY_CALL_OUTPUT` is 320 bytes * fix: handle `expectRevert` with no return data * build: bump revm * chore: remove outdated todo * refactor: use static dispatch in `InspectorStack` * build: use k256 * fix: make gas usage not so crazy * feat(revm): add forking mode (foundry-rs#835) * feat: copy-paste old forking provider * feat(fork): convert to REVM traits * chore: remove unnecessary codehash handler * feat: impl Database for shared backend * chore: fix tests * chore: fmt * fix(fork): correctly convert H256 <> U256 for storage * refactor: separate storage from accounts in cache * feat(fork): fetch block hashes * chore: remove unused DB parameter * test: add test for block hashes * feat: add forked backend to executor builder * feat(cli): set fork url on the executor * refactor: move shared backend to separate file * feat(fork): add fn for instantiating forked env * feat(cli): allow pinning block number * fix(fork): install missing listeners * feat(fork): instantiate environment with forked state * fix: use a CALLER address with maxed out balance for calls this is required because in forking mode otherwise the account wont have enough balance to transact * chore: fmt Co-authored-by: Oliver Nordbjerg <[email protected]> * chore: fmt * REVM tracing and gas reports (foundry-rs#867) * feat: very simple traces * feat: creation traces * feat: setup and revert traces * fix: fix lib addresses * refactor: simplify tracer inspector * fix: fill traces in correct order * build: bump revm * fix: get code for newly created contracts * refactor: unify log extraction logic * feat: trace logs * refactor: unify labels and names * refactor: return string from trace Instead of passing in an empty string we then pass around inside the trace display logic, we just return strings where appropriate. * refactor: remove identified contracts * refactor: remove unused vars * refactor: simplify `construct_func_call` * refactor: name special characters in traces * refactor: rework all display logic * feat: first pass identify/decode for traces * refactor: move tracing to own module * refactor: simplify `test` * feat: traces for fuzz tests * fix: make fuzz revert reasons less verbose * feat: port gas reports * refactor: small readability nits * feat: run fuzz *and* unit tests in parallel Previously we would run each test contract in parallel, but within each `ContractRunner` we would run unit tests first (in parallel) and then fuzz tests (in parallel). * refactor: move colouring logic to its own function * fix: test contract identification We now include three kinds of traces that are used for identification of contracts: - Deployment traces: these are the initial deployments of the test contract and libraries - Setup traces: these are traces of calls to the `setUp` function - Execution traces: these are the traces of calls to the test contract itself * fix: mark setup trace as a setup trace * fix: get correct nonce in tracer * fix: log extraction outside of current memory * chore: clean up complex types * chore: remove outdated comment * fix: make tests compile * fix: add missing test filter function * feat: display full address in traces * fix: color "new" keyword in traces * fix: filter out `console.log` calls from traces * chore: remove unnecessary comment * feat: add gas cost to creation traces * fix: properly decode outputs * refactor: destructure `TestSetup` in test funcs * fix: ignore address for func output decoding * fix: fix expect emit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> * REVM debugger (foundry-rs#920) * feat: port debugger data structures * feat: initial port of `ui` crate * chore: add `ui` crate as a workspace member * refactor: adjust ui contract identification * feat: grey out 0 values in debugger memory Closes foundry-rs#902 * style: minor debugger ui beautification * feat: better stack display in debugger ui * feat: gray out zero bytes in stack view * feat: debugger inspector * refactor: minor code cleanup * feat: port `forge run` * fix: temp fix for failing `DsTest.sol` include * chore: fix lints * test: adjust `forge run` tests * refactor: use simple bool for revert checks * chore: remove unused display impl * chore: remove unused comment * fix: display number of stack items in ui * docs: prettify cli help for some commands * feat: `forge test --debug` * refactor: `get_create_address` util * refactor: `InspectorData` * docs: more detailed err for `forge test --debug` * feat: support hardhat artifacts in `vm.getCode` (foundry-rs#956) Ports foundry-rs#903 * REVM: FFI cheatcode updates (foundry-rs#955) * feat: only strip 0x in ffi output if present Ports foundry-rs#904 * Update forge/src/executor/inspector/cheatcodes/ext.rs Co-authored-by: Georgios Konstantopoulos <[email protected]> * REVM gas fixes (foundry-rs#950) * feat: account for gas refunds * refactor: merge `call_raw` and committing variant * fix: actually use refund quotient * feat: strip tx gas stipend * fix: fix reported gas usage in debugger * build: use upstream revm * test: adjust `forge run` gas values in tests * chore: remove unused copy * chore: add note on push maths * feat: make stipend reduction optional * fix: remove tx stipend in `forge run` * REVM: Pull EVM executor into own crate (foundry-rs#961) * refactor: move evm executor to own crate * refactor: `evm::executor::fuzz` -> `evm::fuzz` * refactor: `evm::debugger` -> `evm::debug` * test: fix multi runner test * feat: better ux for expect revert without reason (foundry-rs#962) * Cross-crate testdata (foundry-rs#965) * feat: cross-crate shared testdata * refactor: move `foundry-utils` to common tests * fix: fix getcode test * fix: compile once in tests * fix: fix prank cheatcode (foundry-rs#973) Correctly apply `msg.sender` prank to both transfers and calls. * fix: prank depth math * test: fix lib linking test * refactor: use revm `log` hook (foundry-rs#984) * refactor: use revm `log` hook * chore: bump revm Co-authored-by: Georgios Konstantopoulos <[email protected]> * test: add lil-web3 to integration tests * test: add maple labs loans to integration tests Closes foundry-rs#959 * REVM fuzz dictionary (foundry-rs#985) * feat: fuzz dictionary Co-authored-by: brockelmore <[email protected]> * fix: handle malformed bytecode * fix: limit search for push bytes * feat: collect fuzz state from logs * feat: build initial fuzz state from db * perf: use `Index` instead of `Selector` Co-authored-by: brockelmore <[email protected]> * feat(config): add caching settings * feat: add none option * feat: add foundry data dir * feat: add storage map support * bump ethers * chore(clippy): make clippy happy * refactor: diskmap * feat: add rpc caching support * feat: add no storage cache option * refactor: rename cnfig value * docs: more storage caching docs * fix: with config builder function * refactor: address review Co-authored-by: Bjerg <[email protected]> Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Oliver Nordbjerg <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> * fix: default to 80m gas * fix(evm): gracefully shutdown backendhandler (foundry-rs#1021) * feat(evm/cache): improve json file caching (foundry-rs#1025) * feat(cache): proper json cache * refactor: use new db types * chore(clippy): make clippy happy * bump revm * docs: some docs * refactor: extend Fork type * remove diskmap types * test: refactor tests * remove sharedmemcache * add tests * more tracing * chore(clippy): make clippy happy * release: 0.2.0 Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: brockelmore <[email protected]> Co-authored-by: abigger87 <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
In draft while I address the remaining items
Ports all the cheatcodes to REVM in a cheatcode-specific inspector. The cheatcodes have been split up into different modules so we don't end up with a huge file like we had with Sputnik, because we can.
This PR also incldues an update to ethers, which we needed to bump
primitive-types
(needed byrevm
), but it also brought in a lot of other changes. I tried to resolve the breaking changes as best I could, but I'm sure it was changed differently on master.Also adds
InspectorStack
which is an inspector that calls a bunch of underlying inspectors.Using my branch of revm until bluealloy/revm#69 is merged.
Remaining items:
expectEmit
expectCall
roll
InspectorStack
using an enumSome questions:
In our(we're now recording a read on every write)record
/accesses
test we assert that 2 reads have taken place because "SSTORE does an SLOAD", but this is not reproduced in REVM. I couldn't find any docs that suggest this is supposed to be the case? If it is, or if we want to replicate the behavior, the change is small, but I'd like some thoughts on itThe(seems to work after rebase)getCode
cheatcode sort of works, but when I added more files to https://github.com/onbjerg/foundry-test the test started failing. As far as I can see, the bytecode does match except for some Solidity metadata at the end. I cannot figure out if this is an error on my part, or if it is because ethers was updated and that somehow changed the metadata thatsolc
appends at the end of the bytecode?Closes #752
Closes #755
Closes #756