Skip to content

Commit

Permalink
read_felts_from_prover
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Dec 21, 2023
1 parent e6b30c5 commit e5be56c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cairo_verifier::common::{
flip_endiannes::FlipEndiannessTrait, to_array::ToArrayTrait, blake2s::blake2s
};
use poseidon::poseidon_hash_span;

const C_PRIME_AS_UINT256_LOW: u128 = 31;
const C_PRIME_AS_UINT256_HIGH: u128 =
Expand Down Expand Up @@ -62,4 +63,9 @@ impl ChannelImpl of ChannelTrait {

self.digest = blake2s(hash_data).flip_endiannes();
}

fn read_felts_from_prover(ref self: Channel, values: Array<felt252>) {
let hashed = poseidon_hash_span(values.span());
self.read_felt_from_prover(hashed);
}
}
12 changes: 11 additions & 1 deletion src/channel/tests/test_channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ fn test_random_uint256_to_prover() {

#[test]
#[available_gas(9999999999)]
fn test_read_felt_from_prover() {
fn test_read_from_prover() {
let mut channel = ChannelTrait::new(0);

channel.read_felt_from_prover(0xffffffffffffffffffffffffffffffffffffffff);

assert(channel.counter == 0, 'invalid read felt');
assert(channel.digest == 0xb056692f5fc4f27dedd1fb6269b02c542a415f1d84555708a354ffb25cf97ad5, 'invalid read felt');

let mut arr = ArrayTrait::<felt252>::new();
arr.append(2);
arr.append(3);
arr.append(-1);
channel.read_felts_from_prover(arr);

assert(channel.counter == 0, 'invalid read felts');
assert(channel.digest == 0x135bc3291210bb6248a09cea1a97b0023c5602b18a9e0786aeed16352972504, 'invalid read felts');
}

0 comments on commit e5be56c

Please sign in to comment.