Skip to content

Commit

Permalink
Prover version specific hash_data initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Sep 11, 2024
1 parent a73110b commit 37fd642
Showing 1 changed file with 22 additions and 59 deletions.
81 changes: 22 additions & 59 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ trait PublicInputTrait {

// Computes the hash of the public input, which is used as the initial seed for the Fiat-Shamir
// heuristic.
#[cfg(feature: 'stone6')]
fn get_public_input_hash(
public_input: @PublicInput, n_verifier_friendly_commitment_layers: felt252
) -> felt252 {
Expand All @@ -79,10 +78,9 @@ fn get_public_input_hash(
let main_page_hash = main_page_hash_state.finalize();

let mut hash_data = ArrayTrait::<felt252>::new();
hash_data.append(n_verifier_friendly_commitment_layers);
hash_data.append(*public_input.range_check_min);
hash_data.append(*public_input.range_check_max);
hash_data.append(*public_input.layout);

hash_data_init(ref hash_data, public_input, n_verifier_friendly_commitment_layers);

hash_data.extend(public_input.dynamic_params.span());

// Segments.
Expand Down Expand Up @@ -121,64 +119,29 @@ fn get_public_input_hash(
poseidon_hash_span(hash_data.span())
}

#[cfg(feature: 'stone5')]
fn get_public_input_hash(
public_input: @PublicInput, _n_verifier_friendly_commitment_layers: felt252
) -> felt252 {
// Main page hash.
let mut main_page_hash_state = PedersenTrait::new(0);
let mut i: u32 = 0;
loop {
if i == public_input.main_page.len() {
break;
}
main_page_hash_state = main_page_hash_state.update_with(*public_input.main_page.at(i));
i += 1;
};
main_page_hash_state = main_page_hash_state
.update_with(AddrValueSize * public_input.main_page.len());
let main_page_hash = main_page_hash_state.finalize();

let mut hash_data = ArrayTrait::<felt252>::new();
// Stone6 Prover version specific hash_data initialization
#[cfg(feature: 'stone6')]
fn hash_data_init(
ref hash_data: Array<felt252>,
public_input: @PublicInput,
n_verifier_friendly_commitment_layers: felt252
) {
hash_data.append(n_verifier_friendly_commitment_layers);
hash_data.append(*public_input.range_check_min);
hash_data.append(*public_input.range_check_max);
hash_data.append(*public_input.layout);
hash_data.extend(public_input.dynamic_params.span());

// Segments.
let mut segments = public_input.segments.span();
loop {
match segments.pop_front() {
Option::Some(seg) => {
hash_data.append(*seg.begin_addr);
hash_data.append(*seg.stop_ptr);
},
Option::None => { break; }
}
};

hash_data.append(*public_input.padding_addr);
hash_data.append(*public_input.padding_value);
hash_data.append(1 + public_input.continuous_page_headers.len().into());

// Main page.
hash_data.append(public_input.main_page.len().into());
hash_data.append(main_page_hash);

// Add the rest of the pages.
let mut continuous_page_headers = public_input.continuous_page_headers.span();
loop {
match continuous_page_headers.pop_front() {
Option::Some(continuous_page) => {
hash_data.append(*continuous_page.start_address);
hash_data.append(*continuous_page.size);
hash_data.append(*continuous_page.hash);
},
Option::None => { break; }
}
};
}

poseidon_hash_span(hash_data.span())
// Stone5 Prover version specific hash_data initialization
#[cfg(feature: 'stone5')]
fn hash_data_init(
ref hash_data: Array<felt252>,
public_input: @PublicInput,
_n_verifier_friendly_commitment_layers: felt252
) {
hash_data.append(*public_input.range_check_min);
hash_data.append(*public_input.range_check_max);
hash_data.append(*public_input.layout);
}

// Returns the ratio between the product of all public memory cells and z^|public_memory|.
Expand Down

0 comments on commit 37fd642

Please sign in to comment.