From 13c36fb9fbd1ea103fe85892594b2569278b4033 Mon Sep 17 00:00:00 2001 From: Tamir Hemo Date: Mon, 8 Apr 2024 23:14:49 +0300 Subject: [PATCH] feat: recursion permutation challenges as variables (#486) --- Cargo.lock | 50 ++++++++++++++++------------ Cargo.toml | 44 ++++++++++++------------ core/src/stark/debug.rs | 2 ++ core/src/stark/folder.rs | 13 +++++--- core/src/stark/permutation.rs | 15 +++++---- core/src/stark/prover.rs | 7 +++- core/src/stark/quotient.rs | 2 +- recursion/circuit/src/constraints.rs | 9 +++-- recursion/circuit/src/stark.rs | 20 ++--------- recursion/program/src/compress.rs | 7 +--- recursion/program/src/constraints.rs | 13 ++++++-- recursion/program/src/folder.rs | 5 +-- recursion/program/src/stark.rs | 18 ++-------- 13 files changed, 103 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36a3cfdc16..853789dfb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1201,6 +1201,12 @@ dependencies = [ "slab", ] +[[package]] +name = "gcd" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" + [[package]] name = "generic-array" version = "0.14.7" @@ -2242,7 +2248,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3-air" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-field", "p3-matrix", @@ -2251,7 +2257,7 @@ dependencies = [ [[package]] name = "p3-baby-bear" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "num-bigint 0.4.4", "p3-field", @@ -2265,7 +2271,7 @@ dependencies = [ [[package]] name = "p3-blake3" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "blake3", "p3-symmetric", @@ -2274,7 +2280,7 @@ dependencies = [ [[package]] name = "p3-bn254-fr" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "ff 0.13.0", "num-bigint 0.4.4", @@ -2288,7 +2294,7 @@ dependencies = [ [[package]] name = "p3-challenger" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-field", "p3-maybe-rayon", @@ -2300,7 +2306,7 @@ dependencies = [ [[package]] name = "p3-commit" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-challenger", @@ -2313,7 +2319,7 @@ dependencies = [ [[package]] name = "p3-dft" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-field", "p3-matrix", @@ -2325,7 +2331,7 @@ dependencies = [ [[package]] name = "p3-field" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "num-bigint 0.4.4", @@ -2338,7 +2344,7 @@ dependencies = [ [[package]] name = "p3-fri" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-challenger", @@ -2356,7 +2362,7 @@ dependencies = [ [[package]] name = "p3-goldilocks" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "num-bigint 0.4.4", "p3-dft", @@ -2372,7 +2378,7 @@ dependencies = [ [[package]] name = "p3-interpolation" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-field", "p3-matrix", @@ -2382,7 +2388,7 @@ dependencies = [ [[package]] name = "p3-keccak" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-symmetric", "tiny-keccak", @@ -2391,7 +2397,7 @@ dependencies = [ [[package]] name = "p3-keccak-air" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "p3-air", "p3-field", @@ -2403,7 +2409,7 @@ dependencies = [ [[package]] name = "p3-matrix" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-field", @@ -2417,7 +2423,7 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "rayon", ] @@ -2425,7 +2431,7 @@ dependencies = [ [[package]] name = "p3-mds" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.11.0", "p3-dft", @@ -2439,7 +2445,7 @@ dependencies = [ [[package]] name = "p3-merkle-tree" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-commit", @@ -2455,9 +2461,11 @@ dependencies = [ [[package]] name = "p3-poseidon2" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ + "gcd", "p3-field", + "p3-mds", "p3-symmetric", "rand", ] @@ -2465,7 +2473,7 @@ dependencies = [ [[package]] name = "p3-symmetric" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-field", @@ -2475,7 +2483,7 @@ dependencies = [ [[package]] name = "p3-uni-stark" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "itertools 0.12.1", "p3-air", @@ -2493,7 +2501,7 @@ dependencies = [ [[package]] name = "p3-util" version = "0.1.0" -source = "git+https://github.com/Plonky3/Plonky3.git?branch=sp1#7e4f7afedeffbc49c9c123e21f29e0eb1a9b2227" +source = "git+https://github.com/Plonky3/Plonky3.git?branch=random-var#8e3da71774158414e197359fd833450de6f2da13" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 5caee37623..52bddc86b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,29 +28,29 @@ debug = true debug-assertions = true [workspace.dependencies] -p3-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-field = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-util = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-keccak = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-blake3 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } -p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } +p3-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-field = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-util = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-keccak = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-blake3 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } +p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" } # For local development. -# + # p3-air = { path = "../Plonky3/air" } # p3-field = { path = "../Plonky3/field" } # p3-commit = { path = "../Plonky3/commit" } @@ -70,4 +70,4 @@ p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" } # p3-symmetric = { path = "../Plonky3/symmetric" } # p3-uni-stark = { path = "../Plonky3/uni-stark" } # p3-maybe-rayon = { path = "../Plonky3/maybe-rayon" } -# p3-bn254-fr = { path = "../Plonky3/bn254-fr" } \ No newline at end of file +# p3-bn254-fr = { path = "../Plonky3/bn254-fr" } diff --git a/core/src/stark/debug.rs b/core/src/stark/debug.rs index de750b14cb..207a712f5c 100644 --- a/core/src/stark/debug.rs +++ b/core/src/stark/debug.rs @@ -154,6 +154,8 @@ where { type MP = TwoRowMatrixView<'a, EF>; + type RandomVar = EF; + fn permutation(&self) -> Self::MP { self.perm } diff --git a/core/src/stark/folder.rs b/core/src/stark/folder.rs index fcf6ed98a8..e68b771b7d 100644 --- a/core/src/stark/folder.rs +++ b/core/src/stark/folder.rs @@ -16,7 +16,7 @@ pub struct ProverConstraintFolder<'a, SC: StarkGenericConfig> { pub preprocessed: TwoRowMatrixView<'a, PackedVal>, pub main: TwoRowMatrixView<'a, PackedVal>, pub perm: TwoRowMatrixView<'a, PackedChallenge>, - pub perm_challenges: &'a [SC::Challenge], + pub perm_challenges: &'a [PackedChallenge], pub cumulative_sum: SC::Challenge, pub is_first_row: PackedVal, pub is_last_row: PackedVal, @@ -79,11 +79,13 @@ impl<'a, SC: StarkGenericConfig> ExtensionBuilder for ProverConstraintFolder<'a, impl<'a, SC: StarkGenericConfig> PermutationAirBuilder for ProverConstraintFolder<'a, SC> { type MP = TwoRowMatrixView<'a, PackedChallenge>; + type RandomVar = PackedChallenge; + fn permutation(&self) -> Self::MP { self.perm } - fn permutation_randomness(&self) -> &[Self::EF] { + fn permutation_randomness(&self) -> &[Self::RandomVar] { self.perm_challenges } } @@ -122,7 +124,7 @@ pub struct GenericVerifierConstraintFolder<'a, F, EF, Var, Expr> { pub preprocessed: TwoRowMatrixView<'a, Var>, pub main: TwoRowMatrixView<'a, Var>, pub perm: TwoRowMatrixView<'a, Var>, - pub perm_challenges: &'a [EF], + pub perm_challenges: &'a [Var], pub cumulative_sum: Var, pub is_first_row: Var, pub is_last_row: Var, @@ -130,7 +132,7 @@ pub struct GenericVerifierConstraintFolder<'a, F, EF, Var, Expr> { pub alpha: Var, pub accumulator: Expr, pub public_values: &'a [F], - pub _marker: PhantomData, + pub _marker: PhantomData<(F, EF)>, } impl<'a, F, EF, Var, Expr> AirBuilder for GenericVerifierConstraintFolder<'a, F, EF, Var, Expr> @@ -255,12 +257,13 @@ where + Mul, { type MP = TwoRowMatrixView<'a, Var>; + type RandomVar = Var; fn permutation(&self) -> Self::MP { self.perm } - fn permutation_randomness(&self) -> &[Self::EF] { + fn permutation_randomness(&self) -> &[Self::Var] { self.perm_challenges } } diff --git a/core/src/stark/permutation.rs b/core/src/stark/permutation.rs index bb27eb680f..9c39cf4766 100644 --- a/core/src/stark/permutation.rs +++ b/core/src/stark/permutation.rs @@ -1,5 +1,5 @@ use p3_air::{ExtensionBuilder, PairBuilder}; -use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field, Powers, PrimeField}; +use p3_field::{AbstractField, ExtensionField, Field, Powers, PrimeField}; use p3_matrix::{dense::RowMajorMatrix, Matrix, MatrixRowSlices}; use p3_maybe_rayon::prelude::*; @@ -9,11 +9,11 @@ use crate::{air::MultiTableAirBuilder, lookup::Interaction}; /// Generates powers of a random element based on how many interactions there are in the chip. /// /// These elements are used to uniquely fingerprint each interaction. -pub fn generate_interaction_rlc_elements>( +pub fn generate_interaction_rlc_elements( sends: &[Interaction], receives: &[Interaction], - random_element: EF, -) -> Vec { + random_element: AF, +) -> Vec { let n = sends .iter() .chain(receives.iter()) @@ -183,7 +183,8 @@ pub fn eval_permutation_constraints( AB: MultiTableAirBuilder + PairBuilder, { let random_elements = builder.permutation_randomness(); - let (alpha, beta) = (random_elements[0], random_elements[1]); + let (alpha, beta): (AB::ExprEF, AB::ExprEF) = + (random_elements[0].into(), random_elements[1].into()); let main = builder.main(); let main_local: &[AB::Var] = main.row_slice(0); @@ -214,9 +215,9 @@ pub fn eval_permutation_constraints( let mut rlc = AB::ExprEF::zero(); for (field, beta) in interaction.values.iter().zip(betas.clone()) { let elem = field.apply::(preprocessed_local, main_local); - rlc += AB::ExprEF::from_f(beta) * elem; + rlc += beta * elem; } - rlc += AB::ExprEF::from_f(alphas[interaction.argument_index()]); + rlc += alphas[interaction.argument_index()].clone(); builder.assert_one_ext(rlc * perm_local[m].into()); let mult_local = interaction diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index 73688b2f63..c5118ae197 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -27,6 +27,7 @@ use super::{ProvingKey, VerifierConstraintFolder}; use crate::lookup::InteractionBuilder; use crate::stark::record::MachineRecord; use crate::stark::MachineChip; +use crate::stark::PackedChallenge; use crate::stark::ProverConstraintFolder; use crate::air::{MachineAir, PublicValuesDigest, Word}; @@ -277,6 +278,10 @@ where for _ in 0..2 { permutation_challenges.push(challenger.sample_ext_element()); } + let packed_perm_challenges = permutation_challenges + .iter() + .map(|c| PackedChallenge::::from_f(*c)) + .collect::>(); // Generate the permutation traces. let mut permutation_traces = Vec::with_capacity(chips.len()); @@ -378,7 +383,7 @@ where preprocessed_trace_on_quotient_domains, main_trace_on_quotient_domains, permutation_trace_on_quotient_domains, - &permutation_challenges, + &packed_perm_challenges, alpha, shard_data.public_values_digest, ) diff --git a/core/src/stark/quotient.rs b/core/src/stark/quotient.rs index 07e1b26641..6783097ce7 100644 --- a/core/src/stark/quotient.rs +++ b/core/src/stark/quotient.rs @@ -27,7 +27,7 @@ pub fn quotient_values( preprocessed_trace_on_quotient_domain: Mat, main_trace_on_quotient_domain: Mat, permutation_trace_on_quotient_domain: Mat, - perm_challenges: &[SC::Challenge], + perm_challenges: &[PackedChallenge], alpha: SC::Challenge, public_values_digest: PublicValuesDigest>>, ) -> Vec diff --git a/recursion/circuit/src/constraints.rs b/recursion/circuit/src/constraints.rs index 3e3b260a15..6ce0c0bd23 100644 --- a/recursion/circuit/src/constraints.rs +++ b/recursion/circuit/src/constraints.rs @@ -32,7 +32,7 @@ where public_values_digest: PublicValuesDigest>>, selectors: &LagrangeSelectors>, alpha: Ext, - permutation_challenges: &[C::EF], + permutation_challenges: &[Ext], ) -> Ext where A: for<'b> Air>, @@ -133,7 +133,7 @@ where qc_domains: Vec>, zeta: Ext, alpha: Ext, - permutation_challenges: &[C::EF], + permutation_challenges: &[Ext], ) where A: MachineAir + for<'a> Air>, { @@ -342,6 +342,11 @@ mod tests { .map(|domain| builder.eval_const(*domain)) .collect::>(); + let permutation_challenges = permutation_challenges + .iter() + .map(|c| builder.eval(c.cons())) + .collect::>(); + StarkVerifierCircuit::<_, SC>::verify_constraints::( &mut builder, chip, diff --git a/recursion/circuit/src/stark.rs b/recursion/circuit/src/stark.rs index e7ae3d7ada..b8ad68c14e 100644 --- a/recursion/circuit/src/stark.rs +++ b/recursion/circuit/src/stark.rs @@ -10,7 +10,6 @@ use sp1_core::{ air::MachineAir, stark::{MachineStark, ShardCommitment, StarkGenericConfig, VerifyingKey}, }; -use sp1_recursion_compiler::ir::ExtConst; use sp1_recursion_compiler::ir::Usize; use sp1_recursion_compiler::ir::{Builder, Config}; use sp1_recursion_compiler::prelude::SymbolicVar; @@ -43,7 +42,6 @@ where machine: &MachineStark, challenger: &mut MultiField32ChallengerVariable, proof: &RecursionShardProofVariable, - permutation_challenges: &[C::EF], ) where A: MachineAir + for<'a> Air>, C::F: TwoAdicField, @@ -65,17 +63,10 @@ where quotient_commit, } = commitment; - let permutation_challenges_var = (0..2) + let permutation_challenges = (0..2) .map(|_| challenger.sample_ext(builder)) .collect::>(); - for i in 0..2 { - builder.assert_ext_eq( - permutation_challenges_var[i], - permutation_challenges[i].cons(), - ); - } - challenger.observe_commitment(builder, *permutation_commit); let alpha = challenger.sample_ext(builder); @@ -226,7 +217,7 @@ where qc_domains, zeta, alpha, - permutation_challenges, + &permutation_challenges, ); } } @@ -243,7 +234,7 @@ pub(crate) mod tests { }; use p3_baby_bear::DiffusionMatrixBabybear; use p3_bn254_fr::Bn254Fr; - use p3_challenger::{CanObserve, FieldChallenger}; + use p3_challenger::CanObserve; use p3_field::PrimeField32; use serial_test::serial; use sp1_core::{ @@ -396,10 +387,6 @@ pub(crate) mod tests { PublicValuesDigest::>::new(proof.public_values_digest).into(); challenger_val.observe_slice(&pv_digest_field_elms); - let permutation_challenges = (0..2) - .map(|_| challenger_val.sample_ext_element::()) - .collect::>(); - let mut builder = Builder::::default(); let mut challenger = MultiField32ChallengerVariable::new(&mut builder); @@ -432,7 +419,6 @@ pub(crate) mod tests { &machine, &mut challenger.clone(), &proof, - &permutation_challenges, ); break; } diff --git a/recursion/program/src/compress.rs b/recursion/program/src/compress.rs index 473f17e7c2..ac2287218d 100644 --- a/recursion/program/src/compress.rs +++ b/recursion/program/src/compress.rs @@ -11,7 +11,7 @@ use crate::stark::EMPTY; use crate::types::ShardCommitmentVariable; use p3_baby_bear::BabyBear; use p3_baby_bear::DiffusionMatrixBabybear; -use p3_challenger::{CanObserve, FieldChallenger}; +use p3_challenger::CanObserve; use p3_commit::ExtensionMmcs; use p3_commit::TwoAdicMultiplicativeCoset; use p3_field::extension::BinomialExtensionField; @@ -104,10 +104,6 @@ pub fn build_compress( PublicValuesDigest::>::new(proof.public_values_digest).into(); challenger_val.observe_slice(&pv_digest_field_elms); - let permutation_challenges = (0..2) - .map(|_| challenger_val.sample_ext_element::()) - .collect::>(); - let time = Instant::now(); let mut builder = VmBuilder::::default(); let config = const_fri_config(&mut builder, inner_fri_config()); @@ -161,7 +157,6 @@ pub fn build_compress( &machine, &mut challenger.clone(), proof, - &permutation_challenges, sorted_indices, ); } diff --git a/recursion/program/src/constraints.rs b/recursion/program/src/constraints.rs index c096aa123b..790e25b86f 100644 --- a/recursion/program/src/constraints.rs +++ b/recursion/program/src/constraints.rs @@ -33,7 +33,7 @@ where public_values_digest: PublicValuesDigestVariable, selectors: &LagrangeSelectors>, alpha: Ext, - permutation_challenges: &[C::EF], + permutation_challenges: &[Ext], ) -> Ext where A: for<'b> Air>, @@ -138,7 +138,7 @@ where qc_domains: Vec>, zeta: Ext, alpha: Ext, - permutation_challenges: &[C::EF], + permutation_challenges: &[Ext], ) where A: MachineAir + for<'a> Air>, { @@ -361,6 +361,11 @@ mod tests { let trace_domain: TwoAdicMultiplicativeCosetVariable<_> = builder.eval_const(trace_domain_val); let sels = trace_domain.selectors_at_point(&mut builder, zeta); + + let permutation_challenges = permutation_challenges + .iter() + .map(|c| builder.eval(c.cons())) + .collect::>(); let folded_constraints = StarkVerifier::<_, SC>::eval_constrains( &mut builder, chip, @@ -478,6 +483,10 @@ mod tests { builder.set(&mut public_values_digest, i * WORD_SIZE + j, word_val); } } + let permutation_challenges = permutation_challenges + .iter() + .map(|c| builder.eval(c.cons())) + .collect::>(); StarkVerifier::<_, SC>::verify_constraints::( &mut builder, diff --git a/recursion/program/src/folder.rs b/recursion/program/src/folder.rs index 27eb404633..763b6c9aa7 100644 --- a/recursion/program/src/folder.rs +++ b/recursion/program/src/folder.rs @@ -15,7 +15,7 @@ pub struct RecursiveVerifierConstraintFolder<'a, C: Config> { pub preprocessed: TwoRowMatrixView<'a, Ext>, pub main: TwoRowMatrixView<'a, Ext>, pub perm: TwoRowMatrixView<'a, Ext>, - pub perm_challenges: &'a [C::EF], + pub perm_challenges: &'a [Ext], pub public_values: &'a [Felt], pub cumulative_sum: Ext, pub is_first_row: Ext, @@ -74,12 +74,13 @@ impl<'a, C: Config> ExtensionBuilder for RecursiveVerifierConstraintFolder<'a, C impl<'a, C: Config> PermutationAirBuilder for RecursiveVerifierConstraintFolder<'a, C> { type MP = TwoRowMatrixView<'a, Self::Var>; + type RandomVar = Ext; fn permutation(&self) -> Self::MP { self.perm } - fn permutation_randomness(&self) -> &[Self::EF] { + fn permutation_randomness(&self) -> &[Self::RandomVar] { self.perm_challenges } } diff --git a/recursion/program/src/stark.rs b/recursion/program/src/stark.rs index dd6e8e7287..71560fed69 100644 --- a/recursion/program/src/stark.rs +++ b/recursion/program/src/stark.rs @@ -9,7 +9,6 @@ use sp1_core::stark::StarkGenericConfig; use sp1_core::stark::VerifyingKey; use sp1_recursion_compiler::ir::Array; use sp1_recursion_compiler::ir::Ext; -use sp1_recursion_compiler::ir::ExtConst; use sp1_recursion_compiler::ir::Var; use sp1_recursion_compiler::ir::{Builder, Config, Usize}; use sp1_recursion_core::runtime::DIGEST_SIZE; @@ -48,7 +47,6 @@ where machine: &MachineStark, challenger: &mut DuplexChallengerVariable, proof: &ShardProofVariable, - permutation_challenges: &[C::EF], sorted_indices: Array>, ) where A: MachineAir + for<'a> Air>, @@ -69,17 +67,10 @@ where quotient_commit, } = commitment; - let permutation_challenges_var = (0..2) + let permutation_challenges = (0..2) .map(|_| challenger.sample_ext(builder)) .collect::>(); - for i in 0..2 { - builder.assert_ext_eq( - permutation_challenges_var[i], - permutation_challenges[i].cons(), - ); - } - challenger.observe(builder, permutation_commit.clone()); let alpha = challenger.sample_ext(builder); @@ -252,7 +243,7 @@ where qc_domains, zeta, alpha, - permutation_challenges, + &permutation_challenges, ); }); } @@ -404,10 +395,6 @@ pub(crate) mod tests { PublicValuesDigest::>::new(proof.public_values_digest).into(); challenger_val.observe_slice(&pv_digest_field_elms); - let permutation_challenges = (0..2) - .map(|_| challenger_val.sample_ext_element::()) - .collect::>(); - let time = Instant::now(); let mut builder = Builder::::default(); let config = const_fri_config(&mut builder, inner_fri_config()); @@ -463,7 +450,6 @@ pub(crate) mod tests { &machine, &mut challenger.clone(), proof, - &permutation_challenges, sorted_indices, ); }