From 97121f3b994a39c98f339c47e2e6b2d46c37754d Mon Sep 17 00:00:00 2001 From: Ricard Borrell <75077385+rickb80@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:49:28 +0000 Subject: [PATCH] Add uniti tests for ECRecoverPrecalc --- src/ecrecover/ecrecover.cpp | 4 ---- test/sm/ecrecover/ecrecover_test.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ecrecover/ecrecover.cpp b/src/ecrecover/ecrecover.cpp index c8e0a4e75..d3b0b8a77 100644 --- a/src/ecrecover/ecrecover.cpp +++ b/src/ecrecover/ecrecover.cpp @@ -176,8 +176,6 @@ ECRecoverResult ECRecover(mpz_class &signature, mpz_class &r, mpz_class &s, mpz_ } assert(ecrecover_y < FPEC); - // pending: check indeed y^2 has an square root - // parity: int bit0 = mpz_tstbit(ecrecover_y.get_mpz_t(), 0); if (bit0 + ecrecover_v_parity - 1 == 0) @@ -309,8 +307,6 @@ int ECRecoverPrecalc(mpz_class &signature, mpz_class &r, mpz_class &s, mpz_class } assert(ecrecover_y < FPEC); - // pending: check indeed y^2 has an square root - // parity: int bit0 = mpz_tstbit(ecrecover_y.get_mpz_t(), 0); if (bit0 + ecrecover_v_parity - 1 == 0) diff --git a/test/sm/ecrecover/ecrecover_test.cpp b/test/sm/ecrecover/ecrecover_test.cpp index c662e6008..9917eaa11 100644 --- a/test/sm/ecrecover/ecrecover_test.cpp +++ b/test/sm/ecrecover/ecrecover_test.cpp @@ -339,6 +339,22 @@ void ECRecoverTest(void) zklog.error("ECRecoverTest() failed i=" + to_string(i) + " signature=" + ecrecoverTestVectors[i].signature + " address=" + address.get_str(16) + " expectedAddress=" + ecrecoverTestVectors[i].address); failed = true; } + RawFec::Element buffer[1026]; + int precres = ECRecoverPrecalc(signature, r, s, v, ecrecoverTestVectors[i].precompiled, buffer, 2); + if(result != ECR_NO_ERROR ) + { + if(precres != -1) + { + zklog.error("ECRecoverPrecalc() failed i=" + to_string(i) + " signature=" + ecrecoverTestVectors[i].signature + " result=" + to_string(precres) + " expectedResult= -1" ); + failed = true; + } + }else{ + if(precres < 1) + { + zklog.error("ECRecoverPrecalc() failed i=" + to_string(i) + " signature=" + ecrecoverTestVectors[i].signature + " result=" + to_string(precres) + " expectedResult > 0" ); + failed = true; + } + } if (failed) failedTests++; #endif