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

tests ECRecover precalc #519

Merged
merged 2 commits into from
Aug 28, 2023
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
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