Skip to content

Commit

Permalink
mock interaction_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Jan 12, 2024
1 parent 8722a5b commit 4c5e016
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/air/composition.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1

fn eval_composition_polynomial(
interaction_elements: InteractionElements,
public_input: PublicInput,
public_input: @PublicInput,
mask_values: Array<felt252>,
constraint_coefficients: Array<felt252>,
point: felt252,
Expand All @@ -40,7 +40,7 @@ fn eval_composition_polynomial(
);

// Periodic columns
let n_steps = pow(2, public_input.log_n_steps);
let n_steps = pow(2, *public_input.log_n_steps);
let n_pedersen_hash_copies = n_steps / (PEDERSEN_BUILTIN_RATIO * PEDERSEN_BUILTIN_REPETITIONS);
assert_range_u128(n_pedersen_hash_copies);
let pedersen_point = pow(point, n_pedersen_hash_copies);
Expand All @@ -56,8 +56,8 @@ fn eval_composition_polynomial(
initial_pedersen_addr: *public_input.segments.at(segments::PEDERSEN).begin_addr,
initial_rc_addr: *public_input.segments.at(segments::RANGE_CHECK).begin_addr,
initial_bitwise_addr: *public_input.segments.at(segments::BITWISE).begin_addr,
rc_min: public_input.rc_min,
rc_max: public_input.rc_max,
rc_min: *public_input.rc_min,
rc_max: *public_input.rc_max,
offset_size: 0x10000, // 2**16
half_offset_size: 0x8000,
pedersen_shift_point: EcPoint { x: SHIFT_POINT_X, y: SHIFT_POINT_Y },
Expand Down
6 changes: 3 additions & 3 deletions src/air/global_values.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[derive(Drop)]
#[derive(Drop, Copy)]
struct EcPoint {
x: felt252,
y: felt252,
}

// Accumulation of member expressions for auto generated composition polynomial code.
#[derive(Drop)]
#[derive(Drop, Copy)]
struct GlobalValues {
// Public input.
trace_length: felt252,
Expand Down Expand Up @@ -42,6 +42,7 @@ struct GlobalValues {

// Elements that are sent from the prover after the commitment on the original trace.
// Used for components after the first interaction, e.g., memory and range check.
#[derive(Drop, Copy)]
struct InteractionElements {
memory_multi_column_perm_perm_interaction_elm: felt252,
memory_multi_column_perm_hash_interaction_elm0: felt252,
Expand All @@ -50,4 +51,3 @@ struct InteractionElements {
diluted_check_interaction_z: felt252,
diluted_check_interaction_alpha: felt252
}

21 changes: 16 additions & 5 deletions src/oods.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::clone::Clone;
use core::array::ArrayTrait;
use cairo_verifier::common::array_extend::ArrayExtendTrait;
use core::array::SpanTrait;
Expand All @@ -23,27 +24,37 @@ struct OodsEvaluationInfo {
}

fn verify_oods(
oods: OodsValues,
oods: Span<felt252>,
interaction_elements: InteractionElements,
public_input: PublicInput,
public_input: @PublicInput,
constraint_coefficients: Array<felt252>,
oods_point: felt252,
trace_domain_size: felt252,
trace_generator: felt252
) {
let mut mask_values = array![];
let mut i = 0;
loop {
if i == oods.len() - 2 {
break;
}

mask_values.append(*oods.at(i));

i += 1;
};
let composition_from_trace = eval_composition_polynomial(
interaction_elements,
public_input,
oods.mask_values,
mask_values,
constraint_coefficients,
oods_point,
trace_domain_size,
trace_generator
);

// TODO support degree > 2?
let claimed_composition = *oods.split_polynomials.at(0)
+ *oods.split_polynomials.at(1) * oods_point;
let claimed_composition = *oods[oods.len() - 2] + *oods[oods.len() - 1] * oods_point;

assert(composition_from_trace == claimed_composition, 'Invalid OODS');
}
Expand Down
1 change: 1 addition & 0 deletions src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use cairo_verifier::{
fri::{FriUnsentCommitment, FriWitness, FriCommitment}
},
domains::StarkDomainsImpl,
oods::OodsValues,
table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment,
TableCommitment
Expand Down
32 changes: 19 additions & 13 deletions src/stark/stark_commit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cairo_verifier::channel::channel::ChannelTrait;
use cairo_verifier::{
air::{
constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE},
public_input::PublicInput, traces::traces_commit,
global_values::InteractionElements, public_input::PublicInput, traces::traces_commit,
},
channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains,
fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment},
Expand Down Expand Up @@ -56,19 +56,25 @@ fn stark_commit(
let interaction_after_composition = channel.random_felt_to_prover();

let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into();
let sent_oods_values = channel.read_felts_from_prover(*unsent_commitment.oods_values);
channel.read_felts_from_prover(*unsent_commitment.oods_values);

// Check that the trace and the composition agree at oods_point.
// verify_oods(
// air=air,
// oods_values=sent_oods_values,
// traces_commitment=traces_commitment,
// traces_coefficients=traces_coefficients,
// oods_point=interaction_after_composition.oods_point,
// trace_domain_size=stark_domains.trace_domain_size,
// trace_generator=stark_domains.trace_generator,
// );
// verify_oods(sent_oods_values);
let interaction_elements = InteractionElements {
memory_multi_column_perm_perm_interaction_elm: 0,
memory_multi_column_perm_hash_interaction_elm0: 0,
rc16_perm_interaction_elm: 0,
diluted_check_permutation_interaction_elm: 0,
diluted_check_interaction_z: 0,
diluted_check_interaction_alpha: 0,
};
verify_oods(
*unsent_commitment.oods_values,
interaction_elements,
public_input,
traces_coefficients,
interaction_after_composition,
*stark_domains.trace_generator,
*stark_domains.trace_domain_size
);

let oods_alpha = channel.random_felt_to_prover();
let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap());
Expand Down

0 comments on commit 4c5e016

Please sign in to comment.