From cd6fa75eb9c6c8cfe0a142088c940bf7ae881256 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 01:03:05 +0800 Subject: [PATCH 01/15] feat: add todo --- starky/src/compressor12/compressor12_exec.rs | 3 ++ starky/src/compressor12/mod.rs | 35 ++++++++++++++++++++ starky/src/compressor12/plonk_setup.rs | 1 + 3 files changed, 39 insertions(+) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index 3d22d3ee..bcc82830 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -54,9 +54,11 @@ pub fn exec( .collect::>(); for i in 0..adds_len { + // add[i], PlonkAdd.2/3 let w2 = FGL::from_raw_repr(::Repr::from(adds[i * 4 + 2])).unwrap(); let w3 = FGL::from_raw_repr(::Repr::from(adds[i * 4 + 3])).unwrap(); + // add[i], PlonkAdd.0/1 let f_w = (w[adds[i * 4] as usize] * w2) + (w[adds[i * 4 + 1] as usize] * w3); w.push(f_w); } @@ -67,6 +69,7 @@ pub fn exec( for i in 0..s_map_column_len { for c in 0..12 { + // s_map[c][i] let s = s_map[i * 12 + c] as usize; cm_pols.set_matrix( diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index fd15a593..caf572f9 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -1,6 +1,41 @@ #![allow(non_snake_case)] + +use crate::compressor12_exec::exec; +use crate::compressor12_setup::setup; + pub mod compressor12_exec; pub(crate) mod compressor12_pil; pub mod compressor12_setup; pub(crate) mod constants; pub(crate) mod plonk_setup; + +// compress12 phase: +// input: .r1cs, .wasm, zkin.json(input_file) +// output: .const, .cm +pub fn compress12( + // setup + r1cs_file: &str, + // pil_file: &str, + const_file: &str, + // exec_file: &str, + force_n_bits: usize, + // exec + input_file: &str, + wasm_file: &str, + pil_file: &str, + exec_file: &str, + commit_file: &str, +) { + // todo remove the pil_file and exec_file. + + // setup phase: + // input: .r1cs + // output: .pil, .const, .exec, + // return: todo PIL, exec file. + setup(r1cs_file, pil_file, const_file, exec_file, force_n_bits); + + // exec phase: + // input files: .wasm, .exec, .pil, zkin.json(input file), + // output: .cm + exec(input_file, wasm_file, pil_file, exec_file, commit_file); +} diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index 7288e12b..05b644ff 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -16,6 +16,7 @@ use std::collections::BTreeMap; #[derive(Default, Debug)] pub struct PlonkSetup { pub(crate) pil_str: String, + // pub(crate) pil_json: PIL, //todo pub(crate) const_pols: PolsArray, pub(crate) s_map: Vec>, pub(crate) plonk_additions: Vec, From 459a8a5a4f552717f789040e6ffd889661caa4b8 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 01:12:05 +0800 Subject: [PATCH 02/15] feat: first try --- starky/src/compressor12/compressor12_exec.rs | 31 ++++++++++++------- starky/src/compressor12/compressor12_setup.rs | 18 +++++------ starky/src/compressor12/mod.rs | 20 ++++++++++-- starky/src/compressor12/plonk_setup.rs | 6 ++-- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index bcc82830..156bc21b 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -1,3 +1,4 @@ +use crate::compressor12::plonk_setup::PlonkSetup; use crate::compressor12_pil::CompressorNameSpace::*; use crate::compressor12_pil::CompressorPolName::a; use crate::errors::EigenError; @@ -18,21 +19,28 @@ pub type Result = std::result::Result; // input files: .wasm, .exec, .pil, zkin.json(input file), // output: .cm pub fn exec( + plonk_setup: PlonkSetup, input_file: &str, wasm_file: &str, - pil_file: &str, - exec_file: &str, + // pil_file: &str, + // exec_file: &str, commit_file: &str, ) -> Result<()> { // 0. load exec_file, - let (adds_len, s_map_column_len, adds, s_map) = read_exec_file(exec_file); + // let (adds_len, s_map_column_len, adds, s_map) = read_exec_file(exec_file); + let adds = plonk_setup.plonk_additions; + let s_map = plonk_setup.s_map; + + let adds_len = adds.len(); + let s_map_column_len = s_map[0].len(); // 1. Compiles a .pil file to its json form , and save it. // TODO: the pil_str has been compiled in plonk_setup#3 - let pil_json = compile_pil_from_path(pil_file); - let mut file = File::create(Path::new(&format!("{pil_file}.json"))).unwrap(); - let input = serde_json::to_string(&pil_json).unwrap(); - write!(file, "{}", input).unwrap(); + // let pil_json = compile_pil_from_path(pil_file); + // let mut file = File::create(Path::new(&format!("{pil_file}.json"))).unwrap(); + // let input = serde_json::to_string(&pil_json).unwrap(); + // write!(file, "{}", input).unwrap(); + let pil_json = plonk_setup.pil_json; // 2. construct cmPol: .pil.json -> .cm let mut cm_pols = PolsArray::new(&pil_json, PolKind::Commit); @@ -55,11 +63,11 @@ pub fn exec( for i in 0..adds_len { // add[i], PlonkAdd.2/3 - let w2 = FGL::from_raw_repr(::Repr::from(adds[i * 4 + 2])).unwrap(); - let w3 = FGL::from_raw_repr(::Repr::from(adds[i * 4 + 3])).unwrap(); + let w2 = adds[i * 4].2; + let w3 = adds[i * 4].3; // add[i], PlonkAdd.0/1 - let f_w = (w[adds[i * 4] as usize] * w2) + (w[adds[i * 4 + 1] as usize] * w3); + let f_w = (w[adds[i * 4].0] * w2) + (w[adds[i * 4].1] * w3); w.push(f_w); } @@ -70,7 +78,8 @@ pub fn exec( for i in 0..s_map_column_len { for c in 0..12 { // s_map[c][i] - let s = s_map[i * 12 + c] as usize; + // let s = s_map[i * 12 + c] as usize; + let s = s_map[c][i] as usize; cm_pols.set_matrix( &pil_json, diff --git a/starky/src/compressor12/compressor12_setup.rs b/starky/src/compressor12/compressor12_setup.rs index 8912b9cc..439506a1 100644 --- a/starky/src/compressor12/compressor12_setup.rs +++ b/starky/src/compressor12/compressor12_setup.rs @@ -19,11 +19,11 @@ pub struct Options { // output: .pil, .const, .exec, pub fn setup( r1cs_file: &str, - pil_file: &str, + // pil_file: &str, const_file: &str, - exec_file: &str, + // exec_file: &str, force_n_bits: usize, -) -> Result<()> { +) -> Result { // 0. readR1cs let r1cs = load_r1cs::(r1cs_file); let opts = Options { @@ -33,17 +33,17 @@ pub fn setup( // 1. plonk setup: generate plonk circuit, the pil file. let res = PlonkSetup::new(&r1cs, &opts); - // 2. And write it into pil_file. - let mut file = File::create(pil_file).unwrap(); - write!(file, "{}", res.pil_str).unwrap(); + // // 2. And write it into pil_file. + // let mut file = File::create(pil_file).unwrap(); + // write!(file, "{}", res.pil_str).unwrap(); // 3. write const pols file res.const_pols.save(const_file)?; - // 4. construct and save ExecFile: plonk additions + sMap -> BigUint64Array - write_exec_file(exec_file, &res.plonk_additions, &res.s_map); + // // 4. construct and save ExecFile: plonk additions + sMap -> BigUint64Array + // write_exec_file(exec_file, &res.plonk_additions, &res.s_map); - Ok(()) + Ok(res) } // construct and save ExecFile: plonk additions + sMap -> BigUint64Array diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index caf572f9..6bca2328 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -2,6 +2,8 @@ use crate::compressor12_exec::exec; use crate::compressor12_setup::setup; +use algebraic::errors::EigenError; +pub type Result = std::result::Result; pub mod compressor12_exec; pub(crate) mod compressor12_pil; @@ -25,17 +27,29 @@ pub fn compress12( pil_file: &str, exec_file: &str, commit_file: &str, -) { +) -> Result<()> { // todo remove the pil_file and exec_file. // setup phase: // input: .r1cs // output: .pil, .const, .exec, // return: todo PIL, exec file. - setup(r1cs_file, pil_file, const_file, exec_file, force_n_bits); + let plonk_setup = setup( + r1cs_file, + // pil_file, + const_file, + // exec_file, + force_n_bits, + )?; // exec phase: // input files: .wasm, .exec, .pil, zkin.json(input file), // output: .cm - exec(input_file, wasm_file, pil_file, exec_file, commit_file); + exec( + plonk_setup, + input_file, + wasm_file, + // pil_file, exec_file, + commit_file, + )?; } diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index 05b644ff..e4634adb 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -15,8 +15,8 @@ use std::collections::BTreeMap; #[derive(Default, Debug)] pub struct PlonkSetup { - pub(crate) pil_str: String, - // pub(crate) pil_json: PIL, //todo + // pub(crate) pil_str: String, + pub(crate) pil_json: PIL, //todo pub(crate) const_pols: PolsArray, pub(crate) s_map: Vec>, pub(crate) plonk_additions: Vec, @@ -39,7 +39,7 @@ impl PlonkSetup { let (const_pols, s_map) = plonk_setup_compressor(r1cs, &pil_json, &plonk_setup_info); Self { - pil_str, + pil_json, const_pols, s_map, plonk_additions: plonk_setup_info.pa, From 83bbed049689daaab5ca68462fcfb6787679c6ca Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 01:22:41 +0800 Subject: [PATCH 03/15] feat: add command --- starkjs/README.md | 12 ++++++-- starky/src/compressor12/mod.rs | 14 +++------ zkit/src/main.rs | 56 ++++++++++++++++++++++++++-------- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/starkjs/README.md b/starkjs/README.md index a0d59234..d1e9d745 100644 --- a/starkjs/README.md +++ b/starkjs/README.md @@ -27,9 +27,15 @@ export CIRCUIT=fib RUST_LOG=debug ../target/release/eigen-zkit compile -p goldilocks -i circuits/$CIRCUIT.verifier.circom -l node_modules/pil-stark/circuits.gl --O2=full -o /tmp/ # Circom to Stark -RUST_LOG=debug ../target/release/eigen-zkit compressor12_setup --r /tmp/$CIRCUIT.verifier.r1cs --c /tmp/c12.const --p /tmp/c12.pil --e /tmp/c12.exec - -RUST_LOG=debug ../target/release/eigen-zkit compressor12_exec --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm --i circuits/$CIRCUIT.verifier.zkin.json --p /tmp/c12.pil --e /tmp/c12.exec --m /tmp/c12.cm +#RUST_LOG=debug ../target/release/eigen-zkit compressor12_setup --r /tmp/$CIRCUIT.verifier.r1cs --c /tmp/c12.const --p /tmp/c12.pil --e /tmp/c12.exec +#RUST_LOG=debug ../target/release/eigen-zkit compressor12_exec --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm --i circuits/$CIRCUIT.verifier.zkin.json --p /tmp/c12.pil --e /tmp/c12.exec --m /tmp/c12.cm + +RUST_LOG=debug ../target/release/eigen-zkit compressor12 \ + --r /tmp/$CIRCUIT.verifier.r1cs \ + --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm\ + --i circuits/$CIRCUIT.verifier.zkin.json \ + --c /tmp/c12.const \ + --m /tmp/c12.cm RUST_LOG=debug ../target/release/eigen-zkit stark_prove -s ../starky/data/c12.starkStruct.bn128.json \ -p /tmp/c12.pil.json \ diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index 6bca2328..b11dc36f 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -15,17 +15,11 @@ pub(crate) mod plonk_setup; // input: .r1cs, .wasm, zkin.json(input_file) // output: .const, .cm pub fn compress12( - // setup - r1cs_file: &str, - // pil_file: &str, - const_file: &str, - // exec_file: &str, force_n_bits: usize, - // exec - input_file: &str, + r1cs_file: &str, wasm_file: &str, - pil_file: &str, - exec_file: &str, + input_file: &str, + const_file: &str, commit_file: &str, ) -> Result<()> { // todo remove the pil_file and exec_file. @@ -51,5 +45,5 @@ pub fn compress12( wasm_file, // pil_file, exec_file, commit_file, - )?; + ) } diff --git a/zkit/src/main.rs b/zkit/src/main.rs index fa39c408..a0d76262 100644 --- a/zkit/src/main.rs +++ b/zkit/src/main.rs @@ -246,6 +246,25 @@ struct Compressor12SetupOpt { force_n_bits: usize, } +/// Exec compressor12 for converting R1CS to PIL +#[derive(Parser, Debug)] +struct Compressor12Opt { + #[arg(long, default_value = "0")] + force_n_bits: usize, + // input: .r1cs, .wasm, zkin.json(input_file) + #[arg(long = "r", default_value = "mycircuit.verifier.r1cs")] + r1cs_file: String, + #[arg(long = "w", default_value = "mycircuit.verifier.wasm")] + wasm_file: String, + #[arg(long = "i", default_value = "mycircuit.proof.zkin.json")] + input_file: String, + // output: .const, .cm + #[arg(long = "c", default_value = "mycircuit.c12.const")] + const_file: String, // Output file required to build the constants + #[arg(long = "m", default_value = "mycircuit.c12.cm")] + commit_file: String, +} + /// Exec compressor12 for converting R1CS to PIL #[derive(Parser, Debug)] struct Compressor12ExecOpt { @@ -363,6 +382,9 @@ enum Command { #[command(name = "analyse")] Analyse(AnalyseOpt), + #[command(name = "compressor12")] + Compressor12(Compressor12Opt), + #[command(name = "compressor12_setup")] Compressor12Setup(Compressor12SetupOpt), #[command(name = "compressor12_exec")] @@ -454,22 +476,32 @@ fn main() { .map_err(|e| EigenError::from(format!("stark prove error {:?}", e))), Command::Analyse(args) => analyse(&args.circuit_file, &args.output), - Command::Compressor12Setup(args) => starky::compressor12_setup::setup( - &args.r1cs_file, - &args.pil_file, - &args.const_file, - &args.exec_file, + // Command::Compressor12Setup(args) => starky::compressor12_setup::setup( + // &args.r1cs_file, + // &args.pil_file, + // &args.const_file, + // &args.exec_file, + // args.force_n_bits, + // ) + // .map_err(|_| EigenError::from("compreesor12 setup error".to_string())), + Command::Compressor12(args) => starky::compress12( args.force_n_bits, - ) - .map_err(|_| EigenError::from("compreesor12 setup error".to_string())), - Command::Compressor12Exec(args) => starky::compressor12_exec::exec( - &args.input_file, + &args.r1cs_file, &args.wasm_file, - &args.pil_file, - &args.exec_file, + &args.input_file, + &args.const_file, &args.commit_file, ) - .map_err(|_| EigenError::from("compreesor12 exec error".to_string())), + .map_err(|_| EigenError::from("compreesor12 setup error".to_string())), + + // Command::Compressor12Exec(args) => starky::compressor12_exec::exec( + // &args.input_file, + // &args.wasm_file, + // &args.pil_file, + // &args.exec_file, + // &args.commit_file, + // ) + // .map_err(|_| EigenError::from("compreesor12 exec error".to_string())), Command::JoinZkin(args) => { starky::zkin_join::join_zkin(&args.zkin1, &args.zkin2, &args.zkinout) .map_err(|_| EigenError::from("join_zkin error".to_string())) From 22d7c2848b2c60bdc24e4e562a6b3de3a4bd3bf3 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 01:34:05 +0800 Subject: [PATCH 04/15] todo debug exec.rs#70 --- starky/src/compressor12/plonk_setup.rs | 2 +- zkit/src/main.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index e4634adb..503b9903 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -13,7 +13,7 @@ use plonky::field_gl::Fr as FGL; use plonky::field_gl::GL; use std::collections::BTreeMap; -#[derive(Default, Debug)] +#[derive(Debug)] pub struct PlonkSetup { // pub(crate) pil_str: String, pub(crate) pil_json: PIL, //todo diff --git a/zkit/src/main.rs b/zkit/src/main.rs index a0d76262..71460ab0 100644 --- a/zkit/src/main.rs +++ b/zkit/src/main.rs @@ -385,10 +385,10 @@ enum Command { #[command(name = "compressor12")] Compressor12(Compressor12Opt), - #[command(name = "compressor12_setup")] - Compressor12Setup(Compressor12SetupOpt), - #[command(name = "compressor12_exec")] - Compressor12Exec(Compressor12ExecOpt), + // #[command(name = "compressor12_setup")] + // Compressor12Setup(Compressor12SetupOpt), + // #[command(name = "compressor12_exec")] + // Compressor12Exec(Compressor12ExecOpt), #[command(name = "join_zkin")] JoinZkin(JoinZkinExecOpt), @@ -492,7 +492,7 @@ fn main() { &args.const_file, &args.commit_file, ) - .map_err(|_| EigenError::from("compreesor12 setup error".to_string())), + .map_err(|_| EigenError::from("compreesor12 error".to_string())), // Command::Compressor12Exec(args) => starky::compressor12_exec::exec( // &args.input_file, From 462de481558bb3af8f5ee8d0e27e0a16bbce7e96 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 11:28:23 +0800 Subject: [PATCH 05/15] todo debug exec.rs#70 --- starkjs/README.md | 13 +++++++------ starky/src/compressor12/compressor12_exec.rs | 5 ++++- starky/src/compressor12/mod.rs | 8 +++++--- zkit/src/main.rs | 3 +++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/starkjs/README.md b/starkjs/README.md index d1e9d745..4f8b57df 100644 --- a/starkjs/README.md +++ b/starkjs/README.md @@ -34,13 +34,14 @@ RUST_LOG=debug ../target/release/eigen-zkit compressor12 \ --r /tmp/$CIRCUIT.verifier.r1cs \ --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm\ --i circuits/$CIRCUIT.verifier.zkin.json \ - --c /tmp/c12.const \ - --m /tmp/c12.cm - + --c /tmp/c12_new.const \ + --m /tmp/c12_new.cm \ + --p /tmp/c12_new.pil.json + RUST_LOG=debug ../target/release/eigen-zkit stark_prove -s ../starky/data/c12.starkStruct.bn128.json \ - -p /tmp/c12.pil.json \ - --o /tmp/c12.const \ - --m /tmp/c12.cm -c circuits/circuit.circom --i circuits/circuit.zkin.json --norm_stage + -p /tmp/c12_new.pil.json \ + --o /tmp/c12_new.const \ + --m /tmp/c12_new.cm -c circuits/circuit.circom --i circuits/circuit.zkin.json --norm_stage ``` ### Top Layer: Snark proof diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index 156bc21b..75045b33 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -22,7 +22,7 @@ pub fn exec( plonk_setup: PlonkSetup, input_file: &str, wasm_file: &str, - // pil_file: &str, + pil_json_file: &str, // exec_file: &str, commit_file: &str, ) -> Result<()> { @@ -41,6 +41,9 @@ pub fn exec( // let input = serde_json::to_string(&pil_json).unwrap(); // write!(file, "{}", input).unwrap(); let pil_json = plonk_setup.pil_json; + let mut file = File::create(Path::new(pil_json_file)).unwrap(); + let input = serde_json::to_string(&pil_json).unwrap(); + write!(file, "{}", input).unwrap(); // 2. construct cmPol: .pil.json -> .cm let mut cm_pols = PolsArray::new(&pil_json, PolKind::Commit); diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index b11dc36f..b3c6344a 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -13,7 +13,7 @@ pub(crate) mod plonk_setup; // compress12 phase: // input: .r1cs, .wasm, zkin.json(input_file) -// output: .const, .cm +// output: .const, .cm, pil.json pub fn compress12( force_n_bits: usize, r1cs_file: &str, @@ -21,6 +21,7 @@ pub fn compress12( input_file: &str, const_file: &str, commit_file: &str, + pil_json_file: &str, ) -> Result<()> { // todo remove the pil_file and exec_file. @@ -38,12 +39,13 @@ pub fn compress12( // exec phase: // input files: .wasm, .exec, .pil, zkin.json(input file), - // output: .cm + // output: .cm, .pil.json exec( plonk_setup, input_file, wasm_file, - // pil_file, exec_file, + pil_json_file, + // exec_file, commit_file, ) } diff --git a/zkit/src/main.rs b/zkit/src/main.rs index 71460ab0..7add1226 100644 --- a/zkit/src/main.rs +++ b/zkit/src/main.rs @@ -263,6 +263,8 @@ struct Compressor12Opt { const_file: String, // Output file required to build the constants #[arg(long = "m", default_value = "mycircuit.c12.cm")] commit_file: String, + #[arg(long = "p", default_value = "mycircuit.c12.pil.json")] + pil_json_file: String, } /// Exec compressor12 for converting R1CS to PIL @@ -491,6 +493,7 @@ fn main() { &args.input_file, &args.const_file, &args.commit_file, + &args.pil_json_file, ) .map_err(|_| EigenError::from("compreesor12 error".to_string())), From fd2a0493db3e0cf1e9fcfd3c5bed7f37072fd023 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 11:53:57 +0800 Subject: [PATCH 06/15] add debug info --- starkjs/README.md | 12 +++--- starky/src/compressor12/compressor12_exec.rs | 43 +++++++++++++++---- starky/src/compressor12/compressor12_setup.rs | 12 +++--- starky/src/compressor12/mod.rs | 16 +++---- starky/src/compressor12/plonk_setup.rs | 3 +- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/starkjs/README.md b/starkjs/README.md index 4f8b57df..879654ab 100644 --- a/starkjs/README.md +++ b/starkjs/README.md @@ -34,14 +34,14 @@ RUST_LOG=debug ../target/release/eigen-zkit compressor12 \ --r /tmp/$CIRCUIT.verifier.r1cs \ --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm\ --i circuits/$CIRCUIT.verifier.zkin.json \ - --c /tmp/c12_new.const \ - --m /tmp/c12_new.cm \ - --p /tmp/c12_new.pil.json + --c /tmp/c12.const \ + --m /tmp/c12.cm \ + --p /tmp/c12.pil.json RUST_LOG=debug ../target/release/eigen-zkit stark_prove -s ../starky/data/c12.starkStruct.bn128.json \ - -p /tmp/c12_new.pil.json \ - --o /tmp/c12_new.const \ - --m /tmp/c12_new.cm -c circuits/circuit.circom --i circuits/circuit.zkin.json --norm_stage + -p /tmp/c12.pil.json \ + --o /tmp/c12.const \ + --m /tmp/c12.cm -c circuits/circuit.circom --i circuits/circuit.zkin.json --norm_stage ``` ### Top Layer: Snark proof diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index 75045b33..d7895a2e 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -9,6 +9,7 @@ use num_traits::Zero; use plonky::ff::PrimeField; use plonky::field_gl::Fr as FGL; use plonky::witness::{load_input_for_witness, WitnessCalculator}; +use std::fmt::format; use std::fs::File; use std::io::Write; use std::path::Path; @@ -23,27 +24,36 @@ pub fn exec( input_file: &str, wasm_file: &str, pil_json_file: &str, - // exec_file: &str, + pil_file: &str, // debug one + exec_file: &str, // debug one commit_file: &str, ) -> Result<()> { // 0. load exec_file, - // let (adds_len, s_map_column_len, adds, s_map) = read_exec_file(exec_file); + // debug one + let (adds_len_old, s_map_column_len_old, adds_old, s_map_old) = read_exec_file(exec_file); + let adds = plonk_setup.plonk_additions; let s_map = plonk_setup.s_map; - let adds_len = adds.len(); let s_map_column_len = s_map[0].len(); + assert_eq!(adds_len_old, adds_len); + assert_eq!(s_map_column_len_old, s_map_column_len); // 1. Compiles a .pil file to its json form , and save it. + // debug one // TODO: the pil_str has been compiled in plonk_setup#3 - // let pil_json = compile_pil_from_path(pil_file); - // let mut file = File::create(Path::new(&format!("{pil_file}.json"))).unwrap(); - // let input = serde_json::to_string(&pil_json).unwrap(); - // write!(file, "{}", input).unwrap(); + let pil_json_old = compile_pil_from_path(pil_file); + let mut file = File::create(Path::new(&format!("{pil_file}.old.json"))).unwrap(); + let input_old = serde_json::to_string(&pil_json_old).unwrap(); + write!(file, "{}", input_old).unwrap(); + // debug one above + let pil_json = plonk_setup.pil_json; let mut file = File::create(Path::new(pil_json_file)).unwrap(); - let input = serde_json::to_string(&pil_json).unwrap(); + let input = serde_json::to_string(&pil_json_file).unwrap(); write!(file, "{}", input).unwrap(); + assert_eq!(pil_json_old, pil_json); // meet error. + assert_eq!(input_old, input); // 2. construct cmPol: .pil.json -> .cm let mut cm_pols = PolsArray::new(&pil_json, PolKind::Commit); @@ -65,12 +75,25 @@ pub fn exec( .collect::>(); for i in 0..adds_len { + // debug one + let w2_old = + FGL::from_raw_repr(::Repr::from(adds_old[i * 4 + 2])).unwrap(); + let w3_old = + FGL::from_raw_repr(::Repr::from(adds_old[i * 4 + 3])).unwrap(); + let f_w_old = + (w[adds_old[i * 4] as usize] * w2_old) + (w[adds_old[i * 4 + 1] as usize] * w3_old); + // add[i], PlonkAdd.2/3 let w2 = adds[i * 4].2; let w3 = adds[i * 4].3; // add[i], PlonkAdd.0/1 let f_w = (w[adds[i * 4].0] * w2) + (w[adds[i * 4].1] * w3); + + assert_eq!(w2, w2_old, "{}", i); + assert_eq!(w3, w3_old, "{}", i); + assert_eq!(f_w, f_w_old, "{}", i); + w.push(f_w); } @@ -81,8 +104,10 @@ pub fn exec( for i in 0..s_map_column_len { for c in 0..12 { // s_map[c][i] - // let s = s_map[i * 12 + c] as usize; + let s_old = s_map_old[i * 12 + c] as usize; // debug one + let s = s_map[c][i] as usize; + assert_eq!(s_old, s); cm_pols.set_matrix( &pil_json, diff --git a/starky/src/compressor12/compressor12_setup.rs b/starky/src/compressor12/compressor12_setup.rs index 439506a1..e749e82e 100644 --- a/starky/src/compressor12/compressor12_setup.rs +++ b/starky/src/compressor12/compressor12_setup.rs @@ -19,9 +19,9 @@ pub struct Options { // output: .pil, .const, .exec, pub fn setup( r1cs_file: &str, - // pil_file: &str, + pil_file: &str, const_file: &str, - // exec_file: &str, + exec_file: &str, force_n_bits: usize, ) -> Result { // 0. readR1cs @@ -34,14 +34,14 @@ pub fn setup( let res = PlonkSetup::new(&r1cs, &opts); // // 2. And write it into pil_file. - // let mut file = File::create(pil_file).unwrap(); - // write!(file, "{}", res.pil_str).unwrap(); + let mut file = File::create(pil_file).unwrap(); + write!(file, "{}", res.pil_str).unwrap(); // 3. write const pols file res.const_pols.save(const_file)?; - // // 4. construct and save ExecFile: plonk additions + sMap -> BigUint64Array - // write_exec_file(exec_file, &res.plonk_additions, &res.s_map); + // 4. construct and save ExecFile: plonk additions + sMap -> BigUint64Array + write_exec_file(exec_file, &res.plonk_additions, &res.s_map); Ok(res) } diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index b3c6344a..1887fd3b 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -25,17 +25,14 @@ pub fn compress12( ) -> Result<()> { // todo remove the pil_file and exec_file. + let pil_file = "/tmp/c12.pil"; + let exec_file = "/tmp/c12.exec"; + // setup phase: // input: .r1cs // output: .pil, .const, .exec, // return: todo PIL, exec file. - let plonk_setup = setup( - r1cs_file, - // pil_file, - const_file, - // exec_file, - force_n_bits, - )?; + let plonk_setup = setup(r1cs_file, pil_file, const_file, exec_file, force_n_bits)?; // exec phase: // input files: .wasm, .exec, .pil, zkin.json(input file), @@ -45,7 +42,10 @@ pub fn compress12( input_file, wasm_file, pil_json_file, - // exec_file, + // debug one + pil_file, + exec_file, + // debug one above commit_file, ) } diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index 503b9903..267d685e 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -15,7 +15,7 @@ use std::collections::BTreeMap; #[derive(Debug)] pub struct PlonkSetup { - // pub(crate) pil_str: String, + pub(crate) pil_str: String, pub(crate) pil_json: PIL, //todo pub(crate) const_pols: PolsArray, pub(crate) s_map: Vec>, @@ -39,6 +39,7 @@ impl PlonkSetup { let (const_pols, s_map) = plonk_setup_compressor(r1cs, &pil_json, &plonk_setup_info); Self { + pil_str, pil_json, const_pols, s_map, From 8c66d1549d705b45ba5077db59ac26c7e1bd0b73 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 12:01:02 +0800 Subject: [PATCH 07/15] add debug info --- starky/src/compressor12/compressor12_exec.rs | 7 +++++-- starky/src/compressor12/plonk_setup.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index d7895a2e..1794c84d 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -3,7 +3,7 @@ use crate::compressor12_pil::CompressorNameSpace::*; use crate::compressor12_pil::CompressorPolName::a; use crate::errors::EigenError; use crate::io_utils::read_vec_from_file; -use crate::pilcom::compile_pil_from_path; +use crate::pilcom::{compile_pil_from_path, compile_pil_from_str}; use crate::polsarray::{PolKind, PolsArray}; use num_traits::Zero; use plonky::ff::PrimeField; @@ -48,7 +48,10 @@ pub fn exec( write!(file, "{}", input_old).unwrap(); // debug one above - let pil_json = plonk_setup.pil_json; + // TODO: Even if the pil_str has been compiled in plonk_setup#3 + // TODO: however it can be passed as param to here. as the pil_json prior is different with pil_json here. + // let pil_json = plonk_setup.pil_json; + let pil_json = compile_pil_from_str(&plonk_setup.pil_str); let mut file = File::create(Path::new(pil_json_file)).unwrap(); let input = serde_json::to_string(&pil_json_file).unwrap(); write!(file, "{}", input).unwrap(); diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index 267d685e..d584ed96 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -16,7 +16,7 @@ use std::collections::BTreeMap; #[derive(Debug)] pub struct PlonkSetup { pub(crate) pil_str: String, - pub(crate) pil_json: PIL, //todo + // pub(crate) pil_json: PIL, //todo pub(crate) const_pols: PolsArray, pub(crate) s_map: Vec>, pub(crate) plonk_additions: Vec, @@ -40,7 +40,7 @@ impl PlonkSetup { Self { pil_str, - pil_json, + // pil_json, const_pols, s_map, plonk_additions: plonk_setup_info.pa, From a4f3c5020d3c3bfecc2e623333d34025f61a8471 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 20:44:27 +0800 Subject: [PATCH 08/15] feat: add test for pil_compile_from_str and from_path --- starky/src/compressor12/compressor12_pil.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/starky/src/compressor12/compressor12_pil.rs b/starky/src/compressor12/compressor12_pil.rs index 81716d33..8481e986 100644 --- a/starky/src/compressor12/compressor12_pil.rs +++ b/starky/src/compressor12/compressor12_pil.rs @@ -373,6 +373,7 @@ macro_rules! c_mul_add { #[cfg(test)] mod test { use crate::compressor12_pil::render; + use crate::pilcom::{compile_pil_from_path, compile_pil_from_str}; use std::fs::File; use std::io::Write; use std::path::Path; @@ -387,8 +388,13 @@ mod test { #[test] fn test_render_and_compile() { + let pil_file_path = "/tmp/render_pil_rs.pil"; let pil_string = render(5, 5); - let mut file = File::create(Path::new("/tmp/render_pil_rs.pil")).unwrap(); + let mut file = File::create(Path::new(pil_file_path)).unwrap(); write!(file, "{}", pil_string).unwrap(); + + let pil_json_from_str = compile_pil_from_str(&pil_string); + let pil_json_from_path = compile_pil_from_str(pil_file_path); + assert_eq!(pil_json_from_str, pil_json_from_path); } } From 051f3ade28ceb6d389846e46aba9c79c19ff2f19 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 21:11:06 +0800 Subject: [PATCH 09/15] bugfix --- starky/src/compressor12/compressor12_pil.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starky/src/compressor12/compressor12_pil.rs b/starky/src/compressor12/compressor12_pil.rs index 8481e986..79bfc356 100644 --- a/starky/src/compressor12/compressor12_pil.rs +++ b/starky/src/compressor12/compressor12_pil.rs @@ -394,7 +394,7 @@ mod test { write!(file, "{}", pil_string).unwrap(); let pil_json_from_str = compile_pil_from_str(&pil_string); - let pil_json_from_path = compile_pil_from_str(pil_file_path); + let pil_json_from_path = compile_pil_from_path(pil_file_path); assert_eq!(pil_json_from_str, pil_json_from_path); } } From f6fdc4844178f056c163c023d88000d53ef1c5e8 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 22:41:01 +0800 Subject: [PATCH 10/15] bugfix --- starky/src/compressor12/compressor12_exec.rs | 50 ++++--------------- starky/src/compressor12/compressor12_pil.rs | 12 ++++- starky/src/compressor12/compressor12_setup.rs | 5 -- starky/src/compressor12/mod.rs | 3 +- starky/src/compressor12/plonk_setup.rs | 6 +-- 5 files changed, 23 insertions(+), 53 deletions(-) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index 1794c84d..4557b7f4 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -24,39 +24,23 @@ pub fn exec( input_file: &str, wasm_file: &str, pil_json_file: &str, - pil_file: &str, // debug one exec_file: &str, // debug one commit_file: &str, ) -> Result<()> { // 0. load exec_file, // debug one - let (adds_len_old, s_map_column_len_old, adds_old, s_map_old) = read_exec_file(exec_file); + // let (adds_len_old, s_map_column_len_old, adds_old, s_map_old) = read_exec_file(exec_file); let adds = plonk_setup.plonk_additions; let s_map = plonk_setup.s_map; let adds_len = adds.len(); let s_map_column_len = s_map[0].len(); - assert_eq!(adds_len_old, adds_len); - assert_eq!(s_map_column_len_old, s_map_column_len); // 1. Compiles a .pil file to its json form , and save it. - // debug one - // TODO: the pil_str has been compiled in plonk_setup#3 - let pil_json_old = compile_pil_from_path(pil_file); - let mut file = File::create(Path::new(&format!("{pil_file}.old.json"))).unwrap(); - let input_old = serde_json::to_string(&pil_json_old).unwrap(); - write!(file, "{}", input_old).unwrap(); - // debug one above - - // TODO: Even if the pil_str has been compiled in plonk_setup#3 - // TODO: however it can be passed as param to here. as the pil_json prior is different with pil_json here. - // let pil_json = plonk_setup.pil_json; - let pil_json = compile_pil_from_str(&plonk_setup.pil_str); + let pil_json = plonk_setup.pil_json; let mut file = File::create(Path::new(pil_json_file)).unwrap(); - let input = serde_json::to_string(&pil_json_file).unwrap(); + let input = serde_json::to_string(&pil_json).unwrap(); write!(file, "{}", input).unwrap(); - assert_eq!(pil_json_old, pil_json); // meet error. - assert_eq!(input_old, input); // 2. construct cmPol: .pil.json -> .cm let mut cm_pols = PolsArray::new(&pil_json, PolKind::Commit); @@ -78,25 +62,13 @@ pub fn exec( .collect::>(); for i in 0..adds_len { - // debug one - let w2_old = - FGL::from_raw_repr(::Repr::from(adds_old[i * 4 + 2])).unwrap(); - let w3_old = - FGL::from_raw_repr(::Repr::from(adds_old[i * 4 + 3])).unwrap(); - let f_w_old = - (w[adds_old[i * 4] as usize] * w2_old) + (w[adds_old[i * 4 + 1] as usize] * w3_old); - - // add[i], PlonkAdd.2/3 - let w2 = adds[i * 4].2; - let w3 = adds[i * 4].3; - - // add[i], PlonkAdd.0/1 - let f_w = (w[adds[i * 4].0] * w2) + (w[adds[i * 4].1] * w3); - - assert_eq!(w2, w2_old, "{}", i); - assert_eq!(w3, w3_old, "{}", i); - assert_eq!(f_w, f_w_old, "{}", i); + // TODO: here we can's assign `let w2 = adds[i].2;`. As adds[i].2 is mont form. But here w2 need mont_reduce form.? + let a2: u64 = adds[i].2.into(); + let a3: u64 = adds[i].3.into(); + let w2 = FGL::from_raw_repr(::Repr::from(a2))?; + let w3 = FGL::from_raw_repr(::Repr::from(a3))?; + let f_w = (w[adds[i].0] * w2) + (w[adds[i].1] * w3); w.push(f_w); } @@ -106,11 +78,7 @@ pub fn exec( for i in 0..s_map_column_len { for c in 0..12 { - // s_map[c][i] - let s_old = s_map_old[i * 12 + c] as usize; // debug one - let s = s_map[c][i] as usize; - assert_eq!(s_old, s); cm_pols.set_matrix( &pil_json, diff --git a/starky/src/compressor12/compressor12_pil.rs b/starky/src/compressor12/compressor12_pil.rs index 79bfc356..e89b378d 100644 --- a/starky/src/compressor12/compressor12_pil.rs +++ b/starky/src/compressor12/compressor12_pil.rs @@ -395,6 +395,16 @@ mod test { let pil_json_from_str = compile_pil_from_str(&pil_string); let pil_json_from_path = compile_pil_from_path(pil_file_path); - assert_eq!(pil_json_from_str, pil_json_from_path); + + let mut file = File::create(Path::new(&format!("{pil_file_path}.str.json"))).unwrap(); + let input_old = serde_json::to_string(&pil_json_from_str).unwrap(); + write!(file, "{}", input_old).unwrap(); + + let mut file = File::create(Path::new(&format!("{pil_file_path}.path.json"))).unwrap(); + let input_old = serde_json::to_string(&pil_json_from_path).unwrap(); + write!(file, "{}", input_old).unwrap(); + + // The fileName in them are different. + // assert_eq!(pil_json_from_str, pil_json_from_path); } } diff --git a/starky/src/compressor12/compressor12_setup.rs b/starky/src/compressor12/compressor12_setup.rs index e749e82e..60c03fcc 100644 --- a/starky/src/compressor12/compressor12_setup.rs +++ b/starky/src/compressor12/compressor12_setup.rs @@ -19,7 +19,6 @@ pub struct Options { // output: .pil, .const, .exec, pub fn setup( r1cs_file: &str, - pil_file: &str, const_file: &str, exec_file: &str, force_n_bits: usize, @@ -33,10 +32,6 @@ pub fn setup( // 1. plonk setup: generate plonk circuit, the pil file. let res = PlonkSetup::new(&r1cs, &opts); - // // 2. And write it into pil_file. - let mut file = File::create(pil_file).unwrap(); - write!(file, "{}", res.pil_str).unwrap(); - // 3. write const pols file res.const_pols.save(const_file)?; diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index 1887fd3b..38f8bc1f 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -32,7 +32,7 @@ pub fn compress12( // input: .r1cs // output: .pil, .const, .exec, // return: todo PIL, exec file. - let plonk_setup = setup(r1cs_file, pil_file, const_file, exec_file, force_n_bits)?; + let plonk_setup = setup(r1cs_file, const_file, exec_file, force_n_bits)?; // exec phase: // input files: .wasm, .exec, .pil, zkin.json(input file), @@ -43,7 +43,6 @@ pub fn compress12( wasm_file, pil_json_file, // debug one - pil_file, exec_file, // debug one above commit_file, diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index d584ed96..5722bcf6 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -15,8 +15,7 @@ use std::collections::BTreeMap; #[derive(Debug)] pub struct PlonkSetup { - pub(crate) pil_str: String, - // pub(crate) pil_json: PIL, //todo + pub(crate) pil_json: PIL, pub(crate) const_pols: PolsArray, pub(crate) s_map: Vec>, pub(crate) plonk_additions: Vec, @@ -39,8 +38,7 @@ impl PlonkSetup { let (const_pols, s_map) = plonk_setup_compressor(r1cs, &pil_json, &plonk_setup_info); Self { - pil_str, - // pil_json, + pil_json, const_pols, s_map, plonk_additions: plonk_setup_info.pa, From acdb75b9faf94504a877b2fe11f4051071d14a36 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 22:54:10 +0800 Subject: [PATCH 11/15] feat: sync to script --- starkjs/README.md | 3 - starky/src/compressor12/compressor12_exec.rs | 11 +-- starky/src/compressor12/compressor12_setup.rs | 15 +--- starky/src/compressor12/mod.rs | 11 +-- starky/src/compressor12/plonk_setup.rs | 3 - test/recursive_proof_to_snark.sh | 36 +++++--- test/simple_bls.sh | 26 ++++-- test/stark_aggregation.sh | 86 +++++++++++-------- 8 files changed, 99 insertions(+), 92 deletions(-) diff --git a/starkjs/README.md b/starkjs/README.md index 879654ab..83718e11 100644 --- a/starkjs/README.md +++ b/starkjs/README.md @@ -27,9 +27,6 @@ export CIRCUIT=fib RUST_LOG=debug ../target/release/eigen-zkit compile -p goldilocks -i circuits/$CIRCUIT.verifier.circom -l node_modules/pil-stark/circuits.gl --O2=full -o /tmp/ # Circom to Stark -#RUST_LOG=debug ../target/release/eigen-zkit compressor12_setup --r /tmp/$CIRCUIT.verifier.r1cs --c /tmp/c12.const --p /tmp/c12.pil --e /tmp/c12.exec -#RUST_LOG=debug ../target/release/eigen-zkit compressor12_exec --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm --i circuits/$CIRCUIT.verifier.zkin.json --p /tmp/c12.pil --e /tmp/c12.exec --m /tmp/c12.cm - RUST_LOG=debug ../target/release/eigen-zkit compressor12 \ --r /tmp/$CIRCUIT.verifier.r1cs \ --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm\ diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index 4557b7f4..c5c3f3ed 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -24,19 +24,15 @@ pub fn exec( input_file: &str, wasm_file: &str, pil_json_file: &str, - exec_file: &str, // debug one commit_file: &str, ) -> Result<()> { - // 0. load exec_file, - // debug one - // let (adds_len_old, s_map_column_len_old, adds_old, s_map_old) = read_exec_file(exec_file); - + // 0. prepare data, let adds = plonk_setup.plonk_additions; let s_map = plonk_setup.s_map; let adds_len = adds.len(); let s_map_column_len = s_map[0].len(); - // 1. Compiles a .pil file to its json form , and save it. + // 1. save pil_json data.. let pil_json = plonk_setup.pil_json; let mut file = File::create(Path::new(pil_json_file)).unwrap(); let input = serde_json::to_string(&pil_json).unwrap(); @@ -107,9 +103,10 @@ pub fn exec( cm_pols.save(commit_file)?; log::debug!("files Generated Correctly"); - Result::Ok(()) + Ok(()) } +#[deprecated] fn read_exec_file(exec_file: &str) -> (usize, usize, Vec, Vec) { let mut buff = read_vec_from_file(exec_file).unwrap(); diff --git a/starky/src/compressor12/compressor12_setup.rs b/starky/src/compressor12/compressor12_setup.rs index 60c03fcc..15f1fcaf 100644 --- a/starky/src/compressor12/compressor12_setup.rs +++ b/starky/src/compressor12/compressor12_setup.rs @@ -17,31 +17,24 @@ pub struct Options { // setup phase: // input: .r1cs // output: .pil, .const, .exec, -pub fn setup( - r1cs_file: &str, - const_file: &str, - exec_file: &str, - force_n_bits: usize, -) -> Result { +pub fn setup(r1cs_file: &str, const_file: &str, force_n_bits: usize) -> Result { // 0. readR1cs let r1cs = load_r1cs::(r1cs_file); let opts = Options { force_bits: force_n_bits, }; - // 1. plonk setup: generate plonk circuit, the pil file. + // 1. plonk setup: generate plonk circuit, the pil_json. let res = PlonkSetup::new(&r1cs, &opts); - // 3. write const pols file + // 2. write const pols file res.const_pols.save(const_file)?; - // 4. construct and save ExecFile: plonk additions + sMap -> BigUint64Array - write_exec_file(exec_file, &res.plonk_additions, &res.s_map); - Ok(res) } // construct and save ExecFile: plonk additions + sMap -> BigUint64Array +#[deprecated] pub(super) fn write_exec_file(exec_file: &str, adds: &Vec, s_map: &Vec>) { let adds_len = adds.len(); let s_map_row_len = s_map.len(); diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index 38f8bc1f..06df0293 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -23,16 +23,10 @@ pub fn compress12( commit_file: &str, pil_json_file: &str, ) -> Result<()> { - // todo remove the pil_file and exec_file. - - let pil_file = "/tmp/c12.pil"; - let exec_file = "/tmp/c12.exec"; - // setup phase: // input: .r1cs // output: .pil, .const, .exec, - // return: todo PIL, exec file. - let plonk_setup = setup(r1cs_file, const_file, exec_file, force_n_bits)?; + let plonk_setup = setup(r1cs_file, const_file, force_n_bits)?; // exec phase: // input files: .wasm, .exec, .pil, zkin.json(input file), @@ -42,9 +36,6 @@ pub fn compress12( input_file, wasm_file, pil_json_file, - // debug one - exec_file, - // debug one above commit_file, ) } diff --git a/starky/src/compressor12/plonk_setup.rs b/starky/src/compressor12/plonk_setup.rs index 5722bcf6..d2426d10 100644 --- a/starky/src/compressor12/plonk_setup.rs +++ b/starky/src/compressor12/plonk_setup.rs @@ -26,10 +26,7 @@ impl PlonkSetup { // 1. plonk_setup_render phase let plonk_setup_info = PlonkSetupRenderInfo::plonk_setup_render(r1cs, opts); // 2. render .pil file by template. - // // And save as a file. let pil_str = compressor12_pil::render(plonk_setup_info.n_bits, plonk_setup_info.n_publics); - // let mut file = File::create(out_pil.clone()).unwrap(); - // write!(file, "{}", pil_str).unwrap(); // 3. compile pil to pil_json let pil_json = compile_pil_from_str(&pil_str); diff --git a/test/recursive_proof_to_snark.sh b/test/recursive_proof_to_snark.sh index 950a2beb..d32ce1e7 100755 --- a/test/recursive_proof_to_snark.sh +++ b/test/recursive_proof_to_snark.sh @@ -39,24 +39,32 @@ mkdir -p $RUNDIR/circuits && node $RUNDIR/$PILEXECJS -w $RUNDIR/circuits -i $TAS ../target/release/eigen-zkit compile -p goldilocks -i $WORKSPACE/circuits/$C12_VERIFIER.circom -l $RUNDIR/node_modules/pil-stark/circuits.gl --O2=full -o $WORKSPACE/$TASK_NO -# generate the pil files and const constant polynomial files -# input files : $C12_VERIFIER.r1cs -# output files : $C12_VERIFIER.exec, $C12_VERIFIER.const $C12_VERIFIER.pil -../target/release/eigen-zkit compressor12_setup \ - --r $WORKSPACE/$C12_VERIFIER.r1cs \ - --c $WORKSPACE/$C12_VERIFIER.const \ - --p $WORKSPACE/$C12_VERIFIER.pil \ - --e $WORKSPACE/$C12_VERIFIER.exec +## generate the pil files and const constant polynomial files +## input files : $C12_VERIFIER.r1cs +## output files : $C12_VERIFIER.exec, $C12_VERIFIER.const $C12_VERIFIER.pil +#../target/release/eigen-zkit compressor12_setup \ +# --r $WORKSPACE/$C12_VERIFIER.r1cs \ +# --c $WORKSPACE/$C12_VERIFIER.const \ +# --p $WORKSPACE/$C12_VERIFIER.pil \ +# --e $WORKSPACE/$C12_VERIFIER.exec +# +## generate the commit polynomials files +## input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec +## output files : $C12_VERIFIER.cm +#../target/release/eigen-zkit compressor12_exec \ +# --w $WORKSPACE/$C12_VERIFIER"_js"/$CIRCUIT.c12.wasm \ +# --i $WORKSPACE/circuits/$C12_VERIFIER.zkin.json \ +# --p $WORKSPACE/$C12_VERIFIER.pil \ +# --e $WORKSPACE/$C12_VERIFIER.exec \ +# --m $WORKSPACE/$C12_VERIFIER.cm -# generate the commit polynomials files -# input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec -# output files : $C12_VERIFIER.cm -../target/release/eigen-zkit compressor12_exec \ +../target/release/eigen-zkit compressor12 \ + --r $WORKSPACE/$C12_VERIFIER.r1cs \ --w $WORKSPACE/$C12_VERIFIER"_js"/$CIRCUIT.c12.wasm \ --i $WORKSPACE/circuits/$C12_VERIFIER.zkin.json \ - --p $WORKSPACE/$C12_VERIFIER.pil \ - --e $WORKSPACE/$C12_VERIFIER.exec \ + --c $WORKSPACE/$C12_VERIFIER.const \ --m $WORKSPACE/$C12_VERIFIER.cm + --p $WORKSPACE/$C12_VERIFIER.pil.json \ mkdir -p $WORKSPACE/aggregation/$RECURSIVE1_VERIFIER/ diff --git a/test/simple_bls.sh b/test/simple_bls.sh index 24d57b8a..128be92b 100755 --- a/test/simple_bls.sh +++ b/test/simple_bls.sh @@ -12,18 +12,26 @@ npm run $CIRCUIT ../target/release/eigen-zkit compile -p goldilocks -i circuits/$CIRCUIT.verifier.circom -l node_modules/pil-stark/circuits.gl --O2=full -o /tmp/ # Circom to Stark -../target/release/eigen-zkit compressor12_setup \ +#../target/release/eigen-zkit compressor12_setup \ +# --r /tmp/$CIRCUIT.verifier.r1cs \ +# --c /tmp/c12.const \ +# --p /tmp/c12.pil \ +# --e /tmp/c12.exec +# +#../target/release/eigen-zkit compressor12_exec \ +# --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm \ +# --i circuits/$CIRCUIT.verifier.zkin.json \ +# --p /tmp/c12.pil \ +# --e /tmp/c12.exec \ +# --m /tmp/c12.cm + +../target/release/eigen-zkit compressor12 \ --r /tmp/$CIRCUIT.verifier.r1cs \ - --c /tmp/c12.const \ - --p /tmp/c12.pil \ - --e /tmp/c12.exec - -../target/release/eigen-zkit compressor12_exec \ --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm \ --i circuits/$CIRCUIT.verifier.zkin.json \ - --p /tmp/c12.pil \ - --e /tmp/c12.exec \ - --m /tmp/c12.cm + --c /tmp/c12.const \ + --m /tmp/c12.cm \ + --p /tmp/c12.pil.json ../target/release/eigen-zkit stark_prove -s ../starky/data/c12.starkStruct.bls12381.json \ -p /tmp/c12.pil.json \ diff --git a/test/stark_aggregation.sh b/test/stark_aggregation.sh index 2a3f45e3..be8fecd6 100755 --- a/test/stark_aggregation.sh +++ b/test/stark_aggregation.sh @@ -59,30 +59,39 @@ echo "2. combine input1.zkin.json with input2.zkin.json " ${ZKIT} join_zkin --zkin1 $input0/input.zkin.json --zkin2 $input1/input.zkin.json --zkinout $input0/r1_input.zkin.json -echo "3. generate the pil files and const polynomicals files " -# generate the pil files and const polynomicals files -# input files : $C12_VERIFIER.r1cs -# output files : $C12_VERIFIER.const $C12_VERIFIER.pil $C12_VERIFIER.exec -if [ $first_run = "yes" ]; then - ${ZKIT} compressor12_setup \ - --r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \ - --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ - --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ - --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec -fi - -echo "4. generate the commit polynomicals files " -# generate the commit polynomicals files -# input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec -# output files : $C12_VERIFIER.cm -${ZKIT} compressor12_exec \ +#echo "3. generate the pil files and const polynomicals files " +## generate the pil files and const polynomicals files +## input files : $C12_VERIFIER.r1cs +## output files : $C12_VERIFIER.const $C12_VERIFIER.pil $C12_VERIFIER.exec +#if [ $first_run = "yes" ]; then +# ${ZKIT} compressor12_setup \ +# --r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \ +# --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ +# --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ +# --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec +#fi +# +#echo "4. generate the commit polynomicals files " +## generate the commit polynomicals files +## input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec +## output files : $C12_VERIFIER.cm +#${ZKIT} compressor12_exec \ +# --w $WORKSPACE/$RECURSIVE_CIRCUIT"_js"/$RECURSIVE_CIRCUIT.wasm \ +# --i $input0/r1_input.zkin.json \ +# --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ +# --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec \ +# --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm + +echo "3.compressor12. generate commit/const poly and pil.json " +../target/release/eigen-zkit compressor12 \ + --r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \ --w $WORKSPACE/$RECURSIVE_CIRCUIT"_js"/$RECURSIVE_CIRCUIT.wasm \ --i $input0/r1_input.zkin.json \ - --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ - --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec \ + --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm + --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil.json \ -echo "5. generate recursive2 proof" +echo "4. generate recursive2 proof" # generate the stark proof and the circom circuits to verify stark proof. # input files : $C12_VERIFIER.pil.json(stark proof) $C12_VERIFIER.const(const polynomials) $C12_VERIFIER.cm (commit polynomials) # output files : $RECURSIVE2_CIRCUIT.circom $RECURSIVE2_CIRCUIT/r2_input.json @@ -107,25 +116,32 @@ else fi -echo "2. generate the pil files and const polynomicals files " -if [ $first_run = "yes" ]; then - ${ZKIT} compressor12_setup \ - --r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \ - --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ - --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ - --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec -fi - -echo "3. generate the commit polynomicals files " -${ZKIT} compressor12_exec \ +#echo "2. generate the pil files and const polynomicals files " +#if [ $first_run = "yes" ]; then +# ${ZKIT} compressor12_setup \ +# --r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \ +# --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ +# --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ +# --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec +#fi +# +#echo "3. generate the commit polynomicals files " +#${ZKIT} compressor12_exec \ +# --w $WORKSPACE/$RECURSIVE2_CIRCUIT"_js"/$RECURSIVE2_CIRCUIT.wasm \ +# --i $WORKSPACE/aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \ +# --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ +# --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec \ +# --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm +echo "2.compressor12. generate commit/const poly and pil.json " +../target/release/eigen-zkit compressor12 \ + --r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \ --w $WORKSPACE/$RECURSIVE2_CIRCUIT"_js"/$RECURSIVE2_CIRCUIT.wasm \ --i $WORKSPACE/aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \ - --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ - --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec \ + --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm + --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil.json \ - -echo "4. generate final proof " +echo "3. generate final proof " # Remark: the N of final.starkStruct must be 2^20 , because the degree of $RECURSIVE2_CIRCUIT.pil is 2^20 which determined by the proocess of converting $RECURSIVE_CIRCUIT2.circom to $RECURSIVE_CIRCUIT2.pil STARK_STRUCT=$CUR_DIR/../starky/data/final.starkStruct.bls12381.json if [ $CURVE = "BN128" ]; then From bdb1c44b090f688641e8fda368b26bb8df332226 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 23:03:14 +0800 Subject: [PATCH 12/15] bugfix --- test/recursive_proof_to_snark.sh | 2 +- test/stark_aggregation.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/recursive_proof_to_snark.sh b/test/recursive_proof_to_snark.sh index d32ce1e7..ee41c0e4 100755 --- a/test/recursive_proof_to_snark.sh +++ b/test/recursive_proof_to_snark.sh @@ -64,7 +64,7 @@ mkdir -p $RUNDIR/circuits && node $RUNDIR/$PILEXECJS -w $RUNDIR/circuits -i $TAS --i $WORKSPACE/circuits/$C12_VERIFIER.zkin.json \ --c $WORKSPACE/$C12_VERIFIER.const \ --m $WORKSPACE/$C12_VERIFIER.cm - --p $WORKSPACE/$C12_VERIFIER.pil.json \ + --p $WORKSPACE/$C12_VERIFIER.pil.json mkdir -p $WORKSPACE/aggregation/$RECURSIVE1_VERIFIER/ diff --git a/test/stark_aggregation.sh b/test/stark_aggregation.sh index be8fecd6..8f873b60 100755 --- a/test/stark_aggregation.sh +++ b/test/stark_aggregation.sh @@ -89,7 +89,7 @@ echo "3.compressor12. generate commit/const poly and pil.json " --i $input0/r1_input.zkin.json \ --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm - --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil.json \ + --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil.json echo "4. generate recursive2 proof" # generate the stark proof and the circom circuits to verify stark proof. @@ -139,7 +139,7 @@ echo "2.compressor12. generate commit/const poly and pil.json " --i $WORKSPACE/aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \ --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm - --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil.json \ + --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil.json echo "3. generate final proof " # Remark: the N of final.starkStruct must be 2^20 , because the degree of $RECURSIVE2_CIRCUIT.pil is 2^20 which determined by the proocess of converting $RECURSIVE_CIRCUIT2.circom to $RECURSIVE_CIRCUIT2.pil From 245b62f7d4c4761f241d2fae96637dac69bfd313 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 23:13:45 +0800 Subject: [PATCH 13/15] bugfix --- test/recursive_proof_to_snark.sh | 2 +- test/stark_aggregation.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/recursive_proof_to_snark.sh b/test/recursive_proof_to_snark.sh index ee41c0e4..69359333 100755 --- a/test/recursive_proof_to_snark.sh +++ b/test/recursive_proof_to_snark.sh @@ -63,7 +63,7 @@ mkdir -p $RUNDIR/circuits && node $RUNDIR/$PILEXECJS -w $RUNDIR/circuits -i $TAS --w $WORKSPACE/$C12_VERIFIER"_js"/$CIRCUIT.c12.wasm \ --i $WORKSPACE/circuits/$C12_VERIFIER.zkin.json \ --c $WORKSPACE/$C12_VERIFIER.const \ - --m $WORKSPACE/$C12_VERIFIER.cm + --m $WORKSPACE/$C12_VERIFIER.cm \ --p $WORKSPACE/$C12_VERIFIER.pil.json mkdir -p $WORKSPACE/aggregation/$RECURSIVE1_VERIFIER/ diff --git a/test/stark_aggregation.sh b/test/stark_aggregation.sh index 8f873b60..37c21e4d 100755 --- a/test/stark_aggregation.sh +++ b/test/stark_aggregation.sh @@ -88,7 +88,7 @@ echo "3.compressor12. generate commit/const poly and pil.json " --w $WORKSPACE/$RECURSIVE_CIRCUIT"_js"/$RECURSIVE_CIRCUIT.wasm \ --i $input0/r1_input.zkin.json \ --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ - --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm + --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm \ --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil.json echo "4. generate recursive2 proof" @@ -138,7 +138,7 @@ echo "2.compressor12. generate commit/const poly and pil.json " --w $WORKSPACE/$RECURSIVE2_CIRCUIT"_js"/$RECURSIVE2_CIRCUIT.wasm \ --i $WORKSPACE/aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \ --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ - --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm + --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm \ --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil.json echo "3. generate final proof " From f9368dcc7c4424c77dd3941c3c7fb5870a1a29f1 Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Thu, 2 Nov 2023 23:24:09 +0800 Subject: [PATCH 14/15] feat: remove comments --- starky/src/compressor12/compressor12_exec.rs | 56 ------------------- starky/src/compressor12/compressor12_setup.rs | 36 ------------ starky/src/compressor12/mod.rs | 6 -- test/recursive_proof_to_snark.sh | 19 ------- test/simple_bls.sh | 14 ----- test/stark_aggregation.sh | 41 -------------- 6 files changed, 172 deletions(-) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index c5c3f3ed..dc9f085f 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -2,14 +2,11 @@ use crate::compressor12::plonk_setup::PlonkSetup; use crate::compressor12_pil::CompressorNameSpace::*; use crate::compressor12_pil::CompressorPolName::a; use crate::errors::EigenError; -use crate::io_utils::read_vec_from_file; -use crate::pilcom::{compile_pil_from_path, compile_pil_from_str}; use crate::polsarray::{PolKind, PolsArray}; use num_traits::Zero; use plonky::ff::PrimeField; use plonky::field_gl::Fr as FGL; use plonky::witness::{load_input_for_witness, WitnessCalculator}; -use std::fmt::format; use std::fs::File; use std::io::Write; use std::path::Path; @@ -105,56 +102,3 @@ pub fn exec( log::debug!("files Generated Correctly"); Ok(()) } - -#[deprecated] -fn read_exec_file(exec_file: &str) -> (usize, usize, Vec, Vec) { - let mut buff = read_vec_from_file(exec_file).unwrap(); - - let mut new_buff = buff.split_off(2); - let adds_len = buff[0] as usize; - let s_map_column_len = buff[1] as usize; - - let size = adds_len * 4 + s_map_column_len * 12; - assert_eq!(new_buff.len(), size); - - let s_map = new_buff.split_off(adds_len * 4); - let adds = new_buff; - - (adds_len, s_map_column_len, adds, s_map) -} - -#[cfg(test)] -mod test { - use super::*; - use crate::compressor12_setup::write_exec_file; - - #[test] - fn test_write_and_read_exec_file() { - let file_path = String::from("/tmp/test_write_and_read_exec_file.txt"); - - let target_adds = vec![ - // PlonkAdd() - ]; - - let target_s_map = vec![ - vec![1, 2, 4], - vec![2, 3, 42], - vec![1, 1, 3], - vec![4, 5, 2], - vec![3, 4, 5], - vec![1, 2, 4], - vec![2, 3, 42], - vec![1, 1, 3], - vec![4, 5, 2], - vec![3, 4, 5], - vec![3, 4, 5], - vec![3, 4, 5], - ]; - - write_exec_file(&file_path, &target_adds, &target_s_map); - - let (adds_len, _s_map_column_len, _adds, _s_map) = read_exec_file(&file_path); - - assert_eq!(adds_len, target_adds.len()); - } -} diff --git a/starky/src/compressor12/compressor12_setup.rs b/starky/src/compressor12/compressor12_setup.rs index 15f1fcaf..a649b746 100644 --- a/starky/src/compressor12/compressor12_setup.rs +++ b/starky/src/compressor12/compressor12_setup.rs @@ -1,12 +1,8 @@ #![allow(non_snake_case)] use crate::compressor12::plonk_setup::PlonkSetup; use crate::errors::EigenError; -use crate::io_utils::write_vec_to_file; -use crate::r1cs2plonk::PlonkAdd; use algebraic::reader::load_r1cs; use plonky::field_gl::GL; -use std::fs::File; -use std::io::Write; pub type Result = std::result::Result; @@ -32,35 +28,3 @@ pub fn setup(r1cs_file: &str, const_file: &str, force_n_bits: usize) -> Result

BigUint64Array -#[deprecated] -pub(super) fn write_exec_file(exec_file: &str, adds: &Vec, s_map: &Vec>) { - let adds_len = adds.len(); - let s_map_row_len = s_map.len(); - let s_map_column_len = s_map[0].len(); - - assert_eq!(s_map_row_len, 12, "s_map should have 12 rows"); - let size = 2 + adds_len * 4 + s_map_row_len * s_map_column_len; - - let mut buff = vec![0; size]; - - buff[0] = adds_len as u64; - buff[1] = s_map_column_len as u64; - - for i in 0..adds_len { - buff[2 + i * 4] = adds[i].0 as u64; - buff[2 + i * 4 + 1] = adds[i].1 as u64; - buff[2 + i * 4 + 2] = adds[i].2.into(); - buff[2 + i * 4 + 3] = adds[i].3.into(); - } - - // TODO: Should this be a fixed constant or use the s_map_row_len. - for c in 0..12 { - for i in 0..s_map_column_len { - buff[2 + adds_len * 4 + 12 * i + c] = s_map[c][i]; - } - } - - write_vec_to_file(exec_file, &buff).unwrap(); -} diff --git a/starky/src/compressor12/mod.rs b/starky/src/compressor12/mod.rs index 06df0293..4da51ece 100644 --- a/starky/src/compressor12/mod.rs +++ b/starky/src/compressor12/mod.rs @@ -23,14 +23,8 @@ pub fn compress12( commit_file: &str, pil_json_file: &str, ) -> Result<()> { - // setup phase: - // input: .r1cs - // output: .pil, .const, .exec, let plonk_setup = setup(r1cs_file, const_file, force_n_bits)?; - // exec phase: - // input files: .wasm, .exec, .pil, zkin.json(input file), - // output: .cm, .pil.json exec( plonk_setup, input_file, diff --git a/test/recursive_proof_to_snark.sh b/test/recursive_proof_to_snark.sh index 69359333..f1c353af 100755 --- a/test/recursive_proof_to_snark.sh +++ b/test/recursive_proof_to_snark.sh @@ -39,25 +39,6 @@ mkdir -p $RUNDIR/circuits && node $RUNDIR/$PILEXECJS -w $RUNDIR/circuits -i $TAS ../target/release/eigen-zkit compile -p goldilocks -i $WORKSPACE/circuits/$C12_VERIFIER.circom -l $RUNDIR/node_modules/pil-stark/circuits.gl --O2=full -o $WORKSPACE/$TASK_NO -## generate the pil files and const constant polynomial files -## input files : $C12_VERIFIER.r1cs -## output files : $C12_VERIFIER.exec, $C12_VERIFIER.const $C12_VERIFIER.pil -#../target/release/eigen-zkit compressor12_setup \ -# --r $WORKSPACE/$C12_VERIFIER.r1cs \ -# --c $WORKSPACE/$C12_VERIFIER.const \ -# --p $WORKSPACE/$C12_VERIFIER.pil \ -# --e $WORKSPACE/$C12_VERIFIER.exec -# -## generate the commit polynomials files -## input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec -## output files : $C12_VERIFIER.cm -#../target/release/eigen-zkit compressor12_exec \ -# --w $WORKSPACE/$C12_VERIFIER"_js"/$CIRCUIT.c12.wasm \ -# --i $WORKSPACE/circuits/$C12_VERIFIER.zkin.json \ -# --p $WORKSPACE/$C12_VERIFIER.pil \ -# --e $WORKSPACE/$C12_VERIFIER.exec \ -# --m $WORKSPACE/$C12_VERIFIER.cm - ../target/release/eigen-zkit compressor12 \ --r $WORKSPACE/$C12_VERIFIER.r1cs \ --w $WORKSPACE/$C12_VERIFIER"_js"/$CIRCUIT.c12.wasm \ diff --git a/test/simple_bls.sh b/test/simple_bls.sh index 128be92b..f68862b4 100755 --- a/test/simple_bls.sh +++ b/test/simple_bls.sh @@ -11,20 +11,6 @@ npm run $CIRCUIT ../target/release/eigen-zkit compile -p goldilocks -i circuits/$CIRCUIT.verifier.circom -l node_modules/pil-stark/circuits.gl --O2=full -o /tmp/ -# Circom to Stark -#../target/release/eigen-zkit compressor12_setup \ -# --r /tmp/$CIRCUIT.verifier.r1cs \ -# --c /tmp/c12.const \ -# --p /tmp/c12.pil \ -# --e /tmp/c12.exec -# -#../target/release/eigen-zkit compressor12_exec \ -# --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm \ -# --i circuits/$CIRCUIT.verifier.zkin.json \ -# --p /tmp/c12.pil \ -# --e /tmp/c12.exec \ -# --m /tmp/c12.cm - ../target/release/eigen-zkit compressor12 \ --r /tmp/$CIRCUIT.verifier.r1cs \ --w /tmp/$CIRCUIT.verifier_js/$CIRCUIT.verifier.wasm \ diff --git a/test/stark_aggregation.sh b/test/stark_aggregation.sh index 37c21e4d..36310481 100755 --- a/test/stark_aggregation.sh +++ b/test/stark_aggregation.sh @@ -58,30 +58,6 @@ fi echo "2. combine input1.zkin.json with input2.zkin.json " ${ZKIT} join_zkin --zkin1 $input0/input.zkin.json --zkin2 $input1/input.zkin.json --zkinout $input0/r1_input.zkin.json - -#echo "3. generate the pil files and const polynomicals files " -## generate the pil files and const polynomicals files -## input files : $C12_VERIFIER.r1cs -## output files : $C12_VERIFIER.const $C12_VERIFIER.pil $C12_VERIFIER.exec -#if [ $first_run = "yes" ]; then -# ${ZKIT} compressor12_setup \ -# --r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \ -# --c $WORKSPACE/$RECURSIVE_CIRCUIT.const \ -# --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ -# --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec -#fi -# -#echo "4. generate the commit polynomicals files " -## generate the commit polynomicals files -## input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil $C12_VERIFIER.exec -## output files : $C12_VERIFIER.cm -#${ZKIT} compressor12_exec \ -# --w $WORKSPACE/$RECURSIVE_CIRCUIT"_js"/$RECURSIVE_CIRCUIT.wasm \ -# --i $input0/r1_input.zkin.json \ -# --p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \ -# --e $WORKSPACE/$RECURSIVE_CIRCUIT.exec \ -# --m $WORKSPACE/$RECURSIVE_CIRCUIT.cm - echo "3.compressor12. generate commit/const poly and pil.json " ../target/release/eigen-zkit compressor12 \ --r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \ @@ -115,23 +91,6 @@ else echo "1.no need compile circom : "$WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs" already generated" fi - -#echo "2. generate the pil files and const polynomicals files " -#if [ $first_run = "yes" ]; then -# ${ZKIT} compressor12_setup \ -# --r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \ -# --c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \ -# --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ -# --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec -#fi -# -#echo "3. generate the commit polynomicals files " -#${ZKIT} compressor12_exec \ -# --w $WORKSPACE/$RECURSIVE2_CIRCUIT"_js"/$RECURSIVE2_CIRCUIT.wasm \ -# --i $WORKSPACE/aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \ -# --p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \ -# --e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec \ -# --m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm echo "2.compressor12. generate commit/const poly and pil.json " ../target/release/eigen-zkit compressor12 \ --r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \ From f8268f3ebc820258d31cf3aafad0c90c04329b1d Mon Sep 17 00:00:00 2001 From: Paul Cheng Date: Fri, 3 Nov 2023 11:37:32 +0800 Subject: [PATCH 15/15] opti --- starky/src/compressor12/compressor12_exec.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/starky/src/compressor12/compressor12_exec.rs b/starky/src/compressor12/compressor12_exec.rs index dc9f085f..c1d188c5 100644 --- a/starky/src/compressor12/compressor12_exec.rs +++ b/starky/src/compressor12/compressor12_exec.rs @@ -56,10 +56,8 @@ pub fn exec( for i in 0..adds_len { // TODO: here we can's assign `let w2 = adds[i].2;`. As adds[i].2 is mont form. But here w2 need mont_reduce form.? - let a2: u64 = adds[i].2.into(); - let a3: u64 = adds[i].3.into(); - let w2 = FGL::from_raw_repr(::Repr::from(a2))?; - let w3 = FGL::from_raw_repr(::Repr::from(a3))?; + let w2 = FGL::from_raw_repr(adds[i].2.into_raw_repr())?; + let w3 = FGL::from_raw_repr(adds[i].3.into_raw_repr())?; let f_w = (w[adds[i].0] * w2) + (w[adds[i].1] * w3); w.push(f_w);