mirror of
https://github.com/arnaucube/sonobe-light-btc.git
synced 2026-01-27 22:43:46 +01:00
half-migrate to last Sonobe version whith 'external_inputs' at each step
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
/target
|
/target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
generated
|
||||||
|
*.calldata
|
||||||
|
*.inputs
|
||||||
|
|||||||
11
Cargo.toml
11
Cargo.toml
@@ -6,10 +6,11 @@ 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-r1cs-std = { git = "https://github.com/arnaucube/ark-r1cs-std-cherry-picked/" }
|
ark-r1cs-std = { git = "https://github.com/winderica/r1cs-std", branch="cherry-pick" }
|
||||||
folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="folding-schemes", branch="feature/solidity-decider-verifier", features=["light-test"] }
|
folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="folding-schemes", branch="circom-external-inputs", features=["light-test"] }
|
||||||
solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="solidity-verifiers", branch="feature/solidity-decider-verifier" }
|
solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe.git", package="solidity-verifiers", branch="circom-external-inputs" }
|
||||||
ark-light-bitcoin-client = { git = "https://github.com/dmpierre/ark-light-bitcoin-client.git" }
|
# ark-light-bitcoin-client = { git = "https://github.com/dmpierre/ark-light-bitcoin-client.git" }
|
||||||
|
ark-light-bitcoin-client = { path = "../ark-light-bitcoin-client" } # WIP
|
||||||
ark-ff = "0.4.0"
|
ark-ff = "0.4.0"
|
||||||
ark-relations = "0.4.0"
|
ark-relations = "0.4.0"
|
||||||
serde_json = "1.0.114"
|
serde_json = "1.0.114"
|
||||||
@@ -26,6 +27,6 @@ ark-poly-commit = "0.4.0"
|
|||||||
ark-groth16 = "0.4.0"
|
ark-groth16 = "0.4.0"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
ark-r1cs-std = { git = "https://github.com/arnaucube/ark-r1cs-std-cherry-picked/" }
|
ark-r1cs-std = { git = "https://github.com/winderica/r1cs-std", branch="cherry-pick" }
|
||||||
ark-bn254 = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"}
|
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-grumpkin = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"}
|
||||||
|
|||||||
47
src/main.rs
47
src/main.rs
@@ -15,6 +15,7 @@ use folding_schemes::{
|
|||||||
commitment::{kzg::KZG, pedersen::Pedersen},
|
commitment::{kzg::KZG, pedersen::Pedersen},
|
||||||
folding::nova::{decider_eth::Decider, Nova},
|
folding::nova::{decider_eth::Decider, Nova},
|
||||||
frontend::FCircuit,
|
frontend::FCircuit,
|
||||||
|
Error,
|
||||||
};
|
};
|
||||||
use folding_schemes::{folding::nova::decider_eth::prepare_calldata, Decider as DeciderTrait};
|
use folding_schemes::{folding::nova::decider_eth::prepare_calldata, Decider as DeciderTrait};
|
||||||
use folding_schemes::{folding::nova::decider_eth_circuit::DeciderEthCircuit, FoldingScheme};
|
use folding_schemes::{folding::nova::decider_eth_circuit::DeciderEthCircuit, FoldingScheme};
|
||||||
@@ -25,7 +26,7 @@ use solidity_verifiers::{
|
|||||||
get_decider_template_for_cyclefold_decider,
|
get_decider_template_for_cyclefold_decider,
|
||||||
utils::get_function_selector_for_nova_cyclefold_verifier,
|
utils::get_function_selector_for_nova_cyclefold_verifier,
|
||||||
};
|
};
|
||||||
use solidity_verifiers::{Groth16Data, KzgData, NovaCycleFoldData};
|
use solidity_verifiers::{utils::get_formatted_calldata, NovaCycleFoldVerifierKey};
|
||||||
use std::{fs, marker::PhantomData, time::Instant};
|
use std::{fs, marker::PhantomData, time::Instant};
|
||||||
use utils::setup;
|
use utils::setup;
|
||||||
mod utils;
|
mod utils;
|
||||||
@@ -33,26 +34,35 @@ mod utils;
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct BTCBlockCheckerFCircuit<F: PrimeField> {
|
pub struct BTCBlockCheckerFCircuit<F: PrimeField> {
|
||||||
_f: PhantomData<F>,
|
_f: PhantomData<F>,
|
||||||
block: Vec<Block>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: PrimeField> FCircuit<F> for BTCBlockCheckerFCircuit<F> {
|
impl<F: PrimeField> FCircuit<F> for BTCBlockCheckerFCircuit<F> {
|
||||||
type Params = Vec<Block>;
|
type Params = ();
|
||||||
|
|
||||||
fn new(params: Self::Params) -> Self {
|
fn new(params: Self::Params) -> Result<Self, Error> {
|
||||||
Self {
|
Ok(Self { _f: PhantomData })
|
||||||
_f: PhantomData,
|
|
||||||
block: params,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_len(&self) -> usize {
|
fn state_len(&self) -> usize {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
fn external_inputs_len(&self) -> usize {
|
||||||
|
1 // TODO set the number of the external_inputs
|
||||||
|
}
|
||||||
|
|
||||||
fn step_native(&self, i: usize, z_i: Vec<F>) -> Result<Vec<F>, folding_schemes::Error> {
|
fn step_native(
|
||||||
|
&self,
|
||||||
|
i: usize,
|
||||||
|
z_i: Vec<F>,
|
||||||
|
external_inputs: Vec<F>,
|
||||||
|
) -> Result<Vec<F>, folding_schemes::Error> {
|
||||||
let new_z_i = vec![z_i[0] + F::one()];
|
let new_z_i = vec![z_i[0] + F::one()];
|
||||||
|
|
||||||
|
// TODO update internal logic to instead of using `self.block[i]` to use `external_inputs`
|
||||||
|
// ie.:
|
||||||
|
// let block_header = external_inputs[0];
|
||||||
|
// let block_hash = external_inputs[1];
|
||||||
|
|
||||||
// Check block hash
|
// Check block hash
|
||||||
let computed_block_hash = get_block_hash(&self.block[i].block_header);
|
let computed_block_hash = get_block_hash(&self.block[i].block_header);
|
||||||
assert_eq!(computed_block_hash, self.block[i].block_hash);
|
assert_eq!(computed_block_hash, self.block[i].block_hash);
|
||||||
@@ -75,8 +85,11 @@ impl<F: PrimeField> FCircuit<F> for BTCBlockCheckerFCircuit<F> {
|
|||||||
&self,
|
&self,
|
||||||
cs: ConstraintSystemRef<F>,
|
cs: ConstraintSystemRef<F>,
|
||||||
i: usize,
|
i: usize,
|
||||||
z_i: Vec<ark_r1cs_std::fields::fp::FpVar<F>>,
|
z_i: Vec<FpVar<F>>,
|
||||||
) -> Result<Vec<ark_r1cs_std::fields::fp::FpVar<F>>, SynthesisError> {
|
external_inputs: Vec<FpVar<F>>,
|
||||||
|
) -> Result<Vec<FpVar<F>>, SynthesisError> {
|
||||||
|
// TODO update internal logic to instead of using `self.block[i]` to use `external_inputs`
|
||||||
|
|
||||||
let new_z_i = vec![z_i[0].clone() + FpVar::new_constant(cs.clone(), F::one())?];
|
let new_z_i = vec![z_i[0].clone() + FpVar::new_constant(cs.clone(), F::one())?];
|
||||||
let block_var = BlockVar::new_witness(cs.clone(), || Ok(self.block[i].clone()))?;
|
let block_var = BlockVar::new_witness(cs.clone(), || Ok(self.block[i].clone()))?;
|
||||||
let _ = BTCBlockCheckerGadget::check_block(cs.clone(), block_var.clone())?;
|
let _ = BTCBlockCheckerGadget::check_block(cs.clone(), block_var.clone())?;
|
||||||
@@ -130,7 +143,7 @@ fn main() {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
let n_blocks_checked = blocks_prepared.len() / 20; // TMP rm '/20'
|
let n_blocks_checked = blocks_prepared.len() / 20; // TMP rm '/20'
|
||||||
let circuit = BTCBlockCheckerFCircuit::<Fr>::new(blocks_prepared.clone());
|
let circuit = BTCBlockCheckerFCircuit::<Fr>::new(()).unwrap();
|
||||||
let (fs_prover_params, kzg_vk) = setup(circuit.clone());
|
let (fs_prover_params, kzg_vk) = setup(circuit.clone());
|
||||||
let z_0 = vec![Fr::from(0)];
|
let z_0 = vec![Fr::from(0)];
|
||||||
let mut nova = NOVA::init(&fs_prover_params, circuit, z_0.clone()).unwrap();
|
let mut nova = NOVA::init(&fs_prover_params, circuit, z_0.clone()).unwrap();
|
||||||
@@ -142,6 +155,7 @@ fn main() {
|
|||||||
if i % 10 == 0 {
|
if i % 10 == 0 {
|
||||||
println!("--- At block: {}/{} ---", current_state, n_blocks_checked);
|
println!("--- At block: {}/{} ---", current_state, n_blocks_checked);
|
||||||
}
|
}
|
||||||
|
// TODO feed the external_inputs (from blocks_prepared) into prove_step
|
||||||
nova.prove_step().unwrap();
|
nova.prove_step().unwrap();
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
@@ -189,12 +203,7 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verified);
|
assert!(verified);
|
||||||
|
|
||||||
let g16_data = Groth16Data::from(g16_vk);
|
let nova_cyclefold_data = NovaCycleFoldVerifierKey::from((g16_vk, kzg_vk, nova.z_0.len()));
|
||||||
let kzg_data = KzgData::from((
|
|
||||||
kzg_vk,
|
|
||||||
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 function_selector =
|
let function_selector =
|
||||||
get_function_selector_for_nova_cyclefold_verifier(nova.z_0.len() * 2 + 1);
|
get_function_selector_for_nova_cyclefold_verifier(nova.z_0.len() * 2 + 1);
|
||||||
|
|
||||||
@@ -215,6 +224,8 @@ fn main() {
|
|||||||
save_solidity("./NovaLightBTCClientDecider.sol", &decider_template.clone());
|
save_solidity("./NovaLightBTCClientDecider.sol", &decider_template.clone());
|
||||||
// save calldata
|
// save calldata
|
||||||
fs::write("./solidity-calldata.calldata", calldata.clone()).unwrap();
|
fs::write("./solidity-calldata.calldata", calldata.clone()).unwrap();
|
||||||
|
let s = get_formatted_calldata(calldata.clone());
|
||||||
|
fs::write("./solidity-calldata.inputs", s.join(",\n")).expect("");
|
||||||
|
|
||||||
let nova_cyclefold_verifier_bytecode = compile_solidity(decider_template, "NovaDecider");
|
let nova_cyclefold_verifier_bytecode = compile_solidity(decider_template, "NovaDecider");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user