-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1d308c
commit 20afccf
Showing
7 changed files
with
575 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
stwo_cairo_prover/crates/prover/src/components/range_check_builtin_bits_96/component.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#![allow(non_camel_case_types)] | ||
#![allow(unused_imports)] | ||
use num_traits::{One, Zero}; | ||
use serde::{Deserialize, Serialize}; | ||
use stwo_cairo_serialize::CairoSerialize; | ||
use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; | ||
use stwo_prover::constraint_framework::{ | ||
EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, | ||
}; | ||
use stwo_prover::core::backend::simd::m31::LOG_N_LANES; | ||
use stwo_prover::core::channel::Channel; | ||
use stwo_prover::core::fields::m31::M31; | ||
use stwo_prover::core::fields::qm31::SecureField; | ||
use stwo_prover::core::fields::secure_column::SECURE_EXTENSION_DEGREE; | ||
use stwo_prover::core::pcs::TreeVec; | ||
|
||
use crate::cairo_air::preprocessed::{PreProcessedColumn, Seq}; | ||
use crate::relations; | ||
|
||
pub struct Eval { | ||
pub claim: Claim, | ||
pub memory_address_to_id_lookup_elements: relations::MemoryAddressToId, | ||
pub memory_id_to_big_lookup_elements: relations::MemoryIdToBig, | ||
pub range_check_6_lookup_elements: relations::RangeCheck_6, | ||
} | ||
|
||
#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] | ||
pub struct Claim { | ||
pub n_rows: usize, | ||
pub range_check96_builtin_segment_start: u32, | ||
} | ||
impl Claim { | ||
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> { | ||
let log_size = std::cmp::max(self.n_rows.next_power_of_two().ilog2(), LOG_N_LANES); | ||
let trace_log_sizes = vec![log_size; 12]; | ||
let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 2]; | ||
let preprocessed_log_sizes = vec![log_size]; | ||
TreeVec::new(vec![ | ||
preprocessed_log_sizes, | ||
trace_log_sizes, | ||
interaction_log_sizes, | ||
]) | ||
} | ||
|
||
pub fn mix_into(&self, channel: &mut impl Channel) { | ||
channel.mix_u64(self.n_rows as u64); | ||
channel.mix_u64(self.range_check96_builtin_segment_start as u64); | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] | ||
pub struct InteractionClaim { | ||
pub logup_sums: LogupSums, | ||
} | ||
impl InteractionClaim { | ||
pub fn mix_into(&self, channel: &mut impl Channel) { | ||
let (total_sum, claimed_sum) = self.logup_sums; | ||
channel.mix_felts(&[total_sum]); | ||
if let Some(claimed_sum) = claimed_sum { | ||
channel.mix_felts(&[claimed_sum.0]); | ||
channel.mix_u64(claimed_sum.1 as u64); | ||
} | ||
} | ||
} | ||
|
||
pub type Component = FrameworkComponent<Eval>; | ||
|
||
impl FrameworkEval for Eval { | ||
fn log_size(&self) -> u32 { | ||
std::cmp::max(self.claim.n_rows.next_power_of_two().ilog2(), LOG_N_LANES) | ||
} | ||
|
||
fn max_constraint_log_degree_bound(&self) -> u32 { | ||
self.log_size() + 1 | ||
} | ||
|
||
#[allow(unused_parens)] | ||
#[allow(clippy::double_parens)] | ||
#[allow(non_snake_case)] | ||
fn evaluate<E: EvalAtRow>(&self, mut eval: E) -> E { | ||
let seq = | ||
eval.get_preprocessed_column(PreProcessedColumn::Seq(Seq::new(self.log_size())).id()); | ||
let value_id_col0 = eval.next_trace_mask(); | ||
let value_limb_0_col1 = eval.next_trace_mask(); | ||
let value_limb_1_col2 = eval.next_trace_mask(); | ||
let value_limb_2_col3 = eval.next_trace_mask(); | ||
let value_limb_3_col4 = eval.next_trace_mask(); | ||
let value_limb_4_col5 = eval.next_trace_mask(); | ||
let value_limb_5_col6 = eval.next_trace_mask(); | ||
let value_limb_6_col7 = eval.next_trace_mask(); | ||
let value_limb_7_col8 = eval.next_trace_mask(); | ||
let value_limb_8_col9 = eval.next_trace_mask(); | ||
let value_limb_9_col10 = eval.next_trace_mask(); | ||
let value_limb_10_col11 = eval.next_trace_mask(); | ||
|
||
// Read Positive Num Bits 96. | ||
|
||
eval.add_to_relation(RelationEntry::new( | ||
&self.memory_address_to_id_lookup_elements, | ||
E::EF::one(), | ||
&[ | ||
(E::F::from(M31::from(self.claim.range_check96_builtin_segment_start)) + seq), | ||
value_id_col0.clone(), | ||
], | ||
)); | ||
|
||
// Range Check Last Limb Bits In Ms Limb 6. | ||
|
||
eval.add_to_relation(RelationEntry::new( | ||
&self.range_check_6_lookup_elements, | ||
E::EF::one(), | ||
&[value_limb_10_col11.clone()], | ||
)); | ||
|
||
eval.add_to_relation(RelationEntry::new( | ||
&self.memory_id_to_big_lookup_elements, | ||
E::EF::one(), | ||
&[ | ||
value_id_col0.clone(), | ||
value_limb_0_col1.clone(), | ||
value_limb_1_col2.clone(), | ||
value_limb_2_col3.clone(), | ||
value_limb_3_col4.clone(), | ||
value_limb_4_col5.clone(), | ||
value_limb_5_col6.clone(), | ||
value_limb_6_col7.clone(), | ||
value_limb_7_col8.clone(), | ||
value_limb_8_col9.clone(), | ||
value_limb_9_col10.clone(), | ||
value_limb_10_col11.clone(), | ||
], | ||
)); | ||
|
||
eval.finalize_logup_in_pairs(); | ||
eval | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
stwo_cairo_prover/crates/prover/src/components/range_check_builtin_bits_96/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod component; | ||
pub mod prover; | ||
|
||
pub use component::{Claim, Component, Eval, InteractionClaim}; | ||
pub use prover::{ClaimGenerator, InteractionClaimGenerator}; |
Oops, something went wrong.