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

forge script nonce issue related to selectFork #6184

Closed
2 tasks done
sakulstra opened this issue Nov 1, 2023 · 4 comments
Closed
2 tasks done

forge script nonce issue related to selectFork #6184

sakulstra opened this issue Nov 1, 2023 · 4 comments
Labels
T-bug Type: bug

Comments

@sakulstra
Copy link
Contributor

sakulstra commented Nov 1, 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 (deae4f1 2023-10-11T00:27:48.322843000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

Hello, at aave governance v3 we have a script that:

  1. iterates trough multiple chains to check for some configuration correctness
  2. submits a single txn on mainnet

While when testing everything works/worked fine, when actually submitting via ledger we're getting nonce issues like:

nonce changed unexpectedly while sending transactions. Expected 2007 got 2006 from provider.

The issue seems to happen whenever we do selectFork within a script.

Here i created a minimal reproduction:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Script} from 'forge-std/Script.sol';

contract Reproduction is Script {
  function run() public {
    uint256 previousFork = vm.activeFork();
    vm.selectFork(previousFork);
    vm.startBroadcast();
    address(0x25F2226B597E8F9514B3F68F00f494cF4f286491).call{value: 1}(new bytes(0));
  }
}

The script is started with a mainnet rpc, calls selectFork witht he activeForkId which is 0 and i think should essentially just be a noop in that case?.

The trace looks as follows:

Traces:
  [41465] Reproduction::run() 
    ├─ [0] VM::activeFork() [staticcall]
    │   └─ ← 0
    ├─ [0] VM::selectFork(0) 
    │   └─ ← ()
    ├─ [0] VM::startBroadcast() 
    │   └─ ← ()
    ├─ [7180] 0x25F2226B597E8F9514B3F68F00f494cF4f286491::fallback{value: 1}() 
    │   ├─ [55] 0x10c74b37Ad4541E394c607d78062e6d22D9ad632::fallback() [delegatecall]
    │   │   └─ ← ()
    │   └─ ← ()
    └─ ← ()
    
Script ran successfully.

Instead of being able to submit the txn though, i'm getting:

###
Finding wallets for all the necessary addresses...
##
Sending transactions [0 - 0].

Error: 
EOA nonce changed unexpectedly while sending transactions. Expected 46 got 45 from provider.

Seems related:

@sakulstra sakulstra added the T-bug Type: bug label Nov 1, 2023
@gakonst gakonst added this to Foundry Nov 1, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 1, 2023
@sakulstra
Copy link
Contributor Author

sakulstra commented Nov 1, 2023

edit: updated the example to be even more minimal (initially though was related to multichain, but just calling selectFork(activeForkId) will reproduce the same issue.)

In practice what we do is:

  • store the current forkId
  • switch to another fork
  • test some stuff
  • switch back to the previous fork
    The example is simplified, as it seems like most of this is unrelated to the actual error.

Also, for anyone facing this, one workaround which seems to work for us is to simply not switch back to the fork but always create a new one:

- uint256 previousFork = vm.activeFork();
- vm.selectFork(previousFork);
+ vm.createSelectFork(vm.rpcUrl('mainnet'));

@ArshanKhanifar
Copy link
Contributor

I've proposed a fix here. #6271

@RedaOps
Copy link
Contributor

RedaOps commented Nov 19, 2023

@sakulstra @Evalir can close this as completed since #6271 is merged?

@sakulstra
Copy link
Contributor Author

@RedaOps i think it's working fine now thx.

@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 30, 2023
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

No branches or pull requests

3 participants