Skip to content

Commit

Permalink
refactor get_range
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofneto committed Jan 2, 2024
1 parent 66b404c commit 2f4d604
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
19 changes: 1 addition & 18 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,8 @@ impl PublicInputImpl of PublicInputTrait {

let program_end_pc = initial_fp - 2;
let program_len = program_end_pc - initial_pc;
memory.extract_range(initial_pc, program_len);

(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;
}
}
20 changes: 19 additions & 1 deletion src/air/public_memory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct AddrValue {
value: felt252
}

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

// Information about a continuous page (a consecutive section of the public memory)..
Expand Down Expand Up @@ -44,6 +44,24 @@ impl PageImpl of PageTrait {
i += 1;
}
}

fn extract_range(self: @Page, addr: felt252, len: felt252) -> Span<felt252> {
let mut arr = ArrayTrait::new();
let mut i = 0;

loop {
if i == len {
break arr.span();
}

let current = *self.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;
}
}
}

fn get_continuous_pages_product(page_headers: Span<ContinuousPageHeader>) -> (felt252, felt252) {
Expand Down

0 comments on commit 2f4d604

Please sign in to comment.