anvil-zksync icon indicating copy to clipboard operation
anvil-zksync copied to clipboard

bug: `blockhash` differs from testnet/mainnet

Open uF4No opened this issue 1 year ago • 3 comments

🐛 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

  1. Clone https://github.com/desfero/blockhash-zksync-repro/
  2. Install deps
  3. Configure a testnet PK in the .env file.
  4. Run test vs testnet with npx hardhat test --network zkSyncSepoliaTestnet. Runs ok.
  5. Change PK for one of the rich era-test-node wallets
  6. 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.

uF4No avatar Sep 17 '24 15:09 uF4No

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 avatar Dec 02 '24 08:12 itegulov

@itegulov does it make sense to close this as based on your comment this work would primarily be done from core?

dutterbutter avatar Jan 30 '25 23:01 dutterbutter

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

itegulov avatar Jan 31 '25 09:01 itegulov