From eff1e117eac01167555f750f9bc6e7fea4f9a680 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Mon, 6 Apr 2026 15:03:18 +0000 Subject: [PATCH] fix: Fr::from_u64 must use big-endian encoding to match C++ msgpack format Fr::from_u64 was storing values in little-endian, but the C++ field::msgpack_unpack expects big-endian (network byte order). This was masked before because the C++ side silently reduced non-canonical values via to_montgomery_form_reduced(). After #22311 added strict non-canonical field validation (throwing for values >= modulus), values like Fr::from_u64(123) produce 0x7B<<248 which exceeds the BN254 Fr modulus (0x30...) and cause a C++ exception that propagates through the FFI boundary, aborting the Rust test process. --- barretenberg/rust/barretenberg-rs/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/rust/barretenberg-rs/src/types.rs b/barretenberg/rust/barretenberg-rs/src/types.rs index bb6fd3a0c3af..6ad04b26ecd7 100644 --- a/barretenberg/rust/barretenberg-rs/src/types.rs +++ b/barretenberg/rust/barretenberg-rs/src/types.rs @@ -7,10 +7,10 @@ use serde::{Deserialize, Serialize}; pub struct Fr(pub [u8; 32]); impl Fr { - /// Create a new field element from a u64 value (little-endian encoding) + /// Create a new field element from a u64 value (big-endian encoding, matching C++ msgpack format) pub fn from_u64(value: u64) -> Self { let mut bytes = [0u8; 32]; - bytes[0..8].copy_from_slice(&value.to_le_bytes()); + bytes[24..32].copy_from_slice(&value.to_be_bytes()); Fr(bytes) }