-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: remove eddsa from stdlib (#6591)
- Loading branch information
1 parent
b934669
commit 8e046af
Showing
6 changed files
with
127 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,61 @@ | ||
use std::eddsa::eddsa_poseidon_verify; | ||
use std::default::Default; | ||
use std::ec::consts::te::baby_jubjub; | ||
use std::ec::tecurve::affine::Point as TEPoint; | ||
use std::hash::Hasher; | ||
use std::hash::poseidon::PoseidonHasher; | ||
|
||
fn main( | ||
msg: pub Field, | ||
pub_key_x: Field, | ||
pub_key_y: Field, | ||
r8_x: Field, | ||
r8_y: Field, | ||
s: Field | ||
s: Field, | ||
) -> pub bool { | ||
eddsa_poseidon_verify(pub_key_x, pub_key_y, s, r8_x, r8_y, msg) | ||
eddsa_verify::<PoseidonHasher>(pub_key_x, pub_key_y, s, r8_x, r8_y, msg) | ||
} | ||
|
||
pub fn eddsa_verify<H>( | ||
pub_key_x: Field, | ||
pub_key_y: Field, | ||
signature_s: Field, | ||
signature_r8_x: Field, | ||
signature_r8_y: Field, | ||
message: Field, | ||
) -> bool | ||
where | ||
H: Hasher + Default, | ||
{ | ||
// Verifies by testing: | ||
// S * B8 = R8 + H(R8, A, m) * A8 | ||
let bjj = baby_jubjub(); | ||
|
||
let pub_key = TEPoint::new(pub_key_x, pub_key_y); | ||
assert(bjj.curve.contains(pub_key)); | ||
|
||
let signature_r8 = TEPoint::new(signature_r8_x, signature_r8_y); | ||
assert(bjj.curve.contains(signature_r8)); | ||
// Ensure S < Subgroup Order | ||
assert(signature_s.lt(bjj.suborder)); | ||
// Calculate the h = H(R, A, msg) | ||
let mut hasher = H::default(); | ||
hasher.write(signature_r8_x); | ||
hasher.write(signature_r8_y); | ||
hasher.write(pub_key_x); | ||
hasher.write(pub_key_y); | ||
hasher.write(message); | ||
let hash: Field = hasher.finish(); | ||
// Calculate second part of the right side: right2 = h*8*A | ||
// Multiply by 8 by doubling 3 times. This also ensures that the result is in the subgroup. | ||
let pub_key_mul_2 = bjj.curve.add(pub_key, pub_key); | ||
let pub_key_mul_4 = bjj.curve.add(pub_key_mul_2, pub_key_mul_2); | ||
let pub_key_mul_8 = bjj.curve.add(pub_key_mul_4, pub_key_mul_4); | ||
// We check that A8 is not zero. | ||
assert(!pub_key_mul_8.is_zero()); | ||
// Compute the right side: R8 + h * A8 | ||
let right = bjj.curve.add(signature_r8, bjj.curve.mul(hash, pub_key_mul_8)); | ||
// Calculate left side of equation left = S * B8 | ||
let left = bjj.curve.mul(signature_s, bjj.base8); | ||
|
||
left.eq(right) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters