anvil-zksync
anvil-zksync copied to clipboard
bug: `blockhash` differs from testnet/mainnet
🐛 Bug Report for zkSync Era In-Memory Node
📝 Description
When a new block is produced, the algorithm used to generate the blockhash is different than the one used in testnet/mainnet. This causes issues when accessing blockshash(blocknumber) in Solidity and compare its result with the hash returned by the RPC getBlock as they're different.
🔄 Reproduction Steps
- Clone https://github.com/desfero/blockhash-zksync-repro/
- Install deps
- Configure a testnet PK in the
.envfile. - Run test vs testnet with
npx hardhat test --network zkSyncSepoliaTestnet. Runs ok. - Change PK for one of the rich era-test-node wallets
- Run test vs era-test-node with
npx hardhat test --network inMemoryNode. Test fails
🤔 Expected Behavior
Same blockhash in Solidity and RPC for the same block
😯 Current Behavior
Blockhash differs in Solidity and RPC for the same block
🖥️ Environment
- Rust version: rustc 1.77.2 (25ef9e3d8 2024-04-09)
- Operating System & Version: MacOS Sonoma 14.4.1
- Other relevant environment details: era_test_node 0.1.0-alpha.27
📋 Additional Context
N/A
📎 Log Output
Paste any relevant log output here.
Moving some thoughts from https://github.com/matter-labs/era-test-node/issues/364 to here.
Indeed, era-test-node uses a placeholder block hash computation function that produces different results from zksync-era. My assumption was that this is perhaps not easily observable by users but thanks for proving me wrong that there is actual demand for this.
I think the most sane way to fix this would be to make a significant refactoring of metadata_calculator from core so that it is agnostic to where the data is coming from (it is heavily intertwined with PG connections right now).
@itegulov does it make sense to close this as based on your comment this work would primarily be done from core?
Most of the work needs to be done from core side but realistically has to be driven from our side as there is zero demand for having storage-agnostic metadata calculator otherwise