From 24309200f600ad20a51d9f2c6c53849466fccda4 Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:12:49 +0200 Subject: [PATCH] fix: check for Schnorr null signature (#6226) # Description ## Problem\* Resolves #6218 ## Summary\* return false when signature is null ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- noir_stdlib/src/schnorr.nr | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/noir_stdlib/src/schnorr.nr b/noir_stdlib/src/schnorr.nr index e24aabf3cda..0623f116dea 100644 --- a/noir_stdlib/src/schnorr.nr +++ b/noir_stdlib/src/schnorr.nr @@ -41,6 +41,8 @@ pub fn verify_signature_noir( for i in 0..32 { is_ok &= result[i] == signature[32 + i]; } + } else { + is_ok = false; } is_ok } @@ -92,3 +94,12 @@ fn calculate_signature_challenge( let result = crate::hash::blake2s(hash_input); (r.is_infinite, result) } + +#[test] +fn test_zero_signature() { + let public_key: EmbeddedCurvePoint = EmbeddedCurvePoint { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false }; + let signature: [u8; 64] = [0; 64]; + let message: [u8; _] = [2; 64]; // every message + let verified = verify_signature_noir(public_key, signature, message); + assert(!verified); +}