Skip to content

Commit

Permalink
use commitment type in blob
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Feb 7, 2025
1 parent 0ab9cc0 commit 3940789
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
21 changes: 7 additions & 14 deletions saffron/src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
commitment::fold_commitments,
commitment::Commitment,
utils::{decode_into, encode_for_domain},
};
use ark_ff::PrimeField;
Expand All @@ -22,10 +22,7 @@ use tracing::{debug, debug_span, instrument};
pub struct FieldBlob<G: CommitmentCurve> {
pub n_bytes: usize,
pub domain_size: usize,
pub commitments: Vec<PolyComm<G>>,
pub folded_commitment: PolyComm<G>,
#[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub alpha: G::ScalarField,
pub commitment: Commitment<G>,
#[serde_as(as = "Vec<o1_utils::serialization::SerdeAs>")]
pub data: Vec<DensePolynomial<G::ScalarField>>,
}
Expand Down Expand Up @@ -60,12 +57,10 @@ impl<G: KimchiCurve> FieldBlob<G> {
.map(|chunk| Evaluations::from_vec_and_domain(chunk.to_vec(), domain).interpolate())
.collect()
});

let commitments = commit_to_blob_data(srs, &data);

let (folded_commitment, alpha) = {
let commitment = {
let chunks = commit_to_blob_data(srs, &data);
let mut sponge = EFqSponge::new(G::other_curve_sponge_params());
fold_commitments(&mut sponge, &commitments)
Commitment::from_chunks(chunks, &mut sponge)
};

debug!(
Expand All @@ -77,9 +72,7 @@ impl<G: KimchiCurve> FieldBlob<G> {
FieldBlob {
n_bytes: bytes.len(),
domain_size,
commitments,
folded_commitment,
alpha,
commitment,
data,
}
}
Expand Down Expand Up @@ -160,7 +153,7 @@ mod tests {
{ let elems = encode_for_domain(&*DOMAIN, &xs);
let user_commitments = commit_to_field_elems(&*SRS, *DOMAIN, elems);
let blob = FieldBlob::<Vesta>::encode::<_, VestaFqSponge>(&*SRS, *DOMAIN, &xs);
prop_assert_eq!(user_commitments, blob.commitments);
prop_assert_eq!(user_commitments, blob.commitment.chunks);
}
}
}
2 changes: 1 addition & 1 deletion saffron/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn encode_file(args: cli::EncodeFileArgs) -> Result<()> {
.into_iter()
.for_each(|asserted_commitment| {
let c = rmp_serde::from_slice(&asserted_commitment.0).unwrap();
if blob.folded_commitment != c {
if blob.commitment.folded != c {
panic!(
"commitment hash mismatch: asserted {}, computed {}",
asserted_commitment,
Expand Down
2 changes: 1 addition & 1 deletion saffron/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
.fold(init, |(acc_poly, curr_power), curr_poly| {
(
acc_poly + curr_poly.scale(curr_power),
curr_power * blob.alpha,
curr_power * blob.commitment.alpha,
)
})
.0
Expand Down

0 comments on commit 3940789

Please sign in to comment.