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.03k stars 1.64k forks source link

bug(`anvil`): unable to submit blob transaction #8447

Closed iAmMichaelConnor closed 2 days ago

iAmMichaelConnor commented 1 month 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 (de33b6a 2024-07-03T14:00:39.781698671Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

Anvil throws an error, when it's sent valid blob transactions.

I've written a repo and test to highlight the bug here: https://github.com/iAmMichaelConnor/demo-anvil-blob-issue Details of how to build the repo and run the failing test are in the README.

The test successfully runs when using a "Hardhat Network Node", but not when using an Anvil node. The fact that viem, cKzg, a hardhat node, and a Solidity contract compiled via forge, all work together to result in a passing test, suggests to me that it's Anvil that's likely got a bug interpreting blob txs.

When submitting a blob tx, Anvil says:

InvalidParamsRpcError: Invalid parameters were provided to the RPC method.
[1]     Double check you have provided the correct parameters.

Details of the test:

The test seeks to submit a blob transaction. Using viem and cKzg, I construct a valid blob transaction and send it via viem's sendRawTransaction() method. Using sendRawTransaction ensures a Hardhat node can understand the blobby tx format. I've not been able to get Anvil to correctly interpret the data, regardless of how I send the tx. A Solidity contract - compiled via forge -- then accepts the blob and stores its versionedHash. A second tx then verifies thte kzg proof. This test fails when using Anvil.

The failing test is triggered via:

yarn test:anvil

whereas the passing test is triggered via:

yarn test:hardhat

Thanks for reading! :)

zerosnacks commented 1 month ago

Hi Michael, thanks for the report and the detailed repro!

mattsse commented 2 days ago

this has since been fixed

❯ yarn test
yarn run v1.22.21
$ export PRIV_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 && node --experimental-vm-modules node_modules/jest/bin/jest.js
(node:94207) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:94206) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 PASS  src/blob-submission.test.ts

Test Suites: 1 skipped, 1 passed, 1 of 2 total
Tests:       2 skipped, 2 passed, 4 total
Snapshots:   0 total
Time:        4.995 s, estimated 5 s
Ran all test suites.
✨  Done in 5.49s.

but I had to add timeouts to bypass receipt error

diff --git a/src/blob-submission.test.ts b/src/blob-submission.test.ts
index 2ff2cc5..1c24a0e 100644
--- a/src/blob-submission.test.ts
+++ b/src/blob-submission.test.ts
@@ -220,6 +220,8 @@ test("Test blob submission", async () => {
     serializedTransaction,
   });

+  await new Promise(f => setTimeout(f, 1000));
+
   const submitBlobsReceipt = await client.getTransactionReceipt({
     hash: submitBlobsHash,
   });
@@ -258,6 +260,9 @@ test("Test blob submission", async () => {
     serializedTransaction: verifyKzgProofSerializedTransaction,
   });

+
+  await new Promise(f => setTimeout(f, 1000));
+
   const verifyKzgProofReceipt = await client.getTransactionReceipt({
     hash: verifyKzgProofHash,
   });
iAmMichaelConnor commented 2 days ago

Amazing thanks! I've just validated that updating anvil and running the test successfully accepts a blob tx. And then your suggestion to add a timeout fixed a new error of not waiting long enough before querying for a receipt.