Skip to content

refactor(rpc): type the MMR proof leaf as a fixed 32-byte array - #237

Merged
prajwolrg merged 1 commit into
mainfrom
fix/mmr-proof-leaf-fixed-size
Aug 18, 2026
Merged

refactor(rpc): type the MMR proof leaf as a fixed 32-byte array#237
prajwolrg merged 1 commit into
mainfrom
fix/mmr-proof-leaf-fixed-size

Conversation

@prajwolrg

Copy link
Copy Markdown
Collaborator

Description

getExportEntryMMRProof took its leaf parameter as Vec<u8>, but the only thing the endpoint can do with a leaf is look it up as a 32-byte entry hash. build_export_entry_mmr_proof did the length check itself and returned InvalidLeafLength for anything else, so the wire type was looser than the code behind it. The practical effect was that a wrong-sized leaf still cost a get_block_height round trip to bitcoind before being rejected.

Typing the parameter as [u8; 32] pushes the check into jsonrpsee's parameter deserialization, ahead of the handler. The signature now says what the builder already enforced, and the error variant is no longer reachable, so it is gone along with the test that covered it.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests
  • Dependency update
  • Security fix

Notes to Reviewers

The JSON wire format does not change. Vec<u8> and [u8; 32] both serialize as an array of 32 numbers, so any well-formed request that worked before still works. What changes for a malformed request is where it fails: a jsonrpsee parameter parse error instead of an application error from the handler.

The generated client signature does change for anyone building this crate with the client feature, since the parameter type is part of it. Nothing in this repo calls it.

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.

The removed test asserted the error the type system now makes unrepresentable, so there is nothing left to test at that layer. The remaining build_export_entry_mmr_proof tests pass unchanged.

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bin/asm-runner/src/rpc_server.rs 97.81% <100.00%> (-0.11%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

Commit: 8fd2a73
SP1 Execution Results

program cycles gas
asm-stf 136,427,562 134,143,979
moho 5,223,688 5,525,436

The proof builder already required exactly 32 bytes and rejected
anything else with InvalidLeafLength, but the wire type was Vec<u8>.
A wrong-sized leaf was therefore only caught after the handler had
resolved the block commitment through a bitcoind height lookup.

Typing the parameter as [u8; 32] moves the check into parameter
deserialization and makes the signature state the invariant the builder
already enforces, which lets the error variant go away. Well-formed
requests are unaffected: both types encode as an array of 32 numbers.
@prajwolrg
prajwolrg force-pushed the fix/mmr-proof-leaf-fixed-size branch from 20de155 to 2e19251 Compare August 18, 2026 02:25
@prajwolrg
prajwolrg marked this pull request as ready for review August 18, 2026 02:38
@github-actions

Copy link
Copy Markdown

🔒 AI Security Review (claude-opus-5)

✅ No security issues found.

@prajwolrg
prajwolrg merged commit a844986 into main Aug 18, 2026
26 checks passed
@prajwolrg
prajwolrg deleted the fix/mmr-proof-leaf-fixed-size branch August 18, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant