mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Should work (does not)
This commit is contained in:
parent
5c1173379e
commit
85c1e1d5e0
@ -2,16 +2,21 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use plonky2::field::extension_field::{Extendable, FieldExtension};
|
use plonky2::field::extension_field::{Extendable, FieldExtension};
|
||||||
use plonky2::field::packed_field::PackedField;
|
use plonky2::field::packed_field::PackedField;
|
||||||
|
use plonky2::fri::structure::{FriInstanceInfo, FriInstanceInfoTarget};
|
||||||
use plonky2::hash::hash_types::RichField;
|
use plonky2::hash::hash_types::RichField;
|
||||||
|
use plonky2::iop::ext_target::ExtensionTarget;
|
||||||
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
|
use crate::config::StarkConfig;
|
||||||
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
|
||||||
|
use crate::permutation::PermutationPair;
|
||||||
use crate::stark::Stark;
|
use crate::stark::Stark;
|
||||||
use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars};
|
use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars};
|
||||||
|
|
||||||
/// Toy STARK system used for testing.
|
/// Toy STARK system used for testing.
|
||||||
/// Computes a Fibonacci sequence with state `[x0, x1]` using the state transition
|
/// Computes a Fibonacci sequence with state `[x0, x1, i, j]` using the state transition
|
||||||
/// `x0 <- x1, x1 <- x0 + x1`.
|
/// `x0' <- x1, x1' <- x0 + x1, i' <- i+1, j' <- j+1`.
|
||||||
|
/// Note: The `i, j` columns are used to test the permutation argument.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct FibonacciStark<F: RichField + Extendable<D>, const D: usize> {
|
struct FibonacciStark<F: RichField + Extendable<D>, const D: usize> {
|
||||||
num_rows: usize,
|
num_rows: usize,
|
||||||
@ -34,21 +39,25 @@ impl<F: RichField + Extendable<D>, const D: usize> FibonacciStark<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate the trace using `x0, x1` as inital state values.
|
/// Generate the trace using `x0, x1, 0, 1` as initial state values.
|
||||||
fn generate_trace(&self, x0: F, x1: F) -> Vec<[F; Self::COLUMNS]> {
|
fn generate_trace(&self, x0: F, x1: F) -> Vec<[F; Self::COLUMNS]> {
|
||||||
(0..self.num_rows)
|
let mut trace = (0..self.num_rows)
|
||||||
.scan([x0, x1], |acc, _| {
|
.scan([x0, x1, F::ZERO, F::ONE], |acc, _| {
|
||||||
let tmp = *acc;
|
let tmp = *acc;
|
||||||
acc[0] = tmp[1];
|
acc[0] = tmp[1];
|
||||||
acc[1] = tmp[0] + tmp[1];
|
acc[1] = tmp[0] + tmp[1];
|
||||||
|
acc[2] = tmp[2] + F::ONE;
|
||||||
|
acc[3] = tmp[3] + F::ONE;
|
||||||
Some(tmp)
|
Some(tmp)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>();
|
||||||
|
trace[self.num_rows - 1][3] = F::ZERO;
|
||||||
|
trace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for FibonacciStark<F, D> {
|
impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for FibonacciStark<F, D> {
|
||||||
const COLUMNS: usize = 2;
|
const COLUMNS: usize = 4;
|
||||||
const PUBLIC_INPUTS: usize = 3;
|
const PUBLIC_INPUTS: usize = 3;
|
||||||
|
|
||||||
fn eval_packed_generic<FE, P, const D2: usize>(
|
fn eval_packed_generic<FE, P, const D2: usize>(
|
||||||
@ -105,6 +114,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for FibonacciStar
|
|||||||
fn constraint_degree(&self) -> usize {
|
fn constraint_degree(&self) -> usize {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn permutation_pairs(&self) -> Vec<PermutationPair> {
|
||||||
|
vec![PermutationPair {
|
||||||
|
column_pairs: vec![(2, 3)],
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -211,10 +211,10 @@ where
|
|||||||
|
|
||||||
/// Computes the quotient polynomials `(sum alpha^i C_i(x)) / Z_H(x)` for `alpha` in `alphas`,
|
/// Computes the quotient polynomials `(sum alpha^i C_i(x)) / Z_H(x)` for `alpha` in `alphas`,
|
||||||
/// where the `C_i`s are the Stark constraints.
|
/// where the `C_i`s are the Stark constraints.
|
||||||
fn compute_quotient_polys<F, C, S, const D: usize>(
|
fn compute_quotient_polys<'a, F, C, S, const D: usize>(
|
||||||
stark: &S,
|
stark: &S,
|
||||||
trace_commitment: &PolynomialBatch<F, C, D>,
|
trace_commitment: &'a PolynomialBatch<F, C, D>,
|
||||||
permutation_zs_commitment_challenges: &Option<(
|
permutation_zs_commitment_challenges: &'a Option<(
|
||||||
PolynomialBatch<F, C, D>,
|
PolynomialBatch<F, C, D>,
|
||||||
Vec<PermutationChallengeSet<F>>,
|
Vec<PermutationChallengeSet<F>>,
|
||||||
)>,
|
)>,
|
||||||
@ -251,9 +251,8 @@ where
|
|||||||
let z_h_on_coset = ZeroPolyOnCoset::<F>::new(degree_bits, quotient_degree_bits);
|
let z_h_on_coset = ZeroPolyOnCoset::<F>::new(degree_bits, quotient_degree_bits);
|
||||||
|
|
||||||
// Retrieve the LDE values at index `i`.
|
// Retrieve the LDE values at index `i`.
|
||||||
let get_at_index = |comm: &PolynomialBatch<F, C, D>, i: usize| -> [F; S::COLUMNS] {
|
let get_at_index =
|
||||||
comm.get_lde_values(i * step).try_into().unwrap()
|
|comm: &'a PolynomialBatch<F, C, D>, i: usize| -> &'a [F] { comm.get_lde_values(i * step) };
|
||||||
};
|
|
||||||
// Last element of the subgroup.
|
// Last element of the subgroup.
|
||||||
let last = F::primitive_root_of_unity(degree_bits).inverse();
|
let last = F::primitive_root_of_unity(degree_bits).inverse();
|
||||||
let size = degree << quotient_degree_bits;
|
let size = degree << quotient_degree_bits;
|
||||||
@ -274,8 +273,10 @@ where
|
|||||||
lagrange_last.values[i],
|
lagrange_last.values[i],
|
||||||
);
|
);
|
||||||
let vars = StarkEvaluationVars::<F, F, { S::COLUMNS }, { S::PUBLIC_INPUTS }> {
|
let vars = StarkEvaluationVars::<F, F, { S::COLUMNS }, { S::PUBLIC_INPUTS }> {
|
||||||
local_values: &get_at_index(trace_commitment, i),
|
local_values: &get_at_index(trace_commitment, i).try_into().unwrap(),
|
||||||
next_values: &get_at_index(trace_commitment, (i + next_step) % size),
|
next_values: &get_at_index(trace_commitment, (i + next_step) % size)
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
public_inputs: &public_inputs,
|
public_inputs: &public_inputs,
|
||||||
};
|
};
|
||||||
let permutation_check_data = permutation_zs_commitment_challenges.as_ref().map(
|
let permutation_check_data = permutation_zs_commitment_challenges.as_ref().map(
|
||||||
|
|||||||
@ -11,8 +11,10 @@ use plonky2::plonk::plonk_common::reduce_with_powers;
|
|||||||
|
|
||||||
use crate::config::StarkConfig;
|
use crate::config::StarkConfig;
|
||||||
use crate::constraint_consumer::ConstraintConsumer;
|
use crate::constraint_consumer::ConstraintConsumer;
|
||||||
|
use crate::permutation::PermutationCheckData;
|
||||||
use crate::proof::{StarkOpeningSet, StarkProofChallenges, StarkProofWithPublicInputs};
|
use crate::proof::{StarkOpeningSet, StarkProofChallenges, StarkProofWithPublicInputs};
|
||||||
use crate::stark::Stark;
|
use crate::stark::Stark;
|
||||||
|
use crate::vanishing_poly::eval_vanishing_poly;
|
||||||
use crate::vars::StarkEvaluationVars;
|
use crate::vars::StarkEvaluationVars;
|
||||||
|
|
||||||
pub fn verify_stark_proof<
|
pub fn verify_stark_proof<
|
||||||
@ -88,7 +90,19 @@ where
|
|||||||
l_1,
|
l_1,
|
||||||
l_last,
|
l_last,
|
||||||
);
|
);
|
||||||
stark.eval_ext(vars, &mut consumer);
|
// stark.eval_ext(vars, &mut consumer);
|
||||||
|
let permutation_data = stark.uses_permutation_args().then(|| PermutationCheckData {
|
||||||
|
local_zs: permutation_zs.as_ref().unwrap().clone(),
|
||||||
|
next_zs: permutation_zs_right.as_ref().unwrap().clone(),
|
||||||
|
permutation_challenge_sets: challenges.permutation_challenge_sets,
|
||||||
|
});
|
||||||
|
eval_vanishing_poly::<F, F::Extension, C, S, D, D>(
|
||||||
|
&stark,
|
||||||
|
config,
|
||||||
|
vars,
|
||||||
|
permutation_data,
|
||||||
|
&mut consumer,
|
||||||
|
);
|
||||||
// TODO: Add in constraints for permutation arguments.
|
// TODO: Add in constraints for permutation arguments.
|
||||||
let vanishing_polys_zeta = consumer.accumulators();
|
let vanishing_polys_zeta = consumer.accumulators();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user