Skip to content

fix: BN254 G2 msgpack serialization in barretenberg-rs#22360

Open
johnathan79717 wants to merge 4 commits intomerge-train/barretenbergfrom
jh/fix-bn254-g2-serde
Open

fix: BN254 G2 msgpack serialization in barretenberg-rs#22360
johnathan79717 wants to merge 4 commits intomerge-train/barretenbergfrom
jh/fix-bn254-g2-serde

Conversation

@johnathan79717
Copy link
Copy Markdown
Contributor

Summary

  • Fix missing serde_bytes handling for field2 primitive type ([Vec<u8>; 2]) in Rust codegen, which caused Bn254G2Point fields to serialize as msgpack integer arrays instead of bin32 blobs. The C++ backend expects bin32, so bn254_g2_mul would abort on deserialization.
  • Add serde_array2_bytes module (same pattern as existing serde_array4_bytes) and detection logic in the codegen.
  • Add FFI tests for bn254_g1_mul and bn254_g2_mul using the EIP-197 G2 generator.

Fixes AztecProtocol/barretenberg#1669. Reported by Porco from Obsidion.

Test plan

  • test_bn254_g1_mul_by_one passes (baseline, confirms G1 serialization is correct)
  • test_bn254_g2_mul_by_one passes (1 * G2 = G2, confirms fix)
  • test_bn254_g2_mul_by_two passes (2 * G2 != G2, confirms non-trivial operation works)
  • CI passes

Commands used:

BB_LIB_DIR=barretenberg/cpp/build/lib cargo test -p barretenberg-tests --features ffi -- bn254_g

G2 tests currently fail due to missing serde_bytes annotations on
Bn254G2Point fields (AztecProtocol/barretenberg#1669).
The Rust codegen was missing serde handling for the field2 primitive
type ([Vec<u8>; 2]), causing Bn254G2Point fields to serialize as
msgpack integer arrays instead of bin32 blobs. The C++ backend expects
bin32, so G2 operations would abort on deserialization.

Fixes AztecProtocol/barretenberg#1669
Verify 2*(3*G) == 3*(2*G) for both G1 and G2 instead of just
multiplying by 1.
@johnathan79717 johnathan79717 added the ci-barretenberg-full Run all barretenberg checks. label Apr 7, 2026
@johnathan79717 johnathan79717 enabled auto-merge (squash) April 7, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-barretenberg-full Run all barretenberg checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant