Skip to content

Commit

Permalink
hash_felts
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofneto committed Jan 3, 2024
1 parent 07bf1af commit 6ff27b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,21 @@ 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);
let program = memory.extract_range(initial_pc, program_len);

assert(
*program[0] == 0x40780017fff7fff, 'Invalid program'
); // Instruction: ap += N_BUILTINS.
assert(*program[1] == builtins.len().into(), 'Invalid program');
assert(*program[2] == 0x1104800180018000, 'Invalid program'); // Instruction: call rel ?.
assert(*program[4] == 0x10780017fff7fff, 'Invalid program'); // Instruction: jmp rel 0.
assert(*program[5] == 0x0, 'Invalid program');

// TODO hash program
let program_hash = 0;

// 2. Execution segment
// 2.1 Initial_fp, initial_pc

(0, 0)
}
Expand Down
1 change: 1 addition & 0 deletions src/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod math;
mod array_print;
mod array_extend;
mod consts;
mod hash;

#[cfg(test)]
mod tests;
15 changes: 15 additions & 0 deletions src/common/hash.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use pedersen::PedersenTrait;
use hash::HashStateTrait;

fn hash_felts(s: Span<felt252>) -> felt252 {
let mut hash_state = PedersenTrait::new(0);
let mut i = 0;

loop {
if i == s.len() {
break hash_state.finalize();
}

hash_state.update(*s.at(i));
}
}

0 comments on commit 6ff27b3

Please sign in to comment.