diff --git a/noir_stdlib/src/hash/poseidon.nr b/noir_stdlib/src/hash/poseidon.nr index f5609fbf065..36ac6bdf6af 100644 --- a/noir_stdlib/src/hash/poseidon.nr +++ b/noir_stdlib/src/hash/poseidon.nr @@ -1,7 +1,5 @@ mod bn254; // Instantiations of Poseidon for prime field of the same order as BN254 -use crate::array; -use crate::pow_32; use crate::field::modulus_num_bits; struct PoseidonConfig { @@ -22,8 +20,8 @@ fn config( mds: [Field; N]) -> PoseidonConfig { // Input checks - constrain t as u8 * (rf + rp) == array::len(ark) as u8; - constrain t * t == array::len(mds); + constrain t as u8 * (rf + rp) == ark.len() as u8; + constrain t * t == mds.len(); constrain alpha != 0; PoseidonConfig {t, rf, rp, alpha, ark, mds} @@ -36,22 +34,22 @@ fn permute( -> [Field; O] { let PoseidonConfig {t, rf, rp, alpha, ark, mds} = pos_conf; - constrain t == array::len(state); + constrain t == state.len(); let mut count = 0; // for r in 0..rf + rp - for r in 0..(array::len(ark)/array::len(state)) { - for i in 0..array::len(state) { + for r in 0..(ark.len()/state.len()) { + for i in 0..state.len() { state[i] = state[i] + ark[count + i]; } // Shift by round constants - state[0] = pow_32(state[0], alpha); + state[0] = state[0].pow_32(alpha); // Check whether we are in a full round if (r as u8 < rf/2) | (r as u8 >= rf/2 + rp) { - for i in 1..array::len(state) { - state[i] = pow_32(state[i], alpha); + for i in 1..state.len() { + state[i] = state[i].pow_32(alpha); } } @@ -74,7 +72,7 @@ fn absorb( let mut i = 0; - for k in 0..array::len(msg) { + for k in 0..msg.len() { // Add current block to state state[capacity + i] += msg[k]; i = i+1; @@ -106,10 +104,10 @@ fn check_security(rate: Field, width: Field, security: Field) -> bool { fn apply_matrix(a: [Field], x: [Field; N]) -> [Field; N] { let mut y = x; - for i in 0..array::len(x) { + for i in 0..x.len() { y[i] = 0; - for j in 0..array::len(x) { - y[i] = y[i] + a[array::len(x)*i + j]* x[j]; + for j in 0..x.len() { + y[i] = y[i] + a[x.len()*i + j]* x[j]; } } diff --git a/noir_stdlib/src/hash/poseidon/bn254.nr b/noir_stdlib/src/hash/poseidon/bn254.nr index 64311ff56fc..488d6db3a84 100644 --- a/noir_stdlib/src/hash/poseidon/bn254.nr +++ b/noir_stdlib/src/hash/poseidon/bn254.nr @@ -3,8 +3,6 @@ mod perm; mod consts; use crate::hash::poseidon::PoseidonConfig; -use crate::array; -use crate::pow_32; use crate::hash::poseidon::apply_matrix; // Optimised permutation for this particular field; uses hardcoded rf and rp values, @@ -15,9 +13,9 @@ fn permute( -> [Field; O] { let PoseidonConfig {t, rf: config_rf, rp: config_rp, alpha, ark, mds} = pos_conf; let rf = 8; - let rp = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68][array::len(state) - 2]; + let rp = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68][state.len() - 2]; - constrain t == array::len(state); + constrain t == state.len(); constrain rf == config_rf as Field; constrain rp == config_rp as Field; @@ -25,12 +23,12 @@ fn permute( // First half of full rounds for _r in 0..rf/2 { - for i in 0..array::len(state) { + for i in 0..state.len() { state[i] = state[i] + ark[count + i]; } // Shift by round constants - for i in 0..array::len(state) { - state[i] = pow_32(state[i], alpha); + for i in 0..state.len() { + state[i] = state[i].pow_32(alpha); } state = apply_matrix(mds, state); // Apply MDS matrix @@ -39,11 +37,11 @@ fn permute( // Partial rounds for _r in 0..rp { - for i in 0..array::len(state) { + for i in 0..state.len() { state[i] = state[i] + ark[count + i]; } // Shift by round constants - state[0] = pow_32(state[0], alpha); + state[0] = state[0].pow_32(alpha); state = apply_matrix(mds, state); // Apply MDS matrix count = count + t; @@ -51,12 +49,12 @@ fn permute( // Second half of full rounds for _r in 0..rf/2 { - for i in 0..array::len(state) { + for i in 0..state.len() { state[i] = state[i] + ark[count + i]; } // Shift by round constants - for i in 0..array::len(state) { - state[i] = pow_32(state[i], alpha); + for i in 0..state.len() { + state[i] = state[i].pow_32(alpha); } state = apply_matrix(mds, state); // Apply MDS matrix @@ -79,7 +77,7 @@ fn absorb( let mut i = 0; - for k in 0..array::len(msg) { + for k in 0..msg.len() { // Add current block to state state[capacity + i] += msg[k]; i = i+1;