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

bug(anvil): anvil_dumpState is non-deterministic again #9570

Open
2 tasks done
KholdStare opened this issue Dec 17, 2024 · 2 comments
Open
2 tasks done

bug(anvil): anvil_dumpState is non-deterministic again #9570

KholdStare opened this issue Dec 17, 2024 · 2 comments
Labels
A-reth-anvil Area: reth-anvil T-bug Type: bug

Comments

@KholdStare
Copy link
Contributor

KholdStare commented Dec 17, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (6b07c77 2024-12-17T16:21:09.880972720Z)

What command(s) is the bug in?

anvil

Operating System

Linux

Describe the bug

anvil_dumpState should be deterministic. In particular, running anvil_dumpState on the same anvil state should result in the same output. This is very important to us, as we rely on dumpState in CI to verify that what we are testing is the same thing that is deployed. If it's not deterministic, then we cannot rely on this check, and could inadvertently start running our tests on slightly different code than what we deployed. This does not fill me with confidence.

There is a long history of this popping back up. I first reported a variation of this 2 years ago here: #3891

To reproduce, see this repo: https://github.com/KholdStare/foundry-dumpstate-bug. In particular this script to reproduce after forge init: https://github.com/KholdStare/foundry-dumpstate-bug/blob/main/run_dumpstate.sh

My main hope from this bug is to have some basic unittests established that will catch regressions in this. This has cropped up numerous times, and each time the issue is fixed but no unittest is added to catch non-determinism in anvil_dumpState. Some tests to try:

  • blank anvil state should produce the same anvil_dumpState every time
  • deploying something should produce the same anvil_dumpState every time
  • round trip test. anvil_dumpState -> anvil_loadState -> anvil_dumpState should produce the same output
@KholdStare KholdStare added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Dec 17, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Dec 17, 2024
@mattsse
Copy link
Member

mattsse commented Dec 17, 2024

what regression have you observed besides the output being different?
which can be explained by different gzip output due to different ordering and thinks like different timestamp of the first block

@KholdStare
Copy link
Contributor Author

KholdStare commented Dec 18, 2024

We upgrade foundry only when we release a new version of our contracts. Last time we updated was a year ago, when anvil_dumpState was deterministic (https://github.com/foundry-rs/foundry/releases/tag/nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a).

The regression is that the output is different. We were relying on the output being the same.

Our setup:

  • We have some integration tests in typescript that load up a "golden" starting state in anvil before every test. We check this golden state into git as a reference, and also to avoid rebuilding it when the team is not touching the contracts. The golden state is what is currently deployed.
  • We have CI checks to ensure that the source contracts/deployment that is checked in, matches what is in the saved golden state. If they differ, something changed. (e.g. this could be an unintended contract change, could be different optimization setting, could be new foundry bug, who knows) This sanity check is important because we can confidently say the tests are checking the exact same thing that was deployed.

IMHO, anvil_dumpState being completely opaque without any determinism really hurts its utility.

Regarding the block timestamp - to make sure that's not the only source of non-determinism, is there any way to guarantee block timestamps when anvil mines them?

@zerosnacks zerosnacks added A-reth-anvil Area: reth-anvil and removed T-needs-triage Type: this issue needs to be labelled labels Dec 18, 2024
@zerosnacks zerosnacks changed the title anvil_dumpState is non-deterministic again bug(anvil): anvil_dumpState is non-deterministic again Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reth-anvil Area: reth-anvil T-bug Type: bug
Projects
Status: Todo
Development

No branches or pull requests

3 participants