Skip to content

Commit

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

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

(self.digest + 1).to_array_be(ref hash_data);
value_u256.to_array_be(ref hash_data);

self.digest = blake2s(hash_data).flip_endiannes();
}
}
10 changes: 10 additions & 0 deletions src/channel/tests/test_channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ fn test_random_uint256_to_prover() {
'invalid random uint256'
);
}

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

channel.read_felt_from_prover(0xffffffffffffffffffffffffffffffffffffffff);

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

0 comments on commit 88c2d69

Please sign in to comment.