From 63607e13c07d80f8d84708f2c03a51e578ae92a5 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Wed, 20 Dec 2023 18:11:50 -0700 Subject: [PATCH 1/6] feat: add (de)compress trait in bls module --- src/bls.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bls.rs b/src/bls.rs index c983152..550bbcf 100644 --- a/src/bls.rs +++ b/src/bls.rs @@ -47,6 +47,20 @@ impl From for Error { } } +/// A data structure that can be serialized into the compressed format defined by Zcash. +/// +/// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md +pub trait Compress { + fn compress(&self, buf: impl AsMut<[u8]>) -> Result; +} + +/// A data structure that can be deserialized from the compressed format defined by Zcash. +/// +/// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md +pub trait Decompress: Sized { + fn decompress(compressed: impl AsRef<[u8]>) -> Result; +} + #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct Scalar { element: blst_scalar, From 899affc3a88f7937738ac60b580782dc487ba2b3 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 7 Mar 2024 11:53:26 -0700 Subject: [PATCH 2/6] impl (de)compress traits for group elements --- src/blob.rs | 7 ++- src/bls.rs | 129 ++++++++++++++++++++++++++++------------------- src/kzg/setup.rs | 28 +++++----- 3 files changed, 98 insertions(+), 66 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index adcfc6b..4779f87 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -1,5 +1,5 @@ use crate::{ - bls::{FiniteFieldError, Fr, P1}, + bls::{Compress, FiniteFieldError, Fr, P1}, kzg::{Commitment, Polynomial, Proof, Setup}, }; @@ -69,7 +69,10 @@ impl Blob { const DOMAIN: &[u8; 16] = b"FSBLOBVERIFY_V1_"; let degree = (N as u128).to_be_bytes(); - let comm = commitment.serialize(); + let mut comm = [0u8; Commitment::BYTES]; + let _ = commitment + .compress(comm.as_mut_slice()) + .expect("sufficient buffer len"); let mut data = Vec::with_capacity(8 + 16 + Commitment::BYTES + Self::BYTES); data.extend_from_slice(DOMAIN); diff --git a/src/bls.rs b/src/bls.rs index 6908684..994996f 100644 --- a/src/bls.rs +++ b/src/bls.rs @@ -10,11 +10,12 @@ use blst::{ blst_fr, blst_fr_add, blst_fr_cneg, blst_fr_eucl_inverse, blst_fr_from_scalar, blst_fr_from_uint64, blst_fr_lshift, blst_fr_mul, blst_fr_rshift, blst_fr_sub, blst_lendian_from_scalar, blst_miller_loop, blst_p1, blst_p1_add, blst_p1_affine, - blst_p1_affine_in_g1, blst_p1_cneg, blst_p1_compress, blst_p1_deserialize, blst_p1_from_affine, - blst_p1_mult, blst_p1_to_affine, blst_p2, blst_p2_add, blst_p2_affine, blst_p2_affine_in_g2, - blst_p2_deserialize, blst_p2_from_affine, blst_p2_mult, blst_p2_to_affine, blst_scalar, - blst_scalar_fr_check, blst_scalar_from_bendian, blst_scalar_from_fr, blst_sha256, - blst_uint64_from_fr, p1_affines, BLS12_381_G2, BLS12_381_NEG_G1, BLS12_381_NEG_G2, BLST_ERROR, + blst_p1_affine_in_g1, blst_p1_cneg, blst_p1_compress, blst_p1_from_affine, blst_p1_mult, + blst_p1_to_affine, blst_p1_uncompress, blst_p2, blst_p2_add, blst_p2_affine, + blst_p2_affine_in_g2, blst_p2_compress, blst_p2_from_affine, blst_p2_mult, blst_p2_to_affine, + blst_p2_uncompress, blst_scalar, blst_scalar_fr_check, blst_scalar_from_bendian, + blst_scalar_from_fr, blst_sha256, blst_uint64_from_fr, p1_affines, BLS12_381_G2, + BLS12_381_NEG_G1, BLS12_381_NEG_G2, BLST_ERROR, }; #[derive(Clone, Copy, Debug)] @@ -52,14 +53,16 @@ impl From for Error { /// /// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md pub trait Compress { - fn compress(&self, buf: impl AsMut<[u8]>) -> Result; + fn compress(&self, buf: impl AsMut<[u8]>) -> Result; } /// A data structure that can be deserialized from the compressed format defined by Zcash. /// /// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md pub trait Decompress: Sized { - fn decompress(compressed: impl AsRef<[u8]>) -> Result; + type Error; + + fn decompress(compressed: impl AsRef<[u8]>) -> Result; } #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] @@ -369,37 +372,6 @@ impl P1 { pub const BITS: usize = 384; pub const BYTES: usize = Self::BITS / 8; - pub fn deserialize(bytes: impl AsRef<[u8; Self::BYTES]>) -> Result { - let mut affine = MaybeUninit::::uninit(); - let mut out = MaybeUninit::::uninit(); - unsafe { - // NOTE: deserialize performs a curve check but not a subgroup check. if that changes, - // then we should encounter `unreachable` for `BLST_POINT_NOT_IN_GROUP` in tests. - match blst_p1_deserialize(affine.as_mut_ptr(), bytes.as_ref().as_ptr()) { - BLST_ERROR::BLST_SUCCESS => {} - BLST_ERROR::BLST_BAD_ENCODING => return Err(ECGroupError::InvalidEncoding), - BLST_ERROR::BLST_POINT_NOT_ON_CURVE => return Err(ECGroupError::NotOnCurve), - other => unreachable!("{other:?}"), - } - if !blst_p1_affine_in_g1(affine.as_ptr()) { - return Err(ECGroupError::NotInGroup); - } - - blst_p1_from_affine(out.as_mut_ptr(), affine.as_ptr()); - Ok(Self { - element: out.assume_init(), - }) - } - } - - pub fn serialize(&self) -> [u8; Self::BYTES] { - let mut out = [0; Self::BYTES]; - unsafe { - blst_p1_compress(out.as_mut_ptr(), &self.element); - } - out - } - pub fn lincomb(points: impl AsRef<[Self]>, scalars: impl AsRef<[Fr]>) -> Self { let n = cmp::min(points.as_ref().len(), scalars.as_ref().len()); let mut lincomb = Self::INF; @@ -520,37 +492,53 @@ impl Neg for P1 { } } -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] -pub struct P2 { - element: blst_p2, +impl Compress for P1 { + fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result { + if buf.as_mut().len() < Self::BYTES { + return Err("insufficient buffer length"); + } + unsafe { + blst_p1_compress(buf.as_mut().as_mut_ptr(), &self.element); + } + Ok(Self::BYTES) + } } -impl P2 { - pub const BITS: usize = 768; - pub const BYTES: usize = Self::BITS / 8; +impl Decompress for P1 { + type Error = ECGroupError; - pub fn deserialize(bytes: impl AsRef<[u8; Self::BYTES]>) -> Result { - let mut affine = MaybeUninit::::uninit(); - let mut out = MaybeUninit::::uninit(); + fn decompress(compressed: impl AsRef<[u8]>) -> Result { + let mut affine = MaybeUninit::::uninit(); + let mut out = MaybeUninit::::uninit(); unsafe { - // NOTE: deserialize performs a curve check but not a subgroup check. if that changes, + // NOTE: uncompress performs a curve check but not a subgroup check. if that changes, // then we should encounter `unreachable` for `BLST_POINT_NOT_IN_GROUP` in tests. - match blst_p2_deserialize(affine.as_mut_ptr(), bytes.as_ref().as_ptr()) { + match blst_p1_uncompress(affine.as_mut_ptr(), compressed.as_ref().as_ptr()) { BLST_ERROR::BLST_SUCCESS => {} BLST_ERROR::BLST_BAD_ENCODING => return Err(ECGroupError::InvalidEncoding), BLST_ERROR::BLST_POINT_NOT_ON_CURVE => return Err(ECGroupError::NotOnCurve), other => unreachable!("{other:?}"), } - if !blst_p2_affine_in_g2(affine.as_ptr()) { + if !blst_p1_affine_in_g1(affine.as_ptr()) { return Err(ECGroupError::NotInGroup); } - blst_p2_from_affine(out.as_mut_ptr(), affine.as_ptr()); + blst_p1_from_affine(out.as_mut_ptr(), affine.as_ptr()); Ok(Self { element: out.assume_init(), }) } } +} + +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +pub struct P2 { + element: blst_p2, +} + +impl P2 { + pub const BITS: usize = 768; + pub const BYTES: usize = Self::BITS / 8; // TODO: make available as `const` pub fn generator() -> Self { @@ -622,6 +610,45 @@ impl Mul for P2 { } } +impl Compress for P2 { + fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result { + if buf.as_mut().len() < Self::BYTES { + return Err("insufficient buffer length"); + } + unsafe { + blst_p2_compress(buf.as_mut().as_mut_ptr(), &self.element); + } + Ok(Self::BYTES) + } +} + +impl Decompress for P2 { + type Error = ECGroupError; + + fn decompress(compressed: impl AsRef<[u8]>) -> Result { + let mut affine = MaybeUninit::::uninit(); + let mut out = MaybeUninit::::uninit(); + unsafe { + // NOTE: uncompress performs a curve check but not a subgroup check. if that changes, + // then we should encounter `unreachable` for `BLST_POINT_NOT_IN_GROUP` in tests. + match blst_p2_uncompress(affine.as_mut_ptr(), compressed.as_ref().as_ptr()) { + BLST_ERROR::BLST_SUCCESS => {} + BLST_ERROR::BLST_BAD_ENCODING => return Err(ECGroupError::InvalidEncoding), + BLST_ERROR::BLST_POINT_NOT_ON_CURVE => return Err(ECGroupError::NotOnCurve), + other => unreachable!("{other:?}"), + } + if !blst_p2_affine_in_g2(affine.as_ptr()) { + return Err(ECGroupError::NotInGroup); + } + + blst_p2_from_affine(out.as_mut_ptr(), affine.as_ptr()); + Ok(Self { + element: out.assume_init(), + }) + } + } +} + pub fn verify_pairings((a1, a2): (P1, P2), (b1, b2): (P1, P2)) -> bool { let mut a1_neg_affine = MaybeUninit::::uninit(); let mut a2_affine = MaybeUninit::::uninit(); diff --git a/src/kzg/setup.rs b/src/kzg/setup.rs index b3da0f5..aec17be 100644 --- a/src/kzg/setup.rs +++ b/src/kzg/setup.rs @@ -7,7 +7,7 @@ use std::{ use super::{Commitment, Polynomial, Proof}; use crate::{ blob::Blob, - bls::{self, ECGroupError, Error as BlsError, Fr, P1, P2}, + bls::{self, Decompress, ECGroupError, Error as BlsError, Fr, P1, P2}, math, }; @@ -60,7 +60,7 @@ impl Setup { // TODO: skip unnecessary allocation let point = FixedBytes::<48>::from_slice(point); let point = - P1::deserialize(point).map_err(|err| LoadSetupError::Bls(BlsError::from(err)))?; + P1::decompress(point).map_err(|err| LoadSetupError::Bls(BlsError::from(err)))?; g1_lagrange[i] = point; } let g1_lagrange_brp = math::bit_reversal_permutation_boxed_array(g1_lagrange.as_slice()); @@ -75,7 +75,7 @@ impl Setup { // TODO: skip unnecessary allocation let point = FixedBytes::<96>::from_slice(point); let point = - P2::deserialize(point).map_err(|err| LoadSetupError::Bls(BlsError::from(err)))?; + P2::decompress(point).map_err(|err| LoadSetupError::Bls(BlsError::from(err)))?; g2_monomial[i] = point; } @@ -196,6 +196,8 @@ impl Setup { #[cfg(test)] mod tests { + use self::bls::Decompress; + use super::*; use crate::blob::Blob; @@ -287,7 +289,7 @@ mod tests { return Err(()); } let commitment = FixedBytes::<{ Commitment::BYTES }>::from_slice(&unchecked.commitment); - let commitment = Commitment::deserialize(commitment).map_err(|_| ())?; + let commitment = Commitment::decompress(commitment).map_err(|_| ())?; Ok(Self { blob, commitment }) } } @@ -319,7 +321,7 @@ mod tests { return Err(()); } let commitment = FixedBytes::<{ Commitment::BYTES }>::from_slice(&unchecked.commitment); - let commitment = Commitment::deserialize(commitment).map_err(|_| ())?; + let commitment = Commitment::decompress(commitment).map_err(|_| ())?; let z = Fr::from_be_slice(unchecked.z).map_err(|_| ())?; let y = Fr::from_be_slice(unchecked.y).map_err(|_| ())?; @@ -328,7 +330,7 @@ mod tests { return Err(()); } let proof = FixedBytes::<{ Proof::BYTES }>::from_slice(&unchecked.proof); - let proof = Proof::deserialize(proof).map_err(|_| ())?; + let proof = Proof::decompress(proof).map_err(|_| ())?; Ok(Self { commitment, @@ -365,12 +367,12 @@ mod tests { return Err(()); } let commitment = FixedBytes::<{ Commitment::BYTES }>::from_slice(&unchecked.commitment); - let commitment = Commitment::deserialize(commitment).map_err(|_| ())?; + let commitment = Commitment::decompress(commitment).map_err(|_| ())?; if unchecked.proof.len() != Proof::BYTES { return Err(()); } let proof = FixedBytes::<{ Proof::BYTES }>::from_slice(&unchecked.proof); - let proof = Proof::deserialize(proof).map_err(|_| ())?; + let proof = Proof::decompress(proof).map_err(|_| ())?; Ok(Self { blob, commitment, @@ -420,7 +422,7 @@ mod tests { return Err(()); } let commitment = FixedBytes::<{ Commitment::BYTES }>::from_slice(&commitment); - let commitment = Commitment::deserialize(commitment).map_err(|_| ())?; + let commitment = Commitment::decompress(commitment).map_err(|_| ())?; commitments.push(commitment); } @@ -430,7 +432,7 @@ mod tests { return Err(()); } let proof = FixedBytes::<{ Proof::BYTES }>::from_slice(&proof); - let proof = Proof::deserialize(proof).map_err(|_| ())?; + let proof = Proof::decompress(proof).map_err(|_| ())?; proofs.push(proof); } @@ -478,7 +480,7 @@ mod tests { Ok(input) => { let (proof, eval) = case.output.unwrap(); let expected_eval = Fr::from_be_bytes(eval).unwrap(); - let expected_proof = P1::deserialize(proof).unwrap(); + let expected_proof = P1::decompress(proof).unwrap(); let poly = Polynomial(&input.blob.elements); let eval = poly.evaluate(input.z, &setup); @@ -508,7 +510,7 @@ mod tests { match ComputeBlobKzgProofInput::from_unchecked(case.input) { Ok(input) => { let proof = case.output.unwrap(); - let proof = P1::deserialize(proof).unwrap(); + let proof = P1::decompress(proof).unwrap(); let expected_proof = Proof::from(proof); let proof = setup.blob_proof(&input.blob, &input.commitment); @@ -537,7 +539,7 @@ mod tests { match BlobToCommitmentInput::from_unchecked(case.input) { Ok(input) => { let comm = case.output.unwrap(); - let comm = P1::deserialize(comm).unwrap(); + let comm = P1::decompress(comm).unwrap(); let expected_comm = Commitment::from(comm); let comm = input.blob.commitment(&setup); From cd674dea0f3ee092e3ce2eedba8ee8b949b0b586 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 7 Mar 2024 12:35:24 -0700 Subject: [PATCH 3/6] chore: cargo fmt --- src/kzg/setup.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/kzg/setup.rs b/src/kzg/setup.rs index ed44fec..8167b7d 100644 --- a/src/kzg/setup.rs +++ b/src/kzg/setup.rs @@ -275,8 +275,7 @@ impl Setup { .collect(); let commitments = commitments.map_err(|err| Error::from(BlsError::ECGroup(err)))?; - let proofs: Result, _> = - proofs.as_ref().iter().map(Proof::decompress).collect(); + let proofs: Result, _> = proofs.as_ref().iter().map(Proof::decompress).collect(); let proofs = proofs.map_err(|err| Error::from(BlsError::ECGroup(err)))?; let verified = self.verify_blob_proof_batch_inner(blobs, commitments, proofs); @@ -288,10 +287,13 @@ impl Setup { mod tests { use super::*; - use crate::{bls::Compress, kzg::spec::{ - BlobToCommitment, ComputeBlobProof, ComputeProof, VerifyBlobProof, VerifyBlobProofBatch, - VerifyProof, - }}; + use crate::{ + bls::Compress, + kzg::spec::{ + BlobToCommitment, ComputeBlobProof, ComputeProof, VerifyBlobProof, + VerifyBlobProofBatch, VerifyProof, + }, + }; use std::{ fs::{self, File}, From a52446398741de994dd8b9a2e32f5206edaa16dd Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 7 Mar 2024 12:54:12 -0700 Subject: [PATCH 4/6] fix benches --- benches/kzg.rs | 25 +++++++++++++++---------- src/lib.rs | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/benches/kzg.rs b/benches/kzg.rs index 512dcca..22c4b19 100644 --- a/benches/kzg.rs +++ b/benches/kzg.rs @@ -1,6 +1,7 @@ use kateth::{ blob::Blob, - kzg::{Bytes48, Setup}, + kzg::{Commitment, Proof, Setup}, + Compress, }; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput}; @@ -17,15 +18,19 @@ pub fn benchmark(c: &mut Criterion) { let blobs: Vec> = (0..max_batch_size) .map(|_| Blob::<4096>::random(&mut rng).to_bytes()) .collect(); - let commitments: Vec = blobs - .iter() - .map(|blob| kzg.blob_to_commitment(blob).unwrap().serialize()) - .collect(); - let proofs: Vec = blobs - .iter() - .zip(commitments.iter()) - .map(|(blob, commitment)| kzg.blob_proof(blob, commitment).unwrap().serialize()) - .collect(); + let mut commitments = Vec::with_capacity(blobs.len()); + let mut proofs = Vec::with_capacity(blobs.len()); + for blob in &blobs { + let commitment = kzg.blob_to_commitment(blob).unwrap(); + let mut bytes = [0u8; Commitment::BYTES]; + commitment.compress(&mut bytes).unwrap(); + commitments.push(bytes); + + let proof = kzg.blob_proof(blob, &bytes).unwrap(); + let mut bytes = [0u8; Proof::BYTES]; + proof.compress(&mut bytes).unwrap(); + proofs.push(bytes); + } c.bench_function("blob to kzg commitment", |b| { b.iter(|| kzg.blob_to_commitment(&blobs[0])) diff --git a/src/lib.rs b/src/lib.rs index 9ed498a..611fc29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ mod bls; mod math; +pub use bls::{Compress, Decompress}; pub mod blob; pub mod kzg; From 32f21ec3bc71299e68df359570e8046bc591b234 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 7 Mar 2024 13:35:54 -0700 Subject: [PATCH 5/6] add const to Compress trait and more documentation --- src/blob.rs | 2 +- src/bls.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index 3fe8dc8..c05ab01 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -80,7 +80,7 @@ impl Blob { let degree = (N as u128).to_be_bytes(); let mut comm = [0u8; Commitment::BYTES]; - let _ = commitment + commitment .compress(comm.as_mut_slice()) .expect("sufficient buffer len"); diff --git a/src/bls.rs b/src/bls.rs index 994996f..ccabdc1 100644 --- a/src/bls.rs +++ b/src/bls.rs @@ -53,15 +53,25 @@ impl From for Error { /// /// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md pub trait Compress { - fn compress(&self, buf: impl AsMut<[u8]>) -> Result; + /// The length in bytes of the compressed representation of `self`. + const COMPRESSED: usize; + + /// Compresses `self` into `buf`. + /// + /// # Errors + /// + /// Compression will fail if the length of `buf` is less than `Self::COMPRESSED`. + fn compress(&self, buf: impl AsMut<[u8]>) -> Result<(), &'static str>; } /// A data structure that can be deserialized from the compressed format defined by Zcash. /// /// github.com/zkcrypto/pairing/blob/34aa52b0f7bef705917252ea63e5a13fa01af551/src/bls12_381/README.md pub trait Decompress: Sized { + /// The error that can occur upon decompression. type Error; + /// Decompresses `compressed` into `Self`. fn decompress(compressed: impl AsRef<[u8]>) -> Result; } @@ -493,14 +503,16 @@ impl Neg for P1 { } impl Compress for P1 { - fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result { - if buf.as_mut().len() < Self::BYTES { + const COMPRESSED: usize = Self::BYTES; + + fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result<(), &'static str> { + if buf.as_mut().len() < Self::COMPRESSED { return Err("insufficient buffer length"); } unsafe { blst_p1_compress(buf.as_mut().as_mut_ptr(), &self.element); } - Ok(Self::BYTES) + Ok(()) } } @@ -611,14 +623,16 @@ impl Mul for P2 { } impl Compress for P2 { - fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result { + const COMPRESSED: usize = Self::BYTES; + + fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result<(), &'static str> { if buf.as_mut().len() < Self::BYTES { return Err("insufficient buffer length"); } unsafe { blst_p2_compress(buf.as_mut().as_mut_ptr(), &self.element); } - Ok(Self::BYTES) + Ok(()) } } From 80b059d68125ba8fa7c501dd134b9e5043c15093 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 7 Mar 2024 13:53:32 -0700 Subject: [PATCH 6/6] use Compress::COMPRESSED const in favor of group element const --- benches/kzg.rs | 4 ++-- src/blob.rs | 2 +- src/bls.rs | 2 +- src/kzg/setup.rs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benches/kzg.rs b/benches/kzg.rs index 22c4b19..4e7d28a 100644 --- a/benches/kzg.rs +++ b/benches/kzg.rs @@ -22,12 +22,12 @@ pub fn benchmark(c: &mut Criterion) { let mut proofs = Vec::with_capacity(blobs.len()); for blob in &blobs { let commitment = kzg.blob_to_commitment(blob).unwrap(); - let mut bytes = [0u8; Commitment::BYTES]; + let mut bytes = [0u8; Commitment::COMPRESSED]; commitment.compress(&mut bytes).unwrap(); commitments.push(bytes); let proof = kzg.blob_proof(blob, &bytes).unwrap(); - let mut bytes = [0u8; Proof::BYTES]; + let mut bytes = [0u8; Proof::COMPRESSED]; proof.compress(&mut bytes).unwrap(); proofs.push(bytes); } diff --git a/src/blob.rs b/src/blob.rs index c05ab01..dc05f80 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -79,7 +79,7 @@ impl Blob { const DOMAIN: &[u8; 16] = b"FSBLOBVERIFY_V1_"; let degree = (N as u128).to_be_bytes(); - let mut comm = [0u8; Commitment::BYTES]; + let mut comm = [0u8; Commitment::COMPRESSED]; commitment .compress(comm.as_mut_slice()) .expect("sufficient buffer len"); diff --git a/src/bls.rs b/src/bls.rs index ccabdc1..82b7090 100644 --- a/src/bls.rs +++ b/src/bls.rs @@ -626,7 +626,7 @@ impl Compress for P2 { const COMPRESSED: usize = Self::BYTES; fn compress(&self, mut buf: impl AsMut<[u8]>) -> Result<(), &'static str> { - if buf.as_mut().len() < Self::BYTES { + if buf.as_mut().len() < Self::COMPRESSED { return Err("insufficient buffer length"); } unsafe { diff --git a/src/kzg/setup.rs b/src/kzg/setup.rs index 8167b7d..2e97e99 100644 --- a/src/kzg/setup.rs +++ b/src/kzg/setup.rs @@ -345,7 +345,7 @@ mod tests { continue; }; let (expected_proof, expected_y) = expected.unwrap(); - let mut proof_bytes = [0u8; Proof::BYTES]; + let mut proof_bytes = [0u8; Proof::COMPRESSED]; proof.compress(&mut proof_bytes).unwrap(); assert_eq!(proof_bytes, expected_proof); assert_eq!(y.to_be_bytes(), expected_y); @@ -371,7 +371,7 @@ mod tests { continue; }; let expected = expected.unwrap(); - let mut proof_bytes = [0u8; Proof::BYTES]; + let mut proof_bytes = [0u8; Proof::COMPRESSED]; proof.compress(&mut proof_bytes).unwrap(); assert_eq!(proof_bytes, expected); } @@ -393,7 +393,7 @@ mod tests { continue; }; let expected = expected.unwrap(); - let mut commitment_bytes = [0u8; Commitment::BYTES]; + let mut commitment_bytes = [0u8; Commitment::COMPRESSED]; commitment.compress(&mut commitment_bytes).unwrap(); assert_eq!(commitment_bytes, expected); }