Skip to content

Commit

Permalink
Implement read_uint64_from_prover
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Dec 21, 2023
1 parent 0384ac7 commit ed537c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ impl ChannelImpl of ChannelTrait {

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

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

assert(self.digest.low != 0xffffffffffffffffffffffffffffffff, 'digest low is 2^128-1');
(self.digest + 1).to_array_be(ref hash_data);

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

self.digest = blake2s(hash_data).flip_endiannes();
}
}
5 changes: 5 additions & 0 deletions src/channel/tests/test_channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ fn test_read_from_prover() {

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

channel.read_uint64_from_prover(6969);

assert(channel.counter == 0, 'invalid read uint64');
assert(channel.digest == 0xeeee1f1910516152d49bea3829151bdd149fcd878fe4e7b52881300c113395ce, 'invalid read uint64');
}

0 comments on commit ed537c6

Please sign in to comment.