Skip to content

Commit

Permalink
Starknet with keccak layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Jul 24, 2024
1 parent e4d935b commit eb991e8
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@
resources/

# Stone-prover repository
stone-prover
stone-prover

**/.DS_Store
19 changes: 15 additions & 4 deletions src/air/layouts/starknet_with_keccak.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ mod constants;
mod global_values;
mod public_input;
mod traces;
mod contract;

use cairo_verifier::{
air::{
constants::{SHIFT_POINT_X, SHIFT_POINT_Y, StarkCurve},
layouts::starknet_with_keccak::{
autogenerated::{eval_composition_polynomial_inner, eval_oods_polynomial_inner},
contract::{
IStarknetWithKeccakLayoutContract1Dispatcher, IStarknetWithKeccakLayoutContract1DispatcherTrait,
IStarknetWithKeccakLayoutContract2Dispatcher, IStarknetWithKeccakLayoutContract2DispatcherTrait,
},
global_values::{
GlobalValues, InteractionElements, EcPoint, EcdsaSigConfig, CurveConfig
},
Expand All @@ -32,6 +36,7 @@ use cairo_verifier::{
},
common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128}
};
use starknet::ContractAddress;

impl StarknetWithKeccakAIRCompositionImpl of AIRComposition<InteractionElements, PublicInput> {
fn eval_composition_polynomial(
Expand All @@ -41,7 +46,8 @@ impl StarknetWithKeccakAIRCompositionImpl of AIRComposition<InteractionElements,
constraint_coefficients: Span<felt252>,
point: felt252,
trace_domain_size: felt252,
trace_generator: felt252
trace_generator: felt252,
contract_address_1: ContractAddress,
) -> felt252 {
let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm;
let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0;
Expand Down Expand Up @@ -161,7 +167,9 @@ impl StarknetWithKeccakAIRCompositionImpl of AIRComposition<InteractionElements,
diluted_check_final_cum_val: diluted_prod
};

eval_composition_polynomial_inner(
IStarknetWithKeccakLayoutContract1Dispatcher {
contract_address: contract_address_1
}. eval_composition_polynomial_inner(
mask_values, constraint_coefficients, point, trace_generator, global_values
)
}
Expand All @@ -175,8 +183,11 @@ impl StarknetWithKeccakAIROodsImpl of AIROods {
point: felt252,
oods_point: felt252,
trace_generator: felt252,
contract_address_2: ContractAddress,
) -> felt252 {
eval_oods_polynomial_inner(
IStarknetWithKeccakLayoutContract2Dispatcher {
contract_address: contract_address_2
}.eval_oods_polynomial_inner(
column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator,
)
}
Expand Down
92 changes: 92 additions & 0 deletions src/air/layouts/starknet_with_keccak/contract.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use cairo_verifier::air::layouts::starknet_with_keccak::global_values::GlobalValues;

#[starknet::interface]
trait IStarknetWithKeccakLayoutContract1<ContractState> {
fn eval_composition_polynomial_inner(
self: @ContractState,
mask_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
trace_generator: felt252,
global_values: GlobalValues
) -> felt252;
}

#[starknet::interface]
trait IStarknetWithKeccakLayoutContract2<ContractState> {
fn eval_oods_polynomial_inner(
self: @ContractState,
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
oods_point: felt252,
trace_generator: felt252,
) -> felt252;
}

// #[starknet::contract]
// mod StarknetWithKeccakLayoutContract1 {
// use super::IStarknetWithKeccakLayoutContract1;
// use cairo_verifier::air::layouts::starknet_with_keccak::{
// global_values::GlobalValues,
// autogenerated::eval_composition_polynomial_inner,
// };

// #[storage]
// struct Storage {}

// #[abi(embed_v0)]
// impl StarknetWithKeccakLayoutContract1 of IStarknetWithKeccakLayoutContract1<ContractState> {
// fn eval_composition_polynomial_inner(
// self: @ContractState,
// mask_values: Span<felt252>,
// constraint_coefficients: Span<felt252>,
// point: felt252,
// trace_generator: felt252,
// global_values: GlobalValues
// ) -> felt252 {
// eval_composition_polynomial_inner(
// mask_values,
// constraint_coefficients,
// point,
// trace_generator,
// global_values
// )
// }
// }
// }

#[starknet::contract]
mod StarknetWithKeccakLayoutContract2 {
use super::IStarknetWithKeccakLayoutContract2;
use cairo_verifier::air::layouts::starknet_with_keccak::{
global_values::GlobalValues,
autogenerated::eval_oods_polynomial_inner,
};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl StarknetWithKeccakLayoutContract2 of IStarknetWithKeccakLayoutContract2<ContractState> {
fn eval_oods_polynomial_inner(
self: @ContractState,
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
oods_point: felt252,
trace_generator: felt252,
) -> felt252 {
eval_oods_polynomial_inner(
column_values,
oods_values,
constraint_coefficients,
point,
oods_point,
trace_generator,
)
}
}
}

0 comments on commit eb991e8

Please sign in to comment.