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

Block hash in anvil and Header.Hash() in go-ethereum are not match #7621

Closed
2 tasks done
YoGhurt111 opened this issue Apr 10, 2024 · 1 comment
Closed
2 tasks done
Labels
T-bug Type: bug

Comments

@YoGhurt111
Copy link

YoGhurt111 commented Apr 10, 2024

Component

Anvil

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

No response

What command(s) is the bug in?

No response

Operating System

macOS (Intel)

Describe the bug

Environment

go-ethereum: v1.13.14
foundry: ghcr.io/foundry-rs/foundry:latest

Description

When I use the command eth_getBlockByNumber, I get the following response from the anvil node.

{"jsonrpc":"2.0","id":1,"result":{"hash":"0xc38eb6be5423170ba3b9253737835e44c2fb2e58c9ff7107685169b1be2329a0","parentHash":"0x369b01a19a6ffbe010a82adc6fc29d34a47888d9b476d409ef1867b1045e040a","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x5fc6d508e43a945f17b535caa40fb1f4b836259bab5019b16034531e8203d598","transactionsRoot":"0x5c6dad443c11e9cc6fcfbd1dcdceb09ed7a4deef2e041de0ba1b12709778430e","receiptsRoot":"0xfa316c79ddf3bc556cd8efe26b4bab92f27e9b64dda0cca321354f83fc590a59","logsBloom":"0x00000000000000000002000000000000200400000000000000000000000000000000000800000000000000000080000000020000000000000000000000240000000000000000000000040008000001000000000240040010000000000800000000000800000000000000000000000020000000000000000000004010000000000000000000000000000000040000000000002000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000002000001080000000000040000000004100000001000000001000040000010000000000000000000000000000001008000000000000000008000000000","difficulty":"0x0","number":"0x16","gasLimit":"0x1c9c380","gasUsed":"0x4cf19","timestamp":"0x6615090d","totalDifficulty":"0x0","extraData":"0x","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","baseFeePerGas":"0x701d305","uncles":[],"transactions":["0x16d5ef32a1d6a104128c05ee71645777f8ecfb8b72063b033cf4e115ab2d0ca1"],"size":"0x7c0"}}

The block hash from the anvil node is 0xc38eb6be5423170ba3b9253737835e44c2fb2e58c9ff7107685169b1be2329a0, but the header hash of HeaderByNumber in go-ethereum is 0x9ccef7404fb79b69399b98a9ae98ddf7e595d8180e21085d432074f62ca4920c.
They are not a match, so I did some tests.

//hash := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
	header := TestHeader{
		ParentHash:      common.HexToHash("0x369b01a19a6ffbe010a82adc6fc29d34a47888d9b476d409ef1867b1045e040a"),
		UncleHash:       common.HexToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"),
		Coinbase:        common.HexToAddress("0x0000000000000000000000000000000000000000"),
		Root:            common.HexToHash("0x5fc6d508e43a945f17b535caa40fb1f4b836259bab5019b16034531e8203d598"),
		TxHash:          common.HexToHash("0x5c6dad443c11e9cc6fcfbd1dcdceb09ed7a4deef2e041de0ba1b12709778430e"),
		ReceiptHash:     common.HexToHash("0xfa316c79ddf3bc556cd8efe26b4bab92f27e9b64dda0cca321354f83fc590a59"),
		Bloom:           types.BytesToBloom(common.FromHex("0x00000000000000000002000000000000200400000000000000000000000000000000000800000000000000000080000000020000000000000000000000240000000000000000000000040008000001000000000240040010000000000800000000000800000000000000000000000020000000000000000000004010000000000000000000000000000000040000000000002000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000002000001080000000000040000000004100000001000000001000040000010000000000000000000000000000001008000000000000000008000000000")),
		Difficulty:      new(big.Int).SetUint64(0),
		Number:          new(big.Int).SetUint64(22),
		GasLimit:        30000000,
		GasUsed:         315161,
		Time:            1712654605,
		Extra:           common.FromHex("0x"),
		MixDigest:       common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
		//WithdrawalsHash: &hash,
		Nonce:           types.EncodeNonce(0),
		BaseFee:         new(big.Int).SetUint64(117560069),
	}
	headerHash := rlpHash(header)

This time the result is 0x9ccef7404fb79b69399b98a9ae98ddf7e595d8180e21085d432074f62ca4920c, it is the same as the header hash of HeaderByNumber.

hash := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
	header := TestHeader{
		ParentHash:  common.HexToHash("0x369b01a19a6ffbe010a82adc6fc29d34a47888d9b476d409ef1867b1045e040a"),
		UncleHash:   common.HexToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"),
		Coinbase:    common.HexToAddress("0x0000000000000000000000000000000000000000"),
		Root:        common.HexToHash("0x5fc6d508e43a945f17b535caa40fb1f4b836259bab5019b16034531e8203d598"),
		TxHash:      common.HexToHash("0x5c6dad443c11e9cc6fcfbd1dcdceb09ed7a4deef2e041de0ba1b12709778430e"),
		ReceiptHash: common.HexToHash("0xfa316c79ddf3bc556cd8efe26b4bab92f27e9b64dda0cca321354f83fc590a59"),
		Bloom:       types.BytesToBloom(common.FromHex("0x00000000000000000002000000000000200400000000000000000000000000000000000800000000000000000080000000020000000000000000000000240000000000000000000000040008000001000000000240040010000000000800000000000800000000000000000000000020000000000000000000004010000000000000000000000000000000040000000000002000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000002000001080000000000040000000004100000001000000001000040000010000000000000000000000000000001008000000000000000008000000000")),
		Difficulty:  new(big.Int).SetUint64(0),
		Number:      new(big.Int).SetUint64(22),
		GasLimit:    30000000,
		GasUsed:     315161,
		Time:        1712654605,
		Extra:       common.FromHex("0x"),
		MixDigest:   common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
		WithdrawalsHash: &hash,
		Nonce:   types.EncodeNonce(0),
		BaseFee: new(big.Int).SetUint64(117560069),
	}
	headerHash := rlpHash(header)

And this time the result is 0xc38eb6be5423170ba3b9253737835e44c2fb2e58c9ff7107685169b1be2329a0, it is the same as the block hash from the anvil node.
So I guess there is something wrong with withdrawals_root: Some(partial_header.mix_hash) in crates/anvil/core/src/eth/block.rs.
By the way, There is no problem in this version ghcr.io/foundry-rs/foundry:nightly-4a643801d0b3855934cdec778e33e79c79971783.

I understand that your team may be busy, but I would greatly appreciate it if you could acknowledge receipt of this report and provide an estimated timeline for resolving this issue. Your prompt attention to this matter would be highly appreciated.

Thank you for your time and assistance in addressing this bug.

@YoGhurt111
Copy link
Author

It works now in nightly version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

1 participant