Skip to content

Commit

Permalink
add hash_to_field_native
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Oct 29, 2023
1 parent 1637083 commit 7399739
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 13 additions & 0 deletions noir_stdlib/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ pub fn pedersen_hash_with_separator<N>(_input : [Field; N], _separator : u32) ->

#[foreign(hash_to_field_128_security)]
pub fn hash_to_field<N>(_input : [Field; N]) -> Field {}
pub fn hash_to_field_native<N>(_input : [Field; N]) -> Field {
let mut inputs_as_bytes = [];

for i in 0..N {
let input_bytes = _input[i].to_le_bytes(32);
for i in 0..32 {
inputs_as_bytes = inputs_as_bytes.push_back(input_bytes[i]);
}
}

let hashed_input = blake2s(inputs_as_bytes);
crate::field::bytes32_to_field(hashed_input)
}

#[foreign(keccak256)]
pub fn keccak256<N>(_input : [u8; N], _message_size: u32) -> [u8; 32] {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use dep::std;

fn main(input : Field) -> pub Field {
let expected = std::hash::hash_to_field([input]);

let input_bytes = input.to_le_bytes(32);
let blake2s = std::hash::blake2s(input_bytes);
let got = dep::std::field::bytes32_to_field(blake2s);

let got = std::hash::hash_to_field_native([input]);
assert(expected == got);
expected
}

0 comments on commit 7399739

Please sign in to comment.