Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions ipa-multipoint/src/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ impl IPAProof {
let mut L_vec = Vec::with_capacity(num_points as usize);
let mut R_vec = Vec::with_capacity(num_points as usize);

assert_eq!(((num_points * 2) + 1) * 32, bytes.len() as u32);
assert!(bytes.len().is_multiple_of(32));
let expected_len = ((num_points * 2) + 1) * 32;
if bytes.len() != expected_len as usize {
return Err(IOError::new(
IOErrorKind::InvalidData,
format!(
"invalid proof length, expected {} bytes, got {} bytes",
expected_len,
bytes.len()
),
));
}

// Chunk the byte slice into 32 bytes
let mut chunks = bytes.chunks_exact(32);
Expand Down
17 changes: 16 additions & 1 deletion ipa-multipoint/src/multiproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,15 @@ impl MultiPointProof {
pub fn from_bytes(bytes: &[u8], poly_degree: usize) -> crate::IOResult<MultiPointProof> {
use crate::{IOError, IOErrorKind};

if bytes.len() < 32 {
return Err(IOError::new(
IOErrorKind::InvalidData,
"bytes length is less than 32",
));
}

let g_x_comm_bytes = &bytes[0..32];
let ipa_bytes = &bytes[32..]; // TODO: we should return a Result here incase the user gives us bad bytes
let ipa_bytes = &bytes[32..];
let point: Element = Element::from_bytes(g_x_comm_bytes.try_into().unwrap())
.map_err(|_| IOError::from(IOErrorKind::InvalidData))?;
let g_x_comm = point;
Expand Down Expand Up @@ -661,4 +668,12 @@ mod tests {
}
transcript.state
}

#[test]
fn test_from_bytes_invalid_length() {
let bytes = [0u8; 31];
let result = MultiPointProof::from_bytes(&bytes, 256);
assert!(result.is_err());
assert_eq!(result.unwrap_err().kind(), std::io::ErrorKind::InvalidData);
}
}