Browse Source

update to last sonobe version with full solidity-verifier

main
arnaucube 7 months ago
parent
commit
84fe161812
4 changed files with 33 additions and 42 deletions
  1. +4
    -5
      Cargo.lock
  2. +2
    -2
      Cargo.toml
  3. +27
    -32
      src/main.rs
  4. +0
    -3
      src/utils.rs

+ 4
- 5
Cargo.lock

@ -135,7 +135,7 @@ dependencies = [
[[package]]
name = "ark-circom"
version = "0.1.0"
source = "git+https://github.com/gakonst/ark-circom.git#170b10fc9ed182b5f72ecf379033dda023d0bf07"
source = "git+https://github.com/arnaucube/circom-compat.git#8b2d7915a029f4a6a9285eed3eb7322172cc64d4"
dependencies = [
"ark-bn254",
"ark-crypto-primitives",
@ -1316,7 +1316,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "folding-schemes"
version = "0.1.0"
source = "git+https://github.com/privacy-scaling-explorations/folding-schemes.git?branch=feature/solidity-decider-verifier#a45761a395d9a9a917c5a36d8cc8cddcd9541a87"
source = "git+https://github.com/privacy-scaling-explorations/sonobe.git?branch=feature/solidity-decider-verifier#9c68076782017b0fe205574c894cf6b3e1b5204f"
dependencies = [
"ark-bn254",
"ark-circom",
@ -1333,6 +1333,7 @@ dependencies = [
"ark-std",
"color-eyre",
"num-bigint",
"num-integer",
"rayon",
"subroutines",
"thiserror",
@ -2453,11 +2454,9 @@ dependencies = [
"auto_impl",
"bitflags 2.5.0",
"bitvec",
"c-kzg",
"enumn",
"hashbrown 0.14.3",
"hex",
"once_cell",
]
[[package]]
@ -2816,7 +2815,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "solidity-verifiers"
version = "0.1.0"
source = "git+https://github.com/privacy-scaling-explorations/folding-schemes.git?branch=feature/solidity-decider-verifier#a45761a395d9a9a917c5a36d8cc8cddcd9541a87"
source = "git+https://github.com/privacy-scaling-explorations/sonobe.git?branch=feature/solidity-decider-verifier#9c68076782017b0fe205574c894cf6b3e1b5204f"
dependencies = [
"ark-bn254",
"ark-ec",

+ 2
- 2
Cargo.toml

@ -7,8 +7,8 @@ edition = "2021"
[dependencies]
ark-r1cs-std = { git = "https://github.com/arnaucube/ark-r1cs-std-cherry-picked/" }
folding-schemes = { git = "https://github.com/privacy-scaling-explorations/folding-schemes.git", branch="feature/solidity-decider-verifier" }
solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/folding-schemes.git", package="solidity-verifiers", branch="feature/solidity-decider-verifier" }
folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="folding-schemes", branch="feature/solidity-decider-verifier", features=["light-test"] }
solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="solidity-verifiers", branch="feature/solidity-decider-verifier" }
ark-light-bitcoin-client = { git = "https://github.com/dmpierre/ark-light-bitcoin-client.git" }
ark-ff = "0.4.0"
ark-relations = "0.4.0"

+ 27
- 32
src/main.rs

@ -25,7 +25,7 @@ use solidity_verifiers::{
get_decider_template_for_cyclefold_decider,
utils::get_function_selector_for_nova_cyclefold_verifier,
};
use solidity_verifiers::{Groth16Data, KzgData, NovaCyclefoldData};
use solidity_verifiers::{Groth16Data, KzgData, NovaCycleFoldData};
use std::{fs, marker::PhantomData, time::Instant};
use utils::setup;
mod utils;
@ -129,14 +129,14 @@ fn main() {
NOVA,
>;
let n_blocks_checked = blocks_prepared.len();
let n_blocks_checked = blocks_prepared.len() / 20; // TMP rm '/20'
let circuit = BTCBlockCheckerFCircuit::<Fr>::new(blocks_prepared.clone());
let (prover_params, poseidon_config, kzg_vk) = setup(circuit.clone());
let (fs_prover_params, kzg_vk) = setup(circuit.clone());
let z_0 = vec![Fr::from(0)];
let mut nova = NOVA::init(&prover_params, circuit, z_0.clone()).unwrap();
let mut nova = NOVA::init(&fs_prover_params, circuit, z_0.clone()).unwrap();
println!("Computing folds...");
let now = Instant::now();
let start = Instant::now();
for i in 0..n_blocks_checked {
let current_state = nova.z_i[0].into_bigint();
if i % 10 == 0 {
@ -144,13 +144,13 @@ fn main() {
}
nova.prove_step().unwrap();
}
let elapsed = now.elapsed();
println!(
"Done folding. Checked {} blocks in: {:.2?}",
n_blocks_checked, elapsed
n_blocks_checked,
start.elapsed()
);
let circuit = DeciderEthCircuit::<
let decider_circuit = DeciderEthCircuit::<
Projective,
GVar,
Projective2,
@ -163,23 +163,17 @@ fn main() {
// decider setup
println!("Starting setup...");
let now = Instant::now();
let start = Instant::now();
let (g16_pk, g16_vk) =
Groth16::<Bn254>::circuit_specific_setup(circuit.clone(), &mut rng).unwrap();
let elapsed = now.elapsed();
println!("Setup done in: {:.2?}", elapsed);
Groth16::<Bn254>::circuit_specific_setup(decider_circuit.clone(), &mut rng).unwrap();
println!("Setup done in: {:.2?}", start.elapsed());
// decider proof generation
println!("Generating proof...");
let now = Instant::now();
let decider_pp = (
poseidon_config.clone(),
g16_pk,
prover_params.clone().cs_params,
);
let start = Instant::now();
let decider_pp = (g16_pk, fs_prover_params.cs_params.clone());
let proof = DECIDER::prove(decider_pp, rng, nova.clone()).unwrap();
let elapsed = now.elapsed();
println!("Proof generated in: {:.2?}", elapsed);
println!("Proof generated in: {:.2?}", start.elapsed());
// decider proof verification
println!("Verifying proof...");
@ -198,9 +192,9 @@ fn main() {
let g16_data = Groth16Data::from(g16_vk);
let kzg_data = KzgData::from((
kzg_vk,
Some(prover_params.cs_params.powers_of_g[0..3].to_vec()),
fs_prover_params.cs_params.powers_of_g[0..3].to_vec(),
));
let nova_cyclefold_data = NovaCyclefoldData::from((g16_data, kzg_data, nova.z_0.len()));
let nova_cyclefold_data = NovaCycleFoldData::from((g16_data, kzg_data, nova.z_0.len()));
let function_selector =
get_function_selector_for_nova_cyclefold_verifier(nova.z_0.len() * 2 + 1);
@ -216,17 +210,18 @@ fn main() {
.unwrap();
let decider_template = get_decider_template_for_cyclefold_decider(nova_cyclefold_data);
save_solidity("./NovaLightBTCClientDecider.sol", &decider_template);
fs::write("./solidity-calldata.calldata", calldata).unwrap();
// save smart contract
save_solidity("./NovaLightBTCClientDecider.sol", &decider_template.clone());
// save calldata
fs::write("./solidity-calldata.calldata", calldata.clone()).unwrap();
let nova_cyclefold_verifier_bytecode = compile_solidity(decider_template, "NovaDecider");
let mut evm = Evm::default();
let verifier_address = evm.create(nova_cyclefold_verifier_bytecode);
// let nova_cyclefold_verifier_bytecode = compile_solidity(decider_template, "NovaDecider");
//
// let mut evm = Evm::default();
// let verifier_address = evm.create(nova_cyclefold_verifier_bytecode);
//
// let (_, output) = evm.call(verifier_address, calldata.clone());
// println!("Output: {:?}", output);
// assert_eq!(*output.last().unwrap(), 1);
let (_, output) = evm.call(verifier_address, calldata);
println!("Output: {:?}", output);
assert_eq!(*output.last().unwrap(), 1);
}

+ 0
- 3
src/utils.rs

@ -1,6 +1,5 @@
use crate::BTCBlockCheckerFCircuit;
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as Projective};
use ark_crypto_primitives::sponge::poseidon::PoseidonConfig;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as Projective2};
use ark_poly_commit::kzg10::VerifierKey as KZGVerifierKey;
use folding_schemes::{
@ -17,7 +16,6 @@ pub fn setup(
circuit: BTCBlockCheckerFCircuit<Fr>,
) -> (
ProverParams<Projective, Projective2, KZG<'static, Bn254>, Pedersen<Projective2>>,
PoseidonConfig<Fr>,
KZGVerifierKey<Bn254>,
) {
let mut rng = ark_std::test_rng();
@ -40,7 +38,6 @@ pub fn setup(
cs_params: kzg_pk.clone(),
cf_cs_params: cf_pedersen_params,
},
poseidon_config,
kzg_vk,
)
}

Loading…
Cancel
Save