Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keccak gates for zkVM #1244

Merged
merged 25 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3a3a463
initial specs with layout distribution
querolita Sep 11, 2023
611dc78
created macro and env function to access states from layout
querolita Sep 12, 2023
862fc50
created constraints for theta step
querolita Sep 12, 2023
9e5c635
pirho constraints
querolita Sep 12, 2023
aa78a19
expand function and round constants and offsets update
querolita Sep 12, 2023
ecf475d
chi constraints
querolita Sep 12, 2023
be51993
iota constraints
querolita Sep 12, 2023
8bac2ff
fix constraints indentation and add next row wiring
querolita Sep 12, 2023
ec06272
include xor of state inside gate
querolita Sep 12, 2023
a33120a
fix clippy
querolita Sep 13, 2023
57327d8
remove unnecessary ranges in loops
querolita Sep 13, 2023
c217976
remove unused function in this pr
querolita Sep 13, 2023
1179b8d
update chainable layout
querolita Sep 13, 2023
4c7f074
simplify macro to need half less rows
querolita Sep 14, 2023
360468b
added constraints of KeccakSponge
querolita Sep 18, 2023
0c360e1
add variants in all matches for this type
querolita Sep 18, 2023
94967f6
included all bytes in KeccakSponge layout to check composition at abs…
querolita Sep 21, 2023
b4a94d8
rename resets for shifts
querolita Sep 26, 2023
e1b318a
update comments
querolita Sep 26, 2023
c593da7
update fixes after testing
querolita Oct 3, 2023
8caedce
fix bug found during testing
querolita Oct 5, 2023
431d562
add support for 10*1 padding in gate
querolita Oct 7, 2023
e35b0a5
refactor macros to fix wrong index accesses, and cleaner code to work…
querolita Oct 20, 2023
18579b8
Merge branch 'master' into zkvm/keccak/gate
querolita Oct 30, 2023
6f819ba
fix typo in comments of witness_next_chunk
querolita Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions kimchi/src/circuits/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,38 @@ impl<F: Field, T: ExprOps<F>> ArgumentEnv<F, T> {
T::witness(Next, col, self.data.as_ref())
}

/// Witness cells in current row in an interval [from, to)
pub fn witness_curr_chunk(&self, from: usize, to: usize) -> Vec<T> {
let mut chunk = Vec::with_capacity(to - from);
for i in from..to {
chunk.push(self.witness_curr(i));
}
chunk
}

/// Witness cells in current row in an interval [from, to)
querolita marked this conversation as resolved.
Show resolved Hide resolved
pub fn witness_next_chunk(&self, from: usize, to: usize) -> Vec<T> {
let mut chunk = Vec::with_capacity(to - from);
for i in from..to {
chunk.push(self.witness_next(i));
}
chunk
}

/// Coefficient value at index idx
pub fn coeff(&self, idx: usize) -> T {
T::coeff(idx, self.data.as_ref())
}

/// Chunk of consecutive coefficients in an interval [from, to)
pub fn coeff_chunk(&self, from: usize, to: usize) -> Vec<T> {
let mut chunk = Vec::with_capacity(to - from);
for i in from..to {
chunk.push(self.coeff(i));
}
chunk
}

/// Constant value (see [ConstantExpr] for supported constants)
pub fn constant(&self, expr: ConstantExpr<F>) -> T {
T::constant(expr, self.data.as_ref())
Expand Down
12 changes: 11 additions & 1 deletion kimchi/src/circuits/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use thiserror::Error;
use super::{
argument::ArgumentWitness,
expr,
polynomials::{rot, xor},
polynomials::{keccak, rot, xor},
};

/// A row accessible from a given row, corresponds to the fact that we open all polynomials
Expand Down Expand Up @@ -113,6 +113,8 @@ pub enum GateType {
// Gates for Keccak
Xor16,
Rot64,
KeccakRound,
KeccakSponge,
}

/// Gate error
Expand Down Expand Up @@ -230,6 +232,12 @@ impl<F: PrimeField + SquareRootField> CircuitGate<F> {
Rot64 => self
.verify_witness::<G>(row, witness, &index.cs, public)
.map_err(|e| e.to_string()),
KeccakRound => self
.verify_witness::<G>(row, witness, &index.cs, public)
.map_err(|e| e.to_string()),
KeccakSponge => self
.verify_witness::<G>(row, witness, &index.cs, public)
.map_err(|e| e.to_string()),
}
}

Expand Down Expand Up @@ -323,6 +331,8 @@ impl<F: PrimeField + SquareRootField> CircuitGate<F> {
}
GateType::Xor16 => xor::Xor16::constraint_checks(&env, &mut cache),
GateType::Rot64 => rot::Rot64::constraint_checks(&env, &mut cache),
GateType::KeccakRound => keccak::KeccakRound::constraint_checks(&env, &mut cache),
GateType::KeccakSponge => keccak::KeccakSponge::constraint_checks(&env, &mut cache),
};

// Check for failed constraints
Expand Down
Loading