Skip to content
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

feat(cheatcode): startDebugTraceRecording and stopDebugTraceRecording for ERC4337 testing #8571

Merged
merged 25 commits into from
Oct 9, 2024

Conversation

boolafish
Copy link
Contributor

@boolafish boolafish commented Jul 31, 2024

Motivation

ERC4337 (account abstraction) has several rules/restrictions on what the UserOperation can do (see: ERC7562). Specifically, it has rules on what opcodes it can access and limitations on certain storage access as well.

These limitations are quite implicit and might not be easily identified during contract development. We want to provide an easier way for developers and security researchers to check/test if the rules are being followed. We aim to enable these checks by running forge test after writing specific tests for that purpose.

Solution

To support this, we need new cheatcodes that can record the debug traces during EVM execution so we can know the opcodes and storages being accessed. With this cheatcode, we will be able to have a helper contract that checks whether the test executions comply with ERC4337 restrictions.

In this solution, we added two cheatcodes:

  1. startDebugTraceRecording: This starts the recording of the debug trace data.
  2. stopAndReturnDebugTraceRecording: This stops and returns the recording of the debug trace data.

Test

@boolafish boolafish marked this pull request as draft July 31, 2024 05:53
@boolafish boolafish force-pushed the erc4337-tool-main branch 2 times, most recently from 50d4c0f to d81495d Compare July 31, 2024 07:21
current_opcode, interpreter.stack(),
)
);
let mem_inputs = get_memory_input_for_opcode(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right path, we already have a tracer and we should reuse that through CheatcodeExecutor

this can likely just be:

  • start: enables tracer at opcode tracing level if not already enabled, saves the current trace index
  • stop: takes the range of traces from saved start to current and abi encodes it

cc @klkvr

Copy link
Member

@klkvr klkvr Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I think this could be possible by extending CheatcodesExecutor with something like this:

fn start_steps_recording(&mut self, cheats: &mut Cheatcodes);
fn get_recorded_step(&mut self, cheats: &mut Cheatcodes) -> Vec<CallTraceStep>;

where CallTraceStep is coming from revm-inspectors and recorded by altering config of InspectorStack.inner.tracer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh, so if I get this comment right, the idea here is to use self.tracer instead where it already have all the tracing needed. And it seems like by self.tracer.traces().into_nodes() I can get the Vec<CallTraceNode>, where it has the CallTrace that I need.

Am i getting this right?

also, I can assume the nodes are append only, so I can just rely on the idx field of the CallTraceNode to determine the range according to your description above, right?

Copy link
Member

@klkvr klkvr Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, once you alter its config it would start recording steps, and you can just collect them by going through nodes

we'd also need some flattening logic here similar to (but likely simpler as we don't need to collect DebugNodes, just a list of steps)

pub fn flatten_call_trace(arena: CallTraceArena, out: &mut Vec<DebugNode>) {
as I believe we want to allow recording of trace steps for subcalls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to consult a bit, got one problem related to this approach after trying it:

For some background on my local env, I have a repository with forge tests that uses this new cheatcodes and I build the forge locally to use on the test repository. When I try the tracer approach, It panics with the error message: more traces were filled than started. I can, however, temporary fix this by turn on the tracing from start in the following function in crates/evm/evm/src/inspectors/stack.rs to fix this:

pub fn tracing(&mut self, mode: TraceMode) {
        if let Some(config) = mode.into_config() {
            *self.tracer.get_or_insert_with(Default::default).config_mut() = config;
        } else {
            // self.tracer = None;  <-- comment out this line
           // Chage: ensures that the tracing will occur on start.
            self.tracer.get_or_insert_with(Default::default);
        }
    }

A sample implementation that updates the config is in the same file:

impl CheatcodesExecutor for InspectorStackInner {
   fn get_inspector<'a, DB: DatabaseExt>(
       &'a mut self,
       cheats: &'a mut Cheatcodes,
   ) -> impl InspectorExt<DB> + 'a {
       InspectorStackRefMut { cheatcodes: Some(cheats), inner: self }
   }

  // Newly added function here!
   fn start_steps_recording(&mut self, cheats: &mut Cheatcodes) {
       // Ensure the tracer exists and configure it
       let tracer = self.tracer.get_or_insert_with(Default::default);

       tracer.update_config(|_config| TracingInspectorConfig::all());
   }

   .....skip
   
}

Wonder if you know any idea/directions to solve the "more traces were filled than started" issue? The current one(turning on the tracer) does not really seems like a great idea....

Copy link
Contributor Author

@boolafish boolafish Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still having the same issue. Currently, I set the trace to use "none()" configuration so make it a dummy one on start instead of having none in the tracer field on start to solve the issue.

@zerosnacks
Copy link
Member

zerosnacks commented Jul 31, 2024

This sounds related to #6704, tagging it here

Would like to make sure this PR covers the design goals of #6704 as the proposed cheatcode name slightly differs

@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 31, 2024
@zerosnacks zerosnacks added A-cheatcodes Area: cheatcodes T-feature Type: feature labels Jul 31, 2024
@boolafish boolafish changed the title feat(forge): new cheatcode startDebugTraceRecording and stopAndReturnDebugTraceRecording feat(cheatcode): startDebugTraceRecording and stopAndReturnDebugTraceRecording for ERC4337 testing Aug 1, 2024
@boolafish boolafish marked this pull request as ready for review August 23, 2024 03:15
@boolafish boolafish changed the title feat(cheatcode): startDebugTraceRecording and stopAndReturnDebugTraceRecording for ERC4337 testing feat(cheatcode): startDebugTraceRecording, stopDebugTraceRecording, and getDebugTraceByIndex for ERC4337 testing Aug 23, 2024
@boolafish
Copy link
Contributor Author

@DaniPopes @klkvr just tagging as I am not sure if re-open a PR from WIP will trigger notifications or not. This should be ready and has accommodated the previous review comments. Sorry for taken so long due to OOO and fixing some OOM bugs on my side.

@boolafish boolafish force-pushed the erc4337-tool-main branch 2 times, most recently from 9ff4d0e to 03bacff Compare August 24, 2024 03:47
@boolafish
Copy link
Contributor Author

Sorry for the failed CI, have fixed those and tested in my own repo workflow: https://github.com/boolafish/foundry/actions/runs/10535493491?pr=1

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move logic for start_steps_recording and stop_and_get_recorded_step from CheatcodesExecutor to cheatcode implementations

We've just merged #8696 which added getter for tracing_inspector to CheatcodesExecutor and example of how we can track step ranges.

regarding more traces were filled than started I think this occurs because in cases when tracing is disabled and vm.startDebugTraceRecording enables tracer, tracer will receive a call_end invocation for that cheatcode call which will not have a node to fill. we can try working around this by creating a fake trace node in this situation. Another approach could be to always enable tracer by default (as it's done now), though this might be expensive in some cases. wdyt @DaniPopes ?

crates/cheatcodes/src/evm/opcode_utils.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/inspectors/stack.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/inspectors/stack.rs Outdated Show resolved Hide resolved
@boolafish boolafish force-pushed the erc4337-tool-main branch 2 times, most recently from cfac4e3 to bde1de2 Compare August 27, 2024 03:03
@boolafish
Copy link
Contributor Author

@klkvr thanks for the review, should have fixed all comments aside from the one re: more traces were filled than started.

we can try working around this by creating a fake trace node in this situation

Might need a bit more elaboration on this. Not exactly sure how to do this on my end. But will also wait to see if that is the preferred approach I guess.

A node can have steps that calls to another node, so the child node's step might occur before
some steps of its parent node. This introduce the flatten_call_trace function back using
recursive call to ensure the steps are in correct order despite not in the same order of the
node index.

see PR comment: foundry-rs#8571 (comment)
Fixe the conflict in evm.rs. Use the new `apply_full` function interface for the cheatcodes.
@boolafish
Copy link
Contributor Author

thanks @klkvr for a fast turn-around!!

Have fixed the comment regarding node-step issue. Please take a look when available again 🙏
Can @DaniPopes also help take a look as well for the requested change part 🙏

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

if summing up this adds steps tracing through cheatodes, only supported when tracing is enabled via increased verbosity or other flags

Possible follow-ups:

  • look into ways to enable tracer on demand, even if inspector was not configured with it initially. this will likely require some helpers on revm-inspectors side
  • consider extending returned DebugStep struct with more context (returdata, read storage, etc) in a way that does not increase memory usage too much

ptal @DaniPopes @zerosnacks @grandizzy

Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR, lgtm - pending other reviewers

@boolafish boolafish changed the title feat(cheatcode): startDebugTraceRecording, stopDebugTraceRecording, and getDebugTraceByIndex for ERC4337 testing feat(cheatcode): startDebugTraceRecording and stopDebugTraceRecording for ERC4337 testing Oct 8, 2024
@boolafish
Copy link
Contributor Author

boolafish commented Oct 9, 2024

slight nudge for the review 🙏 (cc @DaniPopes @grandizzy which were tagged previously by @/klkvr )

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, have only couple of nits, optionally to be applied. thank you

crates/cheatcodes/src/evm/record_debug_step.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/evm/record_debug_step.rs Outdated Show resolved Hide resolved
@DaniPopes DaniPopes removed the request for review from Evalir October 9, 2024 13:44
@zerosnacks
Copy link
Member

Thanks @boolafish! Merging

@zerosnacks zerosnacks merged commit 0c659f0 into foundry-rs:master Oct 9, 2024
22 checks passed
@boolafish
Copy link
Contributor Author

Thanks all!!

boolafish added a commit to boolafish/forge-std that referenced this pull request Oct 10, 2024
Run script/vm.py to update the cheatcode.
Mainly to enable for this new cheatcodes: foundry-rs/foundry#8571
elfedy added a commit to matter-labs/foundry-zksync that referenced this pull request Nov 1, 2024
* chore(cheatcodes): reduce generated code (#8912)

* feat(cheatcodes): display warnings for deprecated cheatcodes (#8883)

* feat(cheatcode): disaply message for cheatcodes marked as deprecated

* Deprecated cheatcodes as hashset, displayed once per test suite

* Add deprecated cheatcode replacement attr

* Add support for fuzz and invariant tests

* Changes after review: add Deprecated(replacement)

* Update crates/cheatcodes/src/inspector.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* chore: touchups

* Fix CI

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* refactor: rewrite the console.log format string parser (#8913)

* refactor: rewrite the console.log format string parser

* chore: clippy

* feat: implement `parseTomlType` cheats (#8911)

* feat: implement `parseTomlType` cheats

* chore: `forge fmt`

* revert: use json naming to indicate to users that they are operating on json data

* chore: nit

* chore: nit

* Log address in checksum format (#8915)

Co-authored-by: jenpaff <jepaff0@gmail.com>

* improve description of `--flamechart` and `--flamegraph` (#8917)

improve description of --flamechart and --flamegraph, explaining the difference

* fix(forge): improve `test --debug` doc (#8918)

improve doc

* chore: use dyn InspectorExt in Backend (#8919)

* chore(evm): use dyn DatabaseExt in inspect (#8921)

chore(evm): use dyn DatabaseExt in inspect

* chore(anvil): use dyn DatabaseRef instead of generics (#8920)

* chore(doc): remove auto_impl (#8922)

* chore(docs): Update testcode path (#8923)

Update testcode path

* chore(deps): weekly `cargo update` (#8927)

* chore: don't display filter used if empty (#8929)

* chore: use serde_json::from_str when possible (#8925)

chore: use serde_json::from_str when possible

* chore: deprecate --debug regex argument (#8930)

* chore: deprecate --debug regex argument

* fix: enable full internal decoding if exactly one test matched

* chore: fixes for --all-features tests (#8937)

* chore: more fixes for --all-features tests (#8946)

* fix(`anvil`): handle OP deposit txs in `TypedTransaction` and `PoolTransaction` conversion (#8942)

* fix(`anvil`): handle OP deposit tx in TypeTransaction conversion.

* nits

* clippy

* test

Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>

* nits

---------

Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>

* feat(cast): add contract creation bytecodes to traces (#8941)

* fix: #8759, default (low) gas limit set even when disabled, use custom gas_limit on forks (#8933)

* fix: #8759, do not set low gas price on block if disabled, use custom gas price in forks

* test(fix): default block gas limit for large mine test

* fix fmt

* fix: optional gas_limit in as_json

* fix: use option not serde_json::Value::Null

* tests: base tests + config tests

* fix: nits

* fix: comment

* chore: add @grandizzy @yash-atreya @zerosnacks as codeowners (#8951)

add @grandizzy @yash-atreya @zerosnacks as codeowners too

* chore(deps): update revm-inspector version in manifest (#8950)

* chore: add Makefile and `codespell` (#8948)

* add makefile + codespell

* update makefile

* fix typos found by codespell

* add codespell CI task

* fix outdated spec

* ignore testdata

* switch default profile to dev, add strat to ignored words list

* chore: add comments for alloy-core patches (#8955)

* fix(coverage): better find of loc start byte position (#8958)

* chore: improve fuzz scrape bytecode test (#8953)

* chore: improve fuzz scrape bytecode test

* Remove duped comments, Trigger CI

* chore: fire shutdown signal on anvil node handle drop (#8947)

* chore: add anvil NodeHandle.fire_shutdown_signal

* Remove DAPP remappings from env vars from cli tests.

* Unwrap fire shutdown

* Fix clippy

* track_caller on fire shutdown

* fire shutdown signal on drop

* feat(`cheatcodes`): `getArtifactPathByCode` and `getArtifactPathByDeployedCode` (#8938)

* feat(`cheatcodes`): vm.getArtifactPath

* cargo cheats

* nit

* nit

* fix

* test: vm.getArtifactPath

* feat: vm.getArtifactPath(creationCode)

* cheats

* nit

* change seed

* rm vm.getArtifactPath(contractName)

* fmt

* nit

* fix

* nit

* rename

* nit

* fix

---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>

* chore: fix base gas limit test and clippy (#8961)

* feat(cheatcodes): random* cheatcodes to aid in symbolic testing (#8882)

* feat(cheatcodes): additional random cheatcodes to aid in symbolic testing

* Use arbitraryUint/address in tests

* Test changes after review

* Fix test

* Add deprecated replacements

* Changes after review:
- add fn rng back
- make sure cheats for uint/int/bytes doesn't panic + added tests

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* Cargo cheats

* Fix test

* Rename Arbitrary -> Random

* Review changes: simplify randomBytes and bool

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* feat: use multi-architecture images in Dockerfile to support apple si… (#8964)

feat: use multi-architecture images in Dockerfile to support apple silicon

* fix: enable `revm/blst` (#8965)

* fix: enable revm/blst

* fix

* fix

* test: redact forge version (#8967)

* chore(tests): bump forge-std version (#8970)

chore: bump forge-std version used for tests

Co-authored-by: DaniPopes <DaniPopes@users.noreply.github.com>

* chore(traces): remove unreachable decoding of expectRevert (#8969)

* chore(traces): remove unreachable decoding of expectRevert

* chore: clippy

* fix(`invariant`): replay should not fail for magic assume (#8966)

* fix(invariant): shrink should not fail for magic assume

* Test & Code Comment

* chore: bump max allowed verification delay (#8974)

* chore: rename `snapshot` to be more specific (#8945)

* update internal naming

* further internals

* deprecate cheats

* update Solidity tests and add dedicated test for testing deprecated cheatcodes

* clarify gas snapshots

* fix build

* final fixes

* fix build

* fix repro 6355 rename

* fix: 4844 fee fixes (#8963)

* fix: use zero blob fee for estimate

* add basic test

* fix gas_price

* support EIP-4844 with with_max_fee_per_blob_gas None

* this should run succesfully once Alloy counterpart has been merged

* undo max_fee_per_blob_gas != 0 check, not necessary anymore

* clean up

* fix setup bug from Matt

* add test with signer, currently failing on Result::unwrap()` on an `Err` value: ErrorResp(ErrorPayload { code: -32003, message: "Block `blob_versioned_hashes` is not supported before the Cancun hardfork", data: None })

* able to reproduce

* apply hotfix by Matt

* remove debugs

* use or_else, only need to do this if the blob_versioned hashes are non zero

* move blob_hashes out

---------

Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* chore(deps): weekly `cargo update` (#8981)

* chore(deps): weekly `cargo update`

     Locking 41 packages to latest compatible versions
    Updating alloy-chains v0.1.33 -> v0.1.34
    Updating alloy-dyn-abi v0.8.3 -> v0.8.5
    Updating alloy-json-abi v0.8.3 -> v0.8.5
    Updating alloy-primitives v0.8.3 -> v0.8.5
    Updating alloy-sol-macro v0.8.3 -> v0.8.5
    Updating alloy-sol-macro-expander v0.8.3 -> v0.8.5
    Updating alloy-sol-macro-input v0.8.3 -> v0.8.5
    Updating alloy-sol-type-parser v0.8.3 -> v0.8.5
    Updating alloy-sol-types v0.8.3 -> v0.8.5
    Updating async-trait v0.1.82 -> v0.1.83
    Updating autocfg v1.3.0 -> v1.4.0
    Updating aws-config v1.5.6 -> v1.5.7
    Updating aws-sdk-kms v1.44.0 -> v1.45.0
    Updating aws-sdk-sso v1.43.0 -> v1.44.0
    Updating aws-sdk-ssooidc v1.44.0 -> v1.45.0
    Updating aws-sdk-sts v1.43.0 -> v1.44.0
    Updating aws-smithy-types v1.2.6 -> v1.2.7
    Updating axum v0.7.6 -> v0.7.7
    Updating axum-core v0.4.4 -> v0.4.5
    Updating cc v1.1.21 -> v1.1.22
    Updating evmole v0.5.0 -> v0.5.1
    Updating flate2 v1.0.33 -> v1.0.34
    Updating hyper-util v0.1.8 -> v0.1.9
    Updating libc v0.2.158 -> v0.2.159
    Updating portable-atomic v1.8.0 -> v1.9.0
    Updating redox_syscall v0.5.4 -> v0.5.6
    Updating revm v14.0.2 -> v14.0.3
    Updating revm-interpreter v10.0.2 -> v10.0.3
    Updating revm-precompile v11.0.2 -> v11.0.3
      Adding revm-primitives v10.0.0
    Updating rustls-pki-types v1.8.0 -> v1.9.0
    Updating serde_spanned v0.6.7 -> v0.6.8
    Updating syn v2.0.77 -> v2.0.79
    Updating syn-solidity v0.8.3 -> v0.8.5
    Updating tempfile v3.12.0 -> v3.13.0
      Adding tokio-tungstenite v0.24.0
    Updating toml_edit v0.22.21 -> v0.22.22
    Updating tonic v0.12.2 -> v0.12.3
      Adding tungstenite v0.24.0
    Updating wasm-streams v0.4.0 -> v0.4.1
    Updating winnow v0.6.18 -> v0.6.20
note: pass `--verbose` to see 143 unchanged dependencies behind latest

* fixes

* chore: clippy

---------

Co-authored-by: mattsse <19890894+mattsse@users.noreply.github.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* fix(forge): generate `evm.legacyAssembly` extra output (#8987)

fix(forge): include legacyAssembly output

* chore: bump alloy-core deps + revm (#8988)

* chore: bump alloy-core deps + revm

* bump alloy to 0.4.0

* bump revm-inspectors + type casting to u128

* fix

* Revert "fix"

This reverts commit 5e0e0d1128b6819acf600b42372156738e666247.

* Revert "bump revm-inspectors + type casting to u128"

This reverts commit 25aa23cffaadef1d047ce7b359b4d7ad5018704a.

* Revert "bump alloy to 0.4.0"

This reverts commit f9721e00f5ba726c4fea6651839d65b45faae488.

* replace std HashMap with alloy_primitives maps

* bump compilers

* replace remaining HashMaps

* fmt

* nit

* replace HashSets

* fmt

* fix(ci): flexibly handle forge-std being installed with tag or untagged (#9003)

flexible handle forge-std being installed with tag or untagged

* docs: clarify keystore path should point to a filename (#9004)

clarify that you should point to a keystore by its file but it can be a custom directory

* feat: gas snapshots over arbitrary sections  (#8952)

* update internal naming

* further internals

* deprecate cheats

* update Solidity tests and add dedicated test for testing deprecated cheatcodes

* clarify gas snapshots

* fix build

* final fixes

* fix build

* fix repro 6355 rename

* add gas snapshot setup from #8755

* fix build + clippy warnings

* fix cheatcodes

* account for fixed CREATE / CALL gas cost

* remove import

* add stipend

* recalculate after a - b setup

* clear call_stipend, update tests

* avoid double counting external calls

* update cheatcodes, remove debug prints

* enable assertions

* clean up tests

* clean up test names

* remove snapshot directory on `forge clean`

* do not remove all snapshots by default due to multiple test suites being able to be ran concurrently or sequentially + optimize gas snapshots check - skip if none were captured

* handle edge case where we ask to compare but file does not exist, remove snapshot directory at a top level before test suites are ran

* fix path issue when attempting removal

* Update crates/cheatcodes/src/evm.rs

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>

* Update crates/cheatcodes/src/inspector.rs

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>

* refactor, apply recommended changes for last_snapshot_group, last_snapshot_name

* remove gas snapshots from fuzz tests for now: this is largely due to it conflicting with the FORGE_SNAPSHOT_CHECK where it is highly likely that with different fuzzed input the gas measurement differs as well. In the future it would be an idea to capture the average gas

* fix clippy

* avoid setting to 0 unnecessarily

* use if let Some

* improve comments, clarify use of last_gas_used != 0

* fix merge conflict issue

* fix arg ordering to address group naming regression

* fix import

* move snapshot name derivation to helper

* only skip initial call w/ overhead, no special handling for call frames

* add flare test

* style nits + use helper method

---------

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>

* chore(deps): bump alloy to 0.4.2 (#9000)

* chore: bump alloy-core deps + revm

* bump alloy to 0.4.0

* bump revm-inspectors + type casting to u128

* fix

* fix

* fix

* bump foundry-fork-db

* bump alloy

* fix

* gas related field to u64

* fmt

* change gas fields types to u64 in DepositTx, TxEssentials

* chore: print parent beacon root (#9006)

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* chore: use dyn DatabaseExt everywhere (#8924)

* wip

* feat: use `dyn DatabaseExt` (#9010)

* wip

* clean up

* fix

* clippy

* doc

* fix imports

* chore: simplify InspectorExt by making it lifetime-generic

* fmt

* chore: remove unnecessary casts and lifetimes

* chore: more unused lifetimes (clippy)

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

---------

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>

* feat: `--eof` flag and config key (#9002)

* feat: --eof flag and config key

* not windows

---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>

* perf: reduce dynamic dispatch for inspectors (#9011)

* feat(randomBytes): adding support to generate different bytes via RngCore (#8996)

* feat(randomBytes): adding support to generate different bytes via RngCore

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* Added needed changes to util file

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* Added support to get random 4 and 8 bytes

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* Refractor code to suggested changes

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* Fixed import with B32

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* updated cheatcodes.json file

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>

* docs

---------

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* chore: add more context to sourcemap error (#9015)

* fix: only test `--eof` on linux (#9016)

fix: only test --eof on linux

* fix(cheatcodes): handle create2 deployer with broadcastRawTransaction (#9020)

fix(cheatcodes): fix deploy create with broadcastRawTransaction

* fix(`anvil`): set `storage.best_hash` while loading state (#9021)

* fix(anvil): set `storage.best_hash` while loading state

* clippy nit

* test: strengthen can_load_state

* chore: reduce size of DynCheatcode vtable (#9023)

* chore: unify tx env filling + add missing members (#9022)

* chore: fix clippy (#9028)

* fix(`--isolate`): track state in journal (#9018)

* track in journal

* wip

* add test

* forge fmt

* rm selfdestruct test

* fix: handle large years (#9032)

* fix(`forge eip712`): fix handling of subtypes (#9035)

* fix(forge eip712): fix handling of subtypes

* fmt

* clippy

* chore(deps): weekly `cargo update` (#9041)

Locking 40 packages to latest compatible versions
    Updating alloy-chains v0.1.34 -> v0.1.36
    Updating alloy-network-primitives v0.4.0 -> v0.4.2
    Updating alloy-rpc-types-anvil v0.4.0 -> v0.4.2
    Updating alloy-rpc-types-engine v0.4.0 -> v0.4.2
    Updating alloy-rpc-types-eth v0.4.0 -> v0.4.2
    Updating alloy-rpc-types-trace v0.4.0 -> v0.4.2
    Updating alloy-rpc-types-txpool v0.4.0 -> v0.4.2
    Updating async-compression v0.4.12 -> v0.4.13
    Updating async-stream v0.3.5 -> v0.3.6
    Updating async-stream-impl v0.3.5 -> v0.3.6
    Updating aws-config v1.5.7 -> v1.5.8
    Updating aws-sdk-kms v1.45.0 -> v1.46.0
    Updating aws-sdk-sso v1.44.0 -> v1.45.0
    Updating aws-sdk-ssooidc v1.45.0 -> v1.46.0
    Updating aws-sdk-sts v1.44.0 -> v1.45.0
    Updating cc v1.1.24 -> v1.1.25
    Updating clap v4.5.18 -> v4.5.19
    Updating clap_builder v4.5.18 -> v4.5.19
    Updating clap_complete v4.5.29 -> v4.5.32
    Updating futures v0.3.30 -> v0.3.31
    Updating futures-channel v0.3.30 -> v0.3.31
    Updating futures-core v0.3.30 -> v0.3.31
    Updating futures-executor v0.3.30 -> v0.3.31
    Updating futures-io v0.3.30 -> v0.3.31
    Updating futures-macro v0.3.30 -> v0.3.31
    Updating futures-sink v0.3.30 -> v0.3.31
    Updating futures-task v0.3.30 -> v0.3.31
    Updating futures-util v0.3.30 -> v0.3.31
    Updating gcloud-sdk v0.25.6 -> v0.25.7
      Adding hashbrown v0.15.0
    Updating indexmap v2.5.0 -> v2.6.0
    Updating ipnet v2.10.0 -> v2.10.1
    Updating once_cell v1.20.1 -> v1.20.2
    Updating pin-project v1.1.5 -> v1.1.6
    Updating pin-project-internal v1.1.5 -> v1.1.6
    Updating rustls v0.23.13 -> v0.23.14
    Updating snapbox v0.6.17 -> v0.6.18
    Updating terminal_size v0.3.0 -> v0.4.0
    Updating unicode-bidi v0.3.15 -> v0.3.17
      Adding unicode-width v0.2.0
note: pass `--verbose` to see 9 unchanged dependencies behind latest

Co-authored-by: mattsse <19890894+mattsse@users.noreply.github.com>

* fix: normalize EVM version in chisel (#9040)

* fix: normalize EVM version in chisel

* rm test

* clippy

* fix

* fix(`cheatcodes`): mark `vm.breakpoint` as `pure`  (#9051)

breakpoint external -> external pure

* fix: include `traces` field when running `forge test -vvvv --json` (#9034)

* enable traces as part of verbose output when tests are ran with --json, includes tests

* Update crates/forge/tests/cli/test_cmd.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* Update crates/forge/tests/cli/test_cmd.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* use forgetest! directly

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* feat(cheatcodes): Add `vm.mockCalls` to mock different return data for multiple calls (#9024)

* Refactor vm.mockCall to be based on mutable VecDeque

* Add vm.mockCalls cheatcode

* Refactor mock_call to be wrapper for mock_calls

* Add a test to vm.mockCalls

* Add test for vm.mockCalls with msg.value

* Fix fmt & clippy following vm.mockCalls implementation

* Fix Solidity fmt in testdata/default/cheats/MockCalls.t.sol

* Add test in MockCalls.t.sol to check last mocked data persists

* Remove allow(clippy::ptr_arg) from mock_call & mock_calls

* Apply suggestions from code review

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* chore(deps): bump alloy-core 0.8.6 (#9045)

* feat(cheatcodes): add vm.cloneAccount() cheatcode (#9048)

* feat(cheatcodes): add vm.cloneAccount() cheatcode

* Fmt

* Cargo cheats

* Changes after review:
- use autogenerated getter
- consistent clone naming
- nits

* fix(`anvil`): eth_gasPrice returned `1000000000` with `--block-base-fee-per-gas 0`, adds new `--disable-min-priority-fee` to return `0` (#9049)

* add new flag to disable min suggested priority fee: `--disable-min-priority-fee`

* documentation

* remove unnecessary value_name

* feat: update to Soldeer v0.4.0 (#9014)

* updated to version 0.4.0

* fmt and clippy

* added cargo modifications

* solving small nits

* forcing special chars on windows

* escaping special chars

* removing stderr checks

* fmt

* remvoving err assert from login

* fix(invariant): do not commit state if assume returns (#9062)

* feat(`cheatcodes`): vm.getScriptWallets() (#9052)

* feat(`cheatcodes`): vm.getScriptWallets()

* feat: load default anvil accounts in script

* Revert "feat: load default anvil accounts in script"

This reverts commit 4d64356a51bf226482269a2af47f947c4e49e462.

* clippy

* test

---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>

---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>

* fix: support EOF opcodes in `cast da` (#9070)

* fix: support EOF opcodes in cast da

* fix

* fix doc

* fmt

* feat(forge): allow passing value to `--optimize` (#9071)

feat(forge): allow passing value to --optimize

* fix(forge): add logs/decoded logs in json test results (#9074)

* fix(`forge`): avoid panic when empty fuzz selectors in invariants (#9076)

* chore(`anvil`): use op-alloy types (#9047)

* fix: redact RPC URLs in traces if URL is passed in directly (#9077)

redact RPC urls if string is a URL, not an alias

* test: relax pragmas (#9078)

* test: relax pragmas

* test: update rust tests too

* feat(cheatcode): `startDebugTraceRecording` and `stopDebugTraceRecording` for ERC4337 testing (#8571)

* feat: add record opcode cheat code

feat: capture stack inputs as part of the opcode

feat: record opcode -> record debug trace

fix: memory OOG, need to only use needed stack, mem input

fix: missing op code, instruction results

fix: accessing out-of-bound idx memory

When running on some project, we noticed that it sometimes try to access memory with out of bound
index and panics.

This commit fix it by:
1. Enfore reset to Nonce after stopDebugTraceRecording(), this ensures the `some(..) = ...` part will not be triggered
2. Change how opcode_utils.rs accesses memory. Return empty vector if trying access out-of-bound memory.

* test: add DebugTrace.t.sol for the debug trace cheatcode

* fix: rebase errors

* feat: use tracer for debug trace instead of recording during inspector

This commit also cleans up the previous implementaiton on inspector.
And then change the cheatcode interface to be of three steps:
1. start recording debug trace
2. stop recording
3. get the debug trace by index

The reason is to avoid out-of-memory issue by returning the whole traces at once.

* fix: rebase duplication

* feat: replace instruction result with isOutOfGas

* fix: CI issues

* fix: remove DebugTrace wrapper in inspector

* fix: revert to original tracer config when stops

* chore: reuse existing opcode functions

* chore: refactor, fmt, clippy run

* chore: use ref instead of clone, returning Error when not able to access

* chore: move buffer to evm_core from debugger

* fix: disable dummy tracer by default, return explicit error

Since enabling dummy tracer still come with performance impact, remove the auto dummy tracer
initiation. The cheatcode will return explicit error and require the test to be run in -vvv mode
to have the tracer enabled by default.

* fix: return all traces, turn on necessary tracer config

There was OOM concern but using the get-by-index style, despite improved, does not solve the root cause.
The main issue is that the tracer config did not turn off after the stop recording cheatcode being called.
It seems too much burden for the tracer to record the returned traces inside forge tests as the tests will
also pass around the debug traces, causing memory boost.

This commit also only turns on necessary tracer config instead of using all().

* chore: cleanup comments, typo

* fix: use bytes for memory, remove flattern function, fix get_slice_from_memory

* fix: style fmt

* fix: ensure steps in the order of node when flatten

A node can have steps that calls to another node, so the child node's step might occur before
some steps of its parent node. This introduce the flatten_call_trace function back using
recursive call to ensure the steps are in correct order despite not in the same order of the
node index.

see PR comment: foundry-rs/foundry#8571 (comment)

* doc: remove legacy comment in test

* style: reuse empty initialized var on return val

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* feat(`forge doc`): include @Custom natspec (#9075)

* feat(`forge doc`): include @Custom natspec

* chore: make clippy happy

* test: implement test for `is_custom`

* chore: make rustfmt happy

* doc: nit

* chore: format custom tags

* chore: add alias (#9082)

add alias

* fix(chisel): final statement & fetch err with complex type fixes (#9081)

* fix(chisel): consider assembly block return as final statement

* Fix 4938

* Start from first assembly block when checking for return statement

* Fix 6618

* feat(chisel): add eval command (#9086)

* feat: make `--gas-report` JSON output compatible (#9063)

* add gas report generation in JSON

* skip junit for now

* add json formatted tests, trailing space and invalid formatting

* avoid redundant modifications for calls count

* replace existing tests with snapbox

* clean up snapbox tests

* merge in master

* calls -> frames

* use .is_jsonlines()

* chore: replace criterion with divan (#9080)

* chore: reduce length of a common error message (#9089)

* feat: update to Soldeer v0.4.1 (#9092)

Hotfix #212

* feat: bump alpine to `3.20.3` (#9094)

* feat: bump alpine to `3.20.3`

* feat: alpine v`3.20`

* chore: update chains (#9097)

* feat(cheatcodes): implement new cheatcode to check if a string contains another string (#9085)

* feat: implement new cheatcode to check if a string contains another string

* chore: make clippy and rustfmt happy

* chore: vm.contains should return a boolean

* Update testdata/cheats/Vm.sol

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* chore: update `cheatcodes.json`

* chore: update var names

* chore: rename to `vm.contains`

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* chore: address PR comments

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* chore(deps): weekly `cargo update` (#9100)

Locking 35 packages to latest compatible versions
    Updating alloy-dyn-abi v0.8.6 -> v0.8.7
    Updating alloy-json-abi v0.8.6 -> v0.8.7
    Updating alloy-primitives v0.8.6 -> v0.8.7
    Updating alloy-sol-macro v0.8.6 -> v0.8.7
    Updating alloy-sol-macro-expander v0.8.6 -> v0.8.7
    Updating alloy-sol-macro-input v0.8.6 -> v0.8.7
    Updating alloy-sol-type-parser v0.8.6 -> v0.8.7
    Updating alloy-sol-types v0.8.6 -> v0.8.7
    Updating async-compression v0.4.13 -> v0.4.14
    Updating aws-sdk-kms v1.46.0 -> v1.47.0
    Updating aws-sdk-sso v1.45.0 -> v1.46.0
    Updating aws-sdk-ssooidc v1.46.0 -> v1.47.0
    Updating aws-sdk-sts v1.45.0 -> v1.46.0
    Updating aws-smithy-runtime v1.7.1 -> v1.7.2
    Updating cc v1.1.28 -> v1.1.30
    Updating clap v4.5.19 -> v4.5.20
    Updating clap_builder v4.5.19 -> v4.5.20
    Updating clap_complete v4.5.32 -> v4.5.33
    Updating derive_builder v0.20.1 -> v0.20.2
    Updating derive_builder_core v0.20.1 -> v0.20.2
    Updating derive_builder_macro v0.20.1 -> v0.20.2
    Updating js-sys v0.3.70 -> v0.3.72
    Updating lru v0.12.4 -> v0.12.5
    Updating newtype-uuid v1.1.0 -> v1.1.2
    Updating proc-macro2 v1.0.86 -> v1.0.87
    Updating scc v2.2.0 -> v2.2.1
    Updating sdd v3.0.3 -> v3.0.4
    Updating syn-solidity v0.8.6 -> v0.8.7
    Updating wasm-bindgen v0.2.93 -> v0.2.95
    Updating wasm-bindgen-backend v0.2.93 -> v0.2.95
    Updating wasm-bindgen-futures v0.4.43 -> v0.4.45
    Updating wasm-bindgen-macro v0.2.93 -> v0.2.95
    Updating wasm-bindgen-macro-support v0.2.93 -> v0.2.95
    Updating wasm-bindgen-shared v0.2.93 -> v0.2.95
    Updating web-sys v0.3.70 -> v0.3.72
note: pass `--verbose` to see 10 unchanged dependencies behind latest

Co-authored-by: mattsse <19890894+mattsse@users.noreply.github.com>

* feat(`cheatcodes`): vm.rememberKeys (#9087)

* feat(`cheatcodes`): vm.rememberKeys

* docs + return addresses + test

* remeberKeys with language

* doc nits

* cargo cheats

* set script wallet in config if unset

* nit

* test

* refactor(`cheatcodes`): mv `ScriptWallets` into `Cheatcode` (#9106)

* refactor(`cheatcodes`): mv `ScriptWallets` into `Cheatcode` from `CheatsConfig`

* nit

* rename `ScriptWallets` to `Wallets`

* rename cheatcode

* doc nits

* fix: running script with `--broadcast` for a transaction sequence can error out due to nonce desync from rpc latency (#9096)

* fix for issue #9095

* changed 'if' statement into 'match'

* fmt fix

* repeat ask for provider nonce on desync

* loop break and tokio::time use instead of std::thread

* fix(fmt): do not panic when no named arg (#9114)

* fix(traces): identify artifacts using both deployed and creation code (#9050)

* Identify by creation code

* Compute score for both creation and runtime code

* Fallback to deployed bytecode only if min creation bytecode score is under threshold

* reuse check closure, add basic test

* chore(`cheatcodes`): wallet nits (#9118)

* refactor(`script`): mv `ScriptSequence` to new crate (#9098)

* refac(`script`): extract script sequence and related types to new crate

* replace MultiChainSequence in script crate

* replace TransactionWithMetadata and AdditionalContract

* replace ScriptSequence

* replace all underlying ScriptSequence and related types

* doc nits

* add `ScriptTransactionBuilder`

* remove `TxWithMetadata`

* mv verify fns and use `ScriptSequence` directly

* clippy

* chore: remove duplicated RecordAccess

* fix: replace generic with dyn DatabaseExt

* chore: pending merge conflicts on script/src/lib.rs

* fix: f5aa05e upstream update compilation errors (#681)

* chore: update foundry-block-explorers

* chore: remove deployments from LocalTraceIdentifier

* fix: use dyn DatabaseExt in TraceCollector

* chore: fix duplicate method definition

* fix: solve some dependency issues in cheatcodes crate

* fix: adapt cheatcode crate to usage of dyn DatabaseExt

* fix: adapt to usage of hash maps with different hashes

* fix: further adaptations to dyn DatabaseExt usage

* fix: hardhat console import

* fix: adapt zk mock code to multiple calls (#9024)

* fix lifetime issues in trace_zksync

* inline env and l1_block_info fields

* fix: remove deployments and fix usage of different HashMaps on evm crate

* fix: remove stale std HashMap reference

* fix: clone zk_metadata before taking mutable reference

* fix: remove deployment references in forge

* fix: use u64 for gas limit

* fix: adapt to compiler optimize being an Option

* fix: restore lost code during conflict resolution in tests

* chore: remove uneeded uses of std HashMap

---------

Co-authored-by: Nisheeth Barthwal <nbaztec@gmail.com>

* fix: clippy

* fix: remove duplicate clippy ci job

* chore: fix codespell errors

* chore: remove ci success job

---------

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Co-authored-by: Léo Vincent <28714795+leovct@users.noreply.github.com>
Co-authored-by: Jennifer <jenpaff0@gmail.com>
Co-authored-by: jenpaff <jepaff0@gmail.com>
Co-authored-by: Qiwei Yang <yangqiwei97@gmail.com>
Co-authored-by: aganisgash <aganisgash@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Yash Atreya <44857776+yash-atreya@users.noreply.github.com>
Co-authored-by: Igor Żuk <igor.zuk@protonmail.com>
Co-authored-by: N <n@push0.dev>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>
Co-authored-by: Drake Evans <31104161+DrakeEvans@users.noreply.github.com>
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: DaniPopes <DaniPopes@users.noreply.github.com>
Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
Co-authored-by: mattsse <19890894+mattsse@users.noreply.github.com>
Co-authored-by: Abhishek kochar <abhishekkochar1@proton.me>
Co-authored-by: Yotam Bar-On <tudmotu@gmail.com>
Co-authored-by: m4rio <92288535+mario-eth@users.noreply.github.com>
Co-authored-by: boolafish <boolafish945@gmail.com>
Co-authored-by: Giovanni Napoli <gnapoli.dev@gmail.com>
Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
Co-authored-by: pogobounce <borgster04@yahoo.com>
Co-authored-by: Nisheeth Barthwal <nbaztec@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes T-feature Type: feature
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add vm.getStateDiffOpcodes to access opcodes inside of tests
7 participants