Skip to content

feat(common): encode the SNARK aggregate signature as bytes in the certificate message - #3437

Open
jpraynaud wants to merge 3 commits into
mainfrom
jpraynaud/3379-fix-snark-aggregate-signature-encoding
Open

feat(common): encode the SNARK aggregate signature as bytes in the certificate message#3437
jpraynaud wants to merge 3 commits into
mainfrom
jpraynaud/3379-fix-snark-aggregate-signature-encoding

Conversation

@jpraynaud

@jpraynaud jpraynaud commented Jul 27, 2026

Copy link
Copy Markdown
Member

Content

This PR includes the encoding of the certificate message aggregate signature by type, so SNARK and IVC proofs use the compact bytes-hex encoding while concatenation proofs remain backward compatible:

  • Encode the certificate message multi_signature field by aggregate signature type: JSON-hex for concatenation proofs (backward compatible with all deployed clients) and bytes-hex for SNARK and IVC proofs.
  • Route the genesis signatures through the native ProtocolKey codec (String::try_from) instead of an explicit bytes-hex call.
  • Keep the certificate hash and chain walking JSON-hex based, so certificate hashes stay byte-identical.

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • CHANGELOG file is updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • All check jobs of the CI have succeeded
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Issue(s)

Closes #3379

@jpraynaud jpraynaud self-assigned this Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

Test Results

     5 files  ± 0     209 suites  ±0   2h 18m 1s ⏱️ - 53m 49s
 3 369 tests  - 32   3 369 ✅  - 32  0 💤 ±0  0 ❌ ±0 
11 124 runs   - 31  11 124 ✅  - 31  0 💤 ±0  0 ❌ ±0 

Results for commit a37adb3. ± Comparison against base commit bc9d8c1.

This pull request removes 35 and adds 3 tests. Note that renamed tests count towards both.
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::index_out_of_bounds
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::index_too_large_for_circuit_range
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::indices_not_increasing
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_merkle_path_mismatch
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_swap_keep_merkle_path
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::leaf_wrong_verification_key
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_corrupt_sibling
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_flip_position
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_length_long
mithril-stm ‑ circuits::halo2::tests::golden::cases::negative::slow::merkle_path_length_short
…
mithril-aggregator ‑ database::record::certificate::tests::snark_multi_signature::snark_multi_signature_is_stored_as_bytes_hex
mithril-common ‑ messages::certificate::tests::multi_signature_encoding::concatenation_multi_signature_is_encoded_as_json_hex
mithril-common ‑ messages::certificate::tests::multi_signature_encoding::snark_multi_signature_is_encoded_as_bytes_hex

♻️ This comment has been updated with latest results.

@jpraynaud
jpraynaud temporarily deployed to testing-2-preview July 27, 2026 15:37 — with GitHub Actions Inactive
@jpraynaud
jpraynaud temporarily deployed to testing-preview July 27, 2026 15:37 — with GitHub Actions Inactive
@jpraynaud
jpraynaud force-pushed the jpraynaud/3379-fix-snark-aggregate-signature-encoding branch from 6981ddd to 897008f Compare July 28, 2026 14:14
Encode the multi-signature by type through the ProtocolKey codec: JSON-hex for concatenation (backward compatible), bytes-hex for SNARK and IVC proofs.
…codec

The record now encodes the certificate crypto fields via the ProtocolKey codec, so the served SNARK multi-signature is bytes-hex instead of JSON-hex.
Serialize the aggregate signature and proof byte vectors as byte strings instead of arrays of integers, which halves their encoded size at each nesting level.
@jpraynaud
jpraynaud force-pushed the jpraynaud/3379-fix-snark-aggregate-signature-encoding branch from 897008f to a37adb3 Compare July 28, 2026 15:39
@jpraynaud
jpraynaud requested a review from Copilot July 28, 2026 16:25
@jpraynaud
jpraynaud marked this pull request as ready for review July 28, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates how certificate-related cryptographic payloads are encoded so that SNARK/IVC proofs use a more compact byte-string CBOR representation (and bytes-hex on the wire where applicable), while keeping concatenation proofs backward compatible via JSON-hex encoding. This aligns certificate message/record serialization with the ProtocolKey codec to ensure consistent encoding decisions by aggregate signature type.

Changes:

  • Emit CBOR byte strings for proof byte vectors by using serde_bytes for SNARK/IVC proof fields and the aggregate signature CBOR envelope.
  • Route certificate message and DB record encoding through String::try_from(&ProtocolKey<...>) to centralize encoding decisions in the ProtocolKeyCodec.
  • Introduce a custom ProtocolKeyCodec for AggregateSignature that encodes concatenation as JSON-hex and (when enabled) SNARK/IVC as bytes-hex.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mithril-stm/src/protocol/aggregate_signature/signature.rs Encodes CBOR envelope proof_bytes as a CBOR byte string and updates golden CBOR fixtures accordingly.
mithril-stm/src/proof_system/halo2_snark/proof.rs Serializes SNARK circuit_proof with serde_bytes for compact CBOR bytes.
mithril-stm/src/circuits/halo2_ivc/types.rs Serializes IVC proof byte wrapper with serde_bytes for compact CBOR bytes.
mithril-stm/Cargo.toml Adds serde_bytes dependency (and ignores it for cargo-machete).
mithril-common/src/messages/certificate.rs Uses ProtocolKey codec (String::try_from) for certificate crypto fields; adds tests for multi-signature encoding by type.
mithril-common/src/crypto_helper/types/wrappers.rs Implements custom ProtocolKeyCodec for AggregateSignature to encode by signature type (JSON-hex vs bytes-hex).
mithril-aggregator/src/database/record/certificate.rs Stores certificate signatures/keys via ProtocolKey codec (String::try_from) and adds a test for SNARK multi-signature storage encoding.
Cargo.lock Locks the new serde_bytes dependency.

@jpraynaud
jpraynaud temporarily deployed to testing-2-preview July 28, 2026 16:33 — with GitHub Actions Inactive
@jpraynaud
jpraynaud temporarily deployed to testing-preview July 28, 2026 16:33 — with GitHub Actions Inactive

@damrobi damrobi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

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.

Use bytes encoding for aggregate signature in certificate message

3 participants