Skip to content

fix: anchor EVM roots by multihash digest#760

Open
eloramirez1356 wants to merge 2 commits intoceramicnetwork:mainfrom
eloramirez1356:fix/evm-anchor-root-digest
Open

fix: anchor EVM roots by multihash digest#760
eloramirez1356 wants to merge 2 commits intoceramicnetwork:mainfrom
eloramirez1356:fix/evm-anchor-root-digest

Conversation

@eloramirez1356
Copy link
Copy Markdown

Summary

This PR fixes EVM self-anchoring for Ceramic roots whose encoded CID prefix is not a fixed length.

The main bug was in cid_to_bytes32: it previously sliced the encoded CID bytes assuming a fixed 4-byte prefix before passing the value to anchorDagCbor(bytes32 root). That works for some CIDs, but fails for others because CID prefixes are varint-encoded and their length is not stable across codecs / wrappers.

This PR changes anchoring to extract the raw multihash digest directly and updates validation to compare the committed multihash digest, which is what the on-chain f(bytes32) proof format actually commits.

What changed

Anchoring fix

  • update anchor-evm/src/evm_transaction_manager.rs to derive the bytes32 root from cid.hash().digest() instead of slicing encoded CID bytes
  • add a regression test covering variable-length CID prefixes

Validation fix

  • update event-svc/src/event/validator/time.rs to compare root multihashes rather than requiring full CID equality
  • add a test showing validation succeeds when two root CIDs use different wrappers but preserve the same multihash digest

Debugging / observability

  • add targeted debug logging in:
    • anchor-evm/src/proof_builder.rs
    • anchor-service/src/merkle_tree.rs
    • anchor-evm/src/evm_transaction_manager.rs

Documentation

  • update anchor-evm/README.md to explain the bytes32 root semantics and why digest-based extraction / comparison is required

Why this is needed

The contract interface is:

function anchorDagCbor(bytes32 root) external;

Additional cleanup

The first commit contains a few small unrelated fixes required to pass the repository's current make build / make check-clippy / make check-fmt checks:

  • remove an unused struct in anchor-remote
  • add a scoped clippy::large_enum_variant allow in event
  • simplify a clippy-reported conditional in pipeline
  • apply a formatting fix in event-svc

@eloramirez1356 eloramirez1356 requested a review from a team as a code owner April 14, 2026 16:15
@eloramirez1356 eloramirez1356 requested review from stbrody and removed request for a team April 14, 2026 16:15
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