Skip to content

Commit

Permalink
Make settings argument a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Sep 22, 2024
1 parent d039881 commit ad4562d
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/air/layouts/dex/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
2 changes: 1 addition & 1 deletion src/air/layouts/recursive/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
2 changes: 1 addition & 1 deletion src/air/layouts/recursive_with_poseidon/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
2 changes: 1 addition & 1 deletion src/air/layouts/small/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
2 changes: 1 addition & 1 deletion src/air/layouts/starknet/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
2 changes: 1 addition & 1 deletion src/air/layouts/starknet_with_keccak/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn traces_decommit(
commitment: TracesCommitment,
decommitment: TracesDecommitment,
witness: TracesWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
table_decommit(commitment.original, queries, decommitment.original, witness.original, settings);
table_decommit(
Expand Down
4 changes: 2 additions & 2 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait PublicInputTrait {
fn get_public_input_hash(
public_input: @PublicInput,
n_verifier_friendly_commitment_layers: felt252,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> felt252 {
// Main page hash.
let mut main_page_hash_state = PedersenTrait::new(0);
Expand All @@ -76,7 +76,7 @@ fn get_public_input_hash(

let mut hash_data = ArrayTrait::<felt252>::new();

if settings.stone_version == StoneVersion::Stone6 {
if *settings.stone_version == StoneVersion::Stone6 {
hash_data.append(n_verifier_friendly_commitment_layers);
}
hash_data.append(*public_input.log_n_steps);
Expand Down
6 changes: 3 additions & 3 deletions src/common/hasher.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn hash(mut data: Array<u64>) -> u256 {
}

#[cfg(feature: 'blake2s')]
fn hash_truncated(data: Array<u32>, settings: VerifierSettings) -> felt252 {
fn hash_truncated(data: Array<u32>, settings: @VerifierSettings) -> felt252 {
let mask = if settings.hasher_bit_length == HasherBitLength::Lsb160 {
0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
} else {
Expand All @@ -27,8 +27,8 @@ fn hash_truncated(data: Array<u32>, settings: VerifierSettings) -> felt252 {
}

#[cfg(feature: 'keccak')]
fn hash_truncated(mut data: Array<u64>, settings: VerifierSettings) -> felt252 {
let mask = if settings.hasher_bit_length == HasherBitLength::Lsb160 {
fn hash_truncated(mut data: Array<u64>, settings: @VerifierSettings) -> felt252 {
let mask = if *settings.hasher_bit_length == HasherBitLength::Lsb160 {
0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
} else {
0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Expand Down
4 changes: 2 additions & 2 deletions src/fri/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn fri_verify_layer_step(
eval_point: felt252,
commitment: TableCommitment,
layer_witness: FriLayerWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> Array<FriLayerQuery> {
// Compute fri_group.
let fri_group = get_fri_group().span();
Expand Down Expand Up @@ -211,7 +211,7 @@ fn fri_verify_step(
stateConstant: FriVerificationStateConstant,
stateVariable: FriVerificationStateVariable,
witness: FriLayerWitness,
settings: VerifierSettings
settings: @VerifierSettings
) -> (FriVerificationStateConstant, FriVerificationStateVariable) {
assert(stateVariable.iter <= stateConstant.n_layers, 'Too many fri steps called');

Expand Down
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use cairo_verifier::air::layouts::starknet_with_keccak::public_input::StarknetWi
const SECURITY_BITS: u32 = 50;

#[cfg(feature: 'monolith')]
fn main(mut serialized: Span<felt252>, settings: VerifierSettings) -> (felt252, felt252) {
fn main(mut serialized: Span<felt252>, settings: @VerifierSettings) -> (felt252, felt252) {
let stark_proof_serde = Serde::<StarkProofWithSerde>::deserialize(ref serialized).unwrap();
let stark_proof: StarkProof = stark_proof_serde.into();

Expand Down
6 changes: 3 additions & 3 deletions src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl StarkProofImpl of StarkProofTrait {
self: @StarkProof,
composition_contract_address: ContractAddress,
oods_contract_address: ContractAddress,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> (FriVerificationStateConstant, FriVerificationStateVariable, Span<felt252>, u32) {
// Validate config.
let security_bits = self.config.validate();
Expand Down Expand Up @@ -132,7 +132,7 @@ impl StarkProofImpl of StarkProofTrait {
stateConstant: FriVerificationStateConstant,
stateVariable: FriVerificationStateVariable,
witness: FriLayerWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> (FriVerificationStateConstant, FriVerificationStateVariable) {
fri_verify_step(stateConstant, stateVariable, witness, settings)
}
Expand All @@ -149,7 +149,7 @@ impl StarkProofImpl of StarkProofTrait {
self: @StarkProof,
composition_contract_address: ContractAddress,
oods_contract_address: ContractAddress,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> u32 {
let (mut con, mut var, last_layer_coefficients, security_bits) = self
.verify_initial(composition_contract_address, oods_contract_address, settings);
Expand Down
2 changes: 1 addition & 1 deletion src/stark/stark_verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn stark_verify(
witness: StarkWitness,
stark_domains: StarkDomains,
contract_address_2: ContractAddress,
settings: VerifierSettings,
settings: @VerifierSettings,
) -> (FriVerificationStateConstant, FriVerificationStateVariable) {
// First layer decommit.
traces_decommit(
Expand Down
4 changes: 2 additions & 2 deletions src/table_commitment/table_commitment.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn table_decommit(
queries: Span<felt252>,
decommitment: TableDecommitment,
witness: TableCommitmentWitness,
settings: VerifierSettings,
settings: @VerifierSettings,
) {
let n_queries: felt252 = queries.len().into();

Expand Down Expand Up @@ -116,7 +116,7 @@ fn generate_vector_queries(
values: Span<felt252>,
n_columns: u32,
is_verifier_friendly: bool,
settings: VerifierSettings
settings: @VerifierSettings
) -> Array<VectorQuery> {
let queries_len = queries.len();
let mut vector_queries = ArrayTrait::new();
Expand Down
6 changes: 3 additions & 3 deletions src/vector_commitment/vector_commitment.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn vector_commitment_decommit(
commitment: VectorCommitment,
queries: Span<VectorQuery>,
witness: VectorCommitmentWitness,
settings: VerifierSettings
settings: @VerifierSettings
) {
let shift = pow(2, commitment.config.height);
let shifted_queries = shift_queries(queries, shift, commitment.config.height);
Expand All @@ -99,7 +99,7 @@ fn compute_root_from_queries(
n_verifier_friendly_layers: felt252,
authentications: Span<felt252>,
auth_start: u32,
settings: VerifierSettings
settings: @VerifierSettings
) -> felt252 {
let current: VectorQueryWithDepth = *queue[start];

Expand Down Expand Up @@ -175,7 +175,7 @@ fn shift_queries(
}

fn hash_blake_or_poseidon(
x: felt252, y: felt252, is_verifier_friendly: bool, settings: VerifierSettings
x: felt252, y: felt252, is_verifier_friendly: bool, settings: @VerifierSettings
) -> felt252 {
if is_verifier_friendly {
let (hash, _, _) = hades_permutation(x, y, 2);
Expand Down
6 changes: 3 additions & 3 deletions src/verifier.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mod CairoVerifier {
.verify(
self.composition_contract_address.read(),
self.oods_contract_address.read(),
settings
@settings
);

let fact = PoseidonImpl::new().update(program_hash).update(output_hash).finalize();
Expand Down Expand Up @@ -149,7 +149,7 @@ mod CairoVerifier {
.verify_initial(
self.composition_contract_address.read(),
self.oods_contract_address.read(),
settings
@settings
);
self.state_constant.entry(job_id).write(Option::Some(hash_constant(@con)));
self.state_variable.entry(job_id).write(Option::Some(hash_variable(@var)));
Expand Down Expand Up @@ -196,7 +196,7 @@ mod CairoVerifier {
let settings = self.state_settings.entry(job_id).read().expect('No settings saved');

let (con, var) = StarkProofImpl::verify_step(
state_constant, state_variable, witness, settings
state_constant, state_variable, witness, @settings
);
self.state_variable.entry(job_id).write(Option::Some(hash_variable(@var)));

Expand Down

0 comments on commit ad4562d

Please sign in to comment.