Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Sep 11, 2024
1 parent f04a92e commit b6579ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ fn verify_cairo1_public_input(public_input: @PublicInput) -> (felt252, felt252)
(program_hash, output_hash)
}


#[cfg(feature: 'stone5')]
#[cfg(feature: 'recursive')]
#[cfg(feature: 'keccak')]
#[cfg(test)]
mod tests {
use super::get_public_input_hash;
Expand All @@ -254,9 +255,9 @@ mod tests {
#[available_gas(9999999999)]
fn test_get_public_input_hash() {
let public_input = get();
let hash = get_public_input_hash(@public_input);
let hash = get_public_input_hash(@public_input, 0);
assert(
hash == 0xaf91f2c71f4a594b1575d258ce82464475c82d8fb244142d0db450491c1b52, 'Hash invalid'
hash == 0x1c3097c2a1665c78d69edc47ff35a3f3c9c0678e3daaa74d2b68331a5757a37, 'Hash invalid'
)
}
}
2 changes: 1 addition & 1 deletion src/common/hasher.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn hash_n_bytes(mut data: Array<u8>, n: u8, hash_len: bool) -> u256 {
#[cfg(feature: 'blake2s_160_lsb')]
fn hash_truncated(data: Array<u32>) -> felt252 {
(blake2s(data).flip_endianness()
& 0x0000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
& 0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
.try_into()
.unwrap()
}
Expand Down
22 changes: 16 additions & 6 deletions src/common/tests/test_blake2s.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cairo_verifier::common::{
array_append::ArrayAppendTrait, blake2s::{blake2s, truncated_blake2s}, blake2s_u8::load32,
array_append::ArrayAppendTrait, blake2s::blake2s, hasher::hash_truncated, blake2s_u8::load32,
};

fn get_arr_v1(n: u32) -> Array<u32> {
Expand Down Expand Up @@ -84,14 +84,24 @@ fn test_blake2s_v2() {
);
}

#[cfg(feature: 'blake2s_160_lsb')]
#[test]
#[available_gas(9999999999)]
fn test_truncated_blake2s() {
fn test_blake2s_160_lsb() {
let mut data = ArrayTrait::<u32>::new();
data.append_big_endian(1157029198022238202306346125123666191662554108005_u256);
data.append_big_endian(129252051435949032402481343903845417193011527432_u256);
assert(
truncated_blake2s(data) == 642191007116032514313255519742888271333651019057,
'invalid truncated_blake2s'
hash_truncated(data) == 0x00000000000000000000000042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9,
'invalid value'
);
}

#[cfg(feature: 'blake2s_248_lsb')]
#[test]
#[available_gas(9999999999)]
fn test_blake2s_248_lsb() {
let mut data = ArrayTrait::<u32>::new();
assert(
hash_truncated(data) == 0x00217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9,
'invalid value'
);
}

0 comments on commit b6579ef

Please sign in to comment.