Skip to content

Commit

Permalink
Backport: Fix byte ordering in encoding of aggregation guest state (#410
Browse files Browse the repository at this point in the history
) (#411)
  • Loading branch information
nategraf authored Jan 23, 2025
1 parent db265a8 commit 3c2a605
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/aggregation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ impl MerkleMountainRange {
bitmap.set_bit(peak.max_depth as usize, true);
peaks.push(peak.digest);
}
[&bitmap.as_le_bytes(), bytemuck::cast_slice(&peaks)].concat()
[
&bitmap.to_be_bytes::<{ U256::BYTES }>(),
bytemuck::cast_slice(&peaks),
]
.concat()
}

/// Decode the specialized journal encoding. See [MerkleMountainRange::encode].
Expand All @@ -316,7 +320,7 @@ impl MerkleMountainRange {
.as_ref()
.split_at_checked(U256::BYTES)
.ok_or(DecodingError::UnexpectedEnd)?;
let bitmap = U256::from_le_slice(chunk);
let bitmap = U256::from_be_slice(chunk);
if bitmap > (uint!(1_U256 << u8::MAX)) {
// When the leading bit is set, it must be finalized. Any value above 2^255 is invalid.
return Err(DecodingError::InvalidBitmap);
Expand Down

0 comments on commit 3c2a605

Please sign in to comment.