Skip to content

Commit

Permalink
renamed relations
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Dec 1, 2024
1 parent 918e901 commit 3d9eac1
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 44 deletions.
29 changes: 15 additions & 14 deletions stwo_cairo_prover/crates/prover/src/cairo_air/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ impl PublicData {
.public_memory
.iter()
.map(|(addr, id, val)| {
let memory_address_to_id = <relations::AddrToId as Relation<M31, QM31>>::combine(
&lookup_elements.memory_memory_address_to_id,
&[M31::from_u32_unchecked(*addr), M31::from_u32_unchecked(*id)],
)
.inverse();
let id_to_value = <relations::IdToValue as Relation<M31, QM31>>::combine(
let memory_address_to_id =
<relations::MemoryAddressToId as Relation<M31, QM31>>::combine(
&lookup_elements.memory_memory_address_to_id,
&[M31::from_u32_unchecked(*addr), M31::from_u32_unchecked(*id)],
)
.inverse();
let id_to_value = <relations::MemoryIdToBig as Relation<M31, QM31>>::combine(
&lookup_elements.memory_id_to_value,
&[
[M31::from_u32_unchecked(*id)].as_slice(),
Expand All @@ -131,12 +132,12 @@ impl PublicData {
.sum::<QM31>();

// Yield initial state and use the final.
sum += <relations::Vm as Relation<M31, QM31>>::combine(
sum += <relations::Opcodes as Relation<M31, QM31>>::combine(
&lookup_elements.opcodes,
&self.final_state.values(),
)
.inverse();
sum -= <relations::Vm as Relation<M31, QM31>>::combine(
sum -= <relations::Opcodes as Relation<M31, QM31>>::combine(
&lookup_elements.opcodes,
&self.initial_state.values(),
)
Expand Down Expand Up @@ -491,10 +492,10 @@ impl CairoInteractionClaimGenerator {
}

pub struct CairoInteractionElements {
pub opcodes: relations::Vm,
pub opcodes: relations::Opcodes,
pub verify_instruction: relations::VerifyInstruction,
pub memory_memory_address_to_id: relations::AddrToId,
pub memory_id_to_value: relations::IdToValue,
pub memory_memory_address_to_id: relations::MemoryAddressToId,
pub memory_id_to_value: relations::MemoryIdToBig,
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 @@ -504,10 +505,10 @@ pub struct CairoInteractionElements {
impl CairoInteractionElements {
pub fn draw(channel: &mut impl Channel) -> CairoInteractionElements {
CairoInteractionElements {
opcodes: relations::Vm::draw(channel),
opcodes: relations::Opcodes::draw(channel),
verify_instruction: relations::VerifyInstruction::draw(channel),
memory_memory_address_to_id: relations::AddrToId::draw(channel),
memory_id_to_value: relations::IdToValue::draw(channel),
memory_memory_address_to_id: relations::MemoryAddressToId::draw(channel),
memory_id_to_value: relations::MemoryIdToBig::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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ impl RelationElements {

pub struct Eval {
pub claim: Claim,
pub memoryaddresstoid_lookup_elements: relations::AddrToId,
pub memoryidtobig_lookup_elements: relations::IdToValue,
pub memoryaddresstoid_lookup_elements: relations::MemoryAddressToId,
pub memoryidtobig_lookup_elements: relations::MemoryIdToBig,
pub range_check_19_lookup_elements: relations::RangeCheck_19,
pub range_check_9_9_lookup_elements: relations::RangeCheck_9_9,
pub verifyinstruction_lookup_elements: relations::VerifyInstruction,
pub opcodes_lookup_elements: relations::Vm,
pub opcodes_lookup_elements: relations::Opcodes,
}

#[derive(Copy, Clone, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::relations;
use crate::components::{pack_values, verifyinstruction};
use crate::components::range_check_vector::range_check_9_9;
use crate::components::range_check_vector::range_check_19;
use crate::relations::AddrToId;
use crate::relations::MemoryAddressToId;

pub type InputType = CasmState;
pub type PackedInputType = PackedCasmState;
Expand Down Expand Up @@ -1290,17 +1290,17 @@ impl InteractionClaimGenerator {
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>,
memoryaddresstoid_lookup_elements:
&relations::AddrToId,
&relations::MemoryAddressToId,
memoryidtobig_lookup_elements:
&relations::IdToValue,
&relations::MemoryIdToBig,
range_check_19_lookup_elements:
&relations::RangeCheck_19,
range_check_9_9_lookup_elements:
&relations::RangeCheck_9_9,
verifyinstruction_lookup_elements:
&relations::VerifyInstruction,
opcodes_lookup_elements:
&relations::Vm,
&relations::Opcodes,
) -> InteractionClaim {
let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES);
let mut logup_gen = LogupTraceGenerator::new(log_size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub type Component = FrameworkComponent<Eval>;
#[derive(Clone)]
pub struct Eval {
pub log_n_rows: u32,
pub lookup_elements: relations::AddrToId,
pub lookup_elements: relations::MemoryAddressToId,
}
impl Eval {
// TODO(ShaharS): use Seq column for address, and also use repititions.
pub const fn n_columns(&self) -> usize {
N_ADDR_TO_ID_COLUMNS
}

pub fn new(claim: Claim, lookup_elements: relations::AddrToId) -> Self {
pub fn new(claim: Claim, lookup_elements: relations::MemoryAddressToId) -> Self {
Self {
log_n_rows: claim.log_size,
lookup_elements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>,
lookup_elements: &relations::AddrToId,
lookup_elements: &relations::MemoryAddressToId,
) -> InteractionClaim {
let log_size = self.addresses.len().ilog2() + LOG_N_LANES;
let mut logup_gen = LogupTraceGenerator::new(log_size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ relation!(RelationElements, N_LOGUP_POWERS);
#[derive(Clone)]
pub struct BigEval {
pub log_n_rows: u32,
pub lookup_elements: relations::IdToValue,
pub lookup_elements: relations::MemoryIdToBig,
pub range9_9_lookup_elements: relations::RangeCheck_9_9,
}
impl BigEval {
Expand All @@ -45,7 +45,7 @@ impl BigEval {
}
pub fn new(
claim: Claim,
lookup_elements: relations::IdToValue,
lookup_elements: relations::MemoryIdToBig,
range9_9_lookup_elements: relations::RangeCheck_9_9,
) -> Self {
Self {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl FrameworkEval for BigEval {

pub struct SmallEval {
pub log_n_rows: u32,
pub lookup_elements: relations::IdToValue,
pub lookup_elements: relations::MemoryIdToBig,
pub range_check_9_9_relation: relations::RangeCheck_9_9,
}
impl SmallEval {
Expand All @@ -100,7 +100,7 @@ impl SmallEval {
}
pub fn new(
claim: Claim,
lookup_elements: relations::IdToValue,
lookup_elements: relations::MemoryIdToBig,
range_check_9_9_relation: relations::RangeCheck_9_9,
) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>,
lookup_elements: &relations::IdToValue,
lookup_elements: &relations::MemoryIdToBig,
range9_9_lookup_elements: &relations::RangeCheck_9_9,
) -> InteractionClaim {
let big_table_log_size = self.big_ids_and_values[0].len().ilog2() + LOG_N_LANES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ impl RelationElements {

pub struct Eval {
pub claim: Claim,
pub memoryaddresstoid_lookup_elements: relations::AddrToId,
pub memoryidtobig_lookup_elements: relations::IdToValue,
pub memoryaddresstoid_lookup_elements: relations::MemoryAddressToId,
pub memoryidtobig_lookup_elements: relations::MemoryIdToBig,
pub verifyinstruction_lookup_elements: relations::VerifyInstruction,
pub opcodes_lookup_elements: relations::Vm,
pub opcodes_lookup_elements: relations::Opcodes,
}

#[derive(Copy, Clone, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>,
memoryaddresstoid_lookup_elements: &relations::AddrToId,
memoryidtobig_lookup_elements: &relations::IdToValue,
memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId,
memoryidtobig_lookup_elements: &relations::MemoryIdToBig,
verifyinstruction_lookup_elements: &relations::VerifyInstruction,
opcodes_lookup_elements: &relations::Vm,
opcodes_lookup_elements: &relations::Opcodes,
) -> InteractionClaim {
let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES);
let mut logup_gen = LogupTraceGenerator::new(log_size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ relation!(RelationElements, 30);

pub struct Eval {
pub claim: Claim,
pub memoryaddresstoid_lookup_elements: relations::AddrToId,
pub memoryidtobig_lookup_elements: relations::IdToValue,
pub memoryaddresstoid_lookup_elements: relations::MemoryAddressToId,
pub memoryidtobig_lookup_elements: relations::MemoryIdToBig,
pub rangecheck_4_3_lookup_elements: relations::RangeCheck_4_3,
pub range_check_7_2_5_lookup_elements: relations::RangeCheck_7_2_5,
pub verifyinstruction_lookup_elements: relations::VerifyInstruction,
}
impl Eval {
pub fn new(
claim: Claim,
memoryaddresstoid_lookup_elements: relations::AddrToId,
memoryidtobig_lookup_elements: relations::IdToValue,
memoryaddresstoid_lookup_elements: relations::MemoryAddressToId,
memoryidtobig_lookup_elements: relations::MemoryIdToBig,
rangecheck_4_3_lookup_elements: relations::RangeCheck_4_3,
range_check_7_2_5_lookup_elements: relations::RangeCheck_7_2_5,
verifyinstruction_lookup_elements: relations::VerifyInstruction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ impl InteractionClaimGenerator {
pub fn write_interaction_trace(
self,
tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>,
memoryaddresstoid_lookup_elements: &relations::AddrToId,
memoryidtobig_lookup_elements: &relations::IdToValue,
memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId,
memoryidtobig_lookup_elements: &relations::MemoryIdToBig,
rangecheck_4_3_lookup_elements: &relations::RangeCheck_4_3,
range_check_7_2_5_lookup_elements: &relations::RangeCheck_7_2_5,
verifyinstruction_lookup_elements: &relations::VerifyInstruction,
Expand Down
6 changes: 3 additions & 3 deletions stwo_cairo_prover/crates/prover/src/relations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(non_camel_case_types)]
use stwo_prover::relation;

relation!(AddrToId, 2);
relation!(IdToValue, 29);
relation!(Vm, 3);
relation!(MemoryAddressToId, 2);
relation!(MemoryIdToBig, 29);
relation!(Opcodes, 3);
relation!(RangeCheck_18, 1);
relation!(RangeCheck_19, 1);
relation!(RangeCheck_9_9, 2);
Expand Down

0 comments on commit 3d9eac1

Please sign in to comment.