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: nargo fmt #3549

Merged
merged 1 commit into from Nov 24, 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
16 changes: 11 additions & 5 deletions noir_stdlib/src/ec/consts/te.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ struct BabyJubjub {
pub fn baby_jubjub() -> BabyJubjub {
BabyJubjub {
// Baby Jubjub (ERC-2494) parameters in affine representation
curve: TECurve::new(168700,
curve: TECurve::new(
168700,
168696,
// G
TEPoint::new(995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905)),
TEPoint::new(
995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905
)
),
// [8]G precalculated
base8: TEPoint::new(5299619240641551281634865583518297030282874472190772894086521144482721001553,
16950150798460657717958625567821834550301663161624707787222815936182638968203),
base8: TEPoint::new(
5299619240641551281634865583518297030282874472190772894086521144482721001553,
16950150798460657717958625567821834550301663161624707787222815936182638968203
),
// The size of the group formed from multiplying the base field by 8.
suborder: 2736030358979909402780800718157159386076813972158567259200215660948447373041
}
Expand Down
7 changes: 6 additions & 1 deletion noir_stdlib/src/ecdsa_secp256k1.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#[foreign(ecdsa_secp256k1)]
pub fn verify_signature<N>(_public_key_x: [u8; 32], _public_key_y: [u8; 32], _signature: [u8; 64], _message_hash: [u8; N]) -> bool {}
pub fn verify_signature<N>(
_public_key_x: [u8; 32],
_public_key_y: [u8; 32],
_signature: [u8; 64],
_message_hash: [u8; N]
) -> bool {}
7 changes: 6 additions & 1 deletion noir_stdlib/src/ecdsa_secp256r1.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#[foreign(ecdsa_secp256r1)]
pub fn verify_signature<N>(_public_key_x: [u8; 32], _public_key_y: [u8; 32], _signature: [u8; 64], _message_hash: [u8; N]) -> bool {}
pub fn verify_signature<N>(
_public_key_x: [u8; 32],
_public_key_y: [u8; 32],
_signature: [u8; 64],
_message_hash: [u8; N]
) -> bool {}
9 changes: 8 additions & 1 deletion noir_stdlib/src/hash/poseidon.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ struct PoseidonConfig<M,N> {
mds: [Field; N] // MDS Matrix in row-major order
}

pub fn config<M, N>(t: Field, rf: u8, rp: u8, alpha: Field, ark: [Field; M], mds: [Field; N]) -> PoseidonConfig<M,N> {
pub fn config<M, N>(
t: Field,
rf: u8,
rp: u8,
alpha: Field,
ark: [Field; M],
mds: [Field; N]
) -> PoseidonConfig<M,N> {
// Input checks
let mul = crate::wrapping_mul(t as u8, (rf + rp));
assert(mul == ark.len() as u8);
Expand Down
7 changes: 6 additions & 1 deletion noir_stdlib/src/schnorr.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#[foreign(schnorr_verify)]
pub fn verify_signature<N>(_public_key_x: Field, _public_key_y: Field, _signature: [u8; 64], _message: [u8; N]) -> bool {}
pub fn verify_signature<N>(
_public_key_x: Field,
_public_key_y: Field,
_signature: [u8; 64],
_message: [u8; N]
) -> bool {}
10 changes: 7 additions & 3 deletions noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ fn sha_c(msg: [u32; 16], hash: [u32; 8]) -> [u32; 8] {
let mut out_h: [u32; 8] = hash;
let w = sha_w(msg);
for j in 0..64 {
let t1 = crate::wrapping_add(crate::wrapping_add(crate::wrapping_add(out_h[7], bigma1(out_h[4])),
ch(out_h[4], out_h[5], out_h[6])),
crate::wrapping_add(K[j], w[j]));
let t1 = crate::wrapping_add(
crate::wrapping_add(
crate::wrapping_add(out_h[7], bigma1(out_h[4])),
ch(out_h[4], out_h[5], out_h[6])
),
crate::wrapping_add(K[j], w[j])
);
let t2 = crate::wrapping_add(bigma0(out_h[0]), maj(out_h[0], out_h[1], out_h[2]));
out_h[7] = out_h[6];
out_h[6] = out_h[5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,39 @@ fn main() {
// This test only makes sense if Field is the right prime field.
if 21888242871839275222246405745257275088548364400416034343698204186575808495617 == 0 {
// Define Baby Jubjub (ERC-2494) parameters in affine representation
let bjj_affine = AffineCurve::new(168700,
let bjj_affine = AffineCurve::new(
168700,
168696,
Gaffine::new(995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905));
Gaffine::new(
995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905
)
);
// Test addition
let p1_affine = Gaffine::new(17777552123799933955779906779655732241715742912184938656739573121738514868268,
2626589144620713026669568689430873010625803728049924121243784502389097019475);
let p2_affine = Gaffine::new(16540640123574156134436876038791482806971768689494387082833631921987005038935,
20819045374670962167435360035096875258406992893633759881276124905556507972311);
let p1_affine = Gaffine::new(
17777552123799933955779906779655732241715742912184938656739573121738514868268,
2626589144620713026669568689430873010625803728049924121243784502389097019475
);
let p2_affine = Gaffine::new(
16540640123574156134436876038791482806971768689494387082833631921987005038935,
20819045374670962167435360035096875258406992893633759881276124905556507972311
);

let p3_affine = bjj_affine.add(p1_affine, p2_affine);
assert(p3_affine.eq(Gaffine::new(7916061937171219682591368294088513039687205273691143098332585753343424131937,
14035240266687799601661095864649209771790948434046947201833777492504781204499)));
assert(p3_affine.eq(
Gaffine::new(
7916061937171219682591368294088513039687205273691143098332585753343424131937,
14035240266687799601661095864649209771790948434046947201833777492504781204499
)
));
// Test scalar multiplication
let p4_affine = bjj_affine.mul(2, p1_affine);
assert(p4_affine.eq(Gaffine::new(6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889)));
assert(p4_affine.eq(
Gaffine::new(
6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889
)
));
assert(p4_affine.eq(bjj_affine.bit_mul([0, 1], p1_affine)));
// Test subtraction
let p5_affine = bjj_affine.subtract(p3_affine, p3_affine);
Expand Down Expand Up @@ -161,14 +177,22 @@ fn main() {
// Elligator 2 map-to-curve
let ell2_pt_map = bjj_affine.elligator2_map(27);

assert(ell2_pt_map.eq(MGaffine::new(7972459279704486422145701269802978968072470631857513331988813812334797879121,
8142420778878030219043334189293412482212146646099536952861607542822144507872).into_tecurve()));
assert(ell2_pt_map.eq(
MGaffine::new(
7972459279704486422145701269802978968072470631857513331988813812334797879121,
8142420778878030219043334189293412482212146646099536952861607542822144507872
).into_tecurve()
));
// SWU map-to-curve
let swu_pt_map = bjj_affine.swu_map(5, 27);

assert(swu_pt_map.eq(bjj_affine.map_from_swcurve(
SWGaffine::new(2162719247815120009132293839392097468339661471129795280520343931405114293888,
5341392251743377373758788728206293080122949448990104760111875914082289313973)
)));
assert(swu_pt_map.eq(
bjj_affine.map_from_swcurve(
SWGaffine::new(
2162719247815120009132293839392097468339661471129795280520343931405114293888,
5341392251743377373758788728206293080122949448990104760111875914082289313973
)
)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ use dep::std::ec::montcurve::curvegroup::Point as MG;

fn main() {
// Define Baby Jubjub (ERC-2494) parameters in affine representation
let bjj_affine = AffineCurve::new(168700,
let bjj_affine = AffineCurve::new(
168700,
168696,
Gaffine::new(995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905));
Gaffine::new(
995203441582195749578291179787384436505546430278305826713579947235728471134,
5472060717959818805561601436314318772137091100104008585924551046643952123905
)
);
// Test addition
let p1_affine = Gaffine::new(17777552123799933955779906779655732241715742912184938656739573121738514868268,
2626589144620713026669568689430873010625803728049924121243784502389097019475);
let p2_affine = Gaffine::new(16540640123574156134436876038791482806971768689494387082833631921987005038935,
20819045374670962167435360035096875258406992893633759881276124905556507972311);
let p1_affine = Gaffine::new(
17777552123799933955779906779655732241715742912184938656739573121738514868268,
2626589144620713026669568689430873010625803728049924121243784502389097019475
);
let p2_affine = Gaffine::new(
16540640123574156134436876038791482806971768689494387082833631921987005038935,
20819045374670962167435360035096875258406992893633759881276124905556507972311
);
let _p3_affine = bjj_affine.add(p1_affine, p2_affine);
// Test SWCurve equivalents of the above
// First the affine representation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main(x: [u32; 5], mut z: u32, t: u32, index: [Field;5], index2: [Field;5], offset: Field, sublen: Field) {
fn main(
x: [u32; 5], mut z: u32, t: u32, index: [Field;5], index2: [Field;5], offset: Field, sublen: Field
) {
let idx = (z - 5 * t - 5) as Field;
//dynamic array test
dyn_array(x, idx, idx - 3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use dep::std;

unconstrained fn main(a: Field, a_pub_x: pub Field, a_pub_y: pub Field, b: Field, b_pub_x: pub Field, b_pub_y: pub Field) {
unconstrained fn main(
a: Field, a_pub_x: pub Field, a_pub_y: pub Field, b: Field, b_pub_x: pub Field, b_pub_y: pub Field
) {
let mut priv_key = a;
let mut pub_x: Field = a_pub_x;
let mut pub_y: Field = a_pub_y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use dep::std;
// Note: If main has any unsized types, then the verifier will never be able
// to figure out the circuit instance
unconstrained fn main(message: [u8; 10], message_field: Field, pub_key_x: Field, pub_key_y: Field, signature: [u8; 64]) {
unconstrained fn main(
message: [u8; 10], message_field: Field, pub_key_x: Field, pub_key_y: Field, signature: [u8; 64]
) {
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
// Regression for issue #2421
// We want to make sure that we can accurately verify a signature whose message is a slice vs. an array
let message_field_bytes = message_field.to_be_bytes(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ fn main(x: u4) {
if x == 7 {
x - 8;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ fn main(
input_aggregation_object: [Field; 16],
proof_b: [Field; 94]
) -> pub [Field; 16] {
let output_aggregation_object_a = std::verify_proof(verification_key.as_slice(),
let output_aggregation_object_a = std::verify_proof(
verification_key.as_slice(),
proof.as_slice(),
public_inputs.as_slice(),
key_hash,
input_aggregation_object);
input_aggregation_object
);

let output_aggregation_object = std::verify_proof(verification_key.as_slice(),
let output_aggregation_object = std::verify_proof(
verification_key.as_slice(),
proof_b.as_slice(),
public_inputs.as_slice(),
key_hash,
output_aggregation_object_a);
output_aggregation_object_a
);

let mut output = [0; 16];
for i in 0..16 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use dep::std;

fn main(message: [u8;38], hashed_message: [u8;32], pub_key_x: [u8;32], pub_key_y: [u8;32], signature: [u8;64]) {
fn main(
message: [u8;38],
hashed_message: [u8;32],
pub_key_x: [u8;32],
pub_key_y: [u8;32],
signature: [u8;64]
) {
// Hash the message, since secp256k1 expects a hashed_message
let expected = std::hash::sha256(message);
assert(hashed_message == expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use dep::std;

fn main(a: Field, a_pub_x: pub Field, a_pub_y: pub Field, b: Field, b_pub_x: pub Field, b_pub_y: pub Field) {
fn main(
a: Field,
a_pub_x: pub Field,
a_pub_y: pub Field,
b: Field,
b_pub_x: pub Field,
b_pub_y: pub Field
) {
let mut priv_key = a;
let mut pub_x: Field = a_pub_x;
let mut pub_y: Field = a_pub_y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use dep::std;
// Note: If main has any unsized types, then the verifier will never be able
// to figure out the circuit instance
fn main(message: [u8; 10], message_field: Field, pub_key_x: Field, pub_key_y: Field, signature: [u8; 64]) {
fn main(
message: [u8; 10], message_field: Field, pub_key_x: Field, pub_key_y: Field, signature: [u8; 64]
) {
// Regression for issue #2421
// We want to make sure that we can accurately verify a signature whose message is a slice vs. an array
let message_field_bytes = message_field.to_be_bytes(10);
Expand Down
Loading