From 4fc099167b379516cbaf4c93fbfb3b39f7a5cc1d Mon Sep 17 00:00:00 2001 From: tiagofneto Date: Tue, 2 Jan 2024 17:22:11 +0000 Subject: [PATCH] builtins and extract_range --- src/air/constants.cairo | 9 +++++++++ src/air/public_input.cairo | 30 +++++++++++++++++++++++++++++- src/air/public_memory.cairo | 3 ++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/air/constants.cairo b/src/air/constants.cairo index e888c41bd..7247ae9ca 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -46,3 +46,12 @@ const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1 const SECURITY_BITS: felt252 = 128; const MAX_ADDRESS: felt252 = 0xffffffffffffffff; const INITIAL_PC: felt252 = 1; + +fn get_builtins() -> Array { + array![ + 'output', + 'pedersen', + 'range_check', + 'bitwise' + ] +} diff --git a/src/air/public_input.cairo b/src/air/public_input.cairo index abb29db10..623a1146f 100644 --- a/src/air/public_input.cairo +++ b/src/air/public_input.cairo @@ -2,7 +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}; +use cairo_verifier::air::constants::{segments, MAX_ADDRESS, get_builtins, INITIAL_PC}; #[derive(Drop)] struct SegmentInfo { @@ -77,6 +77,34 @@ impl PublicInputImpl of PublicInputTrait { // TODO support more pages? assert((*self.continuous_page_headers).len() == 0, 'Invalid continuous_page_headers'); + let builtins = get_builtins(); + let memory = self.main_page; + + // 1. Program segment + assert(initial_pc == INITIAL_PC, 'Invalid initial_pc'); + assert(final_pc == INITIAL_PC + 4, 'Invalid final_pc'); + + let program_end_pc = initial_fp - 2; + let program_len = program_end_pc - initial_pc; + (0, 0) } } + +fn extract_range(memory: Page, addr: felt252, length: felt252) -> Span { + let mut arr = ArrayTrait::new(); + let mut i = 0; + + loop { + if i == length { + break arr.span(); + } + + let current = *memory.at((addr + i).try_into().unwrap()); + + // TODO is this needed? If not we can just use slice directly + assert(current.address == addr + i, 'Invalid address'); + arr.append(current.value); + i += 1; + } +} diff --git a/src/air/public_memory.cairo b/src/air/public_memory.cairo index 262af7ddc..96d10f534 100644 --- a/src/air/public_memory.cairo +++ b/src/air/public_memory.cairo @@ -1,9 +1,10 @@ -#[derive(Drop)] +#[derive(Drop, Copy)] struct AddrValue { address: felt252, value: felt252 } +#[derive(Drop)] type Page = Array; // Information about a continuous page (a consecutive section of the public memory)..