Skip to content

ethexe: typed MB/EB hashes via HashOf<MB> and HashOf<EB> #5507

Description

@grishasobol

Problem

H256 is the lingua franca for many distinct hash kinds across ethexe — Ethereum block hashes, malachite envelope hashes, payload digests, etc. Mixing them at signature level is dangerous; the most visible footgun today is the MB hash vs the EB (Ethereum block) hash, which both appear in CompactMb, in MalachiteEvent, and in the MbStorageRO/RW trait surface as bare H256. Compiler can't help when a caller swaps one for the other.

Goal

  • Add ethexe-common as a dep of ethexe-malachite-core (currently leaf-isolated).
  • Move ethexe_malachite_core::Block to ethexe_common::malachite::MB (carrying parent_hash: HashOf<MB>, height: u64, payload: BlockPayload, reserved: [u8; 64]). BlockPayload moves with it.
  • Restructure CompactMb: same fields as MB but with payload_hash: H256 in place of BlockPayload. Move it to ethexe_common::malachite alongside MB.
  • Replace H256 with HashOf<MB> everywhere it represents a malachite block hash: trait sigs in MbStorageRO/RW, DBGlobals::latest_finalized_mb_hash, Externalities callbacks, CommitCertificate::block_hash, MalachiteEvent::*::mb_hash, etc.
  • Introduce pub type EB = SimpleBlockData; and a SimpleBlockData::typed_hash() -> HashOf<EB> that lifts the existing Ethereum block hash into the typed wrapper without recomputing.

HashOf<T> encodes/decodes as 32 bytes (phantom is #[codec(skip)]), so the wire format stays byte-identical to bare H256.

Non-goals

  • No data migrations — DB can change shape freely on this branch.

Acceptance

  • ethexe-common::malachite exports MB, BlockPayload, CompactMb, EB.
  • MbStorageRO/RW keys take HashOf<MB> not H256.
  • DBGlobals::latest_finalized_mb_hash, CompactMb::parent, Externalities callback hash args all typed.
  • All ethexe-* tests pass.

Metadata

Metadata

Assignees

Labels

scope: vara.ethVara Ethereum application layer (L2)type: refactorInternal improvements without changing behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions