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.33k stars 1.76k forks source link

bug(`alloy` + `anvil`): `data did not match any variant of untagged enum SerializableTransactionType` #9324

Closed PatrickAlphaC closed 1 day ago

PatrickAlphaC commented 1 week ago

Component

Anvil

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

What version of Foundry are you on?

forge 0.2.0 (31c24b0 2024-11-14T00:20:56.222819000Z)

What command(s) is the bug in?

anvil --load-state

Operating System

macOS (Apple Silicon)

Describe the bug

Running:

anvil --load-state /path/anvil_data/state.json

Gives me:

error: invalid value '/path/anvil_data/state.json' for '--load-state <PATH>': failed to parse json file: "/path/anvil_data/state.json": data did not match any variant of untagged enum SerializableTransactionType at line 1 column 11125

However, this command worked on a previously working edition of foundry & anvil.

I was able to revert to an older version where I did not get such an error with the following command:

foundryup -C 1d2379a22a78d48a6f1a159868ca5978f31c5462

Here is the block that was erroring:

{
            "header": {
                "parentHash": "0x4974542d1b2db2ffc73b16aa6394fe5a90b338cc0586ebbecc47c146430d526b",
                "ommersHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
                "beneficiary": "0x0000000000000000000000000000000000000000",
                "stateRoot": "0x230b4caf2bd80724bf342cdf4829b1940934848e6aad0f2783436ee72492f3ae",
                "transactionsRoot": "0xab916ba5327c96fc466ed5b8c97511a68fdee5969ed2664d355ebdb6ec79d47e",
                "receiptsRoot": "0xdcb8d1138a074583db4436c14009728a21adce5a5f31ff989a62bd20a239819f",
                "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                "difficulty": "0x0",
                "number": "0x6",
                "gasLimit": "0x1c9c380",
                "gasUsed": "0x13c56",
                "timestamp": "0x66ff46ba",
                "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "nonce": "0x0000000000000000",
                "baseFeePerGas": "0x1eaa23e3",
                "blobGasUsed": "0x0",
                "excessBlobGas": "0x0",
                "extraData": "0x"
            },
            "transactions": [
                {
                    "transaction": {
                        "EIP1559": {
                            "chainId": "0x7a69",
                            "nonce": "0x1",
                            "gasLimit": "0x13c56",
                            "maxFeePerGas": "0x7a90ed8f",
                            "maxPriorityFeePerGas": "0x3b9aca00",
                            "value": "0x0",
                            "accessList": [],
                            "input": "0x61008061000f6000396100806000f35f3560e01c60026003820660011b61007a01601e395f51565b63d6d1ee14811861007257602436103417610076576004355f55005b63d09de08a81186100575734610076575f54600181018181106100765790505f55005b638381f58a81186100725734610076575f5460405260206040f35b5f5ffd5b5f80fd001800340072841880810600a1657679706572830004000013",
                            "r": "0x77e68ead43366987d79a008b4b2d170dde77cf8696b0621871de78e7882a7f3b",
                            "s": "0xa3ebb096729873e4e09287734cdd8bc043b31eb1a40bbeeb77f391ebc15a2d0",
                            "yParity": "0x1",
                            "hash": "0x5ef0b097eac1311b110fdb3b76e8d6029199c9f9bc3197f9ed51548834617c79"
                        }
                    },
                    "impersonated_sender": null
                }
            ], # Error here
            "ommers": []
        },

Where line 1 column 11125 was pointing to the spot I have marked Error here.

This state.json was created on an older version of anvil using --dump-state originally.

klkvr commented 1 week ago

This transaction has gasLimit field name, however, it was changed to gas recently in alloy (as this is correct per JSON-RPC spec). Changing the field name in the JSON file should fix this

@grandizzy @mattsse unsure if we need to take any action here? eg we could add gasLimit back as an alias to alloy

PatrickAlphaC commented 1 week ago

That did the job! Thank you.

Maybe flag a warning that this was deprecated? Although, IMO it's unlikely a lot of people use this feature... Maybe its OK just as a breaking change.

grandizzy commented 6 days ago

I'm OK with taking no action here, since the breaking change is already introduced and an workaround exists. Also, in scope of v1.0 we're looking into removing all deprecation (as in https://github.com/foundry-rs/foundry/issues/8931, deprecated cheatcodes, etc.) so not sure we should introduce the warning now to just remove it in couple of weeks. @zerosnacks wdyt?

zerosnacks commented 6 days ago

I tend to agree, this ticket can serve as a reference for anyone that does happen to run into the issue. The new gas field is JSON-RPC spec compliant whereas the previous gasLimit is not. For now marking as won't fix

zerosnacks commented 6 days ago

Re-opening, this will be resolved as part of https://github.com/foundry-rs/foundry/pull/9280#discussion_r1844004048

It looks like there have been other breaking changes in Alloy that should be handled gracefully, including this one.