Skip to content

Commit

Permalink
stone5 stone6 features
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Sep 10, 2024
1 parent 7e6f83a commit f04a92e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ keccak_248_lsb = []
blake2s_160_lsb = []
blake2s_248_lsb = []

stone5 = []
stone6 = []

monolith = []
split = []

default = ["recursive", "keccak_160_lsb", "monolith"]
default = ["recursive", "keccak_160_lsb", "stone5", "monolith"]
8 changes: 4 additions & 4 deletions examples/prover/cpu_air_params.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"field": "PrimeField0",
"channel_hash": "poseidon3",
"commitment_hash": "keccak256_masked160_lsb",
"commitment_hash": "blake256_masked160_lsb",
"n_verifier_friendly_commitment_layers": 9999,
"pow_hash": "keccak256",
"pow_hash": "blake256",
"statement": {
"page_hash": "pedersen"
},
Expand All @@ -16,8 +16,8 @@
3
],
"last_layer_degree_bound": 128,
"n_queries": 10,
"proof_of_work_bits": 30
"n_queries": 18,
"proof_of_work_bits": 24
},
"log_n_cosets": 2
},
Expand Down
67 changes: 65 additions & 2 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,71 @@ trait PublicInputTrait {

// Computes the hash of the public input, which is used as the initial seed for the Fiat-Shamir
// heuristic.
fn get_public_input_hash(public_input: @PublicInput) -> felt252 {
#[cfg(feature: 'stone6')]
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();
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())
}

#[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;
Expand All @@ -76,7 +140,6 @@ fn get_public_input_hash(public_input: @PublicInput) -> felt252 {
let main_page_hash = main_page_hash_state.finalize();

let mut hash_data = ArrayTrait::<felt252>::new();
hash_data.append(*public_input.log_n_steps);
hash_data.append(*public_input.range_check_min);
hash_data.append(*public_input.range_check_max);
hash_data.append(*public_input.layout);
Expand Down
5 changes: 4 additions & 1 deletion src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ impl StarkProofImpl of StarkProofTrait {
self.public_input.validate(@stark_domains);

// Compute the initial hash seed for the Fiat-Shamir channel.
let digest = get_public_input_hash(self.public_input);
let digest = get_public_input_hash(
self.public_input, *self.config.n_verifier_friendly_commitment_layers
);

// Construct the channel.
let mut channel = ChannelImpl::new(digest);

Expand Down

0 comments on commit f04a92e

Please sign in to comment.