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

fuzz results differ on local vs github CI #4917

Closed
2 tasks done
xenide opened this issue May 10, 2023 · 7 comments · Fixed by #7951
Closed
2 tasks done

fuzz results differ on local vs github CI #4917

xenide opened this issue May 10, 2023 · 7 comments · Fixed by #7951
Labels
T-bug Type: bug

Comments

@xenide
Copy link

xenide commented May 10, 2023

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 (7bba788 2023-05-10T00:11:46.049317000Z)

What command(s) is the bug in?

forge snapshot

Operating System

macOS (Apple Silicon)

Describe the bug

The fuzz run gas usages differ on my machine vs in github CI. This has been going on for 1-2 months already

Things I tried

  • comparing the forge config on my machine vs in github CI
    • discovered that the default remappings for ds-test was defaulted to "ds-test/=lib/forge-std/lib/ds-test/src/" while it was "ds-test/=lib/solmate/lib/ds-test/src/" on the github CI
    • tried changing to both, but the fuzz runs gas outputs still differ slightly, and therefore CI tests failing

This is the original foundry.toml

[profile.default]
solc = "0.8.19"
#via_ir = true
bytecode_hash = "none"
optimizer_runs = 1_000_000
libs = ['lib']
remappings = [
    "@openzeppelin/=lib/openzeppelin-contracts/contracts/",
]
match_path = "test/unit/*.sol"
verbosity = 3
fs_permissions = [
    { access = "write", path = "./script/optimized-deployer-meta" },
    { access = "write", path = "./script/unoptimized-deployer-meta" },
]
ignored_error_codes = []

[profile.integration]
match_path = "test/integration/*.sol"

[profile.differential]
fs_permissions = [{ access = "read", path = "./reference/balancer-v2-monorepo" }]
match_path     = "test/differential/*.sol"

[profile.differential.fuzz]
runs = 10_000

[fmt]
bracket_spacing   = true
wrap_comments     = false
number_underscore = "thousands"
int_types         = "long"

[profile.script]
optimizer_runs = 1_000_000
@xenide xenide added the T-bug Type: bug label May 10, 2023
@xenide xenide changed the title fuzz results differ fuzz results differ on local vs github CI May 10, 2023
@gakonst gakonst added this to Foundry May 10, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry May 10, 2023
@mds1
Copy link
Collaborator

mds1 commented May 10, 2023

Are you setting a fuzz seed? Most likely this is because each fuzz run uses different random values which affects gas costs

@xenide
Copy link
Author

xenide commented May 10, 2023

did not set a fuzz seed in foundry.toml as you can see. But when I run forge config it doesn't have anything related to the seed as well

@mds1
Copy link
Collaborator

mds1 commented May 10, 2023

Right, so if a fuzz seed is not present in the config (which is the default, and which is why you don't see it when running forge config), then it means "use a random seed each time forge test is invoked

@mds1
Copy link
Collaborator

mds1 commented May 10, 2023

did not set a fuzz seed in foundry.toml as you can see.

You may have been setting a fuzz seed with the FOUNDRY_FUZZ_SEED env var which overrides what's in the config (which is why I asked)

@xenide
Copy link
Author

xenide commented May 11, 2023

Alright so I just tried setting a fuzz seed and the github CI gas usage still differs from my local machine's.

Check out my branch and the failing CI gas check.

Also made sure that FOUNDRY_FUZZ_SEED is not set in both my local env and the ci's env

@xenide
Copy link
Author

xenide commented May 12, 2023

the only other difference that the github CI runs with the ci profile. But the config displayed by forge config does not show any difference compared to the default profile.

Any thoughts? @mds1

@mds1
Copy link
Collaborator

mds1 commented May 12, 2023

A few possibilities:

  • The file you are checking against may be out of date and need to be rengenerated with the new fuzz seed
  • Your CI has FOUNDRY_PROFILE: ci, but the config file has no ci profile
  • The way you currently specify the seed only applies to the default profile, so if you use a different profile it may not have the seed set. Check out the foundry book for more info here
  • Try seed = 1 e.g. a number instead of a hex string. I don't recall offhand which format is required, but I've always used numbers, so maybe that matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants