Skip to content

Commit

Permalink
feat(ecc): Add Grumpkin curve + refactor fuzzer (#811)
Browse files Browse the repository at this point in the history
* add grumpkin + add fuzzer + refactor fuzzer module

* fmt

* comment for tests to add

* add additional tests

* rm extraneous comment

* add point operate_with test

* fmt
  • Loading branch information
PatStiles authored Mar 6, 2024
1 parent ea74b0a commit 0b8a287
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 10 deletions.
26 changes: 16 additions & 10 deletions fuzz/no_gpu_fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,57 @@ ibig = "0.3.6"
p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3", rev = "41cd843" }
p3-mersenne-31 = { git = "https://github.com/Plonky3/Plonky3", rev = "41cd843" }

[[bin]]
name = "curve_bls12_381"
path = "fuzz_targets/curve/bls12_381.rs"
test = false
doc = false

[[bin]]
name = "curve_bn254"
path = "fuzz_targets/curve_bn254.rs"
path = "fuzz_targets/curve/bn254.rs"
test = false
doc = false

[[bin]]
name = "field_fuzzer"
path = "fuzz_targets/field_fuzzer.rs"
name = "curve_grumpkin"
path = "fuzz_targets/curve/grumpkin.rs"
test = false
doc = false

[[bin]]
name = "curve_bls12_381"
path = "fuzz_targets/curve_bls12_381.rs"
name = "field_fuzzer"
path = "fuzz_targets/field/fuzzer.rs"
test = false
doc = false

[[bin]]
name = "field_fuzz_mersenne31"
path = "fuzz_targets/field_mersenne31.rs"
path = "fuzz_targets/field/mersenne31.rs"
test = false
doc = false

[[bin]]
name = "field_mini_goldilocks"
path = "fuzz_targets/field_mini_goldilocks.rs"
path = "fuzz_targets/field/mini_goldilocks.rs"
test = false
doc = false

[[bin]]
name = "field_from_hex"
path = "fuzz_targets/field_from_hex.rs"
path = "fuzz_targets/field/from_hex.rs"
test = false
doc = false

[[bin]]
name = "field_from_raw"
path = "fuzz_targets/field_from_raw.rs"
path = "fuzz_targets/field/from_raw.rs"
test = false
doc = false

[[bin]]
name = "stark_field_addition"
path = "fuzz_targets/stark_field_addition.rs"
path = "fuzz_targets/field/stark_field_addition.rs"
test = false
doc = false

Expand Down
45 changes: 45 additions & 0 deletions fuzz/no_gpu_fuzz/fuzz_targets/curve/curve_grumpkin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use lambdaworks_math::{
cyclic_group::IsGroup,
elliptic_curve::{
traits::{IsEllipticCurve, IsPairing},
short_weierstrass::{
curves::grumpkin::curve::GrumpkinCurve,
point::ShortWeierstrassProjectivePoint,
}
},
field::element::FieldElement,
};

type LambdaG1 = ShortWeierstrassProjectivePoint<GrumpkinCurve>;

//TODO: derive arbitrary for Affine and Projective or change this to use &[u8] as input to cover more cases
fuzz_target!(|values: (u64, u64)| {
let (a_val, b_val) = values;

let a_g1 = GrumpkinCurve::generator().operate_with_self(a_val);
let b_g1 = GrumpkinCurve::generator().operate_with_self(b_val);

// ***AXIOM SOUNDNESS***
let g1_zero = LambdaG1::neutral_element();

// -O = O
assert_eq!(g1_zero.neg(), g1_zero, "Neutral mul element a failed");

// P * O = O
assert_eq!(a_g1.operate_with(&g1_zero), a_g1, "Neutral operate_with element a failed");
assert_eq!(b_g1.operate_with(&g1_zero), b_g1, "Neutral operate_with element b failed");

// P * Q = Q * P
assert_eq!(a_g1.operate_with(&b_g1), b_g1.operate_with(&a_g1), "Commutative add property failed");

// (P * Q) * R = Q * (P * R)
let c_g1 = a_g1.operate_with(&b_g1);
assert_eq!((a_g1.operate_with(&b_g1)).operate_with(&c_g1), a_g1.operate_with(&b_g1.operate_with(&c_g1)), "Associative operate_with property failed");

// P * -P = O
assert_eq!(a_g1.operate_with(&a_g1.neg()), g1_zero, "Inverse add a failed");
assert_eq!(b_g1.operate_with(&b_g1.neg()), g1_zero, "Inverse add b failed");
});
Loading

0 comments on commit 0b8a287

Please sign in to comment.