Skip to content

Commit

Permalink
refactor: rename TE and TE1 to FoldingTE and CompressTE (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
RequiemOfSoul authored Jun 14, 2024
1 parent 94080e8 commit f061800
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/gadgets/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<G: Group> AllocatedIOPVerifierState<G> {
&mut self,
mut cs: CS,
prover_msg: &AllocatedIOPProverMessage<G>,
transcript: &mut G::TECircuit,
transcript: &mut G::FoldTECircuit,
) -> Result<AllocatedNum<G::Base>, SynthesisError> {
assert!(!self.finished);

Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn sumcheck_verify<CS: ConstraintSystem<<G as Group>::Base>, G: Group>(
claimed_sum: &AllocatedNum<G::Base>,
proof: &AllocatedIOPProof<G>,
aux_info: &VPAuxInfo<G::Base>,
transcript: &mut G::TECircuit,
transcript: &mut G::FoldTECircuit,
) -> Result<(AllocatedSumCheckSubClaim<G>, AllocatedBit), SynthesisError> {
transcript.absorb(
cs.namespace(|| "absorb num_variables"),
Expand Down
10 changes: 6 additions & 4 deletions src/nimfs/ccs/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<C: Group> Pedersen<C> {

pub fn prove(
params: &Params<C>,
transcript: &mut C::TE,
transcript: &mut C::FoldTE,
cm: &Commitment<C>,
v: &[C::Scalar],
r: &C::Scalar,
Expand All @@ -77,7 +77,7 @@ impl<C: Group> Pedersen<C> {
}
pub fn verify(
params: &Params<C>,
transcript: &mut C::TE,
transcript: &mut C::FoldTE,
cm: Commitment<C>,
proof: Proof<C>,
) -> bool {
Expand Down Expand Up @@ -114,10 +114,12 @@ mod tests {
let params = Pedersen::new_params(OsRng, n);

// init Prover's transcript
let mut transcript_p = <bn256::Point as Group>::TE::new(Default::default(), b"pedersen_test");
let mut transcript_p =
<bn256::Point as Group>::FoldTE::new(Default::default(), b"pedersen_test");
transcript_p.squeeze(b"init").unwrap();
// init Verifier's transcript
let mut transcript_v = <bn256::Point as Group>::TE::new(Default::default(), b"pedersen_test");
let mut transcript_v =
<bn256::Point as Group>::FoldTE::new(Default::default(), b"pedersen_test");
transcript_v.squeeze(b"init").unwrap();

let v: Vec<bn256::Scalar> = vec![bn256::Scalar::random(OsRng); n];
Expand Down
2 changes: 1 addition & 1 deletion src/nimfs/espresso/sum_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<C: Group> SumCheck<C> for PolyIOP<C::Scalar> {
type VPAuxInfo = VPAuxInfo<C::Scalar>;
type MultilinearExtension = Arc<MultiLinearPolynomial<C::Scalar>>;
type SumCheckProof = IOPProof<C>;
type Transcript = C::TE;
type Transcript = C::FoldTE;
type SumCheckSubClaim = SumCheckSubClaim<C::Scalar>;

fn extract_sum(proof: &Self::SumCheckProof) -> C::Scalar {
Expand Down
2 changes: 1 addition & 1 deletion src/nimfs/espresso/sum_check/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<C: Group> SumCheckVerifier<C::Scalar> for IOPVerifierState<C> {
type VPAuxInfo = VPAuxInfo<C::Scalar>;
type ProverMessage = IOPProverMessage<C>;
type Challenge = C::Scalar;
type Transcript = C::TE;
type Transcript = C::FoldTE;
type SumCheckSubClaim = SumCheckSubClaim<C::Scalar>;

/// Initialize the verifier's state.
Expand Down
12 changes: 6 additions & 6 deletions src/nimfs/multifolding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<C: Group> MultiFolding<C> {
/// Return the final folded LCCCS, the folded witness, the sumcheck proof, and the helper
/// sumcheck claims sigmas and thetas.
pub fn prove<const ENABLE_SANITY_CHECK: bool>(
transcript: &mut C::TE,
transcript: &mut C::FoldTE,
running_instances: &[LCCCS<C>],
new_instances: &[CCCS<C>],
w_lcccs: &[CCSWitness<C>],
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<C: Group> MultiFolding<C> {
///
/// Return the folded LCCCS instance.
pub fn verify(
transcript: &mut C::TE,
transcript: &mut C::FoldTE,
running_instances: &[LCCCS<C>],
new_instances: &[CCCS<C>],
proof: Proof<C>,
Expand Down Expand Up @@ -655,7 +655,7 @@ pub mod test {

// Prover's transcript
let constants = PoseidonConstantsCircuit::<Fr>::default();
let mut transcript_p = <Point as Group>::TE::new(constants, b"multifolding");
let mut transcript_p = <Point as Group>::FoldTE::new(constants, b"multifolding");
transcript_p.squeeze(b"init").unwrap();
// Verifier's transcript
let mut transcript_v = transcript_p.clone();
Expand Down Expand Up @@ -698,7 +698,7 @@ pub mod test {

let constants = PoseidonConstantsCircuit::<Fr>::default();
// Prover's transcript
let mut transcript_p = <Point as Group>::TE::new(constants, b"multifolding");
let mut transcript_p = <Point as Group>::FoldTE::new(constants, b"multifolding");
transcript_p.squeeze(b"init").unwrap();
// Verifier's transcript
let mut transcript_v = transcript_p.clone();
Expand Down Expand Up @@ -783,7 +783,7 @@ pub mod test {

let constants = PoseidonConstantsCircuit::<Fr>::default();
// Prover's transcript
let mut transcript_p = <Point as Group>::TE::new(constants, b"multifolding");
let mut transcript_p = <Point as Group>::FoldTE::new(constants, b"multifolding");
transcript_p.squeeze(b"init").unwrap();
// Verifier's transcript
let mut transcript_v = transcript_p.clone();
Expand Down Expand Up @@ -817,7 +817,7 @@ pub mod test {

let constants = PoseidonConstantsCircuit::<Fr>::default();
// Prover's transcript
let mut transcript_p = <Point as Group>::TE::new(constants, b"multifolding");
let mut transcript_p = <Point as Group>::FoldTE::new(constants, b"multifolding");
transcript_p.squeeze(b"init").unwrap();
// Verifier's transcript
let mut transcript_v = transcript_p.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/nimfs/pcd_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ where
assert!(!lcccs.is_empty());
assert!(!cccs.is_empty());

let mut transcript = G::TECircuit::new(
let mut transcript = G::FoldTECircuit::new(
self.te_consts.clone(),
cs.namespace(|| "init NIMFS transcript"),
b"multifolding",
Expand Down
4 changes: 2 additions & 2 deletions src/pcd_compressed_snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ where
recursive_snark: &PCDRecursiveSNARK<G1, G2, SC, ARITY, R>,
) -> Result<Self, NovaError> {
// Prover's transcript
let mut transcript_p = G1::TE::new(Default::default(), b"multifolding");
let mut transcript_p = G1::FoldTE::new(Default::default(), b"multifolding");
transcript_p.squeeze(Self::TRANSCRIPT_INIT_STR).unwrap();

// fold the primary circuit's instance
Expand Down Expand Up @@ -322,7 +322,7 @@ where
}

// Verifier's transcript
let mut transcript_v = G1::TE::new(Default::default(), b"multifolding");
let mut transcript_v = G1::FoldTE::new(Default::default(), b"multifolding");
transcript_v.squeeze(Self::TRANSCRIPT_INIT_STR).unwrap();

// fold the running instance and last instance to get a folded instance
Expand Down
4 changes: 2 additions & 2 deletions src/pcd_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
> {
// First, handling PCD auxiliary secondary circuit
println!("=================================================proving NIMFS=================================================");
let mut transcript_p = <G1 as Group>::TE::new(Default::default(), b"multifolding");
let mut transcript_p = <G1 as Group>::FoldTE::new(Default::default(), b"multifolding");
transcript_p.squeeze(b"init").unwrap();
let (nimfs_proof, lcccs, lcccs_witness) = NIMFS::prove::<ENABLE_SANITY_CHECK>(
&mut transcript_p,
Expand All @@ -96,7 +96,7 @@ where
self.w_cccs.as_ref().unwrap(),
);
if !IS_GENESIS && ENABLE_SANITY_CHECK {
let mut transcript_v = <G1 as Group>::TE::new(Default::default(), b"multifolding");
let mut transcript_v = <G1 as Group>::FoldTE::new(Default::default(), b"multifolding");
transcript_v.squeeze(b"init")?;
let verified_lcccs = NIMFS::verify(
&mut transcript_v,
Expand Down
10 changes: 5 additions & 5 deletions src/provider/ipa_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
fn prove(
ck: &CommitmentKey<G>,
pk: &Self::ProverKey,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
comm: &Commitment<G>,
poly: &[G::Scalar],
point: &[G::Scalar],
Expand All @@ -80,7 +80,7 @@ where
/// A method to verify purported evaluations of a batch of polynomials
fn verify(
vk: &Self::VerifierKey,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
comm: &Commitment<G>,
point: &[G::Scalar],
eval: &G::Scalar,
Expand Down Expand Up @@ -184,7 +184,7 @@ where
ck_c: &CommitmentKey<G>,
U: &InnerProductInstance<G>,
W: &InnerProductWitness<G>,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<Self, NovaError> {
transcript.dom_sep(Self::protocol_name());

Expand All @@ -205,7 +205,7 @@ where
let prove_inner = |a_vec: &[G::Scalar],
b_vec: &[G::Scalar],
ck: &CommitmentKey<G>,
transcript: &mut G::TE1|
transcript: &mut G::CompressTE|
-> Result<
(
CompressedCommitment<G>,
Expand Down Expand Up @@ -297,7 +297,7 @@ where
ck_c: &CommitmentKey<G>,
n: usize,
U: &InnerProductInstance<G>,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<(), NovaError> {
let (ck, _) = ck.split_at(U.b_vec.len());

Expand Down
6 changes: 3 additions & 3 deletions src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ macro_rules! impl_traits {
type PreprocessedGroupElement = $name::Affine;
type RO = PoseidonRO<Self::Base, Self::Scalar>;
type ROCircuit = PoseidonROCircuit<Self::Base>;
type TE = PoseidonTranscript<Self>;
type TECircuit = PoseidonTranscriptCircuit<Self>;
type TE1 = Keccak256Transcript<Self>;
type FoldTE = PoseidonTranscript<Self>;
type FoldTECircuit = PoseidonTranscriptCircuit<Self>;
type CompressTE = Keccak256Transcript<Self>;
type CE = CommitmentEngine<Self>;

fn vartime_multiscalar_mul(
Expand Down
6 changes: 3 additions & 3 deletions src/provider/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ macro_rules! impl_traits {
type PreprocessedGroupElement = $name::Affine;
type RO = PoseidonRO<Self::Base, Self::Scalar>;
type ROCircuit = PoseidonROCircuit<Self::Base>;
type TE = PoseidonTranscript<Self>;
type TECircuit = PoseidonTranscriptCircuit<Self>;
type TE1 = Keccak256Transcript<Self>;
type FoldTE = PoseidonTranscript<Self>;
type FoldTECircuit = PoseidonTranscriptCircuit<Self>;
type CompressTE = Keccak256Transcript<Self>;
type CE = CommitmentEngine<Self>;

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/lcccs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> LinearCommittedCCSTrait<G> for LCCC
W: &CCSWitness<G>, //
) -> Result<Self, NovaError> {
let W = W.pad(&pk.S); // pad the witness
let mut transcript = G::TE1::new(Default::default(), b"LCCCSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"LCCCSSNARK");

// append the digest of vk (which includes LCCCS matrices) and the LCCCSInstance to the transcript
transcript.absorb(b"vk", &pk.vk_digest);
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> LinearCommittedCCSTrait<G> for LCCC

/// verifies a proof of satisfiability of a `LCCCS` instance
fn verify(&self, vk: &Self::VerifierKey, U: &LCCCS<G>) -> Result<(), NovaError> {
let mut transcript = G::TE1::new(Default::default(), b"LCCCSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"LCCCSSNARK");

// append the digest of R1CS matrices and the RelaxedR1CSInstance to the transcript
transcript.absorb(b"vk", &vk.digest);
Expand Down
8 changes: 4 additions & 4 deletions src/spartan/ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<G: Group> ProductSumcheckInstance<G> {
pub fn new(
ck: &CommitmentKey<G>,
input_vec: Vec<Vec<G::Scalar>>, // list of input vectors
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<Self, NovaError> {
let compute_layer = |input: &[G::Scalar]| -> (Vec<G::Scalar>, Vec<G::Scalar>, Vec<G::Scalar>) {
let left = (0..input.len() / 2)
Expand Down Expand Up @@ -736,7 +736,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARK<G, EE> {
mem: &mut T1,
outer: &mut T2,
inner: &mut T3,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<
(
SumcheckProof<G>,
Expand Down Expand Up @@ -886,7 +886,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe
W: &RelaxedR1CSWitness<G>,
) -> Result<Self, NovaError> {
let W = W.pad(&pk.S); // pad the witness
let mut transcript = G::TE1::new(Default::default(), b"RelaxedR1CSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"RelaxedR1CSSNARK");

// a list of polynomial evaluation claims that will be batched
let mut w_u_vec = Vec::new();
Expand Down Expand Up @@ -1490,7 +1490,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe

/// verifies a proof of satisfiability of a `RelaxedR1CS` instance
fn verify(&self, vk: &Self::VerifierKey, U: &RelaxedR1CSInstance<G>) -> Result<(), NovaError> {
let mut transcript = G::TE1::new(Default::default(), b"RelaxedR1CSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"RelaxedR1CSSNARK");
let mut u_vec: Vec<PolyEvalInstance<G>> = Vec::new();

// append the verifier key (including commitment to R1CS matrices) and the RelaxedR1CSInstance to the transcript
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe
W: &RelaxedR1CSWitness<G>,
) -> Result<Self, NovaError> {
let W = W.pad(&pk.S); // pad the witness
let mut transcript = G::TE1::new(Default::default(), b"RelaxedR1CSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"RelaxedR1CSSNARK");

// sanity check that R1CSShape has certain size characteristics
pk.S.check_regular_shape();
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe

/// verifies a proof of satisfiability of a `RelaxedR1CS` instance
fn verify(&self, vk: &Self::VerifierKey, U: &RelaxedR1CSInstance<G>) -> Result<(), NovaError> {
let mut transcript = G::TE1::new(Default::default(), b"RelaxedR1CSSNARK");
let mut transcript = G::CompressTE::new(Default::default(), b"RelaxedR1CSSNARK");

// append the digest of R1CS matrices and the RelaxedR1CSInstance to the transcript
transcript.absorb(b"vk", &vk.digest);
Expand Down
8 changes: 4 additions & 4 deletions src/spartan/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<G: Group> SumcheckProof<G> {
claim: G::Scalar,
num_rounds: usize,
degree_bound: usize,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<(G::Scalar, Vec<G::Scalar>), NovaError> {
let mut e = claim;
let mut r: Vec<G::Scalar> = Vec::new();
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<G: Group> SumcheckProof<G> {
poly_A: &mut MultiLinearPolynomial<G::Scalar>,
poly_B: &mut MultiLinearPolynomial<G::Scalar>,
comb_func: F,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<(Self, Vec<G::Scalar>, Vec<G::Scalar>), NovaError>
where
F: Fn(&G::Scalar, &G::Scalar) -> G::Scalar + Sync,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<G: Group> SumcheckProof<G> {
poly_B_vec: &mut [MultiLinearPolynomial<G::Scalar>],
coeffs: &[G::Scalar],
comb_func: F,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<(Self, Vec<G::Scalar>, (Vec<G::Scalar>, Vec<G::Scalar>)), NovaError>
where
F: Fn(&G::Scalar, &G::Scalar) -> G::Scalar + Sync,
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<G: Group> SumcheckProof<G> {
poly_C: &mut MultiLinearPolynomial<G::Scalar>,
poly_D: &mut MultiLinearPolynomial<G::Scalar>,
comb_func: F,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
) -> Result<(Self, Vec<G::Scalar>, Vec<G::Scalar>), NovaError>
where
F: Fn(&G::Scalar, &G::Scalar, &G::Scalar, &G::Scalar) -> G::Scalar + Sync,
Expand Down
4 changes: 2 additions & 2 deletions src/traits/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait EvaluationEngineTrait<G: Group>: Clone + Send + Sync {
fn prove(
ck: &<<G as Group>::CE as CommitmentEngineTrait<G>>::CommitmentKey,
pk: &Self::ProverKey,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
comm: &<<G as Group>::CE as CommitmentEngineTrait<G>>::Commitment,
poly: &[G::Scalar],
point: &[G::Scalar],
Expand All @@ -37,7 +37,7 @@ pub trait EvaluationEngineTrait<G: Group>: Clone + Send + Sync {
/// A method to verify the purported evaluation of a multilinear polynomials
fn verify(
vk: &Self::VerifierKey,
transcript: &mut G::TE1,
transcript: &mut G::CompressTE,
comm: &<<G as Group>::CE as CommitmentEngineTrait<G>>::Commitment,
point: &[G::Scalar],
eval: &G::Scalar,
Expand Down
12 changes: 6 additions & 6 deletions src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ pub trait Group:
/// An alternate implementation of `Self::RO` in the circuit model
type ROCircuit: ROCircuitTrait<Self::Base>;

/// A type that provides a generic Fiat-Shamir transcript to be used when externalizing proofs
type TE: TranscriptEngineTrait<Self>;
/// A type that provides a generic Fiat-Shamir transcript to be used when folding NIMFS proofs
type FoldTE: TranscriptEngineTrait<Self>;

/// An alternate implementation of `Self::TE` in the circuit model
type TECircuit: TranscriptCircuitEngineTrait<Self>;
type FoldTECircuit: TranscriptCircuitEngineTrait<Self>;

/// A type that provides a generic Fiat-Shamir transcript to be used when externalizing proofs
type TE1: TranscriptEngineTrait<Self>;
type CompressTE: TranscriptEngineTrait<Self>;

/// A type that defines a commitment engine over scalars in the group
type CE: CommitmentEngineTrait<Self>;
Expand Down Expand Up @@ -214,11 +214,11 @@ pub type ROConstantsCircuit<G> =
<<G as Group>::ROCircuit as ROCircuitTrait<<G as Group>::Base>>::Constants;

/// An alias for constants associated with `G::TE`
pub type TEConstants<G> = <<G as Group>::TE as TranscriptEngineTrait<G>>::Constants;
pub type TEConstants<G> = <<G as Group>::FoldTE as TranscriptEngineTrait<G>>::Constants;

/// An alias for constants associated with `G::TECircuit`
pub type TEConstantsCircuit<G> =
<<G as Group>::TECircuit as TranscriptCircuitEngineTrait<G>>::Constants;
<<G as Group>::FoldTECircuit as TranscriptCircuitEngineTrait<G>>::Constants;

/// A helper trait for types with a group operation.
pub trait GroupOps<Rhs = Self, Output = Self>:
Expand Down

0 comments on commit f061800

Please sign in to comment.