Skip to content

Commit 65dd659

Browse files
committed
Compute digest of public parameters for strong Fiat-Shamir
1 parent 8ddf176 commit 65dd659

File tree

12 files changed

+68
-19
lines changed

12 files changed

+68
-19
lines changed

crates/fs/src/definitions/keys.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Traits and abstractions for folding scheme keys.
22
3+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
34
use sonobe_primitives::arithmetizations::ArithConfig;
45

56
/// [`DeciderKey`] defines the information that a folding scheme's decider key
67
/// should include or provide access to.
7-
pub trait DeciderKey {
8+
pub trait DeciderKey: CanonicalSerialize + CanonicalDeserialize {
89
/// [`DeciderKey::ProverKey`] is the type of the prover key contained in the
910
/// decider key.
1011
type ProverKey;

crates/fs/src/nova/keys/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Definitions of Nova keys and trait implementations for relation checks and
22
//! witness-instance sampling using Nova keys.
33
4+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
45
use ark_std::{UniformRand, rand::RngCore, sync::Arc};
56
use sonobe_primitives::{
67
arithmetizations::{
@@ -19,8 +20,8 @@ use super::{
1920
use crate::{DeciderKey, Error, PlainInstance as PU, PlainWitness as PW};
2021

2122
/// [`NovaKey`] is Nova's decider key.
22-
#[derive(Clone)]
23-
pub struct NovaKey<A, CM: CommitmentDef> {
23+
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
24+
pub struct NovaKey<A: Arith, CM: CommitmentDef> {
2425
pub(super) arith: Arc<A>,
2526
pub(super) ck: Arc<CM::Key>,
2627
}
@@ -88,7 +89,7 @@ where
8889
}
8990
}
9091

91-
impl<A, CM: CommitmentOps> WitnessInstanceSampler<IW<CM>, IU<CM>> for NovaKey<A, CM> {
92+
impl<A: Arith, CM: CommitmentOps> WitnessInstanceSampler<IW<CM>, IU<CM>> for NovaKey<A, CM> {
9293
type Source = AssignmentsOwned<CM::Scalar>;
9394
type Error = Error;
9495

@@ -99,7 +100,7 @@ impl<A, CM: CommitmentOps> WitnessInstanceSampler<IW<CM>, IU<CM>> for NovaKey<A,
99100
}
100101
}
101102

102-
impl<A, CM: CommitmentDef> WitnessInstanceSampler<PW<CM::Scalar>, PU<CM::Scalar>>
103+
impl<A: Arith, CM: CommitmentDef> WitnessInstanceSampler<PW<CM::Scalar>, PU<CM::Scalar>>
103104
for NovaKey<A, CM>
104105
{
105106
type Source = AssignmentsOwned<CM::Scalar>;

crates/ivc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ ark-ec = { workspace = true }
1111
ark-ff = { workspace = true, features = ["asm"] }
1212
ark-r1cs-std = { workspace = true }
1313
ark-relations = { workspace = true }
14+
ark-serialize = { workspace = true }
1415
ark-std = { workspace = true, features = ["getrandom"] }
1516
num-bigint = { workspace = true, features = ["rand"] }
17+
sha3 = { workspace = true }
1618
thiserror = { workspace = true }
1719

1820
sonobe-primitives = { workspace = true }

crates/ivc/src/compilers/cyclefold/mod.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
//! Implementation of the CycleFold-based IVC compiler.
1+
//! Implementation of the CycleFold-based IVC compiler as described in this
2+
//! [paper].
23
//!
34
//! It turns any compatible folding scheme into a full IVC scheme by running the
45
//! primary circuit on one curve and a "CycleFold" circuit on the secondary
56
//! curve to handle emulated elliptic curve operations.
7+
//!
8+
//! [paper]: https://eprint.iacr.org/2023/1192.pdf
69
7-
use ark_ff::Zero;
10+
use ark_ff::field_hashers::hash_to_field;
811
use ark_relations::gr1cs::{ConstraintSystem, SynthesisError};
9-
use ark_std::{borrow::Borrow, marker::PhantomData, rand::RngCore};
12+
use ark_serialize::CanonicalSerialize;
13+
use ark_std::{
14+
borrow::Borrow,
15+
io::{Error as IoError, Write},
16+
marker::PhantomData,
17+
rand::RngCore,
18+
};
19+
use sha3::{
20+
Shake128,
21+
digest::{ExtendableOutput, Update},
22+
};
1023
use sonobe_fs::{
1124
DeciderKey, FoldingInstance, FoldingSchemeDef, FoldingSchemeDefGadget,
1225
FoldingSchemeFullVerifierGadget, FoldingSchemePartialVerifierGadget,
@@ -214,7 +227,28 @@ where
214227
let dk1 = FS1::generate_keys(pp1, arith1)?;
215228
let dk2 = FS2::generate_keys(pp2, arith2)?;
216229

217-
let pp_hash = Zero::zero(); // TODO
230+
struct HashMarshaller<'a>(&'a mut Shake128);
231+
232+
impl Write for HashMarshaller<'_> {
233+
#[inline]
234+
fn write(&mut self, buf: &[u8]) -> Result<usize, IoError> {
235+
self.0.update(buf);
236+
Ok(buf.len())
237+
}
238+
239+
#[inline]
240+
fn flush(&mut self) -> Result<(), IoError> {
241+
Ok(())
242+
}
243+
}
244+
245+
let pp_hash = {
246+
let mut shake = Shake128::default();
247+
dk1.serialize_compressed(HashMarshaller(&mut shake))?;
248+
dk2.serialize_compressed(HashMarshaller(&mut shake))?;
249+
hash_config.serialize_compressed(HashMarshaller(&mut shake))?;
250+
hash_to_field::<_, _, 128>(&mut shake.finalize_xof())
251+
};
218252

219253
Ok((
220254
Key(dk1.clone(), dk2.clone(), (hash_config.clone(), pp_hash)),

crates/ivc/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
use ark_ff::PrimeField;
1010
use ark_relations::gr1cs::SynthesisError;
11+
use ark_serialize::SerializationError;
1112
use ark_std::rand::RngCore;
1213
use sonobe_fs::Error as FoldingError;
1314
use sonobe_primitives::{arithmetizations::Error as ArithError, circuits::FCircuit, traits::Dummy};
@@ -22,6 +23,9 @@ pub enum Error {
2223
/// system.
2324
#[error(transparent)]
2425
ArithError(#[from] ArithError),
26+
/// [`Error::SerializationError`] indicates an error during serialization.
27+
#[error(transparent)]
28+
SerializationError(#[from] SerializationError),
2529
/// [`Error::FoldingError`] indicates an error from the underlying folding
2630
/// scheme.
2731
#[error(transparent)]

crates/primitives/src/arithmetizations/ccs/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ark_ff::Field;
2323
use ark_poly::DenseMultilinearExtension;
2424
use ark_relations::gr1cs::{ConstraintSystem, Matrix};
25+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
2526
use ark_std::{borrow::Borrow, cfg_into_iter, cfg_iter, fmt::Debug, marker::PhantomData};
2627
#[cfg(feature = "parallel")]
2728
use rayon::prelude::*;
@@ -37,7 +38,7 @@ pub mod circuits;
3738

3839
/// [`CCSVariant`] defines the methods that a CCS variant (e.g., R1CS) should
3940
/// implement.
40-
pub trait CCSVariant: Clone + Debug + PartialEq + Default + Sync {
41+
pub trait CCSVariant: Clone + Debug + PartialEq + Default + Sync + Send {
4142
/// [`CCSVariant::n_matrices`] returns the number of matrices in the CCS
4243
/// variant.
4344
fn n_matrices() -> usize;
@@ -56,7 +57,7 @@ pub trait CCSVariant: Clone + Debug + PartialEq + Default + Sync {
5657

5758
/// [`CCSConfig`] stores the shape parameters of a CCS structure.
5859
#[allow(non_snake_case)]
59-
#[derive(Clone, Debug, Default, PartialEq)]
60+
#[derive(Clone, Debug, Default, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
6061
pub struct CCSConfig<V: CCSVariant> {
6162
_v: PhantomData<V>,
6263
/// m: number of rows in M_i (such that M_i \in F^{m, n})
@@ -114,7 +115,7 @@ impl<F: Field, V: CCSVariant> From<&ConstraintSystem<F>> for CCSConfig<V> {
114115

115116
/// [`CCS`] holds the CCS matrices `M` together with the configuration.
116117
#[allow(non_snake_case)]
117-
#[derive(Clone)]
118+
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
118119
pub struct CCS<F: Field, V: CCSVariant> {
119120
cfg: CCSConfig<V>,
120121

crates/primitives/src/arithmetizations/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! R1CS is the only supported constraint system by ark-relations.
88
99
use ark_relations::gr1cs::SynthesisError;
10+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
1011
use ark_std::{fmt::Debug, log2};
1112
use thiserror::Error;
1213

@@ -64,7 +65,7 @@ pub trait ArithConfig: Clone + Debug + Default + PartialEq {
6465
/// define methods to get and set configuration about the constraint system.
6566
/// In addition to the configuration, the implementor of this trait may also
6667
/// store the actual constraints and other information.
67-
pub trait Arith: Clone + Default {
68+
pub trait Arith: Clone + Default + Send + Sync + CanonicalSerialize + CanonicalDeserialize {
6869
/// [`Arith::Config`] specifies the arithmetization's configuration.
6970
type Config: ArithConfig;
7071

crates/primitives/src/arithmetizations/r1cs/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use ark_ff::Field;
55
use ark_relations::gr1cs::{ConstraintSystem, Matrix, R1CS_PREDICATE_LABEL};
6+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
67
use ark_std::{cfg_into_iter, cfg_iter, iterable::Iterable};
78
#[cfg(feature = "parallel")]
89
use rayon::prelude::*;
@@ -16,7 +17,7 @@ use crate::{
1617
pub mod circuits;
1718

1819
/// [`R1CSConfig`] stores the shape parameters of an R1CS structure.
19-
#[derive(Debug, Clone, Default, PartialEq)]
20+
#[derive(Debug, Clone, Default, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
2021
pub struct R1CSConfig {
2122
m: usize, // number of constraints
2223
n: usize, // number of variables
@@ -96,7 +97,7 @@ impl CCSVariant for R1CSConfig {
9697
/// [`R1CS`] holds the three sparse matrices `A`, `B`, `C` together with the
9798
/// configuration.
9899
#[allow(non_snake_case)]
99-
#[derive(Debug, Clone, Default, PartialEq)]
100+
#[derive(Debug, Clone, Default, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
100101
pub struct R1CS<F: Field> {
101102
cfg: R1CSConfig,
102103
pub(super) A: Matrix<F>,

crates/primitives/src/commitments/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use ark_ff::UniformRand;
44
use ark_r1cs_std::{GR1CSVar, alloc::AllocVar, fields::fp::FpVar, select::CondSelectGadget};
55
use ark_relations::gr1cs::SynthesisError;
6+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
67
use ark_std::{
78
fmt::Debug,
89
iter::Sum,
@@ -42,7 +43,7 @@ pub enum Error {
4243

4344
/// [`CommitmentKey`] represents a commitment key (e.g., a vector of group
4445
/// generators for many group-based commitment schemes).
45-
pub trait CommitmentKey: Clone {
46+
pub trait CommitmentKey: Clone + Send + Sync + CanonicalSerialize + CanonicalDeserialize {
4647
/// [`CommitmentKey::max_scalars_len`] returns the maximum number of scalars
4748
/// that can be committed to with this key.
4849
fn max_scalars_len(&self) -> usize;

crates/primitives/src/commitments/pedersen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ark_r1cs_std::{
99
boolean::Boolean, convert::ToBitsGadget, eq::EqGadget, fields::fp::FpVar, groups::CurveVar,
1010
};
1111
use ark_relations::gr1cs::SynthesisError;
12+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
1213
use ark_std::{UniformRand, iter::repeat_with, marker::PhantomData, rand::RngCore};
1314

1415
use super::{CommitmentDef, CommitmentDefGadget, CommitmentKey, CommitmentOps, Error};
@@ -21,7 +22,7 @@ use crate::{
2122

2223
/// [`PedersenKey`] stores the public parameters for the Pedersen commitment
2324
/// scheme, where `H` controls whether the scheme is hiding or not.
24-
#[derive(Clone)]
25+
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
2526
pub struct PedersenKey<C: SonobeCurve, const H: bool> {
2627
g: Vec<C::Affine>,
2728
h: C,

0 commit comments

Comments
 (0)