diff --git a/crates/air/src/layout/dex/mod.rs b/crates/air/src/layout/dex/mod.rs index aa0e3ce..07d1569 100644 --- a/crates/air/src/layout/dex/mod.rs +++ b/crates/air/src/layout/dex/mod.rs @@ -4,8 +4,7 @@ pub mod global_values; use crate::{ consts::*, felt_hex, - layout::stark_curve, - layout::utils::compute_program_hash, + layout::{compute_program_hash, stark_curve}, periodic_columns::{eval_ecdsa_x, eval_ecdsa_y, eval_pedersen_x, eval_pedersen_y}, public_memory::{PublicInput, INITIAL_PC, MAX_ADDRESS, MAX_LOG_N_STEPS, MAX_RANGE_CHECK}, }; diff --git a/crates/air/src/layout/dynamic/mod.rs b/crates/air/src/layout/dynamic/mod.rs index 42d9a67..c75b2f7 100644 --- a/crates/air/src/layout/dynamic/mod.rs +++ b/crates/air/src/layout/dynamic/mod.rs @@ -6,8 +6,7 @@ use crate::{ consts::*, diluted::get_diluted_product, felt, felt_hex, felt_nonzero, felt_try_nonzero, - layout::utils::compute_program_hash, - layout::{safe_div, stark_curve}, + layout::{compute_program_hash, safe_div, stark_curve}, periodic_columns::{ eval_ecdsa_x, eval_ecdsa_y, eval_keccak_round_key0, eval_keccak_round_key1, eval_keccak_round_key15, eval_keccak_round_key3, eval_keccak_round_key31, diff --git a/crates/air/src/layout/mod.rs b/crates/air/src/layout/mod.rs index b68ec0f..2dacaf1 100644 --- a/crates/air/src/layout/mod.rs +++ b/crates/air/src/layout/mod.rs @@ -1,12 +1,15 @@ -use crate::{domains::StarkDomains, public_memory::PublicInput}; +use crate::{ + consts::{FELT_0, FELT_3}, + domains::StarkDomains, + public_memory::PublicInput, +}; +use alloc::vec::Vec; use num_bigint::{BigInt, TryFromBigIntError}; use starknet_core::types::NonZeroFelt; -use starknet_crypto::Felt; +use starknet_crypto::{pedersen_hash, Felt}; use starknet_types_core::felt::FeltIsZeroError; use swiftness_transcript::transcript::Transcript; -pub mod utils; - #[cfg(feature = "dex")] pub mod dex; #[cfg(feature = "dynamic")] @@ -112,6 +115,24 @@ pub fn safe_mult(value: Felt, multiplier: Felt) -> Result { } } +fn compute_program_hash( + memory: &[Felt], + initial_pc: Felt, + initial_fp: Felt, +) -> Result> { + let program: Vec<&Felt> = memory + .iter() + .skip(initial_pc.to_bigint().try_into()?) + .step_by(2) + .take((initial_fp - FELT_3).to_bigint().try_into()?) + .collect(); + + let hash = program.iter().fold(FELT_0, |acc, &e| pedersen_hash(&acc, e)); + let program_hash = pedersen_hash(&hash, &Felt::from(program.len())); + + Ok(program_hash) +} + #[cfg(feature = "std")] use thiserror::Error; diff --git a/crates/air/src/layout/recursive/mod.rs b/crates/air/src/layout/recursive/mod.rs index efffca4..81cf0af 100644 --- a/crates/air/src/layout/recursive/mod.rs +++ b/crates/air/src/layout/recursive/mod.rs @@ -5,7 +5,7 @@ use crate::{ consts::*, diluted::get_diluted_product, felt_hex, - layout::utils::compute_program_hash, + layout::compute_program_hash, periodic_columns::{eval_pedersen_x, eval_pedersen_y}, public_memory::{PublicInput, INITIAL_PC, MAX_ADDRESS, MAX_LOG_N_STEPS, MAX_RANGE_CHECK}, }; diff --git a/crates/air/src/layout/recursive_with_poseidon/mod.rs b/crates/air/src/layout/recursive_with_poseidon/mod.rs index 13401fa..5c0bf92 100644 --- a/crates/air/src/layout/recursive_with_poseidon/mod.rs +++ b/crates/air/src/layout/recursive_with_poseidon/mod.rs @@ -5,7 +5,7 @@ use crate::{ consts::*, diluted::get_diluted_product, felt_hex, - layout::utils::compute_program_hash, + layout::compute_program_hash, periodic_columns::{ eval_pedersen_x, eval_pedersen_y, eval_poseidon_poseidon_full_round_key0, eval_poseidon_poseidon_full_round_key1, eval_poseidon_poseidon_full_round_key2, diff --git a/crates/air/src/layout/small/mod.rs b/crates/air/src/layout/small/mod.rs index 65c23c2..62fa2ed 100644 --- a/crates/air/src/layout/small/mod.rs +++ b/crates/air/src/layout/small/mod.rs @@ -4,8 +4,7 @@ pub mod global_values; use crate::{ consts::*, felt_hex, - layout::stark_curve, - layout::utils::compute_program_hash, + layout::{compute_program_hash, stark_curve}, periodic_columns::{eval_ecdsa_x, eval_ecdsa_y, eval_pedersen_x, eval_pedersen_y}, public_memory::{PublicInput, INITIAL_PC, MAX_ADDRESS, MAX_LOG_N_STEPS, MAX_RANGE_CHECK}, }; diff --git a/crates/air/src/layout/starknet/mod.rs b/crates/air/src/layout/starknet/mod.rs index fd96702..6ed4752 100644 --- a/crates/air/src/layout/starknet/mod.rs +++ b/crates/air/src/layout/starknet/mod.rs @@ -4,8 +4,7 @@ pub mod global_values; use crate::{ consts::*, diluted::get_diluted_product, - layout::stark_curve, - layout::utils::compute_program_hash, + layout::{compute_program_hash, stark_curve}, periodic_columns::{ eval_ecdsa_x, eval_ecdsa_y, eval_pedersen_x, eval_pedersen_y, eval_poseidon_poseidon_full_round_key0, eval_poseidon_poseidon_full_round_key1, diff --git a/crates/air/src/layout/starknet_with_keccak/mod.rs b/crates/air/src/layout/starknet_with_keccak/mod.rs index 6f917a6..a26658b 100644 --- a/crates/air/src/layout/starknet_with_keccak/mod.rs +++ b/crates/air/src/layout/starknet_with_keccak/mod.rs @@ -4,8 +4,7 @@ pub mod global_values; use crate::{ consts::*, diluted::get_diluted_product, - layout::stark_curve, - layout::utils::compute_program_hash, + layout::{compute_program_hash, stark_curve}, periodic_columns::{ eval_ecdsa_x, eval_ecdsa_y, eval_keccak_round_key0, eval_keccak_round_key1, eval_keccak_round_key15, eval_keccak_round_key3, eval_keccak_round_key31, diff --git a/crates/air/src/layout/utils.rs b/crates/air/src/layout/utils.rs deleted file mode 100644 index 3d2662f..0000000 --- a/crates/air/src/layout/utils.rs +++ /dev/null @@ -1,23 +0,0 @@ -use alloc::vec::Vec; -use num_bigint::{BigInt, TryFromBigIntError}; -use starknet_crypto::{pedersen_hash, Felt}; - -use crate::consts::{FELT_0, FELT_3}; - -pub fn compute_program_hash( - memory: &[Felt], - initial_pc: Felt, - initial_fp: Felt, -) -> Result> { - let program: Vec<&Felt> = memory - .iter() - .skip(initial_pc.to_bigint().try_into()?) - .step_by(2) - .take((initial_fp - FELT_3).to_bigint().try_into()?) - .collect(); - - let hash = program.iter().fold(FELT_0, |acc, &e| pedersen_hash(&acc, e)); - let program_hash = pedersen_hash(&hash, &Felt::from(program.len())); - - Ok(program_hash) -}