mirror of
https://github.com/arnaucube/hash-chain-sonobe.git
synced 2026-01-19 20:21:32 +01:00
upgrade to latest Sonobe version (FCircuit interface updated)
This commit is contained in:
@@ -12,8 +12,8 @@ mod tests {
|
|||||||
|
|
||||||
use ark_crypto_primitives::sponge::{
|
use ark_crypto_primitives::sponge::{
|
||||||
constraints::CryptographicSpongeVar,
|
constraints::CryptographicSpongeVar,
|
||||||
poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig, PoseidonSponge},
|
poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig},
|
||||||
Absorb, CryptographicSponge,
|
Absorb,
|
||||||
};
|
};
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
|
|
||||||
@@ -49,21 +49,6 @@ mod tests {
|
|||||||
fn external_inputs_len(&self) -> usize {
|
fn external_inputs_len(&self) -> usize {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
fn step_native(
|
|
||||||
&self,
|
|
||||||
_i: usize,
|
|
||||||
z_i: Vec<F>,
|
|
||||||
_external_inputs: Vec<F>,
|
|
||||||
) -> Result<Vec<F>, Error> {
|
|
||||||
let mut sponge = PoseidonSponge::<F>::new(&self.config);
|
|
||||||
|
|
||||||
let mut v = z_i.clone();
|
|
||||||
for _ in 0..HASHES_PER_STEP {
|
|
||||||
sponge.absorb(&v);
|
|
||||||
v = sponge.squeeze_field_elements(1);
|
|
||||||
}
|
|
||||||
Ok(v)
|
|
||||||
}
|
|
||||||
fn generate_step_constraints(
|
fn generate_step_constraints(
|
||||||
&self,
|
&self,
|
||||||
cs: ConstraintSystemRef<F>,
|
cs: ConstraintSystemRef<F>,
|
||||||
@@ -103,16 +88,12 @@ mod tests {
|
|||||||
// check that the f_circuit produces valid R1CS constraints
|
// check that the f_circuit produces valid R1CS constraints
|
||||||
use ark_r1cs_std::alloc::AllocVar;
|
use ark_r1cs_std::alloc::AllocVar;
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
use ark_r1cs_std::R1CSVar;
|
|
||||||
use ark_relations::r1cs::ConstraintSystem;
|
use ark_relations::r1cs::ConstraintSystem;
|
||||||
let cs = ConstraintSystem::<Fr>::new_ref();
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
||||||
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
||||||
let z_1_var = f_circuit
|
let _z_1_var = f_circuit
|
||||||
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// check z_1_var against the native z_1
|
|
||||||
let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap();
|
|
||||||
assert_eq!(z_1_var.value().unwrap(), z_1_native);
|
|
||||||
// check that the constraint system is satisfied
|
// check that the constraint system is satisfied
|
||||||
assert!(cs.is_satisfied().unwrap());
|
assert!(cs.is_satisfied().unwrap());
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ mod tests {
|
|||||||
use ark_pallas::{constraints::GVar, Fr, Projective as G1};
|
use ark_pallas::{constraints::GVar, Fr, Projective as G1};
|
||||||
use ark_vesta::{constraints::GVar as GVar2, Projective as G2};
|
use ark_vesta::{constraints::GVar as GVar2, Projective as G2};
|
||||||
|
|
||||||
use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256};
|
use ark_crypto_primitives::crh::sha256::constraints::Sha256Gadget;
|
||||||
use ark_ff::PrimeField;
|
use ark_ff::PrimeField;
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
use ark_r1cs_std::{
|
use ark_r1cs_std::{
|
||||||
@@ -30,8 +30,6 @@ mod tests {
|
|||||||
Error, FoldingScheme,
|
Error, FoldingScheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::tests::*;
|
|
||||||
|
|
||||||
/// Test circuit to be folded
|
/// Test circuit to be folded
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct SHA256FoldStepCircuit<F: PrimeField, const HASHES_PER_STEP: usize> {
|
pub struct SHA256FoldStepCircuit<F: PrimeField, const HASHES_PER_STEP: usize> {
|
||||||
@@ -50,22 +48,6 @@ mod tests {
|
|||||||
fn external_inputs_len(&self) -> usize {
|
fn external_inputs_len(&self) -> usize {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
fn step_native(
|
|
||||||
&self,
|
|
||||||
_i: usize,
|
|
||||||
z_i: Vec<F>,
|
|
||||||
_external_inputs: Vec<F>,
|
|
||||||
) -> Result<Vec<F>, Error> {
|
|
||||||
let mut b = f_vec_to_bytes(z_i.to_vec());
|
|
||||||
|
|
||||||
for _ in 0..HASHES_PER_STEP {
|
|
||||||
let mut sha256 = Sha256::default();
|
|
||||||
sha256.update(b);
|
|
||||||
b = sha256.finalize().to_vec();
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_to_f_vec(b.to_vec()) // z_{i+1}
|
|
||||||
}
|
|
||||||
fn generate_step_constraints(
|
fn generate_step_constraints(
|
||||||
&self,
|
&self,
|
||||||
_cs: ConstraintSystemRef<F>,
|
_cs: ConstraintSystemRef<F>,
|
||||||
@@ -115,16 +97,12 @@ mod tests {
|
|||||||
// check that the f_circuit produces valid R1CS constraints
|
// check that the f_circuit produces valid R1CS constraints
|
||||||
use ark_r1cs_std::alloc::AllocVar;
|
use ark_r1cs_std::alloc::AllocVar;
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
use ark_r1cs_std::R1CSVar;
|
|
||||||
use ark_relations::r1cs::ConstraintSystem;
|
use ark_relations::r1cs::ConstraintSystem;
|
||||||
let cs = ConstraintSystem::<Fr>::new_ref();
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
||||||
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
||||||
let z_1_var = f_circuit
|
let _z_1_var = f_circuit
|
||||||
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// check z_1_var against the native z_1
|
|
||||||
let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap();
|
|
||||||
assert_eq!(z_1_var.value().unwrap(), z_1_native);
|
|
||||||
// check that the constraint system is satisfied
|
// check that the constraint system is satisfied
|
||||||
assert!(cs.is_satisfied().unwrap());
|
assert!(cs.is_satisfied().unwrap());
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ mod tests {
|
|||||||
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256};
|
use ark_crypto_primitives::crh::sha256::constraints::Sha256Gadget;
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
use ark_r1cs_std::{
|
use ark_r1cs_std::{
|
||||||
boolean::Boolean,
|
boolean::Boolean,
|
||||||
@@ -48,8 +48,6 @@ mod tests {
|
|||||||
NovaCycleFoldVerifierKey,
|
NovaCycleFoldVerifierKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::tests::*;
|
|
||||||
|
|
||||||
/// Test circuit to be folded
|
/// Test circuit to be folded
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct SHA256FoldStepCircuit<F: PrimeField, const HASHES_PER_STEP: usize> {
|
pub struct SHA256FoldStepCircuit<F: PrimeField, const HASHES_PER_STEP: usize> {
|
||||||
@@ -68,22 +66,6 @@ mod tests {
|
|||||||
fn external_inputs_len(&self) -> usize {
|
fn external_inputs_len(&self) -> usize {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
fn step_native(
|
|
||||||
&self,
|
|
||||||
_i: usize,
|
|
||||||
z_i: Vec<F>,
|
|
||||||
_external_inputs: Vec<F>,
|
|
||||||
) -> Result<Vec<F>, Error> {
|
|
||||||
let mut b = f_vec_to_bytes(z_i.to_vec());
|
|
||||||
|
|
||||||
for _ in 0..HASHES_PER_STEP {
|
|
||||||
let mut sha256 = Sha256::default();
|
|
||||||
sha256.update(b);
|
|
||||||
b = sha256.finalize().to_vec();
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_to_f_vec(b.to_vec()) // z_{i+1}
|
|
||||||
}
|
|
||||||
fn generate_step_constraints(
|
fn generate_step_constraints(
|
||||||
&self,
|
&self,
|
||||||
_cs: ConstraintSystemRef<F>,
|
_cs: ConstraintSystemRef<F>,
|
||||||
@@ -133,16 +115,12 @@ mod tests {
|
|||||||
// check that the f_circuit produces valid R1CS constraints
|
// check that the f_circuit produces valid R1CS constraints
|
||||||
use ark_r1cs_std::alloc::AllocVar;
|
use ark_r1cs_std::alloc::AllocVar;
|
||||||
use ark_r1cs_std::fields::fp::FpVar;
|
use ark_r1cs_std::fields::fp::FpVar;
|
||||||
use ark_r1cs_std::R1CSVar;
|
|
||||||
use ark_relations::r1cs::ConstraintSystem;
|
use ark_relations::r1cs::ConstraintSystem;
|
||||||
let cs = ConstraintSystem::<Fr>::new_ref();
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
||||||
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap();
|
||||||
let z_1_var = f_circuit
|
let _z_1_var = f_circuit
|
||||||
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
.generate_step_constraints(cs.clone(), 1, z_0_var, vec![])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// check z_1_var against the native z_1
|
|
||||||
let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap();
|
|
||||||
assert_eq!(z_1_var.value().unwrap(), z_1_native);
|
|
||||||
// check that the constraint system is satisfied
|
// check that the constraint system is satisfied
|
||||||
assert!(cs.is_satisfied().unwrap());
|
assert!(cs.is_satisfied().unwrap());
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
Reference in New Issue
Block a user