mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 17:53:06 +00:00
INPUT_LIMBS -> NUM_INPUTS
This commit is contained in:
parent
30abe19e42
commit
8bd6bebdc7
@ -64,7 +64,7 @@ mod tests {
|
||||
use crate::cpu;
|
||||
use crate::cpu::cpu_stark::CpuStark;
|
||||
use crate::cross_table_lookup::CrossTableLookup;
|
||||
use crate::keccak::keccak_stark::{KeccakStark, INPUT_LIMBS, NUM_ROUNDS};
|
||||
use crate::keccak::keccak_stark::{KeccakStark, NUM_INPUTS, NUM_ROUNDS};
|
||||
use crate::proof::AllProof;
|
||||
use crate::prover::prove;
|
||||
use crate::recursive_verifier::{
|
||||
@ -87,13 +87,13 @@ mod tests {
|
||||
let keccak_stark = KeccakStark::<F, D> {
|
||||
f: Default::default(),
|
||||
};
|
||||
let keccak_rows = (6 * NUM_ROUNDS + 1).next_power_of_two();
|
||||
let keccak_rows = (2 * NUM_ROUNDS + 1).next_power_of_two();
|
||||
let keccak_looked_col = 3;
|
||||
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(0x6feb51b7ec230f25);
|
||||
let num_inputs = 6;
|
||||
let num_inputs = 2;
|
||||
let keccak_inputs = (0..num_inputs)
|
||||
.map(|_| [0u64; INPUT_LIMBS].map(|_| rng.gen()))
|
||||
.map(|_| [0u64; NUM_INPUTS].map(|_| rng.gen()))
|
||||
.collect_vec();
|
||||
let keccak_trace = keccak_stark.generate_trace(keccak_inputs);
|
||||
let column_to_copy: Vec<_> = keccak_trace[keccak_looked_col].values[..].into();
|
||||
|
||||
@ -27,8 +27,8 @@ use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars};
|
||||
/// Number of rounds in a Keccak permutation.
|
||||
pub(crate) const NUM_ROUNDS: usize = 24;
|
||||
|
||||
/// Number of 64-bit limbs in a preimage of the Keccak permutation.
|
||||
pub(crate) const INPUT_LIMBS: usize = 25;
|
||||
/// Number of 64-bit elements in the Keccak permutation input.
|
||||
pub(crate) const NUM_INPUTS: usize = 25;
|
||||
|
||||
pub(crate) const NUM_PUBLIC_INPUTS: usize = 0;
|
||||
|
||||
@ -42,7 +42,7 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakStark<F, D> {
|
||||
/// in our lookup arguments, as those are computed after transposing to column-wise form.
|
||||
pub(crate) fn generate_trace_rows(
|
||||
&self,
|
||||
inputs: Vec<[u64; INPUT_LIMBS]>,
|
||||
inputs: Vec<[u64; NUM_INPUTS]>,
|
||||
) -> Vec<[F; NUM_REGISTERS]> {
|
||||
let num_rows = (inputs.len() * NUM_ROUNDS).next_power_of_two();
|
||||
info!("{} rows", num_rows);
|
||||
@ -51,7 +51,7 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakStark<F, D> {
|
||||
rows.extend(self.generate_trace_rows_for_perm(*input));
|
||||
}
|
||||
|
||||
let pad_rows = self.generate_trace_rows_for_perm([0; INPUT_LIMBS]);
|
||||
let pad_rows = self.generate_trace_rows_for_perm([0; NUM_INPUTS]);
|
||||
while rows.len() < num_rows {
|
||||
rows.extend(&pad_rows);
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakStark<F, D> {
|
||||
rows
|
||||
}
|
||||
|
||||
fn generate_trace_rows_for_perm(&self, input: [u64; INPUT_LIMBS]) -> Vec<[F; NUM_REGISTERS]> {
|
||||
fn generate_trace_rows_for_perm(&self, input: [u64; NUM_INPUTS]) -> Vec<[F; NUM_REGISTERS]> {
|
||||
let mut rows = vec![[F::ZERO; NUM_REGISTERS]; NUM_ROUNDS];
|
||||
|
||||
self.copy_input(input, &mut rows[0]);
|
||||
@ -187,15 +187,15 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakStark<F, D> {
|
||||
row[out_reg_hi] = F::from_canonical_u64(row[in_reg_hi].to_canonical_u64() ^ rc_hi);
|
||||
}
|
||||
|
||||
fn copy_input(&self, input: [u64; INPUT_LIMBS], row: &mut [F; NUM_REGISTERS]) {
|
||||
for i in 0..INPUT_LIMBS {
|
||||
fn copy_input(&self, input: [u64; NUM_INPUTS], row: &mut [F; NUM_REGISTERS]) {
|
||||
for i in 0..NUM_INPUTS {
|
||||
let (low, high) = (input[i] as u32, input[i] >> 32);
|
||||
row[reg_input_limb(2 * i)] = F::from_canonical_u32(low);
|
||||
row[reg_input_limb(2 * i + 1)] = F::from_canonical_u64(high);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_trace(&self, inputs: Vec<[u64; INPUT_LIMBS]>) -> Vec<PolynomialValues<F>> {
|
||||
pub fn generate_trace(&self, inputs: Vec<[u64; NUM_INPUTS]>) -> Vec<PolynomialValues<F>> {
|
||||
let mut timing = TimingTree::new("generate trace", log::Level::Debug);
|
||||
|
||||
// Generate the witness, except for permuted columns in the lookup argument.
|
||||
@ -230,7 +230,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for KeccakStark<F
|
||||
{
|
||||
eval_round_flags(vars, yield_constr);
|
||||
|
||||
for i in 0..2 * INPUT_LIMBS {
|
||||
for i in 0..2 * NUM_INPUTS {
|
||||
let local_input_limb = vars.local_values[reg_input_limb(i)];
|
||||
let next_input_limb = vars.next_values[reg_input_limb(i)];
|
||||
let is_last_round = vars.local_values[reg_step(NUM_ROUNDS - 1)];
|
||||
@ -390,7 +390,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for KeccakStark<F
|
||||
|
||||
eval_round_flags_recursively(builder, vars, yield_constr);
|
||||
|
||||
for i in 0..2 * INPUT_LIMBS {
|
||||
for i in 0..2 * NUM_INPUTS {
|
||||
let local_input_limb = vars.local_values[reg_input_limb(i)];
|
||||
let next_input_limb = vars.next_values[reg_input_limb(i)];
|
||||
let is_last_round = vars.local_values[reg_step(NUM_ROUNDS - 1)];
|
||||
@ -563,7 +563,7 @@ mod tests {
|
||||
use plonky2::field::field_types::Field;
|
||||
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
use crate::keccak::keccak_stark::{KeccakStark, INPUT_LIMBS, NUM_ROUNDS};
|
||||
use crate::keccak::keccak_stark::{KeccakStark, NUM_INPUTS, NUM_ROUNDS};
|
||||
use crate::keccak::registers::reg_output_limb;
|
||||
use crate::stark_testing::{test_stark_circuit_constraints, test_stark_low_degree};
|
||||
|
||||
@ -595,7 +595,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn keccak_correctness_test() -> Result<()> {
|
||||
let input: [u64; INPUT_LIMBS] = rand::random();
|
||||
let input: [u64; NUM_INPUTS] = rand::random();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
@ -609,7 +609,7 @@ mod tests {
|
||||
let rows = stark.generate_trace_rows(vec![input.try_into().unwrap()]);
|
||||
let last_row = rows[NUM_ROUNDS - 1];
|
||||
let base = F::from_canonical_u64(1 << 32);
|
||||
let output = (0..INPUT_LIMBS)
|
||||
let output = (0..NUM_INPUTS)
|
||||
.map(|i| last_row[reg_output_limb(2 * i)] + base * last_row[reg_output_limb(2 * i + 1)])
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::keccak::keccak_stark::{INPUT_LIMBS, NUM_ROUNDS};
|
||||
use crate::keccak::keccak_stark::{NUM_INPUTS, NUM_ROUNDS};
|
||||
|
||||
/// A register which is set to 1 if we are in the `i`th round, otherwise 0.
|
||||
pub(crate) const fn reg_step(i: usize) -> usize {
|
||||
@ -10,7 +10,7 @@ pub(crate) const fn reg_step(i: usize) -> usize {
|
||||
/// `reg_input_limb(2*i) -> input[i] as u32`
|
||||
/// `reg_input_limb(2*i+1) -> input[i] >> 32`
|
||||
pub(crate) const fn reg_input_limb(i: usize) -> usize {
|
||||
debug_assert!(i < 2 * INPUT_LIMBS);
|
||||
debug_assert!(i < 2 * NUM_INPUTS);
|
||||
NUM_ROUNDS + i
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ pub(crate) const fn reg_input_limb(i: usize) -> usize {
|
||||
/// `reg_output_limb(2*i+1) -> output[i] >> 32`
|
||||
#[allow(dead_code)] // TODO: Remove once it is used.
|
||||
pub(crate) const fn reg_output_limb(i: usize) -> usize {
|
||||
debug_assert!(i < 2 * INPUT_LIMBS);
|
||||
debug_assert!(i < 2 * NUM_INPUTS);
|
||||
let ii = i / 2;
|
||||
let x = ii / 5;
|
||||
let y = ii % 5;
|
||||
@ -38,7 +38,7 @@ const R: [[u8; 5]; 5] = [
|
||||
[27, 20, 39, 8, 14],
|
||||
];
|
||||
|
||||
const START_A: usize = NUM_ROUNDS + 2 * INPUT_LIMBS;
|
||||
const START_A: usize = NUM_ROUNDS + 2 * NUM_INPUTS;
|
||||
pub(crate) const fn reg_a(x: usize, y: usize, z: usize) -> usize {
|
||||
debug_assert!(x < 5);
|
||||
debug_assert!(y < 5);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user