Skip to content

Commit

Permalink
Remove commented code and format
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Feb 22, 2024
1 parent 7127ce1 commit afe7034
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 59 deletions.
7 changes: 3 additions & 4 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use core::{pedersen::PedersenTrait, hash::{HashStateTrait, HashStateExTrait, Hash}};
use cairo_verifier::{
common::{
array_extend::ArrayExtend,
flip_endianness::FlipEndiannessTrait, array_append::ArrayAppendTrait, hasher::hash,
math::{pow, Felt252PartialOrd, Felt252Div}, asserts::assert_range_u128_le,
array_print::SpanPrintTrait, hash::hash_felts,
array_extend::ArrayExtend, flip_endianness::FlipEndiannessTrait,
array_append::ArrayAppendTrait, hasher::hash, math::{pow, Felt252PartialOrd, Felt252Div},
asserts::assert_range_u128_le, array_print::SpanPrintTrait, hash::hash_felts,
},
air::{
public_memory::{
Expand Down
62 changes: 8 additions & 54 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,6 @@ impl ChannelImpl of ChannelTrait {
Channel { digest: digest, counter: counter }
}

// fn random_uint256_to_prover(ref self: Channel) -> u256 {
// let mut hash_data = ArrayTrait::new(); // u32 for blake, u64 for keccak
// hash_data.append_big_endian(self.digest);
// hash_data.append_big_endian(self.counter);
// self.counter += 1;
// hash(hash_data).flip_endianness()
// }

// fn random_felt_to_prover(ref self: Channel) -> felt252 {
// let mut res: felt252 = 0;

// // To ensure a uniform distribution over field elements, if the generated 256-bit number x is in
// // range [0, C * PRIME), take x % PRIME. Otherwise, regenerate.
// // The maximal possible C is 2**256//PRIME = 31.

// loop {
// let rand = self.random_uint256_to_prover();
// if (rand < u256 { low: C_PRIME_AS_UINT256_LOW, high: C_PRIME_AS_UINT256_HIGH }) {
// let to_append = (rand % STARK_PRIME).try_into().unwrap();
// res = to_append * MONTGOMERY_R_INVERSE;
// break;
// }
// };
// res
// }

fn random_felt_to_prover(ref self: Channel) -> felt252 {
let (hash, _, _) = hades_permutation(self.digest, self.counter, 2);
self.counter += 1;
Expand All @@ -69,35 +43,15 @@ impl ChannelImpl of ChannelTrait {
};
res
}
// not sure what to do with it
// fn read_truncated_hash_from_prover(ref self: Channel, value: felt252) {
// let mut hash_data = ArrayTrait::new(); // u32 for blake, u64 for keccak

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

// self.digest = hash(hash_data).flip_endianness();
// self.counter = 0;
// }

fn read_felt_from_prover(ref self: Channel, value: felt252) {
let mut hash_data = ArrayTrait::new();
hash_data.append(self.digest + 1);
hash_data.append(value);

self.digest = poseidon_hash_span(hash_data.span());
self.counter = 0;
}
fn read_felt_from_prover(ref self: Channel, value: felt252) {
let mut hash_data = ArrayTrait::new();
hash_data.append(self.digest + 1);
hash_data.append(value);

// fn read_felts_from_prover(ref self: Channel, mut values: Span<felt252>) {
// loop {
// match values.pop_front() {
// Option::Some(value) => { self.read_felt_from_prover(*value); },
// Option::None => { break; }
// }
// }
// }
self.digest = poseidon_hash_span(hash_data.span());
self.counter = 0;
}

fn read_felt_vector_from_prover(ref self: Channel, mut values: Span<felt252>) {
let mut hash_data = ArrayTrait::new();
Expand All @@ -118,4 +72,4 @@ fn read_felt_from_prover(ref self: Channel, value: felt252) {
fn read_uint64_from_prover(ref self: Channel, value: u64) {
self.read_felt_from_prover(value.into())
}
}
}
2 changes: 1 addition & 1 deletion src/queries/queries.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn sample_random_queries(
}

let res = channel.random_felt_to_prover();
let low128 = Into::<felt252,u256>::into(res).low;
let low128 = Into::<felt252, u256>::into(res).low;
let (_, sample) = DivRem::div_rem(low128, query_upper_bound_nonzero);
result.append(sample.try_into().unwrap());

Expand Down

0 comments on commit afe7034

Please sign in to comment.