From 6cbd375c4fddc0108b72a3092fcd75816305adde Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:16:27 +0000 Subject: [PATCH] feat: switch to using an external noir implementation of Schnorr (#10330) This PR replaces usage of the stdlib implementation of schnorr with the external library https://github.com/noir-lang/schnorr --- .../contracts/schnorr_account_contract/Nargo.toml | 1 + .../contracts/schnorr_account_contract/src/main.nr | 4 +--- .../contracts/schnorr_hardcoded_account_contract/Nargo.toml | 1 + .../contracts/schnorr_hardcoded_account_contract/src/main.nr | 2 +- .../contracts/schnorr_single_key_account_contract/Nargo.toml | 1 + .../schnorr_single_key_account_contract/src/util.nr | 5 ++--- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/schnorr_account_contract/Nargo.toml index 12cf4db0fe8a..1211ad63c05f 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/Nargo.toml @@ -7,3 +7,4 @@ type = "contract" [dependencies] aztec = { path = "../../../aztec-nr/aztec" } authwit = { path = "../../../aztec-nr/authwit" } +schnorr = { tag = "v0.1.1", git = "https://github.com/noir-lang/schnorr" } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr index fdd886d232e9..b040ba5f1fe1 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr @@ -6,8 +6,6 @@ use dep::aztec::macros::aztec; #[aztec] contract SchnorrAccount { - use dep::std; - use dep::authwit::{ account::AccountActions, auth::{compute_authwit_message_hash, compute_authwit_nullifier}, @@ -83,7 +81,7 @@ contract SchnorrAccount { is_infinite: false, }; // Verify signature of the payload bytes - std::schnorr::verify_signature(pub_key, signature, outer_hash.to_be_bytes::<32>()) + schnorr::verify_signature(pub_key, signature, outer_hash.to_be_bytes::<32>()) // docs:end:is_valid_impl } diff --git a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/Nargo.toml index 877f369a8005..771cfa8fd284 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/Nargo.toml @@ -7,3 +7,4 @@ type = "contract" [dependencies] aztec = { path = "../../../aztec-nr/aztec" } authwit = { path = "../../../aztec-nr/authwit" } +schnorr = { tag = "v0.1.1", git = "https://github.com/noir-lang/schnorr" } diff --git a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr index 1bed3b932e72..02582e3e0971 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -45,7 +45,7 @@ contract SchnorrHardcodedAccount { } // Verify signature using hardcoded public key - std::schnorr::verify_signature(public_key, signature, outer_hash.to_be_bytes::<32>()) + schnorr::verify_signature(public_key, signature, outer_hash.to_be_bytes::<32>()) } // docs:end:is-valid } diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/Nargo.toml index 80c39efcba25..161993c5a732 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/Nargo.toml @@ -7,3 +7,4 @@ type = "contract" [dependencies] aztec = { path = "../../../aztec-nr/aztec" } authwit = { path = "../../../aztec-nr/authwit" } +schnorr = { tag = "v0.1.1", git = "https://github.com/noir-lang/schnorr" } diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr index a3610085cea8..e77e943006eb 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr @@ -1,6 +1,6 @@ use crate::auth_oracle::AuthWitness; use dep::aztec::prelude::AztecAddress; -use std::{embedded_curve_ops::EmbeddedCurvePoint, schnorr::verify_signature}; +use std::embedded_curve_ops::EmbeddedCurvePoint; pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddress { let message_bytes: [u8; 32] = message_hash.to_be_bytes(); @@ -11,8 +11,7 @@ pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddres }; // In a single key account contract we re-used ivpk_m as signing key - let verification = verify_signature(public_key, witness.signature, message_bytes); - assert(verification == true); + schnorr::assert_valid_signature(public_key, witness.signature, message_bytes); AztecAddress::compute(witness.keys, witness.partial_address) }