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

dynamic layout #141

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6eef7aa
update changes
Okm165 Jul 31, 2024
da8bf65
public memory fixes
Okm165 Jul 31, 2024
a002b5c
dynamic layout sketch
Okm165 Aug 22, 2024
c465fb8
dynamic consts & public_input verification
Okm165 Aug 23, 2024
3b74077
AIRComposition trait implemented
Okm165 Aug 25, 2024
060b38c
wip
Okm165 Aug 25, 2024
0928851
wip
Okm165 Aug 25, 2024
1779d1c
wip
Okm165 Aug 25, 2024
515e989
wip
Okm165 Aug 25, 2024
8f8f5b6
wip
Okm165 Aug 25, 2024
98a502d
fm
Okm165 Aug 25, 2024
dca1477
wip
Okm165 Aug 25, 2024
ecb7c16
eval_oods_polynomial_inner IMPL
Okm165 Aug 26, 2024
3a7adfb
cleanup
Okm165 Aug 26, 2024
1c4498a
autogenerated complete
Okm165 Aug 28, 2024
a2659dd
dynamic layout integration
Okm165 Aug 28, 2024
ea33821
add dynamic configuration
Okm165 Aug 28, 2024
cc964d1
columns dependent on layout internally in stark_verify function
Okm165 Aug 28, 2024
d9dab7d
traces validation layout specific
Okm165 Aug 28, 2024
70dc8ae
fixes
Okm165 Aug 28, 2024
d464f10
cleanup
Okm165 Aug 29, 2024
909a4b9
test fixes
Okm165 Aug 29, 2024
89c38e6
rm proof verification workflow
Okm165 Aug 29, 2024
eaa794e
Merge branch 'Cairo_v0.13.2a0_fixes' into dynamic_layout_stone6
Okm165 Aug 29, 2024
df4da74
Merge branch 'main' into Cairo_v0.13.2a0_fixes
Okm165 Aug 29, 2024
952bb02
Merge branch 'Cairo_v0.13.2a0_fixes' into dynamic_layout_stone6
Okm165 Aug 29, 2024
3dcb1f9
dynamic public input fixes
Okm165 Aug 29, 2024
767bb42
Merge branch 'parser_standard' into dynamic_layout_stone6
Okm165 Sep 4, 2024
60d0dec
rm check_asserts temporarely - causing issues
Okm165 Sep 4, 2024
2b5a7de
adding example proof to the repo
Okm165 Sep 4, 2024
fcce54b
dynamic check asserts
Okm165 Sep 5, 2024
8d0d236
autogenerated_asserts fix
Okm165 Sep 5, 2024
a70ea4b
check_asserts
Okm165 Sep 5, 2024
7017d81
inline asserts
Okm165 Sep 6, 2024
54239f0
opts rm unsused assignments
Okm165 Sep 6, 2024
a64448a
opts fix
Okm165 Sep 6, 2024
29df665
Merge pull request #142 from HerodotusDev/Cairo_v0.13.2a0_fixes
Okm165 Sep 6, 2024
5ea6d90
Merge pull request #143 from HerodotusDev/dynamic_layout_stone6
Okm165 Sep 6, 2024
906d77c
Merge pull request #159 from HerodotusDev/dynamic_layout_stone6
Okm165 Nov 14, 2024
5668b07
check asserts commented for less resource consumption during compilat…
Okm165 Nov 14, 2024
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
45 changes: 0 additions & 45 deletions .github/workflows/proof_verification_tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from utils import process_file

LAYOUT_TYPES = ("dex", "recursive", "recursive_with_poseidon", "small", "starknet", "starknet_with_keccak")
LAYOUT_TYPES = ("dex", "recursive", "recursive_with_poseidon", "small", "starknet", "starknet_with_keccak", "dynamic")
HASH_TYPES = ("keccak", "blake2s")


Expand Down
4,667 changes: 4,667 additions & 0 deletions examples/proofs/dynamic/cairo0_example_proof.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/air/air.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ trait AIRComposition<IE, PI> {
) -> felt252;
}

trait AIROods {
trait AIROods<DY> {
fn eval_oods_polynomial(
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
oods_point: felt252,
trace_generator: felt252,
dynamic_params: DY,
) -> felt252;
}
3 changes: 3 additions & 0 deletions src/air/layouts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ mod recursive;
// === STARKNET_WITH_KECCAK BEGIN ===
// mod starknet_with_keccak;
// === STARKNET_WITH_KECCAK END ===
// === DYNAMIC BEGIN ===
// mod dynamic;
// === DYNAMIC END ===


7 changes: 4 additions & 3 deletions src/air/layouts/dex.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cairo_verifier::{
global_values::{GlobalValues, InteractionElements, EcPoint, EcdsaSigConfig},
public_input::DexPublicInputImpl,
constants::{
PUBLIC_MEMORY_STEP, PEDERSEN_BUILTIN_RATIO, ECDSA_BUILTIN_RATIO,
DynamicParams, PUBLIC_MEMORY_STEP, PEDERSEN_BUILTIN_RATIO, ECDSA_BUILTIN_RATIO,
ECDSA_BUILTIN_REPETITIONS, PEDERSEN_BUILTIN_REPETITIONS, segments,
},
},
Expand Down Expand Up @@ -95,17 +95,18 @@ impl DexAIRCompositionImpl of AIRComposition<InteractionElements, PublicInput> {
}
}

impl DexAIROodsImpl of AIROods {
impl DexAIROodsImpl of AIROods<DynamicParams> {
fn eval_oods_polynomial(
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
oods_point: felt252,
trace_generator: felt252,
dynamic_params: DynamicParams,
) -> felt252 {
eval_oods_polynomial_inner(
column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator,
column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator
)
}
}
3 changes: 3 additions & 0 deletions src/air/layouts/dex/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const RANGE_CHECK_BUILTIN_RATIO: felt252 = 8;
const RANGE_CHECK_BUILTIN_ROW_RATIO: felt252 = 128;
const RANGE_CHECK_N_PARTS: felt252 = 8;

#[derive(Drop, Copy, Serde)]
struct DynamicParams {}

mod segments {
const ECDSA: usize = 5;
const EXECUTION: usize = 1;
Expand Down
8 changes: 6 additions & 2 deletions src/air/layouts/dex/traces.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use cairo_verifier::{
air::layouts::dex::{
constants::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}, global_values::InteractionElements,
air::{
public_input::PublicInput,
layouts::dex::{
constants::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}, global_values::InteractionElements,
}
},
channel::channel::{Channel, ChannelTrait},
table_commitment::table_commitment::{
Expand Down Expand Up @@ -69,6 +72,7 @@ struct TracesConfig {
impl TracesConfigImpl of TracesConfigTrait {
fn validate(
self: @TracesConfig,
public_input: @PublicInput,
log_eval_domain_size: felt252,
n_verifier_friendly_commitment_layers: felt252,
) {
Expand Down
231 changes: 231 additions & 0 deletions src/air/layouts/dynamic.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
mod autogenerated;
mod constants;
mod global_values;
mod public_input;
mod traces;

use cairo_verifier::{
air::{
layouts::dynamic::{
global_values::{
InteractionElements, GlobalValues, EcPoint, EcdsaSigConfig, CurveConfig
},
autogenerated::{eval_oods_polynomial_inner, eval_composition_polynomial_inner},
constants::{
DynamicParams, segments, PUBLIC_MEMORY_FRACTION, ECDSA_BUILTIN_REPETITIONS,
PEDERSEN_BUILTIN_REPETITIONS, DILUTED_N_BITS, DILUTED_SPACING
}
},
constants::{SHIFT_POINT_X, SHIFT_POINT_Y, StarkCurve}, air::{AIRComposition, AIROods},
diluted::get_diluted_product,
periodic_columns::{
eval_pedersen_x, eval_pedersen_y, eval_ecdsa_x, eval_ecdsa_y,
eval_poseidon_poseidon_full_round_key0, eval_poseidon_poseidon_full_round_key1,
eval_poseidon_poseidon_full_round_key2, eval_poseidon_poseidon_partial_round_key0,
eval_poseidon_poseidon_partial_round_key1, eval_keccak_round_key0,
eval_keccak_round_key1, eval_keccak_round_key3, eval_keccak_round_key7,
eval_keccak_round_key15, eval_keccak_round_key31, eval_keccak_round_key63
},
public_input::{PublicInput, get_public_memory_product_ratio}
},
common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128}
};

impl DynamicAIRCompositionImpl of AIRComposition<InteractionElements, PublicInput> {
fn eval_composition_polynomial(
interaction_elements: InteractionElements,
public_input: @PublicInput,
mask_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
trace_domain_size: felt252,
trace_generator: felt252
) -> felt252 {
let mut dynamic_params_span = public_input.dynamic_params.span();
let dynamic_params = Serde::<DynamicParams>::deserialize(ref dynamic_params_span).unwrap();

let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm;
let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0;

// Public memory
let public_memory_column_size = trace_domain_size
/ (PUBLIC_MEMORY_FRACTION * dynamic_params.memory_units_row_ratio.into());
assert_range_u128(public_memory_column_size);
let public_memory_prod_ratio = get_public_memory_product_ratio(
public_input, memory_z, memory_alpha, public_memory_column_size
);

// Diluted
let diluted_z = interaction_elements.diluted_check_interaction_z;
let diluted_alpha = interaction_elements.diluted_check_interaction_alpha;
let diluted_prod = get_diluted_product(
DILUTED_N_BITS, DILUTED_SPACING, diluted_z, diluted_alpha
);

// Periodic columns.
let (pedersen_points_x, pedersen_points_y) = if dynamic_params.uses_pedersen_builtin == 0 {
(0, 0)
} else {
let n_pedersen_hash_copies = trace_domain_size
/ (PEDERSEN_BUILTIN_REPETITIONS * dynamic_params.pedersen_builtin_row_ratio.into());
assert_range_u128(n_pedersen_hash_copies);
let pedersen_point = pow(point, n_pedersen_hash_copies);
(eval_pedersen_x(pedersen_point), eval_pedersen_y(pedersen_point))
};

let (ecdsa_generator_points_x, ecdsa_generator_points_y) = if dynamic_params
.uses_ecdsa_builtin == 0 {
(0, 0)
} else {
let n_ecdsa_signature_copies = trace_domain_size
/ (ECDSA_BUILTIN_REPETITIONS * dynamic_params.ecdsa_builtin_row_ratio.into());
assert_range_u128(n_ecdsa_signature_copies);
let ecdsa_point = pow(point, n_ecdsa_signature_copies);
(eval_ecdsa_x(ecdsa_point), eval_ecdsa_y(ecdsa_point))
};

let (
keccak_keccak_keccak_round_key0,
keccak_keccak_keccak_round_key1,
keccak_keccak_keccak_round_key3,
keccak_keccak_keccak_round_key7,
keccak_keccak_keccak_round_key15,
keccak_keccak_keccak_round_key31,
keccak_keccak_keccak_round_key63,
) =
if dynamic_params
.uses_keccak_builtin == 0 {
(0, 0, 0, 0, 0, 0, 0)
} else {
let n_keccak_component_copies = trace_domain_size
/ (DILUTED_N_BITS * dynamic_params.keccak_row_ratio.into());
// The following assert enforces that the number of keccak instances is divisible by
// KECCAK_PERMUTATIONS_PER_INSTANCE.
assert_range_u128(n_keccak_component_copies);
let n_keccak_periodic_columns_copies = 2048 * n_keccak_component_copies;
let keccak_point = pow(point, n_keccak_periodic_columns_copies);
(
eval_keccak_round_key0(keccak_point),
eval_keccak_round_key1(keccak_point),
eval_keccak_round_key3(keccak_point),
eval_keccak_round_key7(keccak_point),
eval_keccak_round_key15(keccak_point),
eval_keccak_round_key31(keccak_point),
eval_keccak_round_key63(keccak_point)
)
};

let (
poseidon_poseidon_full_round_key0,
poseidon_poseidon_full_round_key1,
poseidon_poseidon_full_round_key2,
poseidon_poseidon_partial_round_key0,
poseidon_poseidon_partial_round_key1
) =
if dynamic_params
.uses_poseidon_builtin == 0 {
(0, 0, 0, 0, 0)
} else {
let n_poseidon_copies = trace_domain_size / dynamic_params.poseidon_row_ratio.into();
assert_range_u128(n_poseidon_copies);
let poseidon_point = pow(point, n_poseidon_copies);
(
eval_poseidon_poseidon_full_round_key0(poseidon_point),
eval_poseidon_poseidon_full_round_key1(poseidon_point),
eval_poseidon_poseidon_full_round_key2(poseidon_point),
eval_poseidon_poseidon_partial_round_key0(poseidon_point),
eval_poseidon_poseidon_partial_round_key1(poseidon_point)
)
};

let global_values = GlobalValues {
trace_length: trace_domain_size,
initial_pc: *public_input.segments.at(segments::PROGRAM).begin_addr,
final_pc: *public_input.segments.at(segments::PROGRAM).stop_ptr,
initial_ap: *public_input.segments.at(segments::EXECUTION).begin_addr,
final_ap: *public_input.segments.at(segments::EXECUTION).stop_ptr,
initial_pedersen_addr: *public_input.segments.at(segments::PEDERSEN).begin_addr,
initial_range_check_addr: *public_input.segments.at(segments::RANGE_CHECK).begin_addr,
initial_ecdsa_addr: *public_input.segments.at(segments::ECDSA).begin_addr,
initial_bitwise_addr: *public_input.segments.at(segments::BITWISE).begin_addr,
initial_ec_op_addr: *public_input.segments.at(segments::EC_OP).begin_addr,
initial_keccak_addr: *public_input.segments.at(segments::KECCAK).begin_addr,
initial_poseidon_addr: *public_input.segments.at(segments::POSEIDON).begin_addr,
initial_range_check96_addr: *public_input
.segments
.at(segments::RANGE_CHECK96)
.begin_addr,
add_mod_initial_mod_addr: *public_input.segments.at(segments::ADD_MOD).begin_addr,
mul_mod_initial_mod_addr: *public_input.segments.at(segments::MUL_MOD).begin_addr,
range_check_min: *public_input.range_check_min,
range_check_max: *public_input.range_check_max,
offset_size: 0x10000, // 2**16
half_offset_size: 0x8000, // 2**15
pedersen_shift_point: EcPoint { x: SHIFT_POINT_X, y: SHIFT_POINT_Y },
ecdsa_sig_config: EcdsaSigConfig {
alpha: StarkCurve::ALPHA,
beta: StarkCurve::BETA,
shift_point: EcPoint { x: SHIFT_POINT_X, y: SHIFT_POINT_Y },
},
ec_op_curve_config: CurveConfig { alpha: StarkCurve::ALPHA, beta: StarkCurve::BETA },
pedersen_points_x,
pedersen_points_y,
ecdsa_generator_points_x,
ecdsa_generator_points_y,
keccak_keccak_keccak_round_key0,
keccak_keccak_keccak_round_key1,
keccak_keccak_keccak_round_key3,
keccak_keccak_keccak_round_key7,
keccak_keccak_keccak_round_key15,
keccak_keccak_keccak_round_key31,
keccak_keccak_keccak_round_key63,
poseidon_poseidon_full_round_key0,
poseidon_poseidon_full_round_key1,
poseidon_poseidon_full_round_key2,
poseidon_poseidon_partial_round_key0,
poseidon_poseidon_partial_round_key1,
memory_multi_column_perm_perm_interaction_elm: memory_z,
memory_multi_column_perm_hash_interaction_elm0: memory_alpha,
range_check16_perm_interaction_elm: interaction_elements
.range_check16_perm_interaction_elm,
diluted_check_permutation_interaction_elm: interaction_elements
.diluted_check_permutation_interaction_elm,
diluted_check_interaction_z: diluted_z,
diluted_check_interaction_alpha: diluted_alpha,
add_mod_interaction_elm: interaction_elements.add_mod_interaction_elm,
mul_mod_interaction_elm: interaction_elements.mul_mod_interaction_elm,
memory_multi_column_perm_perm_public_memory_prod: public_memory_prod_ratio,
range_check16_perm_public_memory_prod: 1,
diluted_check_first_elm: 0,
diluted_check_permutation_public_memory_prod: 1,
diluted_check_final_cum_val: diluted_prod,
dynamic_params: dynamic_params,
};

eval_composition_polynomial_inner(
mask_values, constraint_coefficients, point, trace_generator, global_values,
)
}
}

impl DynamicAIROodsImpl of AIROods<DynamicParams> {
fn eval_oods_polynomial(
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
oods_point: felt252,
trace_generator: felt252,
dynamic_params: DynamicParams,
) -> felt252 {
eval_oods_polynomial_inner(
column_values,
oods_values,
constraint_coefficients,
point,
oods_point,
trace_generator,
dynamic_params,
)
}
}
7 changes: 7 additions & 0 deletions src/air/layouts/dynamic/autogenerated.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod autogenerated_asserts;
mod autogenerated_composition;
mod autogenerated_oods;

pub use autogenerated_asserts::check_asserts;
pub use autogenerated_composition::eval_composition_polynomial_inner;
pub use autogenerated_oods::eval_oods_polynomial_inner;
Loading
Loading