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: Add eddsa_poseidon_to_pub function to stdlib with test + docs #4473

Merged
merged 5 commits into from
Mar 5, 2024
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
11 changes: 11 additions & 0 deletions docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ fn eddsa_poseidon_verify(public_key_x : Field, public_key_y : Field, signature_s
```

<BlackBoxInfo />

## eddsa::eddsa_to_pub

Private to public key conversion.

Returns `(pub_key_x, pub_key_y)`

```rust
fn eddsa_to_pub(secret : Field) -> (Field, Field)
```

7 changes: 7 additions & 0 deletions noir_stdlib/src/eddsa.nr
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ pub fn eddsa_poseidon_verify(

left.eq(right)
}

// Returns the public key of the given secret key as (pub_key_x, pub_key_y)
pub fn eddsa_to_pub(secret: Field) -> (Field, Field) {
let bjj = baby_jubjub();
let pub_key = bjj.curve.mul(secret, bjj.curve.gen);
(pub_key.x, pub_key.y)
}
10 changes: 8 additions & 2 deletions test_programs/execution_success/eddsa/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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_poseidon_verify;
use dep::std::eddsa::{eddsa_to_pub, eddsa_poseidon_verify};

fn main(msg: pub Field, _priv_key_a: Field, _priv_key_b: Field) {
// Skip this test for non-bn254 backends
if compat::is_bn254() {
let bjj = baby_jubjub();

let pub_key_a = bjj.curve.mul(_priv_key_a, bjj.curve.gen);
// let pub_key_b = bjj.curve.mul(_priv_key_b, bjj.curve.gen);
let pub_key_b = bjj.curve.mul(_priv_key_b, bjj.curve.gen);
let (pub_key_a_x, pub_key_a_y) = eddsa_to_pub(_priv_key_a);
let (pub_key_b_x, pub_key_b_y) = eddsa_to_pub(_priv_key_b);
assert(TEPoint::new(pub_key_a_x, pub_key_a_y) == pub_key_a);
assert(TEPoint::new(pub_key_b_x, pub_key_b_y) == pub_key_b);
// Manually computed as fields can't use modulo. Importantantly the commitment is within
// the subgroup order. Note that choice of hash is flexible for this step.
// let r_a = hash::pedersen_commitment([_priv_key_a, msg])[0] % bjj.suborder; // modulus computed manually
Expand Down
Loading