Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add no-predicate to hash implementations #5253

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions noir_stdlib/src/hash/mimc.nr
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ global MIMC_BN254_CONSTANTS: [Field; MIMC_BN254_ROUNDS] = [

//mimc implementation with hardcoded parameters for BN254 curve.
#[field(bn254)]
#[no_predicates]
pub fn mimc_bn254<N>(array: [Field; N]) -> Field {
let exponent = 7;
let mut r = 0;
Expand Down
1 change: 1 addition & 0 deletions noir_stdlib/src/hash/poseidon.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn config<T, N, X>(
PoseidonConfig { t, rf, rp, alpha, round_constants, mds, presparse_mds, sparse_mds }
}

#[no_predicates]
pub fn permute<T, N, X>(pos_conf: PoseidonConfig<T, N, X>, mut state: [Field; T]) -> [Field; T] {
let PoseidonConfig {t, rf, rp, alpha, round_constants, mds, presparse_mds, sparse_mds } = pos_conf;

Expand Down
16 changes: 16 additions & 0 deletions noir_stdlib/src/hash/poseidon/bn254.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn sponge<N>(msg: [Field; N]) -> Field {

// Various instances of the Poseidon hash function
// Consistent with Circom's implementation
#[no_predicates]
pub fn hash_1(input: [Field; 1]) -> Field {
let mut state = [0; 2];
for i in 0..input.len() {
Expand All @@ -21,6 +22,7 @@ pub fn hash_1(input: [Field; 1]) -> Field {
perm::x5_2(state)[0]
}

#[no_predicates]
pub fn hash_2(input: [Field; 2]) -> Field {
let mut state = [0; 3];
for i in 0..input.len() {
Expand All @@ -30,6 +32,7 @@ pub fn hash_2(input: [Field; 2]) -> Field {
perm::x5_3(state)[0]
}

#[no_predicates]
pub fn hash_3(input: [Field; 3]) -> Field {
let mut state = [0; 4];
for i in 0..input.len() {
Expand All @@ -39,6 +42,7 @@ pub fn hash_3(input: [Field; 3]) -> Field {
perm::x5_4(state)[0]
}

#[no_predicates]
pub fn hash_4(input: [Field; 4]) -> Field {
let mut state = [0; 5];
for i in 0..input.len() {
Expand All @@ -48,6 +52,7 @@ pub fn hash_4(input: [Field; 4]) -> Field {
perm::x5_5(state)[0]
}

#[no_predicates]
pub fn hash_5(input: [Field; 5]) -> Field {
let mut state = [0; 6];
for i in 0..input.len() {
Expand All @@ -57,6 +62,7 @@ pub fn hash_5(input: [Field; 5]) -> Field {
perm::x5_6(state)[0]
}

#[no_predicates]
pub fn hash_6(input: [Field; 6]) -> Field {
let mut state = [0; 7];
for i in 0..input.len() {
Expand All @@ -66,6 +72,7 @@ pub fn hash_6(input: [Field; 6]) -> Field {
perm::x5_7(state)[0]
}

#[no_predicates]
pub fn hash_7(input: [Field; 7]) -> Field {
let mut state = [0; 8];
for i in 0..input.len() {
Expand All @@ -75,6 +82,7 @@ pub fn hash_7(input: [Field; 7]) -> Field {
perm::x5_8(state)[0]
}

#[no_predicates]
pub fn hash_8(input: [Field; 8]) -> Field {
let mut state = [0; 9];
for i in 0..input.len() {
Expand All @@ -84,6 +92,7 @@ pub fn hash_8(input: [Field; 8]) -> Field {
perm::x5_9(state)[0]
}

#[no_predicates]
pub fn hash_9(input: [Field; 9]) -> Field {
let mut state = [0; 10];
for i in 0..input.len() {
Expand All @@ -93,6 +102,7 @@ pub fn hash_9(input: [Field; 9]) -> Field {
perm::x5_10(state)[0]
}

#[no_predicates]
pub fn hash_10(input: [Field; 10]) -> Field {
let mut state = [0; 11];
for i in 0..input.len() {
Expand All @@ -102,6 +112,7 @@ pub fn hash_10(input: [Field; 10]) -> Field {
perm::x5_11(state)[0]
}

#[no_predicates]
pub fn hash_11(input: [Field; 11]) -> Field {
let mut state = [0; 12];
for i in 0..input.len() {
Expand All @@ -111,6 +122,7 @@ pub fn hash_11(input: [Field; 11]) -> Field {
perm::x5_12(state)[0]
}

#[no_predicates]
pub fn hash_12(input: [Field; 12]) -> Field {
let mut state = [0; 13];
for i in 0..input.len() {
Expand All @@ -120,6 +132,7 @@ pub fn hash_12(input: [Field; 12]) -> Field {
perm::x5_13(state)[0]
}

#[no_predicates]
pub fn hash_13(input: [Field; 13]) -> Field {
let mut state = [0; 14];
for i in 0..input.len() {
Expand All @@ -129,6 +142,7 @@ pub fn hash_13(input: [Field; 13]) -> Field {
perm::x5_14(state)[0]
}

#[no_predicates]
pub fn hash_14(input: [Field; 14]) -> Field {
let mut state = [0; 15];
for i in 0..input.len() {
Expand All @@ -138,6 +152,7 @@ pub fn hash_14(input: [Field; 14]) -> Field {
perm::x5_15(state)[0]
}

#[no_predicates]
pub fn hash_15(input: [Field; 15]) -> Field {
let mut state = [0; 16];
for i in 0..input.len() {
Expand All @@ -147,6 +162,7 @@ pub fn hash_15(input: [Field; 15]) -> Field {
perm::x5_16(state)[0]
}

#[no_predicates]
pub fn hash_16(input: [Field; 16]) -> Field {
let mut state = [0; 17];
for i in 0..input.len() {
Expand Down
1 change: 1 addition & 0 deletions noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn hash_final_block(msg_block: [u8; 64], mut state: [u32; 8]) -> [u8; 32] {
}

// Variable size SHA-256 hash
#[no_predicates]
pub fn sha256_var<N>(msg: [u8; N], message_size: u64) -> [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
Expand Down
1 change: 1 addition & 0 deletions noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn msg_u8_to_u64(msg: [u8; 128]) -> [u64; 16] {
msg64
}
// SHA-512 hash function
#[no_predicates]
pub fn digest<N>(msg: [u8; N]) -> [u8; 64] {
let mut msg_block: [u8; 128] = [0; 128];
// noir-fmt:ignore
Expand Down
Loading