Skip to content

Commit

Permalink
(wip) fixed base <-> scalar confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenciak committed Jan 23, 2024
1 parent 379bb33 commit 6088d31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
37 changes: 17 additions & 20 deletions src/cyclefold/nova_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use bellpepper::gadgets::num::AllocatedNum;
use bellpepper_core::{ConstraintSystem, SynthesisError};
use serde::{Deserialize, Serialize};

/// TODO: docs
#[derive(Clone, PartialEq, Serialize, Deserialize, Abomonation)]
pub struct AugmentedCircuitParams {
limb_width: usize,
Expand Down Expand Up @@ -47,7 +46,6 @@ impl<E: Engine> FoldingData<E> {
}
}

/// TODO: Docs
#[derive(Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct AugmentedCircuitInputs<E1, E2>
Expand All @@ -57,16 +55,16 @@ where
{
pp_digest: E1::Scalar,
i: E1::Base,
z0: Vec<E1::Scalar>,
z0: Vec<E1::Base>,

zi: Option<Vec<E1::Scalar>>,
data_p: Option<FoldingData<E1>>,
zi: Option<Vec<E1::Base>>,
data_p: Option<FoldingData<E2>>,

data_c_1: Option<FoldingData<E2>>,
data_c_2: Option<FoldingData<E2>>,
data_c_1: Option<FoldingData<E1>>,
data_c_2: Option<FoldingData<E1>>,

E_new: Option<Commitment<E1>>,
W_new: Option<Commitment<E1>>,
E_new: Option<Commitment<E2>>,
W_new: Option<Commitment<E2>>,
}

impl<E1, E2> AugmentedCircuitInputs<E1, E2>
Expand All @@ -77,13 +75,13 @@ where
pub fn new(
pp_digest: E1::Scalar,
i: E1::Base,
z0: Vec<E1::Scalar>,
zi: Option<Vec<E1::Scalar>>,
data_p: Option<FoldingData<E1>>,
data_c_1: Option<FoldingData<E2>>,
data_c_2: Option<FoldingData<E2>>,
E_new: Option<Commitment<E1>>,
W_new: Option<Commitment<E1>>,
z0: Vec<E1::Base>,
zi: Option<Vec<E1::Base>>,
data_p: Option<FoldingData<E2>>,
data_c_1: Option<FoldingData<E1>>,
data_c_2: Option<FoldingData<E1>>,
E_new: Option<Commitment<E2>>,
W_new: Option<Commitment<E2>>,
) -> Self {
Self {
pp_digest,
Expand All @@ -98,12 +96,11 @@ where
}
}
}

pub struct AugmentedCircuit<'a, E1, E2, SC>
where
E1: Engine<Base = <E2 as Engine>::Scalar>,
E2: Engine<Base = <E1 as Engine>::Scalar>,
SC: StepCircuit<E1::Scalar>,
SC: StepCircuit<E2::Scalar>,
{
params: &'a AugmentedCircuitParams,
ro_consts: ROConstantsCircuit<E1>,
Expand All @@ -115,7 +112,7 @@ impl<'a, E1, E2, SC> AugmentedCircuit<'a, E1, E2, SC>
where
E1: Engine<Base = <E2 as Engine>::Scalar>,
E2: Engine<Base = <E1 as Engine>::Scalar>,
SC: StepCircuit<E1::Scalar>,
SC: StepCircuit<E2::Scalar>,
{
pub const fn new(
params: &'a AugmentedCircuitParams,
Expand Down Expand Up @@ -162,7 +159,7 @@ where
pub fn synthesize<CS: ConstraintSystem<<E1 as Engine>::Base>>(
self,
cs: &mut CS,
) -> Result<Vec<AllocatedNum<E1::Scalar>>, SynthesisError> {
) -> Result<Vec<AllocatedNum<E1::Base>>, SynthesisError> {
// TODO: It's written down here https://hackmd.io/@mpenciak/HybHrnNFT
todo!()
}
Expand Down
8 changes: 4 additions & 4 deletions src/cyclefold/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ where

let data_p = FoldingData::new(self.r_U_primary.clone(), self.l_u_primary.clone(), comm_T);
let data_c_E = FoldingData::new(r_U_cyclefold_E, l_u_cyclefold_E, comm_T_E);
let data_c_W = FoldingData::new(r_U_cyclefold_W, l_u_cyclefold_W, comm_T_W);
let data_c_W = FoldingData::new(r_U_cyclefold_W.clone(), l_u_cyclefold_W, comm_T_W);

let inputs_primary = AugmentedCircuitInputs::new(
pp.digest(),
<E2 as Engine>::Scalar::from(self.i as u64),
let inputs_primary: AugmentedCircuitInputs<E2, E1> = AugmentedCircuitInputs::new(
scalar_as_base::<E1>(pp.digest()),
<E2 as Engine>::Base::from(self.i as u64),
self.z0_primary.clone(),
Some(self.zi_primary.clone()),
Some(data_p),
Expand Down

0 comments on commit 6088d31

Please sign in to comment.