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

layout/starknet with keccak #116

Merged
merged 37 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
239b001
starknet with keccak layout
Okm165 Mar 18, 2024
95921c1
fix
Okm165 Mar 18, 2024
c412e35
fix
Okm165 Mar 18, 2024
75dbf02
runner update vec252 refactor
Okm165 Mar 19, 2024
56244d1
starknet foundry rpc v0_7
Okm165 Mar 20, 2024
121cf7e
newest snfoundry tool version
Okm165 Mar 20, 2024
2751e4f
nightly scarb version
Okm165 Mar 20, 2024
8e9b5f8
Merge branch 'feat/fact_registry' into feat/layout/starknet_with_keccak
Okm165 Mar 20, 2024
69f3844
Merge branch 'feat/layout_changer' into feat/layout/starknet_with_keccak
Okm165 Mar 20, 2024
d79f4a1
starknet with keccak example proof
Okm165 Mar 20, 2024
c2ae1be
merge
Okm165 Mar 21, 2024
8b29aa1
add starknet_with_keccak to ci
Okm165 Mar 21, 2024
ccedef0
recursive layout as default
Okm165 Mar 21, 2024
ff8a865
Revert "add starknet_with_keccak to ci"
Okm165 Mar 21, 2024
5360ecf
Merge branch 'feat/layout_changer' into feat/layout/starknet_with_keccak
Okm165 Mar 21, 2024
8019ae9
starknet_with_keccak pop_front optimization
Okm165 Mar 21, 2024
52a2def
ci turn on proof verification tests
Okm165 Mar 22, 2024
ec60430
starknet_with_keccak loop optimizaton
Okm165 Mar 22, 2024
4d76ad2
starknet pop_front optimization
Okm165 Mar 22, 2024
2043afc
small pop_front optimization
Okm165 Mar 22, 2024
ca9c415
recursive_with_poseidon pop_front optimization
Okm165 Mar 22, 2024
8649efc
recursive pop_front optimization
Okm165 Mar 22, 2024
934596b
dex pop_front optimization
Okm165 Mar 22, 2024
612c1f2
deployed contract update
Okm165 Mar 22, 2024
bdbe904
proof_verification_tests only on main
Okm165 Mar 22, 2024
fef117a
turn off starknet_with_keccak in ci
Okm165 Mar 22, 2024
98b4a3a
Revert "proof_verification_tests only on main"
Okm165 Mar 22, 2024
2550e99
Merge branch 'main' into feat/layout/starknet_with_keccak
Okm165 Mar 25, 2024
0fe3de2
Merge branch 'main' into layouts_optimization
Okm165 Mar 25, 2024
d1bcde7
keccak periodic columns renamed
Okm165 Mar 25, 2024
96fc234
Merge branch 'feat/layout/starknet_with_keccak' into layouts_optimiza…
Okm165 Mar 25, 2024
acbaaae
Revert "turn off starknet_with_keccak in ci"
Okm165 Mar 25, 2024
044341b
Reapply "proof_verification_tests only on main"
Okm165 Mar 25, 2024
8d35531
README layout types fix
Okm165 Mar 25, 2024
77dab5f
Merge pull request #119 from HerodotusDev/layouts_optimization
fmkra Mar 26, 2024
f5da118
README badges
Okm165 Mar 26, 2024
0f82641
version bump & rpc fixed
Okm165 Mar 27, 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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb nightly-2024-03-16
starknet-foundry 0.20.0
starknet-foundry 0.20.0
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")
LAYOUT_TYPES = ("dex", "recursive", "recursive_with_poseidon", "small", "starknet", "starknet_with_keccak")
HASH_TYPES = ("keccak", "blake2s")


Expand Down
1,995 changes: 1,995 additions & 0 deletions examples/proofs/starknet_with_keccak/example_proof.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions examples/starknet/.tool-versions

This file was deleted.

10 changes: 2 additions & 8 deletions examples/starknet/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ edition = "2023_10"

[dependencies]
cairo_verifier = { path = ".." }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.16.0" }
starknet = "2.4.4"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.20.0" }

[[target.starknet-contract]]
casm = true

[tool.sncast.testnet]
account = "testnet-sepolia"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_6"
casm = true
2 changes: 1 addition & 1 deletion examples/starknet/snfoundry.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[sncast.testnet]
account = "testnet-sepolia"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_6"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_7"
8 changes: 4 additions & 4 deletions examples/starknet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn main() -> anyhow::Result<()> {
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();

let proof = chain!(
config.to_vec(),
public_input.to_vec(),
unsent_commitment.to_vec(),
witness.to_vec()
config.into_iter(),
public_input.into_iter(),
unsent_commitment.into_iter(),
witness.into_iter()
)
.collect_vec();

Expand Down
2 changes: 0 additions & 2 deletions fact_registry/.tool-versions

This file was deleted.

10 changes: 2 additions & 8 deletions fact_registry/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ edition = "2023_10"

[dependencies]
cairo_verifier = { path = ".." }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.16.0" }
starknet = "2.4.4"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.20.0" }

[[target.starknet-contract]]
casm = true

[tool.sncast.testnet]
account = "testnet-sepolia"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_6"
casm = true
2 changes: 1 addition & 1 deletion fact_registry/snfoundry.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[sncast.testnet]
account = "testnet-sepolia"
accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_6"
url = "https://free-rpc.nethermind.io/sepolia-juno/v0_7"
8 changes: 4 additions & 4 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ fn main() -> anyhow::Result<()> {
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();

let proof = chain!(
config.to_vec(),
public_input.to_vec(),
unsent_commitment.to_vec(),
witness.to_vec()
config.into_iter(),
public_input.into_iter(),
unsent_commitment.into_iter(),
witness.into_iter()
)
.collect_vec();

Expand Down
9 changes: 9 additions & 0 deletions runner/src/vec252.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ impl VecFelt252 {
}
}

impl IntoIterator for VecFelt252 {
type Item = Felt252;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl Deref for VecFelt252 {
type Target = Vec<Felt252>;
fn deref(&self) -> &Self::Target {
Expand Down
3 changes: 3 additions & 0 deletions src/air/layouts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ mod recursive;
// === STARKNET BEGIN ===
// mod starknet;
// === STARKNET END ===
// === STARKNET_WITH_KECCAK BEGIN ===
// mod starknet_with_keccak;
// === STARKNET_WITH_KECCAK END ===


184 changes: 184 additions & 0 deletions src/air/layouts/starknet_with_keccak.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
mod autogenerated;
mod constants;
mod global_values;
mod public_input;
mod traces;

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},
global_values::{
GlobalValues, InteractionElements, EcPoint, EcdsaSigConfig, CurveConfig
},
public_input::StarknetWithKeccakPublicInputImpl,
constants::{
PUBLIC_MEMORY_STEP, DILUTED_N_BITS, DILUTED_SPACING, PEDERSEN_BUILTIN_RATIO,
PEDERSEN_BUILTIN_REPETITIONS, segments, ECDSA_BUILTIN_RATIO,
ECDSA_BUILTIN_REPETITIONS, POSEIDON_RATIO, KECCAK_RATIO
},
},
air::{AIRComposition, AIROods}, diluted::get_diluted_product,
periodic_columns::{
eval_pedersen_x, eval_pedersen_y, eval_ecdsa_x, eval_ecdsa_y,
eval_keccak_keccak_keccak_round_key0, eval_keccak_keccak_keccak_round_key1,
eval_keccak_keccak_keccak_round_key3, eval_keccak_keccak_keccak_round_key7,
eval_keccak_keccak_keccak_round_key15, eval_keccak_keccak_keccak_round_key31,
eval_keccak_keccak_keccak_round_key63, 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
},
public_input::{PublicInput, get_public_memory_product_ratio}
},
common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128}
};

impl StarknetWithKeccakAIRCompositionImpl 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 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_STEP;
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 n_steps = pow(2, *public_input.log_n_steps);
let n_pedersen_hash_copies = n_steps
/ (PEDERSEN_BUILTIN_RATIO * PEDERSEN_BUILTIN_REPETITIONS);
assert_range_u128(n_pedersen_hash_copies);
let pedersen_point = pow(point, n_pedersen_hash_copies);
let pedersen_points_x = eval_pedersen_x(pedersen_point);
let pedersen_points_y = eval_pedersen_y(pedersen_point);

let n_ecdsa_signature_copies = n_steps / (ECDSA_BUILTIN_RATIO * ECDSA_BUILTIN_REPETITIONS);
assert_range_u128(n_ecdsa_signature_copies);
let ecdsa_point = pow(point, n_ecdsa_signature_copies);
let ecdsa_generator_points_x = eval_ecdsa_x(ecdsa_point);
let ecdsa_generator_points_y = eval_ecdsa_y(ecdsa_point);

let n_keccak_component_copies = n_steps / (DILUTED_N_BITS * KECCAK_RATIO);
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);
let keccak_keccak_keccak_round_key0 = eval_keccak_keccak_keccak_round_key0(keccak_point);
let keccak_keccak_keccak_round_key1 = eval_keccak_keccak_keccak_round_key1(keccak_point);
let keccak_keccak_keccak_round_key3 = eval_keccak_keccak_keccak_round_key3(keccak_point);
let keccak_keccak_keccak_round_key7 = eval_keccak_keccak_keccak_round_key7(keccak_point);
let keccak_keccak_keccak_round_key15 = eval_keccak_keccak_keccak_round_key15(keccak_point);
let keccak_keccak_keccak_round_key31 = eval_keccak_keccak_keccak_round_key31(keccak_point);
let keccak_keccak_keccak_round_key63 = eval_keccak_keccak_keccak_round_key63(keccak_point);

let n_poseidon_copies = n_steps / POSEIDON_RATIO;
assert_range_u128(n_poseidon_copies);
let poseidon_point = pow(point, n_poseidon_copies);
let poseidon_poseidon_full_round_key0 = eval_poseidon_poseidon_full_round_key0(
poseidon_point
);
let poseidon_poseidon_full_round_key1 = eval_poseidon_poseidon_full_round_key1(
poseidon_point
);
let poseidon_poseidon_full_round_key2 = eval_poseidon_poseidon_full_round_key2(
poseidon_point
);
let poseidon_poseidon_partial_round_key0 = eval_poseidon_poseidon_partial_round_key0(
poseidon_point
);
let poseidon_poseidon_partial_round_key1 = 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,
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,
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
};

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

impl StarknetWithKeccakAIROodsImpl of AIROods {
fn eval_oods_polynomial(
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,
)
}
}
Loading
Loading