foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(`anvil`): inconsistent simulation behaviour

Open DicksonWu654 opened this issue 1 year ago • 4 comments

Component

Anvil

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

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (b174c3a 2024-02-09T00:16:22.953958126Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

Hi! I am experiencing inconsistent behaviour from anvil when simulating a transaction on an old block. There are 2 commands: First set up anvil:

anvil --chain-id 1 --port 8545 --base-fee 1000 --fork-block-number 14684306 -f "<NODE_URL>"

Then run eth_sendUnsignedTransaction:

curl -X POST -H "Content-Type: application/json" --data \
'{
  "jsonrpc":"2.0",
  "method":"eth_sendUnsignedTransaction",
  "params":[{
    "from": "0x63341ba917de90498f3903b199df5699b4a55ac0",
    "to": "0x7336F819775B1D31Ea472681D70cE7A903482191",
    "data": "0xaf8271f7",
    "gas": "0x20EF3F",
    "gasPrice": "0x34257"
  }],
  "id":1
}' "http://127.0.0.1:8545"

You might need to run it several times but sometimes it succeeds (as it should) and sometimes it fails. To rerun it, re-run both commands again (to ensure anvil is at the right block level + so it's the same state):

Listening on 127.0.0.1:8545
eth_sendUnsignedTransaction

    Transaction: 0x83b8909a89584001b122eba49310f13a8c7dc690acbc8c7d90350494a1cf7537
    Gas used: 1815058

    Block Number: 14684307
    Block Hash: 0x3f59e4fa81cc720c5d0d7df38ac08fa650cd72c046fe665d428a0e3965595cb9
    Block Time: "Sat, 30 Apr 2022 07:40:14 +0000"

Other times it fails:

Listening on 127.0.0.1:8545
eth_sendUnsignedTransaction

    Transaction: 0x83b8909a89584001b122eba49310f13a8c7dc690acbc8c7d90350494a1cf7537
    Gas used: 2158038
    Error: reverted with: EvmError: Revert

    Block Number: 14684307
    Block Hash: 0x667ea63188956e7fe25fa2806d76651afb745b0c102cf3606c33eb398942c712
    Block Time: "Sat, 30 Apr 2022 07:40:07 +0000"

In general, I'm getting a lot of inconsistent behaviour from anvil VS simulating using trace_call using Erigon:

curl -X POST -H "Content-Type: application/json" --data \
'{
  "jsonrpc":"2.0",
  "method":"trace_call",            
  "params":[{
    "from": "0x63341ba917de90498f3903b199df5699b4a55ac0",
    "to": "0x7336F819775B1D31Ea472681D70cE7A903482191",
    "data": "0xaf8271f7",
    "gas": "0x20EF3F",
    "gasPrice": "0x34257"
  }, ["trace"], "0xE01092"], 
  "id":1
}' "<NODE_URL>"

This succeeds every single time I run it.

(Also the txn I'm replicating in this instance is: "0x2b023d65485c4bb68d781960c2196588d03b871dc9eb1c054f596b7ca6f7da56")

Anvil isn't just failing on this txn, it's failing on many txns across the entire history of the chain.

Thank you in advance!

DicksonWu654 avatar Feb 09 '24 18:02 DicksonWu654

I am encountering this behavior, too. I am forking from mainnet block 19922506 and replaying the first two transactions from the next block: TX 0: 0xce3acf3eeebd6ff6ab7b574c1ef15057b09845254bab110c4afee0c898dfb8d5 TX 1: 0x6c9ec85db14f593dd2290c3be7d067e7e3cce7831d1a03db2004b5dd540180d5

With auto-impersonate active, I can send both transactions in sequence. Consistently, TX 0 completes and TX 1 reverts. This pattern happens using both eth_sendTransaction and eth_sendRawTransaction.

Both transactions confirm as expected when sent to a Hardhat node with similar options.

I tested several old nightly releases via foundryup -v back to Jan 2023 to observe the same behavior.

BowTiedDevil avatar May 23 '24 04:05 BowTiedDevil