foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.31k stars 1.76k forks source link

fuzz results differ on local vs github CI #4917

Closed xenide closed 5 months ago

xenide commented 1 year ago

Component

Forge

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

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

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
mds1 commented 1 year ago

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

xenide commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

A few possibilities: