Skip to content

Commit

Permalink
Merge pull request #519 from 0xPolygonHermez/rick/test_ECRecover_precalc
Browse files Browse the repository at this point in the history
tests ECRecover precalc
  • Loading branch information
rickb80 authored Aug 28, 2023
2 parents f660c8a + 27b6ecf commit 2de0186
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/ecrecover/ecrecover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/sm/ecrecover/ecrecover_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2de0186

Please sign in to comment.