From 92c26b4bf5413002a0999a3db336377d3bf7b441 Mon Sep 17 00:00:00 2001 From: tiagofneto Date: Tue, 2 Jan 2024 13:05:02 +0000 Subject: [PATCH] base public input verification --- src/air/composition.cairo | 5 +---- src/air/constants.cairo | 8 ++++++++ src/air/public_input.cairo | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/air/composition.cairo b/src/air/composition.cairo index e2c82dbae..ab047a3f7 100644 --- a/src/air/composition.cairo +++ b/src/air/composition.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::global_values::{EcPoint, InteractionElements, GlobalValues}; use cairo_verifier::air::constants::{ PUBLIC_MEMORY_STEP, DILUTED_N_BITS, DILUTED_SPACING, PEDERSEN_BUILTIN_RATIO, - PEDERSEN_BUILTIN_REPETITIONS, segments + PEDERSEN_BUILTIN_REPETITIONS, segments, SHIFT_POINT_X, SHIFT_POINT_Y }; use cairo_verifier::air::public_input::{PublicInput, PublicInputTrait}; use cairo_verifier::air::diluted::get_diluted_product; @@ -9,9 +9,6 @@ use cairo_verifier::air::pedersen::{eval_pedersen_x, eval_pedersen_y}; use cairo_verifier::air::autogenerated::eval_composition_polynomial_inner; use cairo_verifier::common::math::{Felt252Div, Felt252PartialOrd, pow}; -const SHIFT_POINT_X: felt252 = 0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804; -const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1d0405d266e10268a; - fn eval_composition_polynomial( interaction_elements: InteractionElements, public_input: PublicInput, diff --git a/src/air/constants.cairo b/src/air/constants.cairo index a42656530..e888c41bd 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -38,3 +38,11 @@ mod segments { const BITWISE: usize = 5; const N_SEGMENTS: usize = 6; } + +// Pedersen builtin +const SHIFT_POINT_X: felt252 = 0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804; +const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1d0405d266e10268a; + +const SECURITY_BITS: felt252 = 128; +const MAX_ADDRESS: felt252 = 0xffffffffffffffff; +const INITIAL_PC: felt252 = 1; diff --git a/src/air/public_input.cairo b/src/air/public_input.cairo index 789c3c192..abb29db10 100644 --- a/src/air/public_input.cairo +++ b/src/air/public_input.cairo @@ -2,6 +2,7 @@ use cairo_verifier::air::public_memory::{ Page, PageTrait, ContinuousPageHeader, get_continuous_pages_product }; use cairo_verifier::common::math::{pow, Felt252PartialOrd, Felt252Div}; +use cairo_verifier::air::constants::{segments, MAX_ADDRESS}; #[derive(Drop)] struct SegmentInfo { @@ -58,4 +59,24 @@ impl PublicInputImpl of PublicInputTrait { (prod, total_length) } + + fn verify(self: @PublicInput) -> (felt252, felt252) { + let public_segments = self.segments; + + let initial_pc = *public_segments.at(segments::PROGRAM).begin_addr; + let final_pc = *public_segments.at(segments::PROGRAM).stop_ptr; + let initial_ap = *public_segments.at(segments::EXECUTION).begin_addr; + let initial_fp = initial_ap; + let final_ap = *public_segments.at(segments::EXECUTION).stop_ptr; + let output_start = *public_segments.at(segments::OUTPUT).begin_addr; + let output_stop = *public_segments.at(segments::OUTPUT).stop_ptr; + + assert(initial_ap < MAX_ADDRESS, 'Invalid initial_ap'); + assert(final_ap < MAX_ADDRESS, 'Invalid final_ap'); + + // TODO support more pages? + assert((*self.continuous_page_headers).len() == 0, 'Invalid continuous_page_headers'); + + (0, 0) + } }