feat(types,evm)!: typed signet headers with invariant validation#223
Merged
feat(types,evm)!: typed signet headers with invariant validation#223
Conversation
Fraser999
reviewed
Apr 3, 2026
Add OnceLock-based memoization for transactions_root using the seal/unseal pattern. Wire receipts_root from trevm's new BlockOutput::receipt_root() accessor. Both roots are now set explicitly in construct_header instead of relying on Default. BREAKING: requires trevm >=0.34.2 (init4tech/trevm#155) ENG-2120 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace pub(crate) unseal with a private method and expose a processed_mut() accessor that unseals and returns &mut Vec for cross-module use. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
601663b to
bff7ba2
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fraser999
approved these changes
Apr 3, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Introduces validated newtype wrapping Sealed<Header> with invariant checks on construction. Removes SealedHeader from public API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dHeader Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tal V2 constructor Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Preserves original behavior where rootless headers have roots set to the empty trie hash (keccak256 of RLP-encoded empty list). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fraser999
approved these changes
Apr 3, 2026
Contributor
Fraser999
left a comment
There was a problem hiding this comment.
One non-blocking suggestion.
|
|
||
| /// Check that shared fields equal their defaults. | ||
| pub(crate) fn check_shared_defaults(header: &Header) -> Vec<&'static str> { | ||
| let d = Header::default(); |
Contributor
There was a problem hiding this comment.
Minor point: we could use a static DEFAULT_HEADER: LazyLock<Header> = LazyLock::new(Header::default); to avoid allocating each time here.
Use a static `LazyLock<Header>` in `check_shared_defaults` to avoid allocating a default Header on every call. Gate `check_roots_non_empty` behind `cfg(feature = "experimental")` to match its only caller. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
SignetHeaderV1andSignetHeaderV2validated newtypes overSealed<Header>to prevent downstream confusion between rootless androoted headers at the type level.
SignetHeaderV1: wrapsSealed<Header>, eagerly caches block hash.Validates that
transactions_rootandreceipts_rootareEMPTY_ROOT_HASH(the empty trie hash — preserving original behavior). Always available.
SignetHeaderV2: same wrapper, but validates roots are notEMPTY_ROOT_HASH. Behind#[cfg(feature = "experimental")]and#[deprecated]— unstable, not yet used in production.ommers_hash,state_root,withdrawals_root,blob_gas_used,excess_blob_gas,requests_hash,extra_data) on construction viaTryFrom<Header>.SignetHeaderErrorreports all violations in both directions(
must_be_default+must_not_be_default) in a single error.Design Decisions
Why newtypes over
Sealed<Header>(notHeader)? The block hash is alwaysneeded downstream. Eagerly sealing on construction avoids repeated hashing and
removes the need for separate
SealedSignetHeaderV1type aliases.Why
EMPTY_ROOT_HASH(notB256::ZERO) for V1? Alloy'sHeader::default()sets roots to
EMPTY_ROOT_HASH(keccak of the empty trie). The originalconstruct_headerused..Default::default()which producedEMPTY_ROOT_HASHroots. V1 mandates this to preserve original behavior.
Why V2 only checks
!= EMPTY_ROOT_HASH? A zero root is not a valid computedroot in practice. The check is intentionally minimal — it distinguishes "someone
computed real roots" from "roots were left at the default empty trie value."
Why feature-gated + deprecated? V2 is the future direction but the root
computation path is not yet stabilized. The
experimentalfeature gate preventsaccidental adoption. The
#[deprecated]warning ensures anyone who opts inknows the API is unstable.
Breaking Changes
SealedHeadertype alias (Sealed<Header>) removed from public APISealedBlock.headerfield type changed fromSealedHeadertoSignetHeaderV1SignetDriver::new()acceptsSignetHeaderV1instead ofSealedHeaderSignetDriver::parent()returns&SignetHeaderV1BlockResult::header()andBlockResult::journal_meta()are no longerconst fndifficulty,mix_hash,nonce) have been stripped to pass V1 validationChanges by Crate
signet-types
header.rsmodule withSignetHeaderV1,SignetHeaderV2,SignetHeaderErrorSealedBlocknow storesSignetHeaderV1instead ofSealed<Header>experimentalfeature addedsignet-evm
SignetDriverparent field and constructor useSignetHeaderV1construct_headersplit intoconstruct_header_v1()(always) andconstruct_header_v2()(experimental)experimentalfeature forwards tosignet-types/experimentaltransactions_rootviaOnceLockseal/unseal pattern (from earlier commits)signet-test-utils
SignetHeaderV1::try_from()Test Plan
cargo t -p signet-types --all-features— 54 pass (V1 + V2 validation tests)cargo t -p signet-test-utils— all passcargo clippy -p signet-types --all-features --all-targets— cleancargo clippy -p signet-types --no-default-features --all-targets— cleancargo clippy -p signet-evm --all-features --all-targets— cleancargo clippy -p signet-evm --no-default-features --all-targets— cleancargo clippy -p signet-test-utils --all-features --all-targets— cleanENG-2120
🤖 Generated with Claude Code