Skip to content

Commit

Permalink
fix: Fix reading ultrahonk proof
Browse files Browse the repository at this point in the history
  • Loading branch information
rw0x0 committed Sep 26, 2024
1 parent d9c4910 commit ee932bf
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions co-noir/ultrahonk/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,31 @@ impl<F: PrimeField> HonkProof<F> {

fn from_buffer_internal(buf: &[u8], size_included: bool) -> HonkProofResult<Self> {
let size = buf.len();
let num_elements = if size_included {
(size - Self::VEC_LEN_BYTES as usize) / Self::FIELDSIZE_BYTES as usize
} else {
size / Self::FIELDSIZE_BYTES as usize
};
let mut offset = 0;

if num_elements * Self::FIELDSIZE_BYTES as usize
+ if size_included {
Self::VEC_LEN_BYTES as usize
} else {
0
// Check sizes
let num_elements = if size_included {
let num_elements =
(size - Self::VEC_LEN_BYTES as usize) / Self::FIELDSIZE_BYTES as usize;
if num_elements * Self::FIELDSIZE_BYTES as usize + Self::VEC_LEN_BYTES as usize != size
{
return Err(HonkProofError::InvalidProofLength);
}
!= size
{
return Err(HonkProofError::InvalidProofLength);
}

let mut offset = 0;
let is_size = Self::read_u32(buf, &mut offset);
if is_size != num_elements as u32 {
return Err(HonkProofError::InvalidProofLength);
}
let read_num_elements = Self::read_u32(buf, &mut offset);
if read_num_elements != num_elements as u32 {
return Err(HonkProofError::InvalidProofLength);
}
num_elements
} else {
let num_elements = size / Self::FIELDSIZE_BYTES as usize;
if num_elements * Self::FIELDSIZE_BYTES as usize != size {
return Err(HonkProofError::InvalidProofLength);
}
num_elements
};

// Read data
let mut res = Vec::with_capacity(num_elements);
for _ in 0..num_elements {
res.push(Self::read_field_element(buf, &mut offset));
Expand Down

0 comments on commit ee932bf

Please sign in to comment.