Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ fn main(x : Field) -> pub [u8; 4] {
for i in 0..4 {
first_four_bytes[i] = byte_array[i];
}

let chash = std::hash::keccak256(x.to_le_bytes(8), 8);
assert(chash[0] > 0 | chash[1] > 0);

// Issue #617 fix
// We were incorrectly mapping our output array from bit decomposition functions during acir generation
first_four_bytes[3] = byte_array[31];
first_four_bytes
}
}
16 changes: 8 additions & 8 deletions noir_stdlib/src/hash.nr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
mod poseidon;

#[foreign(sha256)]
fn sha256<N>(_input : [u8; N]) -> [u8; 32] {}
fn sha256(_input : [u8]) -> [u8; 32] {}

#[foreign(blake2s)]
fn blake2s<N>(_input : [u8; N]) -> [u8; 32] {}
fn blake2s(_input : [u8]) -> [u8; 32] {}

fn pedersen<N>(input : [Field; N]) -> [Field; 2] {
fn pedersen(input : [Field]) -> [Field; 2] {
pedersen_with_separator(input, 0)
}

#[foreign(pedersen)]
fn pedersen_with_separator<N>(_input : [Field; N], _separator : comptime u32) -> [Field; 2] {}
fn pedersen_with_separator(_input : [Field], _separator : comptime u32) -> [Field; 2] {}

#[foreign(hash_to_field_128_security)]
fn hash_to_field<N>(_input : [Field; N]) -> Field {}
fn hash_to_field(_input : [Field]) -> Field {}

#[foreign(keccak256)]
fn keccak256<N>(_input : [u8; N], _message_size: u32) -> [u8; 32] {}
fn keccak256(_input : [u8], _message_size: u32) -> [u8; 32] {}

// mimc-p/p implementation
// constants are (publicly generated) random numbers, for instance using keccak as a ROM.
// You must use constants generated for the native field
// Rounds number should be ~ log(p)/log(exp)
// For 254 bit primes, exponent 7 and 91 rounds seems to be recommended
fn mimc<N>(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field {
fn mimc(x: Field, k: Field, constants: [Field], exp : Field) -> Field {
//round 0
let mut t = x + k;
let mut h = t.pow_32(exp);
Expand All @@ -39,7 +39,7 @@ fn mimc<N>(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field {
global MIMC_BN254_ROUNDS = 91;

//mimc implementation with hardcoded parameters for BN254 curve.
fn mimc_bn254<N>(array: [Field; N]) -> Field {
fn mimc_bn254(array: [Field]) -> Field {
//mimc parameters
let exponent = 7;
//generated from seed "mimc" using keccak256
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod compat;
// Oracle calls are required to be wrapped in an unconstrained function
// Thus, the only argument to the `println` oracle is expected to always be an ident
#[oracle(println)]
unconstrained fn println_oracle<T, A>(_input: T) {}
unconstrained fn println_oracle<T>(_input: T) {}

unconstrained fn println<T>(input: T) {
println_oracle(input);
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn msg_u8_to_u32(msg: [u8; 64]) -> [u32; 16]
}

// SHA-256 hash function
fn digest<N>(msg: [u8; N]) -> [u8; 32] {
fn digest(msg: [u8]) -> [u8; 32] {
let mut msg_block: [u8; 64] = [0; 64];
let mut h: [u32; 8] = [1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]; // Intermediate hash, starting with the canonical initial value
let mut c: [u32; 8] = [0; 8]; // Compression of current message block as sequence of u32
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn msg_u8_to_u64(msg: [u8; 128]) -> [u64; 16]
}

// SHA-512 hash function
fn digest<N>(msg: [u8; N]) -> [u8; 64]
fn digest(msg: [u8]) -> [u8; 64]
{
let mut msg_block: [u8; 128] = [0; 128];
let mut h: [u64; 8] = [7640891576956012808, 13503953896175478587, 4354685564936845355, 11912009170470909681, 5840696475078001361, 11170449401992604703, 2270897969802886507, 6620516959819538809]; // Intermediate hash, starting with the canonical initial value
Expand Down