Browse Source

update to latest Sonobe version & arkworks v0.5.0

main
arnaucube 5 days ago
parent
commit
44899140dd
5 changed files with 37 additions and 39 deletions
  1. +14
    -24
      Cargo.toml
  2. +2
    -6
      src/naive_approach_poseidon_chain.rs
  3. +7
    -3
      src/naive_approach_sha_chain.rs
  4. +7
    -3
      src/sha_chain_offchain.rs
  5. +7
    -3
      src/sha_chain_onchain.rs

+ 14
- 24
Cargo.toml

@ -6,23 +6,23 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ark-groth16 = { version = "^0.4.0" }
ark-pallas = {version="0.4.0", features=["r1cs"]}
ark-vesta = {version="0.4.0", features=["r1cs"]}
ark-bn254 = { version = "0.4.0", features = ["r1cs"] }
ark-grumpkin = {version="0.4.0", features=["r1cs"]}
ark-ec = "0.4.1"
ark-ff = "0.4.1"
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 }
ark-poly-commit = "^0.4.0"
ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = [
ark-groth16 = { version = "^0.5.0" }
ark-pallas = {version="0.5.0", features=["r1cs"]}
ark-vesta = {version="0.5.0", features=["r1cs"]}
ark-bn254 = { version = "0.5.0", features = ["r1cs"] }
ark-grumpkin = {version="0.5.0", features=["r1cs"]}
ark-ec = "0.5.0"
ark-ff = "0.5.0"
ark-r1cs-std = { version = "0.5.0", default-features = false }
ark-relations = { version = "0.5.0", default-features = false }
ark-snark = { version = "^0.5.0", default-features = false }
ark-poly-commit = "^0.5.0"
ark-crypto-primitives = { version = "^0.5.0", default-features = false, features = [
"r1cs", "r1cs",
"sponge", "sponge",
"crh", "crh",
] } ] }
ark-std = "0.4.0"
ark-std = "0.5.0"
color-eyre = "0.6.2" color-eyre = "0.6.2"
num-bigint = "0.4.3" num-bigint = "0.4.3"
# Note: for testing purposes we use the 'light-test' feature when importing # Note: for testing purposes we use the 'light-test' feature when importing
@ -30,7 +30,7 @@ num-bigint = "0.4.3"
# this feature (but then the DeciderETH circuit is bigger and takes more time # this feature (but then the DeciderETH circuit is bigger and takes more time
# to compute). # to compute).
folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "folding-schemes", features=["light-test"]} folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "folding-schemes", features=["light-test"]}
folding-schemes-circom = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "frontends", optional=true}
folding-schemes-circom = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "experimental-frontends", optional=true}
solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "solidity-verifiers"} solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "solidity-verifiers"}
serde = "1.0.198" serde = "1.0.198"
serde_json = "1.0.116" serde_json = "1.0.116"
@ -45,13 +45,3 @@ rand = "0.8.5"
[features] [features]
default = [] default = []
experimental-frontends = ["dep:folding-schemes-circom"] experimental-frontends = ["dep:folding-schemes-circom"]
[patch.crates-io]
# patch ark_curves to use a cherry-picked version which contains
# bn254::constraints & grumpkin for v0.4.0 (once arkworks v0.5.0 is released
# this will no longer be needed)
ark-bn254 = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"}
ark-grumpkin = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"}
ark-circom = { git = "https://github.com/arnaucube/circom-compat" }
ark-r1cs-std = { git = "https://github.com/winderica/r1cs-std", branch="cherry-pick" }

+ 2
- 6
src/naive_approach_poseidon_chain.rs

@ -15,19 +15,16 @@ 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, PoseidonSponge},
Absorb, CryptographicSponge,
CryptographicSponge,
}; };
use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget}; use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget};
use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget};
use ark_relations::r1cs::{ use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError, ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError,
}; };
use folding_schemes::transcript::poseidon::poseidon_canonical_config; use folding_schemes::transcript::poseidon::poseidon_canonical_config;
use crate::utils::tests::*;
/// Test circuit to be folded /// Test circuit to be folded
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PoseidonChainCircuit<F: PrimeField, const N: usize, const HASHES_PER_STEP: usize> { pub struct PoseidonChainCircuit<F: PrimeField, const N: usize, const HASHES_PER_STEP: usize> {
@ -66,9 +63,8 @@ mod tests {
hashes_per_step: usize, hashes_per_step: usize,
) -> Vec<Fr> { ) -> Vec<Fr> {
let mut z_i: Vec<Fr> = z_0.clone(); let mut z_i: Vec<Fr> = z_0.clone();
let mut sponge = PoseidonSponge::<Fr>::new(&poseidon_config);
for _ in 0..n_steps { for _ in 0..n_steps {
let mut sponge = PoseidonSponge::<Fr>::new(&poseidon_config);
for _ in 0..hashes_per_step { for _ in 0..hashes_per_step {
sponge.absorb(&z_i); sponge.absorb(&z_i);
z_i = sponge.squeeze_field_elements(1); z_i = sponge.squeeze_field_elements(1);

+ 7
- 3
src/naive_approach_sha_chain.rs

@ -15,7 +15,11 @@ mod tests {
use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256};
use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget}; use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget};
use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget};
use ark_r1cs_std::{
boolean::Boolean,
convert::{ToBitsGadget, ToBytesGadget},
uint8::UInt8,
};
use ark_relations::r1cs::{ use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError, ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError,
}; };
@ -47,7 +51,7 @@ mod tests {
for _ in 0..HASHES_PER_STEP { for _ in 0..HASHES_PER_STEP {
let mut sha256_var = Sha256Gadget::default(); let mut sha256_var = Sha256Gadget::default();
sha256_var.update(&b).unwrap(); sha256_var.update(&b).unwrap();
b = sha256_var.finalize()?.to_bytes()?;
b = sha256_var.finalize()?.to_bytes_le()?;
} }
// update z_i = z_{i+1} // update z_i = z_{i+1}
@ -55,7 +59,7 @@ mod tests {
.iter() .iter()
.map(|e| { .map(|e| {
let bits = e.to_bits_le().unwrap(); let bits = e.to_bits_le().unwrap();
Boolean::<F>::le_bits_to_fp_var(&bits).unwrap()
Boolean::<F>::le_bits_to_fp(&bits).unwrap()
}) })
.collect(); .collect();
} }

+ 7
- 3
src/sha_chain_offchain.rs

@ -13,7 +13,11 @@ mod tests {
use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256};
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::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget};
use ark_r1cs_std::{
boolean::Boolean,
convert::{ToBitsGadget, ToBytesGadget},
uint8::UInt8,
};
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::time::Instant; use std::time::Instant;
@ -77,14 +81,14 @@ mod tests {
for _ in 0..HASHES_PER_STEP { for _ in 0..HASHES_PER_STEP {
let mut sha256_var = Sha256Gadget::default(); let mut sha256_var = Sha256Gadget::default();
sha256_var.update(&b).unwrap(); sha256_var.update(&b).unwrap();
b = sha256_var.finalize()?.to_bytes()?;
b = sha256_var.finalize()?.to_bytes_le()?;
} }
let z_i1: Vec<FpVar<F>> = b let z_i1: Vec<FpVar<F>> = b
.iter() .iter()
.map(|e| { .map(|e| {
let bits = e.to_bits_le().unwrap(); let bits = e.to_bits_le().unwrap();
Boolean::<F>::le_bits_to_fp_var(&bits).unwrap()
Boolean::<F>::le_bits_to_fp(&bits).unwrap()
}) })
.collect(); .collect();

+ 7
- 3
src/sha_chain_onchain.rs

@ -21,7 +21,11 @@ mod tests {
use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256};
use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget};
use ark_r1cs_std::{
boolean::Boolean,
convert::{ToBitsGadget, ToBytesGadget},
uint8::UInt8,
};
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -95,14 +99,14 @@ mod tests {
for _ in 0..HASHES_PER_STEP { for _ in 0..HASHES_PER_STEP {
let mut sha256_var = Sha256Gadget::default(); let mut sha256_var = Sha256Gadget::default();
sha256_var.update(&b).unwrap(); sha256_var.update(&b).unwrap();
b = sha256_var.finalize()?.to_bytes()?;
b = sha256_var.finalize()?.to_bytes_le()?;
} }
let z_i1: Vec<FpVar<F>> = b let z_i1: Vec<FpVar<F>> = b
.iter() .iter()
.map(|e| { .map(|e| {
let bits = e.to_bits_le().unwrap(); let bits = e.to_bits_le().unwrap();
Boolean::<F>::le_bits_to_fp_var(&bits).unwrap()
Boolean::<F>::le_bits_to_fp(&bits).unwrap()
}) })
.collect(); .collect();

Loading…
Cancel
Save