diff --git a/prover/src/lib.rs b/prover/src/lib.rs index b92e6f0dd1..44db8af091 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -40,7 +40,7 @@ impl SP1ProverImpl { let machine = RiscvAir::machine(config.clone()); let program = Program::from(elf); let (_, vk) = machine.setup(&program); - let reduce_program = build_reduce(vk.chip_information.clone()); + let reduce_program = build_reduce(); println!("nb_shards {}", proof.shard_proofs.len()); let config = InnerSC::default(); @@ -148,7 +148,7 @@ pub fn prove_sp1() -> (Proof, VerifyingKey) { (proof, vk) } pub fn prove_compress(sp1_proof: Proof, vk: VerifyingKey) { - let program = build_reduce(vk.chip_information.clone()); + let program = build_reduce(); todo!() // let config = InnerSC::default(); // let machine = InnerA::machine(config); diff --git a/recursion/program/src/reduce.rs b/recursion/program/src/reduce.rs index 61ca0c1b3e..62c1e991df 100644 --- a/recursion/program/src/reduce.rs +++ b/recursion/program/src/reduce.rs @@ -10,7 +10,6 @@ use crate::stark::StarkVerifier; use p3_baby_bear::BabyBear; use p3_baby_bear::DiffusionMatrixBabybear; use p3_challenger::DuplexChallenger; -use p3_challenger::{CanObserve, FieldChallenger}; use p3_commit::ExtensionMmcs; use p3_commit::TwoAdicMultiplicativeCoset; use p3_field::extension::BinomialExtensionField; @@ -18,29 +17,20 @@ use p3_field::AbstractField; use p3_field::Field; use p3_field::TwoAdicField; use p3_fri::FriConfig; -use p3_matrix::Dimensions; use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::Poseidon2; use p3_poseidon2::Poseidon2ExternalMatrixGeneral; use p3_symmetric::PaddingFreeSponge; use p3_symmetric::TruncatedPermutation; -use sp1_core::air::PublicValues; -use sp1_core::air::Word; -use sp1_core::stark::Dom; -use sp1_core::stark::Proof; use sp1_core::stark::ShardProof; use sp1_core::stark::VerifyingKey; use sp1_core::stark::{RiscvAir, StarkGenericConfig}; use sp1_recursion_compiler::asm::AsmConfig; use sp1_recursion_compiler::asm::VmBuilder; -use sp1_recursion_compiler::ir::Array; use sp1_recursion_compiler::ir::Builder; -use sp1_recursion_compiler::ir::Felt; use sp1_recursion_compiler::ir::MemVariable; use sp1_recursion_compiler::ir::Usize; use sp1_recursion_compiler::ir::Var; -use sp1_recursion_compiler::ir::Variable; -use sp1_recursion_core::air::Block; use sp1_recursion_core::runtime::Program as RecursionProgram; use sp1_recursion_core::runtime::DIGEST_SIZE; use sp1_recursion_core::stark::config::inner_fri_config; @@ -96,8 +86,7 @@ fn clone>(builder: &mut RecursionBuilder, var: &T) -> T { builder.get(&arr, 0) } -// TODO: proof is only necessary now because it's a constant, it should be I/O soon -pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> RecursionProgram { +pub fn build_reduce() -> RecursionProgram { let sp1_machine = RiscvAir::machine(SC::default()); let time = Instant::now(); @@ -105,12 +94,6 @@ pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> Rec let config = const_fri_config(&mut builder, inner_fri_config()); let pcs = TwoAdicFriPcsVariable { config }; - // let mut challenger = DuplexChallengerVariable::new(&mut builder); - - // let preprocessed_commit_val: [F; DIGEST_SIZE] = sp1_vk.commit.into(); - // let preprocessed_commit: Array = builder.eval_const(preprocessed_commit_val.to_vec()); - // challenger.observe(&mut builder, preprocessed_commit); - // Read witness inputs let proofs = Vec::>::read(&mut builder); let is_recursive_flags = Vec::::read(&mut builder); @@ -118,27 +101,15 @@ pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> Rec let start_challenger = DuplexChallenger::read(&mut builder); let mut reconstruct_challenger = DuplexChallenger::read(&mut builder); let prep_sorted_indices = Vec::::read(&mut builder); - builder - .range(Usize::Const(0), prep_sorted_indices.len()) - .for_each(|i, builder| { - let index = builder.get(&prep_sorted_indices, i); - let code = builder.eval_const(F::from_canonical_u32(10001)); - builder.print_f(code); - builder.print_v(index); - }); let prep_domains = Vec::>::read(&mut builder); let sp1_vk = VerifyingKey::::read(&mut builder); let recursion_vk = VerifyingKey::::read(&mut builder); let num_proofs = proofs.len(); - let code = builder.eval_const(F::from_canonical_u32(1)); - builder.print_f(code); let pre_start_challenger = clone(&mut builder, &start_challenger); let pre_reconstruct_challenger = clone(&mut builder, &reconstruct_challenger); let zero: Var<_> = builder.eval_const(F::zero()); let one: Var<_> = builder.eval_const(F::one()); - let code = builder.eval_const(F::from_canonical_u32(2)); - builder.print_f(code); builder .range(Usize::Const(0), num_proofs) .for_each(|i, builder| { @@ -149,20 +120,11 @@ pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> Rec // Non-recursive proof |builder| { builder.if_eq(proof.index, one).then(|builder| { - let code = builder.eval_const(F::from_canonical_u32(3)); - builder.print_f(code); - // Initialize the current challenger // let h: [BabyBear; DIGEST_SIZE] = sp1_vk.commit.into(); // let const_commit: DigestVariable = builder.eval_const(h.to_vec()); reconstruct_challenger = DuplexChallengerVariable::new(builder); reconstruct_challenger.observe(builder, sp1_vk.commitment.clone()); - // for j in 0..DIGEST_SIZE { - // let element = builder.get(&sp1_vk.commit, j); - // reconstruct_challenger.observe(builder, element); - // } - // reconstruct_challenger - // .observe_slice(builder, &recursion_vk.commitment); }); for j in 0..DIGEST_SIZE { let element = builder.get(&proof.commitment.main_commit, j); @@ -170,8 +132,6 @@ pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> Rec // TODO: observe public values // challenger.observe_slice(&public_values.to_vec()); } - let code = builder.eval_const(F::from_canonical_u32(4)); - builder.print_f(code); // reconstruct_challenger // .observe_slice(builder, &proof.commitment.main_commit.vec()); let mut current_challenger = start_challenger.as_clone(builder); @@ -183,12 +143,9 @@ pub fn build_reduce(chip_information: Vec<(String, Dom, Dimensions)>) -> Rec &mut current_challenger, &proof, sorted_indices.clone(), - chip_information.clone(), prep_sorted_indices.clone(), prep_domains.clone(), ); - let code = builder.eval_const(F::from_canonical_u32(5)); - builder.print_f(code); }, // Recursive proof |builder| {}, diff --git a/recursion/program/src/stark.rs b/recursion/program/src/stark.rs index cbdfe8400d..d9cb3c7dd8 100644 --- a/recursion/program/src/stark.rs +++ b/recursion/program/src/stark.rs @@ -50,7 +50,6 @@ where challenger: &mut DuplexChallengerVariable, proof: &ShardProofVariable, chip_sorted_idxs: Array>, - chip_information: Vec<(String, Dom, Dimensions)>, preprocessed_sorted_idxs: Array>, prep_domains: Array>, ) where @@ -111,11 +110,16 @@ where let mut qc_points = builder.dyn_array::>(1); builder.set(&mut qc_points, 0, zeta); + // Iterate through machine.chips filtered for preprocessed chips. for (preprocessed_id, chip_id) in machine.preprocessed_chip_ids().into_iter().enumerate() { + // Get index within sorted preprocessed chips. let preprocessed_sorted_id = builder.get(&preprocessed_sorted_idxs, preprocessed_id); + // Get domain from witnessed domains. Array is ordered by machine.chips ordering. let domain = builder.get(&prep_domains, preprocessed_id); + // Get index within all sorted chips. let chip_sorted_id = builder.get(&chip_sorted_idxs, chip_id); + // Get opening from proof. let opening = builder.get(&opened_values.chips, chip_sorted_id); let mut trace_points = builder.dyn_array::>(2); @@ -379,105 +383,6 @@ pub(crate) mod tests { ); } - #[test] - fn test_recursive_verify_shard() { - // Generate a dummy proof. - sp1_core::utils::setup_logger(); - - let elf = - include_bytes!("../../../examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf"); - - let machine = A::machine(SC::default()); - - let (_, vk) = machine.setup(&Program::from(elf)); - let proof = SP1Prover::prove_with_config(elf, SP1Stdin::new(), machine.config().clone()) - .unwrap() - .proof; - let mut challenger_ver = machine.config().challenger(); - machine.verify(&vk, &proof, &mut challenger_ver).unwrap(); - println!("Proof generated successfully"); - - let mut challenger_val = machine.config().challenger(); - challenger_val.observe(vk.commit); - proof.shard_proofs.iter().for_each(|proof| { - challenger_val.observe(proof.commitment.main_commit); - let public_values_field = PublicValues::, F>::new(proof.public_values); - challenger_val.observe_slice(&public_values_field.to_vec()); - }); - - let time = Instant::now(); - let mut builder = Builder::::default(); - let config = const_fri_config(&mut builder, inner_fri_config()); - let pcs = TwoAdicFriPcsVariable { config }; - - let mut challenger = DuplexChallengerVariable::new(&mut builder); - - let preprocessed_commit_val: [F; DIGEST_SIZE] = vk.commit.into(); - let preprocessed_commit: Array = builder.eval_const(preprocessed_commit_val.to_vec()); - challenger.observe(&mut builder, preprocessed_commit); - - let mut witness_stream = Vec::new(); - let mut shard_proofs = vec![]; - let mut sorted_indices = vec![]; - for proof_val in proof.shard_proofs { - witness_stream.extend(proof_val.write()); - let sorted_indices_raw: Vec = machine - .chips_sorted_indices(&proof_val) - .into_iter() - .map(|x| match x { - Some(x) => x, - None => EMPTY, - }) - .collect(); - witness_stream.extend(sorted_indices_raw.write()); - let proof = ShardProof::<_>::read(&mut builder); - let sorted_indices_arr = Vec::::read(&mut builder); - builder - .range(0, sorted_indices_arr.len()) - .for_each(|i, builder| { - let el = builder.get(&sorted_indices_arr, i); - builder.print_v(el); - }); - let ShardCommitmentVariable { main_commit, .. } = &proof.commitment; - challenger.observe(&mut builder, main_commit.clone()); - let public_values_field = PublicValues::, F>::new(proof_val.public_values); - let public_values_felt: Vec> = public_values_field - .to_vec() - .iter() - .map(|x| builder.eval(*x)) - .collect(); - challenger.observe_slice(&mut builder, &public_values_felt); - shard_proofs.push(proof); - sorted_indices.push(sorted_indices_arr); - } - - let code = builder.eval(InnerVal::two()); - builder.print_v(code); - for (proof, sorted_indices) in shard_proofs.iter().zip(sorted_indices) { - StarkVerifier::::verify_shard( - &mut builder, - &vk, - &pcs, - &machine, - &mut challenger.clone(), - proof, - sorted_indices, - ); - } - - let program = builder.compile(); - let elapsed = time.elapsed(); - println!("Building took: {:?}", elapsed); - - let time = Instant::now(); - let mut runtime = Runtime::::new(&program, machine.config().perm.clone()); - runtime.witness_stream = witness_stream; - runtime.run(); - let elapsed = time.elapsed(); - runtime.print_stats(); - println!("Execution took: {:?}", elapsed); - } - #[test] #[ignore] fn test_kitchen_sink() {