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

feat(stdlib)!: eddsa function using turbofish #5050

Merged
merged 71 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
04ea5d0
Add turbofish operator; add stack overflow crash
jfecher Nov 21, 2023
3a95229
Fix parsing error
jfecher Nov 22, 2023
427cb95
Add test
jfecher Nov 22, 2023
3ab58b8
Add compiler error for incorrect generic count
jfecher Nov 22, 2023
8fc453a
Edit example to have a more problematic case
jfecher Nov 22, 2023
4050fe5
Merge branch 'master' into jf/turbofish
TomAFrench Dec 11, 2023
b9673b2
resolved merge conflicts
vezenovm May 14, 2024
b289b87
fixup remaining fmt stuff
vezenovm May 14, 2024
6127baf
cleanup
vezenovm May 14, 2024
9ebb3b5
cargo fmt
vezenovm May 14, 2024
c652541
working initial turbofish tests
vezenovm May 14, 2024
9660360
cargo fmt
vezenovm May 14, 2024
4cee817
nargo fmt
vezenovm May 15, 2024
e89cde2
clippy
vezenovm May 15, 2024
a2da705
fmt
vezenovm May 15, 2024
da23029
nargo fmt
vezenovm May 15, 2024
da26bc3
fix nargo fmt for turbofish on method calls
vezenovm May 15, 2024
77dfc19
clippy
vezenovm May 15, 2024
0e5a579
initial work to get calling trait methods working, decided this would…
vezenovm May 15, 2024
c17e834
working turbofish with implicit generics now
vezenovm May 16, 2024
8f2be2e
separate out function and implicit generic counts
vezenovm May 16, 2024
405683e
merge conflicts w/ jf/turbofish and working trait methods with mutabl…
vezenovm May 16, 2024
5ad8fb4
cleanup
vezenovm May 16, 2024
e7000d7
Merge branch 'master' into jf/turbofish
vezenovm May 16, 2024
3cbba0b
merge conflicts w/ parent jf/turbofish
vezenovm May 16, 2024
cc135e7
cargo fmt
vezenovm May 16, 2024
a0090c1
cleanup
vezenovm May 16, 2024
954aba7
nargo fmt
vezenovm May 16, 2024
1e22003
add todo comments
vezenovm May 16, 2024
44a4aee
specify type annotation for hasher
vezenovm May 17, 2024
8d5c072
rename
vezenovm May 17, 2024
c6f3057
brought back removed comment
vezenovm May 17, 2024
384e26a
chore: add test for specifying types on function with turbofish
TomAFrench May 17, 2024
98c5d89
chore: add test for using turbofish with generic methods
TomAFrench May 17, 2024
32d1714
chore: add turbofish to cspell
TomAFrench May 17, 2024
dde6d5a
correctly monomorphize turbofish functions
vezenovm May 17, 2024
e26ed36
missed save
vezenovm May 17, 2024
794c082
update eddsa function to use turbofish
vezenovm May 17, 2024
ae12b05
update docs
vezenovm May 17, 2024
9ab7351
nargo fmt tests
vezenovm May 17, 2024
b73d263
fix noirc_frontend tests
vezenovm May 17, 2024
a886946
chore: update formatter test outputs
TomAFrench May 20, 2024
4125804
Revert "chore: update formatter test outputs"
TomAFrench May 20, 2024
bc7abf8
Update compiler/noirc_frontend/src/hir_def/expr.rs
vezenovm May 20, 2024
8b1bbc4
have atom_or_right_unary accept a type parser
vezenovm May 20, 2024
cd1f59e
Merge remote-tracking branch 'origin/jf/turbofish' into jf/turbofish
vezenovm May 20, 2024
bd075fa
clippy and fmt
vezenovm May 20, 2024
b2100ad
Update compiler/noirc_frontend/src/hir/type_check/expr.rs
vezenovm May 20, 2024
0d7fb67
Update test_programs/execution_success/trait_method_mut_self/src/main.nr
vezenovm May 20, 2024
c045540
Update test_programs/execution_success/trait_method_mut_self/src/main.nr
vezenovm May 20, 2024
c6aed8c
fetch implicit generic count from node interner
vezenovm May 20, 2024
9bf4ac2
remove unused method implicit generics map
vezenovm May 20, 2024
22e3cda
add new line to expected formatter tests
vezenovm May 20, 2024
af2c858
fixup after code review
vezenovm May 20, 2024
aa8e49e
fmy and clippy
vezenovm May 20, 2024
af3cc88
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm May 20, 2024
e6850e9
update comment
vezenovm May 20, 2024
e14738b
merge parent
vezenovm May 20, 2024
ca31866
Merge branch 'mv/turbofish-monomorphize-fix' into mv/eddsa-turbofish
vezenovm May 20, 2024
bacb36a
rename to eddsa_verify
vezenovm May 20, 2024
bf07ee8
move where implciit_generic_count is computed
vezenovm May 21, 2024
a9cb6c4
switch to single loop in instantiate_with
vezenovm May 21, 2024
daf151b
rename to turbofish_generics
vezenovm May 21, 2024
0d887de
Merge branch 'master' into jf/turbofish
vezenovm May 21, 2024
8d93a66
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm May 21, 2024
a44782b
Merge branch 'master' into jf/turbofish
vezenovm May 21, 2024
d174e13
Merge branch 'jf/turbofish' into mv/trait-method-reference
vezenovm May 21, 2024
29bb0ae
Merge branch 'mv/trait-method-reference' into mv/turbofish-monomorphi…
vezenovm May 21, 2024
569544c
Merge branch 'mv/turbofish-monomorphize-fix' into mv/eddsa-turbofish
vezenovm May 21, 2024
ea7cc2f
merge w/ master
vezenovm May 21, 2024
0123ac8
delete duplicated function-generic_count
vezenovm May 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Verifier for EdDSA signatures
fn eddsa_poseidon_verify(public_key_x : Field, public_key_y : Field, signature_s: Field, signature_r8_x: Field, signature_r8_y: Field, message: Field) -> bool
```

It is also possible to specify the hash algorithm used for the signature by using the `eddsa_verify_with_hasher` function with a parameter implementing the Hasher trait. For instance, if you want to use Poseidon2 instead, you can do the following:
It is also possible to specify the hash algorithm used for the signature by using the `eddsa_verify` function by passing a type implementing the Hasher trait with the turbofish operator.
For instance, if you want to use Poseidon2 instead, you can do the following:
```rust
use dep::std::hash::poseidon2::Poseidon2Hasher;

let mut hasher = Poseidon2Hasher::default();
eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher);
eddsa_verify::<Poseidon2Hasher>(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg);
```

<BlackBoxInfo />
Expand Down
27 changes: 13 additions & 14 deletions noir_stdlib/src/eddsa.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::ec::consts::te::baby_jubjub;
use crate::ec::tecurve::affine::Point as TEPoint;
use crate::hash::{Hash, Hasher, BuildHasher, BuildHasherDefault};
use crate::hash::poseidon::PoseidonHasher;
use crate::default::Default;

// Returns true if signature is valid
pub fn eddsa_poseidon_verify(
Expand All @@ -13,28 +14,25 @@ pub fn eddsa_poseidon_verify(
signature_r8_y: Field,
message: Field
) -> bool {
let mut hasher = PoseidonHasher::default();
eddsa_verify_with_hasher(
eddsa_verify::<PoseidonHasher>(
pub_key_x,
pub_key_y,
signature_s,
signature_r8_x,
signature_r8_y,
message,
&mut hasher
message
)
}

pub fn eddsa_verify_with_hasher<H>(
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,
hasher: &mut H
message: Field
) -> bool
where H: Hasher {
where H: Hasher + Default {
// Verifies by testing:
// S * B8 = R8 + H(R8, A, m) * A8
let bjj = baby_jubjub();
Expand All @@ -47,12 +45,13 @@ where H: Hasher {
// Ensure S < Subgroup Order
assert(signature_s.lt(bjj.suborder));
// Calculate the h = H(R, A, msg)
signature_r8_x.hash(hasher);
signature_r8_y.hash(hasher);
pub_key_x.hash(hasher);
pub_key_y.hash(hasher);
message.hash(hasher);
let hash: Field = (*hasher).finish();
let mut hasher: H = 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);
Expand Down
5 changes: 2 additions & 3 deletions test_programs/execution_success/eddsa/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::std::compat;
use dep::std::ec::consts::te::baby_jubjub;
use dep::std::ec::tecurve::affine::Point as TEPoint;
use dep::std::hash;
use dep::std::eddsa::{eddsa_to_pub, eddsa_poseidon_verify, eddsa_verify_with_hasher};
use dep::std::eddsa::{eddsa_to_pub, eddsa_poseidon_verify, eddsa_verify};
use dep::std::hash::poseidon2::Poseidon2Hasher;

fn main(msg: pub Field, _priv_key_a: Field, _priv_key_b: Field) {
Expand Down Expand Up @@ -50,7 +50,6 @@ fn main(msg: pub Field, _priv_key_a: Field, _priv_key_b: Field) {
// User A's signature over the message can't be used with another message
assert(!eddsa_poseidon_verify(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg + 1));
// Using a different hash should fail
let mut hasher = Poseidon2Hasher::default();
assert(!eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher));
assert(!eddsa_verify::<Poseidon2Hasher>(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg));
}
}
Loading