Skip to content

Commit eff1e11

Browse files
committed
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.
1 parent 5f09c55 commit eff1e11

File tree

1 file changed

+2
-2
lines changed
  • barretenberg/rust/barretenberg-rs/src

1 file changed

+2
-2
lines changed

barretenberg/rust/barretenberg-rs/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use serde::{Deserialize, Serialize};
77
pub struct Fr(pub [u8; 32]);
88

99
impl Fr {
10-
/// Create a new field element from a u64 value (little-endian encoding)
10+
/// Create a new field element from a u64 value (big-endian encoding, matching C++ msgpack format)
1111
pub fn from_u64(value: u64) -> Self {
1212
let mut bytes = [0u8; 32];
13-
bytes[0..8].copy_from_slice(&value.to_le_bytes());
13+
bytes[24..32].copy_from_slice(&value.to_be_bytes());
1414
Fr(bytes)
1515
}
1616

0 commit comments

Comments
 (0)