diff --git a/noir_stdlib/src/ec.nr b/noir_stdlib/src/ec.nr index be2ba8c1ccf..91727a04a78 100644 --- a/noir_stdlib/src/ec.nr +++ b/noir_stdlib/src/ec.nr @@ -143,22 +143,22 @@ global C5 = 19103219067921713944291392827692070036145651957329286315305642004821 // out //} // TODO: Make this built-in. -pub fn safe_inverse(x: Field) -> Field { +pub fn safe_inverse(x: field) -> field { if x == 0 { 0 } else { 1 / x } } // Boolean indicating whether Field element is a square, i.e. whether there exists a y in Field s.t. x = y*y. -pub fn is_square(x: Field) -> bool { +pub fn is_square(x: field) -> bool { let v = pow(x, 0 - 1 / 2); v * (v - 1) == 0 } // Power function of two Field arguments of arbitrary size. // Adapted from std::field_element::pow_32. -pub fn pow(x: Field, y: Field) -> Field { +pub fn pow(x: field, y: field) -> field { // As in tests with minor modifications let N_BITS = crate::field_element::modulus_num_bits(); - let mut r = 1 as Field; + let mut r = 1 as field; let b = y.to_le_bits(N_BITS as u32); for i in 0..N_BITS { @@ -173,7 +173,7 @@ pub fn pow(x: Field, y: Field) -> Field { // as well as C3 = (C2 - 1)/2, where C2 = (p-1)/(2^c1), // and C5 = ZETA^C2, where ZETA is a non-square element of Field. // These are pre-computed above as globals. -pub fn sqrt(x: Field) -> Field { +pub fn sqrt(x: field) -> field { let mut z = pow(x, C3); let mut t = z * z * x; z *= x; diff --git a/noir_stdlib/src/ec/montcurve.nr b/noir_stdlib/src/ec/montcurve.nr index 7dc756781c0..918038d7f99 100644 --- a/noir_stdlib/src/ec/montcurve.nr +++ b/noir_stdlib/src/ec/montcurve.nr @@ -30,7 +30,7 @@ mod affine { impl Point { // Point constructor - pub fn new(x: Field, y: Field) -> Self { + pub fn new(x: field, y: field) -> Self { Self { x, y, infty: false } } @@ -81,7 +81,7 @@ mod affine { impl Curve { // Curve constructor - pub fn new(j: Field, k: Field, gen: Point) -> Self { + pub fn new(j: field, k: field, gen: Point) -> Self { // Check curve coefficients assert(k != 0); assert(j * j != 4); @@ -119,12 +119,12 @@ mod affine { } // Scalar multiplication (p + ... + p n times) - fn mul(self, n: Field, p: Point) -> Point { + fn mul(self, n: field, p: Point) -> Point { self.into_tecurve().mul(n, p.into_tecurve()).into_montcurve() } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -174,7 +174,7 @@ mod affine { } // Elligator 2 map-to-curve method; see . - fn elligator2_map(self, u: Field) -> Point { + fn elligator2_map(self, u: field) -> Point { let j = self.j; let k = self.k; let z = ZETA; // Non-square Field element required for map @@ -205,7 +205,7 @@ mod affine { } // SWU map-to-curve method (via rational map) - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { self.map_from_swcurve(self.into_swcurve().swu_map(z, u)) } } @@ -237,7 +237,7 @@ mod curvegroup { impl Point { // Point constructor - pub fn new(x: Field, y: Field, z: Field) -> Self { + pub fn new(x: field, y: field, z: field) -> Self { Self { x, y, z } } @@ -282,7 +282,7 @@ mod curvegroup { impl Curve { // Curve constructor - pub fn new(j: Field, k: Field, gen: Point) -> Self { + pub fn new(j: field, k: field, gen: Point) -> Self { // Check curve coefficients assert(k != 0); assert(j * j != 4); @@ -320,12 +320,12 @@ mod curvegroup { } // Scalar multiplication (p + ... + p n times) - pub fn mul(self, n: Field, p: Point) -> Point { + pub fn mul(self, n: field, p: Point) -> Point { self.into_tecurve().mul(n, p.into_tecurve()).into_montcurve() } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -367,12 +367,12 @@ mod curvegroup { } // Elligator 2 map-to-curve method - fn elligator2_map(self, u: Field) -> Point { + fn elligator2_map(self, u: field) -> Point { self.into_affine().elligator2_map(u).into_group() } // SWU map-to-curve method (via rational map) - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { self.into_affine().swu_map(z, u).into_group() } } diff --git a/noir_stdlib/src/ec/swcurve.nr b/noir_stdlib/src/ec/swcurve.nr index 8b34245a71e..2089fc53609 100644 --- a/noir_stdlib/src/ec/swcurve.nr +++ b/noir_stdlib/src/ec/swcurve.nr @@ -26,7 +26,7 @@ mod affine { impl Point { // Point constructor - pub fn new(x: Field, y: Field) -> Self { + pub fn new(x: field, y: field) -> Self { Self { x, y, infty: false } } @@ -70,7 +70,7 @@ mod affine { impl Curve { // Curve constructor - pub fn new(a: Field, b: Field, gen: Point) -> Curve { + pub fn new(a: field, b: field, gen: Point) -> Curve { // Check curve coefficients assert(4 * a * a * a + 27 * b * b != 0); @@ -139,12 +139,12 @@ mod affine { } // Scalar multiplication (p + ... + p n times) - pub fn mul(self, n: Field, p: Point) -> Point { + pub fn mul(self, n: field, p: Point) -> Point { self.into_group().mul(n, p.into_group()).into_affine() } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - pub fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + pub fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -162,7 +162,7 @@ mod affine { // Simplified Shallue-van de Woestijne-Ulas map-to-curve method; see . // First determine non-square z != -1 in Field s.t. g(x) - z irreducible over Field and g(b/(z*a)) is square, // where g(x) = x^3 + a*x + b. swu_map(c,z,.) then maps a Field element to a point on curve c. - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { // Check whether curve is admissible assert(self.a * self.b != 0); @@ -211,7 +211,7 @@ mod curvegroup { impl Point { // Point constructor - pub fn new(x: Field, y: Field, z: Field) -> Self { + pub fn new(x: field, y: field, z: field) -> Self { Self { x, y, z } } @@ -254,7 +254,7 @@ mod curvegroup { impl Curve { // Curve constructor - pub fn new(a: Field, b: Field, gen: Point) -> Curve { + pub fn new(a: field, b: field, gen: Point) -> Curve { // Check curve coefficients assert(4 * a * a * a + 27 * b * b != 0); @@ -349,7 +349,7 @@ mod curvegroup { } // Scalar multiplication (p + ... + p n times) - pub fn mul(self, n: Field, p: Point) -> Point { + pub fn mul(self, n: field, p: Point) -> Point { let N_BITS = crate::field_element::modulus_num_bits(); // TODO: temporary workaround until issue 1354 is solved @@ -363,7 +363,7 @@ mod curvegroup { } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -379,7 +379,7 @@ mod curvegroup { } // Simplified SWU map-to-curve method - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { self.into_affine().swu_map(z, u).into_group() } } diff --git a/noir_stdlib/src/ec/tecurve.nr b/noir_stdlib/src/ec/tecurve.nr index 3739e661de4..6abb704e898 100644 --- a/noir_stdlib/src/ec/tecurve.nr +++ b/noir_stdlib/src/ec/tecurve.nr @@ -27,7 +27,7 @@ mod affine { impl Point { // Point constructor - pub fn new(x: Field, y: Field) -> Self { + pub fn new(x: field, y: field) -> Self { Self { x, y } } @@ -79,7 +79,7 @@ mod affine { impl Curve { // Curve constructor - pub fn new(a: Field, d: Field, gen: Point) -> Curve { + pub fn new(a: field, d: field, gen: Point) -> Curve { // Check curve coefficients assert(a * d * (a - d) != 0); @@ -137,12 +137,12 @@ mod affine { } // Scalar multiplication (p + ... + p n times) - fn mul(self, n: Field, p: Point) -> Point { + fn mul(self, n: field, p: Point) -> Point { self.into_group().mul(n, p.into_group()).into_affine() } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -182,12 +182,12 @@ mod affine { } // Elligator 2 map-to-curve method (via rational map) - fn elligator2_map(self, u: Field) -> Point { + fn elligator2_map(self, u: field) -> Point { self.into_montcurve().elligator2_map(u).into_tecurve() } // Simplified SWU map-to-curve method (via rational map) - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { self.into_montcurve().swu_map(z, u).into_tecurve() } } @@ -221,7 +221,7 @@ mod curvegroup { impl Point { // Point constructor - pub fn new(x: Field, y: Field, t: Field, z: Field) -> Self { + pub fn new(x: field, y: field, t: field, z: field) -> Self { Self { x, y, t, z } } @@ -267,7 +267,7 @@ mod curvegroup { impl Curve { // Curve constructor - pub fn new(a: Field, d: Field, gen: Point) -> Curve { + pub fn new(a: field, d: field, gen: Point) -> Curve { // Check curve coefficients assert(a * d * (a - d) != 0); @@ -353,7 +353,7 @@ mod curvegroup { } // Scalar multiplication (p + ... + p n times) - pub fn mul(self, n: Field, p: Point) -> Point { + pub fn mul(self, n: field, p: Point) -> Point { let N_BITS = crate::field_element::modulus_num_bits(); // TODO: temporary workaround until issue 1354 is solved @@ -367,7 +367,7 @@ mod curvegroup { } // Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication) - fn msm(self, n: [Field; N], p: [Point; N]) -> Point { + fn msm(self, n: [field; N], p: [Point; N]) -> Point { let mut out = Point::zero(); for i in 0..N { @@ -403,12 +403,12 @@ mod curvegroup { } // Elligator 2 map-to-curve method (via rational maps) - fn elligator2_map(self, u: Field) -> Point { + fn elligator2_map(self, u: field) -> Point { self.into_montcurve().elligator2_map(u).into_tecurve() } // Simplified SWU map-to-curve method (via rational map) - fn swu_map(self, z: Field, u: Field) -> Point { + fn swu_map(self, z: field, u: field) -> Point { self.into_montcurve().swu_map(z, u).into_tecurve() } } diff --git a/noir_stdlib/src/eddsa.nr b/noir_stdlib/src/eddsa.nr index 657e791e9c7..cb9ffc5322f 100644 --- a/noir_stdlib/src/eddsa.nr +++ b/noir_stdlib/src/eddsa.nr @@ -4,12 +4,12 @@ use crate::ec::tecurve::affine::Point as TEPoint; // Returns true if signature is valid pub fn eddsa_poseidon_verify( - pub_key_x: Field, - pub_key_y: Field, - signature_s: Field, - signature_r8_x: Field, - signature_r8_y: Field, - message: Field + pub_key_x: field, + pub_key_y: field, + signature_s: field, + signature_r8_x: field, + signature_r8_y: field, + message: field ) -> bool { // Verifies by testing: // S * B8 = R8 + H(R8, A, m) * A8 diff --git a/noir_stdlib/src/field_element.nr b/noir_stdlib/src/field_element.nr index 2069d9a0828..5aa99c0d308 100644 --- a/noir_stdlib/src/field_element.nr +++ b/noir_stdlib/src/field_element.nr @@ -74,7 +74,7 @@ impl field { self as u1 } - pub fn lt(self, another: Field) -> bool { + pub fn lt(self, another: field) -> bool { if crate::compat::is_bn254() { bn254_lt(self, another) } else { @@ -113,7 +113,7 @@ pub fn bytes32_to_field(bytes32: [u8; 32]) -> field { low + high * v } -fn lt_fallback(x: Field, y: Field) -> bool { +fn lt_fallback(x: field, y: field) -> bool { let num_bytes = (modulus_num_bits() as u32 + 7) / 8; let x_bytes = x.to_le_bytes(num_bytes); let y_bytes = y.to_le_bytes(num_bytes); diff --git a/noir_stdlib/src/field_element/bn254.nr b/noir_stdlib/src/field_element/bn254.nr index 9e1445fd3ba..c021ab5567f 100644 --- a/noir_stdlib/src/field_element/bn254.nr +++ b/noir_stdlib/src/field_element/bn254.nr @@ -5,7 +5,7 @@ global PHI: Field = 64323764613183177041862057485226039389; global TWO_POW_128: Field = 0x100000000000000000000000000000000; /// A hint for decomposing a single field into two 16 byte fields. -unconstrained fn decompose_unsafe(x: Field) -> (Field, Field) { +unconstrained fn decompose_unsafe(x: field) -> (field, field) { let x_bytes = x.to_le_bytes(32); let mut low: Field = 0; @@ -22,7 +22,7 @@ unconstrained fn decompose_unsafe(x: Field) -> (Field, Field) { } /// Decompose a single field into two 16 byte fields. -pub fn decompose(x: Field) -> (Field, Field) { +pub fn decompose(x: field) -> (field, field) { // Take hints of the decomposition let (xlo, xhi) = decompose_unsafe(x); let borrow = lt_unsafe(PLO, xlo, 16); @@ -35,8 +35,8 @@ pub fn decompose(x: Field) -> (Field, Field) { assert_eq(x, xlo + TWO_POW_128 * xhi); // Check that (xlo < plo && xhi <= phi) || (xlo >= plo && xhi < phi) - let rlo = PLO - xlo + (borrow as Field) * TWO_POW_128; - let rhi = PHI - xhi - (borrow as Field); + let rlo = PLO - xlo + (borrow as field) * TWO_POW_128; + let rhi = PHI - xhi - (borrow as field); rlo.assert_max_bit_size(128); rhi.assert_max_bit_size(128); @@ -44,7 +44,7 @@ pub fn decompose(x: Field) -> (Field, Field) { (xlo, xhi) } -unconstrained fn lt_unsafe(x: Field, y: Field, num_bytes: u32) -> bool { +unconstrained fn lt_unsafe(x: field, y: field, num_bytes: u32) -> bool { let x_bytes = x.__to_le_radix(256, num_bytes); let y_bytes = y.__to_le_radix(256, num_bytes); let mut x_is_lt = false; @@ -63,11 +63,11 @@ unconstrained fn lt_unsafe(x: Field, y: Field, num_bytes: u32) -> bool { x_is_lt } -unconstrained fn lte_unsafe(x: Field, y: Field, num_bytes: u32) -> bool { +unconstrained fn lte_unsafe(x: field, y: field, num_bytes: u32) -> bool { lt_unsafe(x, y, num_bytes) | (x == y) } -pub fn assert_gt(a: Field, b: Field) { +pub fn assert_gt(a: field, b: field) { // Decompose a and b let (alo, ahi) = decompose(a); let (blo, bhi) = decompose(b); @@ -75,18 +75,18 @@ pub fn assert_gt(a: Field, b: Field) { let borrow = lte_unsafe(alo, blo, 16); // Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi) - let rlo = alo - blo - 1 + (borrow as Field) * TWO_POW_128; - let rhi = ahi - bhi - (borrow as Field); + let rlo = alo - blo - 1 + (borrow as field) * TWO_POW_128; + let rhi = ahi - bhi - (borrow as field); rlo.assert_max_bit_size(128); rhi.assert_max_bit_size(128); } -pub fn assert_lt(a: Field, b: Field) { +pub fn assert_lt(a: field, b: field) { assert_gt(b, a); } -pub fn gt(a: Field, b: Field) -> bool { +pub fn gt(a: field, b: field) -> bool { if a == b { false } else if lt_unsafe(a, b, 32) { @@ -98,6 +98,6 @@ pub fn gt(a: Field, b: Field) -> bool { } } -pub fn lt(a: Field, b: Field) -> bool { +pub fn lt(a: field, b: field) -> bool { gt(b, a) } diff --git a/noir_stdlib/src/grumpkin_scalar.nr b/noir_stdlib/src/grumpkin_scalar.nr index d05158488f4..e425c36e546 100644 --- a/noir_stdlib/src/grumpkin_scalar.nr +++ b/noir_stdlib/src/grumpkin_scalar.nr @@ -4,7 +4,7 @@ struct GrumpkinScalar { } impl GrumpkinScalar { - pub fn new(low: Field, high: Field) -> Self { + pub fn new(low: field, high: field) -> Self { // TODO: check that the low and high value fit within the grumpkin modulus GrumpkinScalar { low, high } } @@ -12,10 +12,10 @@ impl GrumpkinScalar { global GRUMPKIN_SCALAR_SERIALIZED_LEN: Field = 2; -pub fn deserialize_grumpkin_scalar(fields: [Field; GRUMPKIN_SCALAR_SERIALIZED_LEN]) -> GrumpkinScalar { +pub fn deserialize_grumpkin_scalar(fields: [field; GRUMPKIN_SCALAR_SERIALIZED_LEN]) -> GrumpkinScalar { GrumpkinScalar { low: fields[0], high: fields[1] } } -pub fn serialize_grumpkin_scalar(scalar: GrumpkinScalar) -> [Field; GRUMPKIN_SCALAR_SERIALIZED_LEN] { +pub fn serialize_grumpkin_scalar(scalar: GrumpkinScalar) -> [field; GRUMPKIN_SCALAR_SERIALIZED_LEN] { [scalar.low, scalar.high] } diff --git a/noir_stdlib/src/grumpkin_scalar_mul.nr b/noir_stdlib/src/grumpkin_scalar_mul.nr index 06d30d62332..46e60d5b6de 100644 --- a/noir_stdlib/src/grumpkin_scalar_mul.nr +++ b/noir_stdlib/src/grumpkin_scalar_mul.nr @@ -1,7 +1,7 @@ use crate::grumpkin_scalar::GrumpkinScalar; use crate::scalar_mul::fixed_base_embedded_curve; -pub fn grumpkin_fixed_base(scalar: GrumpkinScalar) -> [Field; 2] { +pub fn grumpkin_fixed_base(scalar: GrumpkinScalar) -> [field; 2] { // TODO: this should use both the low and high limbs to do the scalar multiplication fixed_base_embedded_curve(scalar.low, scalar.high) } diff --git a/noir_stdlib/src/hash.nr b/noir_stdlib/src/hash.nr index 87ccc4ed078..aba733ff355 100644 --- a/noir_stdlib/src/hash.nr +++ b/noir_stdlib/src/hash.nr @@ -29,31 +29,31 @@ struct PedersenPoint { y : Field, } -pub fn pedersen_commitment(input: [Field; N]) -> PedersenPoint +pub fn pedersen_commitment(input: [field; N]) -> PedersenPoint // docs:end:pedersen_commitment { pedersen_commitment_with_separator(input, 0) } #[foreign(pedersen_commitment)] -pub fn __pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> [Field; 2] {} +pub fn __pedersen_commitment_with_separator(input: [field; N], separator: u32) -> [field; 2] {} -pub fn pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> PedersenPoint { +pub fn pedersen_commitment_with_separator(input: [field; N], separator: u32) -> PedersenPoint { let values = __pedersen_commitment_with_separator(input, separator); PedersenPoint { x: values[0], y: values[1] } } // docs:start:pedersen_hash -pub fn pedersen_hash(input: [Field; N]) -> Field +pub fn pedersen_hash(input: [field; N]) -> field // docs:end:pedersen_hash { pedersen_hash_with_separator(input, 0) } #[foreign(pedersen_hash)] -pub fn pedersen_hash_with_separator(input: [Field; N], separator: u32) -> Field {} +pub fn pedersen_hash_with_separator(input: [field; N], separator: u32) -> field {} -pub fn hash_to_field(input: [Field; N]) -> Field { +pub fn hash_to_field(input: [field; N]) -> field { let mut inputs_as_bytes = []; for i in 0..N { @@ -74,7 +74,7 @@ pub fn keccak256(input: [u8; N], message_size: u32) -> [u8; 32] {} #[foreign(poseidon2_permutation)] -pub fn poseidon2_permutation(_input: [Field; N], _state_length: u32) -> [Field; N] {} +pub fn poseidon2_permutation(_input: [field; N], _state_length: u32) -> [field; N] {} #[foreign(sha256_compression)] pub fn sha256_compression(_input: [u32; 16], _state: [u32; 8]) -> [u32; 8] {} diff --git a/noir_stdlib/src/hash/mimc.nr b/noir_stdlib/src/hash/mimc.nr index 10c0a48917c..592895ad820 100644 --- a/noir_stdlib/src/hash/mimc.nr +++ b/noir_stdlib/src/hash/mimc.nr @@ -3,7 +3,7 @@ // 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(x: Field, k: Field, constants: [Field; N], exp: Field) -> Field { +fn mimc(x: field, k: field, constants: [field; N], exp: field) -> field { //round 0 let mut t = x + k; let mut h = t.pow_32(exp); @@ -18,7 +18,7 @@ fn mimc(x: Field, k: Field, constants: [Field; N], exp: Field) -> Field { global MIMC_BN254_ROUNDS = 91; //mimc implementation with hardcoded parameters for BN254 curve. #[field(bn254)] -pub fn mimc_bn254(array: [Field; N]) -> Field { +pub fn mimc_bn254(array: [field; N]) -> field { //mimc parameters let exponent = 7; //generated from seed "mimc" using keccak256 diff --git a/noir_stdlib/src/hash/poseidon.nr b/noir_stdlib/src/hash/poseidon.nr index aab60178534..ce57b64048d 100644 --- a/noir_stdlib/src/hash/poseidon.nr +++ b/noir_stdlib/src/hash/poseidon.nr @@ -11,26 +11,26 @@ struct PoseidonConfig { } pub fn config( - t: Field, + t: field, rf: u8, rp: u8, - alpha: Field, - ark: [Field; M], - mds: [Field; N] + alpha: field, + ark: [field; M], + mds: [field; N] ) -> PoseidonConfig { // Input checks let mul = crate::wrapping_mul(t as u8, (rf + rp)); assert(mul == ark.len() as u8); - assert(t * t == mds.len() as Field); + assert(t * t == mds.len() as field); assert(alpha != 0); PoseidonConfig { t, rf, rp, alpha, ark, mds } } // General Poseidon permutation on elements of type Field -fn permute(pos_conf: PoseidonConfig, mut state: [Field; O]) -> [Field; O] { +fn permute(pos_conf: PoseidonConfig, mut state: [field; O]) -> [field; O] { let PoseidonConfig {t, rf, rp, alpha, ark, mds} = pos_conf; - assert(t == state.len() as Field); + assert(t == state.len() as field); let mut count = 0; // for r in 0..rf + rp @@ -55,11 +55,11 @@ fn permute(pos_conf: PoseidonConfig, mut state: [Field; O]) -> [F // Absorption. Fully absorbs input message. fn absorb( pos_conf: PoseidonConfig, - mut state: [Field; O], // Initial state; usually [0; O] - rate: Field, // Rate - capacity: Field, // Capacity; usually 1 - msg: [Field; P] -) -> [Field; O] { + mut state: [field; O], // Initial state; usually [0; O] + rate: field, // Rate + capacity: field, // Capacity; usually 1 + msg: [field; P] +) -> [field; O] { assert(pos_conf.t == rate + capacity); let mut i = 0; @@ -82,13 +82,13 @@ fn absorb( state } // Check security of sponge instantiation -fn check_security(rate: Field, width: Field, security: Field) -> bool { +fn check_security(rate: field, width: field, security: field) -> bool { let n = modulus_num_bits(); - ((n - 1) as Field * (width - rate) / 2) as u8 > security as u8 + ((n - 1) as field * (width - rate) / 2) as u8 > security as u8 } // A*x where A is an n x n matrix in row-major order and x an n-vector -fn apply_matrix(a: [Field; M], x: [Field; N]) -> [Field; N] { +fn apply_matrix(a: [field; M], x: [field; N]) -> [field; N] { let mut y = x; for i in 0..x.len() { diff --git a/noir_stdlib/src/hash/poseidon/bn254.nr b/noir_stdlib/src/hash/poseidon/bn254.nr index 37b08e3c8fb..708d8dad120 100644 --- a/noir_stdlib/src/hash/poseidon/bn254.nr +++ b/noir_stdlib/src/hash/poseidon/bn254.nr @@ -7,12 +7,12 @@ use crate::hash::poseidon::apply_matrix; // Optimised permutation for this particular field; uses hardcoded rf and rp values, // which should agree with those in pos_conf. #[field(bn254)] -pub fn permute(pos_conf: PoseidonConfig, mut state: [Field; O]) -> [Field; O] { +pub fn permute(pos_conf: PoseidonConfig, mut state: [field; O]) -> [field; O] { let PoseidonConfig {t, rf: config_rf, rp: config_rp, alpha, ark, mds} = pos_conf; let rf: u8 = 8; let rp: u8 = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68][state.len() - 2]; - assert(t == state.len() as Field); + assert(t == state.len() as field); assert(rf == config_rf); assert(rp == config_rp); @@ -58,11 +58,11 @@ pub fn permute(pos_conf: PoseidonConfig, mut state: [Field; O]) - #[field(bn254)] fn absorb( pos_conf: PoseidonConfig, - mut state: [Field; O], // Initial state; usually [0; O] - rate: Field, // Rate - capacity: Field, // Capacity; usually 1 - msg: [Field; P] // Arbitrary length message -) -> [Field; O] { + mut state: [field; O], // Initial state; usually [0; O] + rate: field, // Rate + capacity: field, // Capacity; usually 1 + msg: [field; P] // Arbitrary length message +) -> [field; O] { assert(pos_conf.t == rate + capacity); let mut i = 0; @@ -86,12 +86,12 @@ fn absorb( } // Variable-length Poseidon-128 sponge as suggested in second bullet point of ยง3 of https://eprint.iacr.org/2019/458.pdf #[field(bn254)] -pub fn sponge(msg: [Field; N]) -> Field { +pub fn sponge(msg: [field; N]) -> field { absorb(consts::x5_5_config(), [0; 5], 4, 1, msg)[1] } // Various instances of the Poseidon hash function // Consistent with Circom's implementation -pub fn hash_1(input: [Field; 1]) -> Field { +pub fn hash_1(input: [field; 1]) -> field { let mut state = [0; 2]; for i in 0..input.len() { state[i+1] = input[i]; @@ -100,7 +100,7 @@ pub fn hash_1(input: [Field; 1]) -> Field { perm::x5_2(state)[0] } -pub fn hash_2(input: [Field; 2]) -> Field { +pub fn hash_2(input: [field; 2]) -> field { let mut state = [0; 3]; for i in 0..input.len() { state[i+1] = input[i]; @@ -109,7 +109,7 @@ pub fn hash_2(input: [Field; 2]) -> Field { perm::x5_3(state)[0] } -pub fn hash_3(input: [Field; 3]) -> Field { +pub fn hash_3(input: [field; 3]) -> field { let mut state = [0; 4]; for i in 0..input.len() { state[i+1] = input[i]; @@ -118,7 +118,7 @@ pub fn hash_3(input: [Field; 3]) -> Field { perm::x5_4(state)[0] } -pub fn hash_4(input: [Field; 4]) -> Field { +pub fn hash_4(input: [field; 4]) -> field { let mut state = [0; 5]; for i in 0..input.len() { state[i+1] = input[i]; @@ -127,7 +127,7 @@ pub fn hash_4(input: [Field; 4]) -> Field { perm::x5_5(state)[0] } -pub fn hash_5(input: [Field; 5]) -> Field { +pub fn hash_5(input: [field; 5]) -> field { let mut state = [0; 6]; for i in 0..input.len() { state[i+1] = input[i]; @@ -136,7 +136,7 @@ pub fn hash_5(input: [Field; 5]) -> Field { perm::x5_6(state)[0] } -pub fn hash_6(input: [Field; 6]) -> Field { +pub fn hash_6(input: [field; 6]) -> field { let mut state = [0; 7]; for i in 0..input.len() { state[i+1] = input[i]; @@ -145,7 +145,7 @@ pub fn hash_6(input: [Field; 6]) -> Field { perm::x5_7(state)[0] } -pub fn hash_7(input: [Field; 7]) -> Field { +pub fn hash_7(input: [field; 7]) -> field { let mut state = [0; 8]; for i in 0..input.len() { state[i+1] = input[i]; @@ -154,7 +154,7 @@ pub fn hash_7(input: [Field; 7]) -> Field { perm::x5_8(state)[0] } -pub fn hash_8(input: [Field; 8]) -> Field { +pub fn hash_8(input: [field; 8]) -> field { let mut state = [0; 9]; for i in 0..input.len() { state[i+1] = input[i]; @@ -163,7 +163,7 @@ pub fn hash_8(input: [Field; 8]) -> Field { perm::x5_9(state)[0] } -pub fn hash_9(input: [Field; 9]) -> Field { +pub fn hash_9(input: [field; 9]) -> field { let mut state = [0; 10]; for i in 0..input.len() { state[i+1] = input[i]; @@ -172,7 +172,7 @@ pub fn hash_9(input: [Field; 9]) -> Field { perm::x5_10(state)[0] } -pub fn hash_10(input: [Field; 10]) -> Field { +pub fn hash_10(input: [field; 10]) -> field { let mut state = [0; 11]; for i in 0..input.len() { state[i+1] = input[i]; @@ -181,7 +181,7 @@ pub fn hash_10(input: [Field; 10]) -> Field { perm::x5_11(state)[0] } -pub fn hash_11(input: [Field; 11]) -> Field { +pub fn hash_11(input: [field; 11]) -> field { let mut state = [0; 12]; for i in 0..input.len() { state[i+1] = input[i]; @@ -190,7 +190,7 @@ pub fn hash_11(input: [Field; 11]) -> Field { perm::x5_12(state)[0] } -pub fn hash_12(input: [Field; 12]) -> Field { +pub fn hash_12(input: [field; 12]) -> field { let mut state = [0; 13]; for i in 0..input.len() { state[i+1] = input[i]; @@ -199,7 +199,7 @@ pub fn hash_12(input: [Field; 12]) -> Field { perm::x5_13(state)[0] } -pub fn hash_13(input: [Field; 13]) -> Field { +pub fn hash_13(input: [field; 13]) -> field { let mut state = [0; 14]; for i in 0..input.len() { state[i+1] = input[i]; @@ -208,7 +208,7 @@ pub fn hash_13(input: [Field; 13]) -> Field { perm::x5_14(state)[0] } -pub fn hash_14(input: [Field; 14]) -> Field { +pub fn hash_14(input: [field; 14]) -> field { let mut state = [0; 15]; for i in 0..input.len() { state[i+1] = input[i]; @@ -217,7 +217,7 @@ pub fn hash_14(input: [Field; 14]) -> Field { perm::x5_15(state)[0] } -pub fn hash_15(input: [Field; 15]) -> Field { +pub fn hash_15(input: [field; 15]) -> field { let mut state = [0; 16]; for i in 0..input.len() { state[i+1] = input[i]; @@ -226,7 +226,7 @@ pub fn hash_15(input: [Field; 15]) -> Field { perm::x5_16(state)[0] } -pub fn hash_16(input: [Field; 16]) -> Field { +pub fn hash_16(input: [field; 16]) -> field { let mut state = [0; 17]; for i in 0..input.len() { state[i+1] = input[i]; diff --git a/noir_stdlib/src/hash/poseidon/bn254/consts.nr b/noir_stdlib/src/hash/poseidon/bn254/consts.nr index 62b5f4b5212..d357f87c417 100644 --- a/noir_stdlib/src/hash/poseidon/bn254/consts.nr +++ b/noir_stdlib/src/hash/poseidon/bn254/consts.nr @@ -9,7 +9,7 @@ fn rp() -> [u8; 16] { [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68] } // S-box power -fn alpha() -> Field { +fn alpha() -> field { 5 } // Poseidon configurations for states of size 2 to 17. diff --git a/noir_stdlib/src/hash/poseidon/bn254/perm.nr b/noir_stdlib/src/hash/poseidon/bn254/perm.nr index 890f54fdb3f..ed1361ea843 100644 --- a/noir_stdlib/src/hash/poseidon/bn254/perm.nr +++ b/noir_stdlib/src/hash/poseidon/bn254/perm.nr @@ -4,7 +4,7 @@ use crate::hash::poseidon::bn254::permute; use crate::hash::poseidon::PoseidonConfig; #[field(bn254)] -pub fn x5_2(mut state: [Field; 2]) -> [Field; 2] { +pub fn x5_2(mut state: [field; 2]) -> [field; 2] { state = permute( consts::x5_2_config(), state); @@ -13,7 +13,7 @@ pub fn x5_2(mut state: [Field; 2]) -> [Field; 2] { } #[field(bn254)] -pub fn x5_3(mut state: [Field; 3]) -> [Field; 3] { +pub fn x5_3(mut state: [field; 3]) -> [field; 3] { state = permute( consts::x5_3_config(), state); @@ -22,7 +22,7 @@ pub fn x5_3(mut state: [Field; 3]) -> [Field; 3] { } #[field(bn254)] -pub fn x5_4(mut state: [Field; 4]) -> [Field; 4] { +pub fn x5_4(mut state: [field; 4]) -> [field; 4] { state = permute( consts::x5_4_config(), state); @@ -31,7 +31,7 @@ pub fn x5_4(mut state: [Field; 4]) -> [Field; 4] { } #[field(bn254)] -pub fn x5_5(mut state: [Field; 5]) -> [Field; 5] { +pub fn x5_5(mut state: [field; 5]) -> [field; 5] { state = permute( consts::x5_5_config(), state); @@ -40,7 +40,7 @@ pub fn x5_5(mut state: [Field; 5]) -> [Field; 5] { } #[field(bn254)] -pub fn x5_6(mut state: [Field; 6]) -> [Field; 6] { +pub fn x5_6(mut state: [field; 6]) -> [field; 6] { state = permute( consts::x5_6_config(), state); @@ -49,7 +49,7 @@ pub fn x5_6(mut state: [Field; 6]) -> [Field; 6] { } #[field(bn254)] -pub fn x5_7(mut state: [Field; 7]) -> [Field; 7] { +pub fn x5_7(mut state: [field; 7]) -> [field; 7] { state = permute( consts::x5_7_config(), state); @@ -58,7 +58,7 @@ pub fn x5_7(mut state: [Field; 7]) -> [Field; 7] { } #[field(bn254)] -pub fn x5_8(mut state: [Field; 8]) -> [Field; 8] { +pub fn x5_8(mut state: [field; 8]) -> [field; 8] { state = permute( consts::x5_8_config(), state); @@ -67,7 +67,7 @@ pub fn x5_8(mut state: [Field; 8]) -> [Field; 8] { } #[field(bn254)] -pub fn x5_9(mut state: [Field; 9]) -> [Field; 9] { +pub fn x5_9(mut state: [field; 9]) -> [field; 9] { state = permute( consts::x5_9_config(), state); @@ -76,7 +76,7 @@ pub fn x5_9(mut state: [Field; 9]) -> [Field; 9] { } #[field(bn254)] -pub fn x5_10(mut state: [Field; 10]) -> [Field; 10] { +pub fn x5_10(mut state: [field; 10]) -> [field; 10] { state = permute( consts::x5_10_config(), state); @@ -85,7 +85,7 @@ pub fn x5_10(mut state: [Field; 10]) -> [Field; 10] { } #[field(bn254)] -pub fn x5_11(mut state: [Field; 11]) -> [Field; 11] { +pub fn x5_11(mut state: [field; 11]) -> [field; 11] { state = permute( consts::x5_11_config(), state); @@ -94,7 +94,7 @@ pub fn x5_11(mut state: [Field; 11]) -> [Field; 11] { } #[field(bn254)] -pub fn x5_12(mut state: [Field; 12]) -> [Field; 12] { +pub fn x5_12(mut state: [field; 12]) -> [field; 12] { state = permute( consts::x5_12_config(), state); @@ -103,7 +103,7 @@ pub fn x5_12(mut state: [Field; 12]) -> [Field; 12] { } #[field(bn254)] -pub fn x5_13(mut state: [Field; 13]) -> [Field; 13] { +pub fn x5_13(mut state: [field; 13]) -> [field; 13] { state = permute( consts::x5_13_config(), state); @@ -112,7 +112,7 @@ pub fn x5_13(mut state: [Field; 13]) -> [Field; 13] { } #[field(bn254)] -pub fn x5_14(mut state: [Field; 14]) -> [Field; 14] { +pub fn x5_14(mut state: [field; 14]) -> [field; 14] { state = permute( consts::x5_14_config(), state); @@ -121,7 +121,7 @@ pub fn x5_14(mut state: [Field; 14]) -> [Field; 14] { } #[field(bn254)] -pub fn x5_15(mut state: [Field; 15]) -> [Field; 15] { +pub fn x5_15(mut state: [field; 15]) -> [field; 15] { state = permute( consts::x5_15_config(), state); @@ -130,7 +130,7 @@ pub fn x5_15(mut state: [Field; 15]) -> [Field; 15] { } #[field(bn254)] -pub fn x5_16(mut state: [Field; 16]) -> [Field; 16] { +pub fn x5_16(mut state: [field; 16]) -> [field; 16] { state = permute( consts::x5_16_config(), state); @@ -139,7 +139,7 @@ pub fn x5_16(mut state: [Field; 16]) -> [Field; 16] { } #[field(bn254)] -pub fn x5_17(mut state: [Field; 17]) -> [Field; 17] { +pub fn x5_17(mut state: [field; 17]) -> [field; 17] { state = permute( consts::x5_17_config(), state); diff --git a/noir_stdlib/src/hash/poseidon2.nr b/noir_stdlib/src/hash/poseidon2.nr index 8e0fcc6858e..37a219600d7 100644 --- a/noir_stdlib/src/hash/poseidon2.nr +++ b/noir_stdlib/src/hash/poseidon2.nr @@ -9,7 +9,7 @@ struct Poseidon2 { impl Poseidon2 { - pub fn hash(input: [Field; N], message_size: u32) -> Field { + pub fn hash(input: [field; N], message_size: u32) -> field { if message_size == N { Poseidon2::hash_internal(input, N, false) } else { @@ -17,18 +17,13 @@ impl Poseidon2 { } } - fn new(iv: Field) -> Poseidon2 { - let mut result = Poseidon2 { - cache: [0;3], - state: [0;4], - cache_size: 0, - squeeze_mode: false, - }; + fn new(iv: field) -> Poseidon2 { + let mut result = Poseidon2 { cache: [0; 3], state: [0; 4], cache_size: 0, squeeze_mode: false }; result.state[rate] = iv; result } - fn perform_duplex(&mut self) -> [Field; rate] { + fn perform_duplex(&mut self) -> [field; rate] { // zero-pad the cache for i in 0..rate { if i >= self.cache_size { @@ -48,7 +43,7 @@ impl Poseidon2 { result } - fn absorb(&mut self, input: Field) { + fn absorb(&mut self, input: field) { if (!self.squeeze_mode) & (self.cache_size == rate) { // If we're absorbing, and the cache is full, apply the sponge permutation to compress the cache let _ = self.perform_duplex(); @@ -67,8 +62,7 @@ impl Poseidon2 { } } - fn squeeze(&mut self) -> Field - { + fn squeeze(&mut self) -> field { if self.squeeze_mode & (self.cache_size == 0) { // If we're in squeze mode and the cache is empty, there is nothing left to squeeze out of the sponge! // Switch to absorb mode. @@ -98,9 +92,8 @@ impl Poseidon2 { result } - fn hash_internal(input:[Field;N], in_len:u32, is_variable_length: bool) -> Field - { - let iv : Field = (in_len as Field)*18446744073709551616; + fn hash_internal(input: [field; N], in_len: u32, is_variable_length: bool) -> field { + let iv : Field = (in_len as field) * 18446744073709551616; let mut sponge = Poseidon2::new(iv); for i in 0..input.len() { if i as u32 < in_len { diff --git a/noir_stdlib/src/lib.nr b/noir_stdlib/src/lib.nr index f728f3b2289..8b77d065a78 100644 --- a/noir_stdlib/src/lib.nr +++ b/noir_stdlib/src/lib.nr @@ -41,7 +41,7 @@ unconstrained pub fn println(input: T) { } #[foreign(recursive_aggregation)] -pub fn verify_proof(verification_key: [Field], proof: [Field], public_inputs: [Field], key_hash: Field) {} +pub fn verify_proof(verification_key: [field], proof: [field], public_inputs: [field], key_hash: field) {} // Asserts that the given value is known at compile-time. // Useful for debugging for-loop bounds. @@ -51,10 +51,10 @@ pub fn assert_constant(x: T) {} // `as` should be the default for users to cast between primitive types, and in the future // traits can be used to work with generic types. #[builtin(from_field)] -fn from_field(x: Field) -> T {} +fn from_field(x: field) -> T {} #[builtin(as_field)] -fn as_field(x: T) -> Field {} +fn as_field(x: T) -> field {} pub fn wrapping_add(x: T, y: T) -> T { crate::from_field(crate::as_field(x) + crate::as_field(y)) diff --git a/noir_stdlib/src/merkle.nr b/noir_stdlib/src/merkle.nr index 9b15fe7313d..3d56a4fbedc 100644 --- a/noir_stdlib/src/merkle.nr +++ b/noir_stdlib/src/merkle.nr @@ -2,7 +2,7 @@ // Currently we assume that it is a binary tree, so depth k implies a width of 2^k // XXX: In the future we can add an arity parameter // Returns the merkle root of the tree from the provided leaf, its hashpath, using a pedersen hash function. -pub fn compute_merkle_root(leaf: Field, index: Field, hash_path: [Field; N]) -> Field { +pub fn compute_merkle_root(leaf: field, index: field, hash_path: [field; N]) -> field { let n = hash_path.len(); let index_bits = index.to_le_bits(n as u32); let mut current = leaf; diff --git a/noir_stdlib/src/scalar_mul.nr b/noir_stdlib/src/scalar_mul.nr index eee7aac39f2..48df9185a2d 100644 --- a/noir_stdlib/src/scalar_mul.nr +++ b/noir_stdlib/src/scalar_mul.nr @@ -26,9 +26,9 @@ impl Add for EmbeddedCurvePoint { #[foreign(fixed_base_scalar_mul)] // docs:start:fixed_base_embedded_curve pub fn fixed_base_embedded_curve( - low: Field, - high: Field -) -> [Field; 2] + low: field, + high: field +) -> [field; 2] // docs:end:fixed_base_embedded_curve {} @@ -42,4 +42,4 @@ fn embedded_curve_add(point1: EmbeddedCurvePoint, point2: EmbeddedCurvePoint) -> } #[foreign(embedded_curve_add)] -fn embedded_curve_add_array_return(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> [Field; 2] {} +fn embedded_curve_add_array_return(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> [field; 2] {} diff --git a/noir_stdlib/src/schnorr.nr b/noir_stdlib/src/schnorr.nr index 757963d40d7..f5a3076528f 100644 --- a/noir_stdlib/src/schnorr.nr +++ b/noir_stdlib/src/schnorr.nr @@ -1,8 +1,8 @@ #[foreign(schnorr_verify)] // docs:start:schnorr_verify pub fn verify_signature( - public_key_x: Field, - public_key_y: Field, + public_key_x: field, + public_key_y: field, signature: [u8; 64], message: [u8; N] ) -> bool diff --git a/noir_stdlib/src/test.nr b/noir_stdlib/src/test.nr index e1c320215de..500b5cec9be 100644 --- a/noir_stdlib/src/test.nr +++ b/noir_stdlib/src/test.nr @@ -1,17 +1,17 @@ #[oracle(create_mock)] -unconstrained fn create_mock_oracle(name: str) -> Field {} +unconstrained fn create_mock_oracle(name: str) -> field {} #[oracle(set_mock_params)] -unconstrained fn set_mock_params_oracle

(id: Field, params: P) {} +unconstrained fn set_mock_params_oracle

(id: field, params: P) {} #[oracle(set_mock_returns)] -unconstrained fn set_mock_returns_oracle(id: Field, returns: R) {} +unconstrained fn set_mock_returns_oracle(id: field, returns: R) {} #[oracle(set_mock_times)] -unconstrained fn set_mock_times_oracle(id: Field, times: u64) {} +unconstrained fn set_mock_times_oracle(id: field, times: u64) {} #[oracle(clear_mock)] -unconstrained fn clear_mock_oracle(id: Field) {} +unconstrained fn clear_mock_oracle(id: field) {} struct OracleMock { id: Field, diff --git a/noir_stdlib/src/uint128.nr b/noir_stdlib/src/uint128.nr index 1bf285fecac..42a45008721 100644 --- a/noir_stdlib/src/uint128.nr +++ b/noir_stdlib/src/uint128.nr @@ -13,7 +13,7 @@ impl U128 { pub fn from_u64s_le(lo: u64, hi: u64) -> U128 { // in order to handle multiplication, we need to represent the product of two u64 without overflow assert(crate::field_element::modulus_num_bits() as u32 > 128); - U128 { lo: lo as Field, hi: hi as Field } + U128 { lo: lo as field, hi: hi as field } } pub fn from_u64s_be(hi: u64, lo: u64) -> U128 { @@ -84,17 +84,17 @@ impl U128 { base = base*16; } } - U128 { lo: lo as Field, hi: hi as Field } + U128 { lo: lo as field, hi: hi as field } } - fn decode_ascii(ascii: u8) -> Field { + fn decode_ascii(ascii: u8) -> field { if ascii < 58 { ascii - 48 } else if ascii < 71 { ascii - 55 } else { ascii - 87 - } as Field + } as field } unconstrained fn unconstrained_div(self: Self, b: U128) -> (U128, U128) { @@ -116,7 +116,7 @@ impl U128 { let f = crate::as_field(i); // Reject values which would overflow a u128 f.assert_max_bit_size(128); - let lo = f as u64 as Field; + let lo = f as u64 as field; let hi = (f - lo) / pow64; U128 { lo, hi } } @@ -127,14 +127,14 @@ impl U128 { fn wrapping_mul(self: Self, b: U128) -> U128 { let low = self.lo * b.lo; - let lo = low as u64 as Field; + let lo = low as u64 as field; let carry = (low - lo) / pow64; let high = if crate::field_element::modulus_num_bits() as u32 > 196 { (self.lo + self.hi) * (b.lo + b.hi) - low + carry } else { self.lo * b.hi + self.hi * b.lo + carry }; - let hi = high as u64 as Field; + let hi = high as u64 as field; U128 { lo, hi } } }