Skip to content

Commit

Permalink
Add truncated_blake2s
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Dec 29, 2023
1 parent ba5982d commit f0ba9c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod channel;
mod vector_commitment;
mod common;
mod structs;
4 changes: 4 additions & 0 deletions src/vector_commitment.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod vector_commitment;

#[cfg(test)]
mod tests;
1 change: 1 addition & 0 deletions src/vector_commitment/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod test_vector_commitment;
11 changes: 11 additions & 0 deletions src/vector_commitment/tests/test_vector_commitment.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cairo_verifier::vector_commitment::vector_commitment::truncated_blake2s;
use core::debug::PrintTrait;

#[test]
#[available_gas(9999999999)]
fn test_truncated_blake2s() {
let x = 1157029198022238202306346125123666191662554108005;
let y = 129252051435949032402481343903845417193011527432;
let out = truncated_blake2s(x, y);
assert(out == 642191007116032514313255519742888271333651019057, 'invalid truncated_blake2s');
}
13 changes: 13 additions & 0 deletions src/vector_commitment/vector_commitment.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cairo_verifier::common::flip_endianness::FlipEndiannessTrait;
use cairo_verifier::common::{
array_append::ArrayAppendTrait,
blake2s::blake2s,
};

fn truncated_blake2s(x: felt252, y: felt252) -> felt252 {
let mut data = ArrayTrait::<u32>::new();
data.append_big_endian(x);
data.append_big_endian(y);
let hash = blake2s(data).flip_endianness() % 0x10000000000000000000000000000000000000000;
hash.try_into().unwrap()
}

0 comments on commit f0ba9c6

Please sign in to comment.