Skip to content

Commit

Permalink
Integrate Range Check 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Gali-StarkWare committed Jan 28, 2025
1 parent bfeb750 commit 2bcf5da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
37 changes: 35 additions & 2 deletions stwo_cairo_prover/crates/prover/src/cairo_air/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::opcodes_air::{
use super::preprocessed::preprocessed_trace_columns;
use crate::components::memory::{memory_address_to_id, memory_id_to_big};
use crate::components::range_check_vector::{
range_check_19, range_check_4_3, range_check_7_2_5, range_check_9_9,
range_check_19, range_check_4_3, range_check_6, range_check_7_2_5, range_check_9_9,
};
use crate::components::{range_check_11, verify_instruction};
use crate::felt::split_f252;
Expand Down Expand Up @@ -69,6 +69,7 @@ pub struct CairoClaim {
pub builtins: BuiltinsClaim,
pub memory_address_to_id: memory_address_to_id::Claim,
pub memory_id_to_value: memory_id_to_big::Claim,
pub range_check_6: range_check_6::Claim,
pub range_check_11: range_check_11::Claim,
pub range_check_19: range_check_19::Claim,
pub range_check9_9: range_check_9_9::Claim,
Expand All @@ -85,6 +86,7 @@ impl CairoClaim {
self.builtins.mix_into(channel);
self.memory_address_to_id.mix_into(channel);
self.memory_id_to_value.mix_into(channel);
self.range_check_6.mix_into(channel);
self.range_check_11.mix_into(channel);
self.range_check_19.mix_into(channel);
self.range_check9_9.mix_into(channel);
Expand All @@ -99,6 +101,7 @@ impl CairoClaim {
self.builtins.log_sizes(),
self.memory_address_to_id.log_sizes(),
self.memory_id_to_value.log_sizes(),
self.range_check_6.log_sizes(),
self.range_check_11.log_sizes(),
self.range_check_19.log_sizes(),
self.range_check9_9.log_sizes(),
Expand Down Expand Up @@ -173,6 +176,7 @@ pub struct CairoClaimGenerator {
builtins: BuiltinsClaimGenerator,
memory_address_to_id_trace_generator: memory_address_to_id::ClaimGenerator,
memory_id_to_value_trace_generator: memory_id_to_big::ClaimGenerator,
range_check_6_trace_generator: range_check_6::ClaimGenerator,
range_check_11_trace_generator: range_check_11::ClaimGenerator,
range_check_19_trace_generator: range_check_19::ClaimGenerator,
range_check_9_9_trace_generator: range_check_9_9::ClaimGenerator,
Expand All @@ -192,6 +196,7 @@ impl CairoClaimGenerator {
memory_address_to_id::ClaimGenerator::new(&input.memory);
let memory_id_to_value_trace_generator =
memory_id_to_big::ClaimGenerator::new(&input.memory);
let range_check_6_trace_generator = range_check_6::ClaimGenerator::new();
let range_check_11_trace_generator = range_check_11::ClaimGenerator::new();
let range_check_19_trace_generator = range_check_19::ClaimGenerator::new();
let range_check_9_9_trace_generator = range_check_9_9::ClaimGenerator::new();
Expand Down Expand Up @@ -233,6 +238,7 @@ impl CairoClaimGenerator {
builtins,
memory_address_to_id_trace_generator,
memory_id_to_value_trace_generator,
range_check_6_trace_generator,
range_check_11_trace_generator,
range_check_19_trace_generator,
range_check_9_9_trace_generator,
Expand Down Expand Up @@ -279,6 +285,8 @@ impl CairoClaimGenerator {
let (memory_id_to_value_claim, memory_id_to_value_interaction_gen) = self
.memory_id_to_value_trace_generator
.write_trace(tree_builder, &self.range_check_9_9_trace_generator);
let (range_check_6_claim, range_check_6_interaction_gen) =
self.range_check_6_trace_generator.write_trace(tree_builder);
let (range_check_11_claim, range_check_11_interaction_gen) = self
.range_check_11_trace_generator
.write_trace(tree_builder);
Expand All @@ -303,6 +311,7 @@ impl CairoClaimGenerator {
builtins: builtins_claim,
memory_address_to_id: memory_address_to_id_claim,
memory_id_to_value: memory_id_to_value_claim,
range_check_6: range_check_6_claim,
range_check_11: range_check_11_claim,
range_check_19: range_check_19_claim,
range_check9_9: range_check9_9_claim,
Expand All @@ -315,6 +324,7 @@ impl CairoClaimGenerator {
builtins_interaction_gen,
memory_address_to_id_interaction_gen,
memory_id_to_value_interaction_gen,
range_check_6_interaction_gen,
range_check_11_interaction_gen,
range_check_19_interaction_gen,
range_check_9_9_interaction_gen,
Expand All @@ -331,6 +341,7 @@ pub struct CairoInteractionClaimGenerator {
builtins_interaction_gen: BuiltinsInteractionClaimGenerator,
memory_address_to_id_interaction_gen: memory_address_to_id::InteractionClaimGenerator,
memory_id_to_value_interaction_gen: memory_id_to_big::InteractionClaimGenerator,
range_check_6_interaction_gen: range_check_6::InteractionClaimGenerator,
range_check_11_interaction_gen: range_check_11::InteractionClaimGenerator,
range_check_19_interaction_gen: range_check_19::InteractionClaimGenerator,
range_check_9_9_interaction_gen: range_check_9_9::InteractionClaimGenerator,
Expand Down Expand Up @@ -374,6 +385,9 @@ impl CairoInteractionClaimGenerator {
&interaction_elements.range_check_9_9,
);

let range_check_6_interaction_claim = self
.range_check_6_interaction_gen
.write_interaction_trace(tree_builder, &interaction_elements.range_check_6);
let range_check_11_interaction_claim = self
.range_check_11_interaction_gen
.write_interaction_trace(tree_builder, &interaction_elements.range_check_11);
Expand All @@ -396,6 +410,7 @@ impl CairoInteractionClaimGenerator {
builtins: builtins_interaction_claims,
memory_address_to_id: memory_address_to_id_interaction_claim,
memory_id_to_value: memory_id_to_value_interaction_claim,
range_check_6: range_check_6_interaction_claim,
range_check_11: range_check_11_interaction_claim,
range_check_19: range_check_19_interaction_claim,
range_check_9_9: range_check9_9_interaction_claim,
Expand All @@ -410,6 +425,7 @@ pub struct CairoInteractionElements {
pub verify_instruction: relations::VerifyInstruction,
pub memory_address_to_id: relations::MemoryAddressToId,
pub memory_id_to_value: relations::MemoryIdToBig,
pub range_check_6: relations::RangeCheck_6,
pub range_check_11: relations::RangeCheck_11,
pub range_check_19: relations::RangeCheck_19,
pub range_check_9_9: relations::RangeCheck_9_9,
Expand All @@ -424,6 +440,7 @@ impl CairoInteractionElements {
verify_instruction: relations::VerifyInstruction::draw(channel),
memory_address_to_id: relations::MemoryAddressToId::draw(channel),
memory_id_to_value: relations::MemoryIdToBig::draw(channel),
range_check_6: relations::RangeCheck_6::draw(channel),
range_check_11: relations::RangeCheck_11::draw(channel),
range_check_19: relations::RangeCheck_19::draw(channel),
range_check_9_9: relations::RangeCheck_9_9::draw(channel),
Expand All @@ -440,6 +457,7 @@ pub struct CairoInteractionClaim {
pub builtins: BuiltinsInteractionClaim,
pub memory_address_to_id: memory_address_to_id::InteractionClaim,
pub memory_id_to_value: memory_id_to_big::InteractionClaim,
pub range_check_6: range_check_6::InteractionClaim,
pub range_check_11: range_check_11::InteractionClaim,
pub range_check_19: range_check_19::InteractionClaim,
pub range_check_9_9: range_check_9_9::InteractionClaim,
Expand All @@ -453,6 +471,7 @@ impl CairoInteractionClaim {
self.builtins.mix_into(channel);
self.memory_address_to_id.mix_into(channel);
self.memory_id_to_value.mix_into(channel);
self.range_check_6.mix_into(channel);
self.range_check_11.mix_into(channel);
self.range_check_19.mix_into(channel);
self.range_check_9_9.mix_into(channel);
Expand All @@ -477,6 +496,7 @@ pub fn lookup_sum(
sum += interaction_claim.memory_address_to_id.claimed_sum;
sum += interaction_claim.memory_id_to_value.big_claimed_sum;
sum += interaction_claim.memory_id_to_value.small_claimed_sum;
sum += interaction_claim.range_check_6.claimed_sum;
sum += interaction_claim.range_check_11.claimed_sum;
sum += interaction_claim.range_check_19.claimed_sum;
sum += interaction_claim.range_check_9_9.claimed_sum;
Expand All @@ -494,6 +514,7 @@ pub struct CairoComponents {
memory_id_to_big::BigComponent,
memory_id_to_big::SmallComponent,
),
range_check_6: range_check_6::Component,
range_check_11: range_check_11::Component,
range_check_19: range_check_19::Component,
range_check9_9: range_check_9_9::Component,
Expand Down Expand Up @@ -578,6 +599,11 @@ impl CairoComponents {
None,
),
);
let range_check_6_component = range_check_6::Component::new(
tree_span_provider,
range_check_6::Eval::new(interaction_elements.range_check_6.clone()),
(interaction_claim.range_check_6.claimed_sum, None),
);
let range_check_11_component = range_check_11::Component::new(
tree_span_provider,
range_check_11::Eval::new(interaction_elements.range_check_11.clone()),
Expand Down Expand Up @@ -612,6 +638,7 @@ impl CairoComponents {
memory_id_to_value_component,
small_memory_id_to_value_component,
),
range_check_6: range_check_6_component,
range_check_11: range_check_11_component,
range_check_19: range_check_19_component,
range_check9_9: range_check9_9_component,
Expand All @@ -629,6 +656,7 @@ impl CairoComponents {
&self.memory_address_to_id as &dyn ComponentProver<SimdBackend>,
&self.memory_id_to_value.0 as &dyn ComponentProver<SimdBackend>,
&self.memory_id_to_value.1 as &dyn ComponentProver<SimdBackend>,
&self.range_check_6 as &dyn ComponentProver<SimdBackend>,
&self.range_check_11 as &dyn ComponentProver<SimdBackend>,
&self.range_check_19 as &dyn ComponentProver<SimdBackend>,
&self.range_check9_9 as &dyn ComponentProver<SimdBackend>,
Expand Down Expand Up @@ -674,7 +702,12 @@ impl std::fmt::Display for CairoComponents {
)?;
writeln!(
f,
"RangeCheck19: {}",
"RangeCheck6: {}",
indented_component_display(&self.range_check_6)
)?;
writeln!(
f,
"RangeCheck11: {}",
indented_component_display(&self.range_check_11)
)?;
writeln!(
Expand Down
12 changes: 11 additions & 1 deletion stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::components::{
jnz_opcode, jnz_opcode_dst_base_fp, jnz_opcode_taken, jnz_opcode_taken_dst_base_fp,
jump_opcode, jump_opcode_double_deref, jump_opcode_rel, jump_opcode_rel_imm,
memory_address_to_id, memory_id_to_big, mul_opcode, mul_opcode_imm, range_check_11,
range_check_19, range_check_4_3, range_check_7_2_5, range_check_9_9,
range_check_19, range_check_4_3, range_check_6, range_check_7_2_5, range_check_9_9,
range_check_builtin_bits_128, ret_opcode, verify_instruction,
};
use crate::felt::split_f252;
Expand Down Expand Up @@ -573,6 +573,16 @@ where
)
.entries(trace),
);
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
range_check_6::Eval {
lookup_elements: relations::RangeCheck_6::dummy(),
},
1 << 6,
)
.entries(trace),
);

// Public data.
claim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ macro_rules! generate_range_check_code {
};
}

generate_range_check_code!([19]);
generate_range_check_code!([11]);
generate_range_check_code!([19]);
generate_range_check_code!([9, 9]);
generate_range_check_code!([7, 2, 5]);
generate_range_check_code!([4, 3]);
Expand Down

0 comments on commit 2bcf5da

Please sign in to comment.