Skip to content

Commit

Permalink
c backend found u64 overflow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfd committed Jul 15, 2024
1 parent 0fe4a04 commit 4c3b8bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lotordb/src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ static u64 sub(u64 *a, const u64 *b, const u64 *c) {

//
// Multiply
// BUG: Both b[j] and c[k - j] is 18446744073709551615 == u64max
// which is triggered once the run fails. See test howto trigger it repeadedly
static void mul(u64 *a, const u64 *b, const u64 *c) {
u64 r2 = 0, di22 = DIGITS * 2 - 1;
unsigned __int128 r = 0;
Expand Down
5 changes: 5 additions & 0 deletions lotordb/src/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ void test_keys_verify(void) {
uint8_t sig[BYTES * 2], pubkey[BYTES + 1], sec[BYTES], privkey[BYTES], h[BYTES] = {0};
u64 k[BYTES] = {0};
u64rnd_array(h, k, BYTES);
// BUG: uncomment to trigger u64 overflow bug
//for (int i = 0; i < BYTES;++i) {
// h[i] = 66;
// k[i] = 99999999;
//}
assert(keys_make(pubkey, privkey, k));
assert(keys_secr(pubkey, privkey, sec, k));
assert(keys_sign(privkey, h, sig, k));
Expand Down

0 comments on commit 4c3b8bf

Please sign in to comment.