foundry icon indicating copy to clipboard operation
foundry copied to clipboard

fix: script simulation with default sender

Open klkvr opened this issue 4 months ago • 3 comments

Motivation

Closes #8960

Right now, when simulating a script without providing a --sender arg, we will use the default sender both for script contract deployment and setUp/run. This will result in sender nonce being higher than an actual on-chain nonce. For certain scripts, this might result in mismatched addresses and failure during on-chain simulation, if incorrect addresses end up in calldata.

Solution

Fix contains 2 parts:

  1. Follow-up for https://github.com/foundry-rs/foundry/pull/7907 which enables nonce correction even when sender is default foundry sender. Unsure why this case was excluded earlier
  2. Hack during script execution — if we're simulating with default sender, we'd set it's nonce to a hardcoded high value for script contract CREATE transaction. This allows us to reset nonce back to on-chain value when simulating the script, and ensure matching contract addresses during on-chain sumlation

klkvr avatar Oct 06 '24 01:10 klkvr