Skip to content

Commit

Permalink
builtins and extract_range
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofneto committed Jan 2, 2024
1 parent 92c26b4 commit 4fc0991
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/air/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252> {
array![
'output',
'pedersen',
'range_check',
'bitwise'
]
}
30 changes: 29 additions & 1 deletion src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<felt252> {
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;
}
}
3 changes: 2 additions & 1 deletion src/air/public_memory.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[derive(Drop)]
#[derive(Drop, Copy)]
struct AddrValue {
address: felt252,
value: felt252
}

#[derive(Drop)]
type Page = Array<AddrValue>;

// Information about a continuous page (a consecutive section of the public memory)..
Expand Down

0 comments on commit 4fc0991

Please sign in to comment.