diff --git a/Cargo.toml b/Cargo.toml index cbccfb8..8d961df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,13 @@ ark-serialize = { version = "0.4.0", default-features = false, features = [ "der rand = { version = "0.8", features = [ "std", "std_rng" ] } merlin = { version = "3.0.0" } +ark-crypto-primitives = { version = "^0.4.0", default-features = true, features = [ "r1cs", "snark" ] } +ark-r1cs-std = { version = "^0.4.0", default-features = false } +ark-relations = { version = "^0.4.0", default-features = false } +ark-snark = { version = "^0.4.0", default-features = false } +tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } +tracing-subscriber = { version = "0.2" } +derivative = { version = "2.0", features = ["use_core"] } + [dev-dependencies] ark-bn254 = { version = "0.4.0", default-features = false, features=["curve"] } diff --git a/src/lib.rs b/src/lib.rs index e76e3b9..3e823b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![allow(unused)] // TMP mod nifs; +mod novacircuit; mod pedersen; mod r1cs; mod transcript; diff --git a/src/novacircuit.rs b/src/novacircuit.rs new file mode 100644 index 0000000..9e64004 --- /dev/null +++ b/src/novacircuit.rs @@ -0,0 +1,87 @@ +use ark_crypto_primitives::snark::{FromFieldElementsGadget, SNARKGadget, SNARK}; +use ark_ec::CurveGroup; +use ark_ff::{fields::Fp256, Field, PrimeField}; +use ark_r1cs_std::{ + alloc::{AllocVar, AllocationMode}, + bits::uint8::UInt8, + boolean::Boolean, + eq::EqGadget, + fields::{fp::FpVar, FieldVar}, + groups::GroupOpsBounds, + prelude::CurveVar, + ToBitsGadget, +}; +use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, Namespace, SynthesisError}; +use ark_std::ops::Mul; + +use core::{borrow::Borrow, marker::PhantomData}; +use derivative::Derivative; + +// pub trait Nova {} + +pub trait Config { + type AugmentedFunctionCircuit: SNARK; // F' + type FunctionCircuit: ConstraintSynthesizer; // F + type DummyStepCircuit: SNARK; +} + +pub struct AugmentedFCircuit< + Fq: PrimeField, + Fr: PrimeField, + C: CurveGroup, + GC: CurveVar, + Cfg: Config, +> { + pub dummystep_vk: Option<>::VerifyingKey>, + _c: PhantomData, + _gc: PhantomData, +} + +impl, Cfg: Config> + ConstraintSynthesizer for AugmentedFCircuit +{ + fn generate_constraints(self, cs: ConstraintSystemRef) -> Result<(), SynthesisError> { + unimplemented!(); + // nifscircuit::NIFSGadget::>::verify(); + // hash + } +} + +pub struct NIFSGadget> { + _f: PhantomData, + _c: PhantomData, + _gc: PhantomData, +} + +impl> NIFSGadget { + // implements the constraints for NIFS.V + pub fn verify( + r: FpVar, + cmT: GC, + // phi1, phi2 and phi3 + cmE1: GC, + cmE2: GC, + cmE3: GC, + u1: FpVar, + u2: FpVar, + u3: FpVar, + cmW1: GC, + cmW2: GC, + cmW3: GC, + // x's size will depend on the num_publicinputs of F circuit + x1: Vec>, + x2: Vec>, + x3: Vec>, + ) -> Result, SynthesisError> { + let r2 = r.square()?; + cmE3.is_eq( + &(cmE1 + + cmT.scalar_mul_le(r.to_bits_le()?.iter())? + + cmE2.scalar_mul_le(r2.to_bits_le()?.iter())?), + )?; + u3.is_eq(&(u1 + r.clone() * u2))?; + cmW3.is_eq(&(cmW1 + cmW2.scalar_mul_le(r.to_bits_le()?.iter())?)) + + // TODO x's check + } +}