Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

range check 11 #356

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion stwo_cairo_prover/crates/prover/src/cairo_air/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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,
};
use crate::components::verify_instruction;
use crate::components::{range_check_11, verify_instruction};
use crate::felt::split_f252;
use crate::input::ProverInput;
use crate::relations;
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_11: range_check_11::Claim,
pub range_check_19: range_check_19::Claim,
pub range_check9_9: range_check_9_9::Claim,
pub range_check7_2_5: range_check_7_2_5::Claim,
Expand All @@ -84,6 +85,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_11.mix_into(channel);
self.range_check_19.mix_into(channel);
self.range_check9_9.mix_into(channel);
self.range_check7_2_5.mix_into(channel);
Expand All @@ -97,6 +99,7 @@ impl CairoClaim {
self.builtins.log_sizes(),
self.memory_address_to_id.log_sizes(),
self.memory_id_to_value.log_sizes(),
self.range_check_11.log_sizes(),
self.range_check_19.log_sizes(),
self.range_check9_9.log_sizes(),
self.range_check7_2_5.log_sizes(),
Expand Down Expand Up @@ -170,6 +173,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_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,
range_check_7_2_5_trace_generator: range_check_7_2_5::ClaimGenerator,
Expand All @@ -188,6 +192,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_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();
let range_check_7_2_5_trace_generator = range_check_7_2_5::ClaimGenerator::new();
Expand Down Expand Up @@ -228,6 +233,7 @@ impl CairoClaimGenerator {
builtins,
memory_address_to_id_trace_generator,
memory_id_to_value_trace_generator,
range_check_11_trace_generator,
range_check_19_trace_generator,
range_check_9_9_trace_generator,
range_check_7_2_5_trace_generator,
Expand All @@ -247,6 +253,7 @@ impl CairoClaimGenerator {
tree_builder,
&self.memory_address_to_id_trace_generator,
&self.memory_id_to_value_trace_generator,
&self.range_check_11_trace_generator,
&self.range_check_19_trace_generator,
&self.range_check_9_9_trace_generator,
&self.verify_instruction_trace_generator,
Expand All @@ -272,6 +279,9 @@ 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_11_claim, range_check_11_interaction_gen) = self
.range_check_11_trace_generator
.write_trace(tree_builder);
let (range_check_19_claim, range_check_19_interaction_gen) = self
.range_check_19_trace_generator
.write_trace(tree_builder);
Expand All @@ -293,6 +303,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_11: range_check_11_claim,
range_check_19: range_check_19_claim,
range_check9_9: range_check9_9_claim,
range_check7_2_5: range_check_7_2_5_claim,
Expand All @@ -304,6 +315,7 @@ impl CairoClaimGenerator {
builtins_interaction_gen,
memory_address_to_id_interaction_gen,
memory_id_to_value_interaction_gen,
range_check_11_interaction_gen,
range_check_19_interaction_gen,
range_check_9_9_interaction_gen,
range_check_7_2_5_interaction_gen,
Expand All @@ -319,6 +331,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_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,
range_check_7_2_5_interaction_gen: range_check_7_2_5::InteractionClaimGenerator,
Expand Down Expand Up @@ -360,6 +373,10 @@ impl CairoInteractionClaimGenerator {
&interaction_elements.memory_id_to_value,
&interaction_elements.range_check_9_9,
);

let range_check_11_interaction_claim = self
.range_check_11_interaction_gen
.write_interaction_trace(tree_builder, &interaction_elements.range_check_11);
let range_check_19_interaction_claim = self
.range_check_19_interaction_gen
.write_interaction_trace(tree_builder, &interaction_elements.range_check_19);
Expand All @@ -379,6 +396,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_11: range_check_11_interaction_claim,
range_check_19: range_check_19_interaction_claim,
range_check_9_9: range_check9_9_interaction_claim,
range_check_7_2_5: range_check_7_2_5_interaction_claim,
Expand All @@ -392,6 +410,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_11: relations::RangeCheck_11,
pub range_check_19: relations::RangeCheck_19,
pub range_check_9_9: relations::RangeCheck_9_9,
pub range_check_7_2_5: relations::RangeCheck_7_2_5,
Expand All @@ -405,6 +424,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_11: relations::RangeCheck_11::draw(channel),
range_check_19: relations::RangeCheck_19::draw(channel),
range_check_9_9: relations::RangeCheck_9_9::draw(channel),
range_check_7_2_5: relations::RangeCheck_7_2_5::draw(channel),
Expand All @@ -420,6 +440,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_11: range_check_11::InteractionClaim,
pub range_check_19: range_check_19::InteractionClaim,
pub range_check_9_9: range_check_9_9::InteractionClaim,
pub range_check_7_2_5: range_check_7_2_5::InteractionClaim,
Expand All @@ -432,6 +453,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_11.mix_into(channel);
self.range_check_19.mix_into(channel);
self.range_check_9_9.mix_into(channel);
self.range_check_7_2_5.mix_into(channel);
Expand All @@ -455,6 +477,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_11.claimed_sum;
sum += interaction_claim.range_check_19.claimed_sum;
sum += interaction_claim.range_check_9_9.claimed_sum;
sum += interaction_claim.range_check_7_2_5.claimed_sum;
Expand All @@ -471,6 +494,7 @@ pub struct CairoComponents {
memory_id_to_big::BigComponent,
memory_id_to_big::SmallComponent,
),
range_check_11: range_check_11::Component,
range_check_19: range_check_19::Component,
range_check9_9: range_check_9_9::Component,
range_check7_2_5: range_check_7_2_5::Component,
Expand Down Expand Up @@ -554,6 +578,11 @@ impl CairoComponents {
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()),
(interaction_claim.range_check_11.claimed_sum, None),
);
let range_check_19_component = range_check_19::Component::new(
tree_span_provider,
range_check_19::Eval::new(interaction_elements.range_check_19.clone()),
Expand Down Expand Up @@ -583,6 +612,7 @@ impl CairoComponents {
memory_id_to_value_component,
small_memory_id_to_value_component,
),
range_check_11: range_check_11_component,
range_check_19: range_check_19_component,
range_check9_9: range_check9_9_component,
range_check7_2_5: range_check_7_2_5_component,
Expand All @@ -599,6 +629,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_11 as &dyn ComponentProver<SimdBackend>,
&self.range_check_19 as &dyn ComponentProver<SimdBackend>,
&self.range_check9_9 as &dyn ComponentProver<SimdBackend>,
&self.range_check7_2_5 as &dyn ComponentProver<SimdBackend>,
Expand Down Expand Up @@ -641,6 +672,11 @@ impl std::fmt::Display for CairoComponents {
"SmallMemoryIdToValue: {}",
indented_component_display(&self.memory_id_to_value.1)
)?;
writeln!(
f,
"RangeCheck19: {}",
indented_component_display(&self.range_check_11)
)?;
writeln!(
f,
"RangeCheck19: {}",
Expand Down
16 changes: 13 additions & 3 deletions stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::components::{
assert_eq_opcode_imm, call_opcode, call_opcode_op_1_base_fp, call_opcode_rel, generic_opcode,
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_19,
range_check_4_3, range_check_7_2_5, range_check_9_9, range_check_builtin_bits_128, ret_opcode,
verify_instruction,
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_builtin_bits_128, ret_opcode, verify_instruction,
};
use crate::felt::split_f252;
use crate::relations;
Expand Down Expand Up @@ -523,6 +523,16 @@ where
);

// Range Checks.
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
range_check_11::Eval {
lookup_elements: relations::RangeCheck_11::dummy(),
},
1 << 11,
)
.entries(trace),
);
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
Expand Down
5 changes: 3 additions & 2 deletions stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::components::{
assert_eq_opcode_imm, call_opcode, call_opcode_op_1_base_fp, call_opcode_rel, generic_opcode,
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_19,
range_check_9_9, ret_opcode, verify_instruction,
memory_address_to_id, memory_id_to_big, mul_opcode, mul_opcode_imm, range_check_11,
range_check_19, range_check_9_9, ret_opcode, verify_instruction,
};
use crate::input::state_transitions::StateTransitions;

Expand Down Expand Up @@ -363,6 +363,7 @@ impl OpcodesClaimGenerator {
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>,
memory_address_to_id_trace_generator: &memory_address_to_id::ClaimGenerator,
memory_id_to_value_trace_generator: &memory_id_to_big::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,
verify_instruction_trace_generator: &verify_instruction::ClaimGenerator,
Expand Down
4 changes: 3 additions & 1 deletion stwo_cairo_prover/crates/prover/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ pub mod mul_opcode;
pub mod mul_opcode_imm;

pub use memory::{memory_address_to_id, memory_id_to_big};
pub use range_check_vector::{range_check_19, range_check_4_3, range_check_7_2_5, range_check_9_9};
pub use range_check_vector::{
range_check_11, range_check_19, range_check_4_3, range_check_7_2_5, range_check_9_9,
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ macro_rules! generate_range_check_code {
}

generate_range_check_code!([19]);
generate_range_check_code!([11]);
generate_range_check_code!([9, 9]);
generate_range_check_code!([7, 2, 5]);
generate_range_check_code!([4, 3]);
Expand Down
3 changes: 1 addition & 2 deletions stwo_cairo_prover/crates/prover/src/relations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use stwo_prover::relation;
relation!(MemoryAddressToId, 2);
relation!(MemoryIdToBig, 29);
relation!(Opcodes, 3);
relation!(RangeCheck_3, 1);
relation!(RangeCheck_6, 1);
relation!(RangeCheck_11, 1);
relation!(RangeCheck_18, 1);
relation!(RangeCheck_19, 1);
relation!(RangeCheck_9_9, 2);
Expand Down
Loading