diff --git a/Scarb.toml b/Scarb.toml index bfd4cb1e8..461e1fe18 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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"] diff --git a/examples/prover/cpu_air_params.json b/examples/prover/cpu_air_params.json index 415ed7693..c56155c56 100644 --- a/examples/prover/cpu_air_params.json +++ b/examples/prover/cpu_air_params.json @@ -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" }, @@ -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 }, diff --git a/src/air/public_input.cairo b/src/air/public_input.cairo index 3fd14e9bf..185498ac0 100644 --- a/src/air/public_input.cairo +++ b/src/air/public_input.cairo @@ -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::::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; @@ -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::::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); diff --git a/src/stark.cairo b/src/stark.cairo index 8cb8a0f68..58531e28e 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -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);