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 bn254 attribute when needed in the stdlib #3208

Merged
merged 5 commits into from
Oct 26, 2023
Merged
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
3 changes: 1 addition & 2 deletions noir_stdlib/src/ec/consts/te.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ struct BabyJubjub {
suborder: Field,
}

#[field(bn254)]
pub fn baby_jubjub() -> BabyJubjub {
assert(compat::is_bn254());

BabyJubjub {
// Baby Jubjub (ERC-2494) parameters in affine representation
curve: TECurve::new(
Expand Down
1 change: 1 addition & 0 deletions noir_stdlib/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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.
#[field(bn254)]
pub fn mimc_bn254<N>(array: [Field; N]) -> Field {
//mimc parameters
let exponent = 7;
Expand Down
3 changes: 3 additions & 0 deletions noir_stdlib/src/hash/poseidon/bn254.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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<M,N,O>(
pos_conf: PoseidonConfig<M, N>,
mut state: [Field; O])
Expand Down Expand Up @@ -65,6 +66,7 @@ pub fn permute<M,N,O>(
}

// Corresponding absorption.
#[field(bn254)]
fn absorb<M,N,O,P>(
pos_conf: PoseidonConfig<M, N>,
mut state: [Field; O], // Initial state; usually [0; O]
Expand Down Expand Up @@ -98,6 +100,7 @@ fn absorb<M,N,O,P>(
}

// 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<N>(msg: [Field; N]) -> Field {
absorb(consts::x5_5_config(), [0;5], 4, 1, msg)[1]
}
Expand Down
16 changes: 16 additions & 0 deletions noir_stdlib/src/hash/poseidon/bn254/perm.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::hash::poseidon::bn254::consts;
use crate::hash::poseidon::bn254::permute;
use crate::hash::poseidon::PoseidonConfig;

#[field(bn254)]
vezenovm marked this conversation as resolved.
Show resolved Hide resolved
pub fn x5_2(mut state: [Field; 2]) -> [Field; 2] {
state = permute(
consts::x5_2_config(),
Expand All @@ -11,6 +12,7 @@ pub fn x5_2(mut state: [Field; 2]) -> [Field; 2] {
state
}

#[field(bn254)]
pub fn x5_3(mut state: [Field; 3]) -> [Field; 3] {
state = permute(
consts::x5_3_config(),
Expand All @@ -19,6 +21,7 @@ pub fn x5_3(mut state: [Field; 3]) -> [Field; 3] {
state
}

#[field(bn254)]
pub fn x5_4(mut state: [Field; 4]) -> [Field; 4] {
state = permute(
consts::x5_4_config(),
Expand All @@ -27,6 +30,7 @@ pub fn x5_4(mut state: [Field; 4]) -> [Field; 4] {
state
}

#[field(bn254)]
pub fn x5_5(mut state: [Field; 5]) -> [Field; 5] {
state = permute(
consts::x5_5_config(),
Expand All @@ -35,6 +39,7 @@ pub fn x5_5(mut state: [Field; 5]) -> [Field; 5] {
state
}

#[field(bn254)]
pub fn x5_6(mut state: [Field; 6]) -> [Field; 6] {
state = permute(
consts::x5_6_config(),
Expand All @@ -43,6 +48,7 @@ pub fn x5_6(mut state: [Field; 6]) -> [Field; 6] {
state
}

#[field(bn254)]
pub fn x5_7(mut state: [Field; 7]) -> [Field; 7] {
state = permute(
consts::x5_7_config(),
Expand All @@ -51,6 +57,7 @@ pub fn x5_7(mut state: [Field; 7]) -> [Field; 7] {
state
}

#[field(bn254)]
pub fn x5_8(mut state: [Field; 8]) -> [Field; 8] {
state = permute(
consts::x5_8_config(),
Expand All @@ -59,6 +66,7 @@ pub fn x5_8(mut state: [Field; 8]) -> [Field; 8] {
state
}

#[field(bn254)]
pub fn x5_9(mut state: [Field; 9]) -> [Field; 9] {
state = permute(
consts::x5_9_config(),
Expand All @@ -67,6 +75,7 @@ pub fn x5_9(mut state: [Field; 9]) -> [Field; 9] {
state
}

#[field(bn254)]
pub fn x5_10(mut state: [Field; 10]) -> [Field; 10] {
state = permute(
consts::x5_10_config(),
Expand All @@ -75,6 +84,7 @@ pub fn x5_10(mut state: [Field; 10]) -> [Field; 10] {
state
}

#[field(bn254)]
pub fn x5_11(mut state: [Field; 11]) -> [Field; 11] {
state = permute(
consts::x5_11_config(),
Expand All @@ -83,6 +93,7 @@ pub fn x5_11(mut state: [Field; 11]) -> [Field; 11] {
state
}

#[field(bn254)]
pub fn x5_12(mut state: [Field; 12]) -> [Field; 12] {
state = permute(
consts::x5_12_config(),
Expand All @@ -91,6 +102,7 @@ pub fn x5_12(mut state: [Field; 12]) -> [Field; 12] {
state
}

#[field(bn254)]
pub fn x5_13(mut state: [Field; 13]) -> [Field; 13] {
state = permute(
consts::x5_13_config(),
Expand All @@ -99,6 +111,7 @@ pub fn x5_13(mut state: [Field; 13]) -> [Field; 13] {
state
}

#[field(bn254)]
pub fn x5_14(mut state: [Field; 14]) -> [Field; 14] {
state = permute(
consts::x5_14_config(),
Expand All @@ -107,6 +120,7 @@ pub fn x5_14(mut state: [Field; 14]) -> [Field; 14] {
state
}

#[field(bn254)]
pub fn x5_15(mut state: [Field; 15]) -> [Field; 15] {
state = permute(
consts::x5_15_config(),
Expand All @@ -115,6 +129,7 @@ pub fn x5_15(mut state: [Field; 15]) -> [Field; 15] {
state
}

#[field(bn254)]
pub fn x5_16(mut state: [Field; 16]) -> [Field; 16] {
state = permute(
consts::x5_16_config(),
Expand All @@ -123,6 +138,7 @@ pub fn x5_16(mut state: [Field; 16]) -> [Field; 16] {
state
}

#[field(bn254)]
pub fn x5_17(mut state: [Field; 17]) -> [Field; 17] {
state = permute(
consts::x5_17_config(),
Expand Down