Skip to content

Commit

Permalink
channel to blake2s u8 native
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jan 6, 2024
1 parent 5de065d commit f9f2cfa
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ChannelImpl of ChannelTrait {
}

fn random_uint256_to_prover(ref self: Channel) -> u256 {
let mut hash_data = ArrayTrait::<u32>::new();
let mut hash_data = ArrayTrait::<u8>::new();
hash_data.append_big_endian(self.digest);
hash_data.append_big_endian(self.counter);
self.counter += 1;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl ChannelImpl of ChannelTrait {
}

fn read_felt_from_prover(ref self: Channel, value: felt252) {
let mut hash_data = ArrayTrait::<u32>::new();
let mut hash_data = ArrayTrait::<u8>::new();

assert(self.digest.low != BoundedU128::max(), 'digest low is 2^128-1');
hash_data.append_big_endian(self.digest + 1);
Expand All @@ -76,7 +76,7 @@ impl ChannelImpl of ChannelTrait {
}

fn read_felt_vector_from_prover(ref self: Channel, values: Span<felt252>) {
let mut hash_data = ArrayTrait::<u32>::new();
let mut hash_data = ArrayTrait::<u8>::new();

assert(self.digest.low != BoundedU128::max(), 'digest low is 2^128-1');
hash_data.append_big_endian(self.digest + 1);
Expand All @@ -95,15 +95,14 @@ impl ChannelImpl of ChannelTrait {
}

fn read_uint64_from_prover(ref self: Channel, value: u64) {
let mut hash_data = ArrayTrait::<u32>::new();
let mut hash_data = ArrayTrait::<u8>::new();

assert(self.digest.low != BoundedU128::max(), 'digest low is 2^128-1');
hash_data.append_big_endian(self.digest + 1);

let low: u32 = (value % 0x100000000).try_into().unwrap();
let high: u32 = (value / 0x100000000).try_into().unwrap();
hash_data.append(high.flip_endianness());
hash_data.append(low.flip_endianness());
hash_data.append_big_endian(value);

self.digest = blake2s(hash_data).flip_endianness();
self.counter = 0;
Expand Down

0 comments on commit f9f2cfa

Please sign in to comment.