From 4c3b8bf73c3228e38687ec7be6702f57f3c3a401 Mon Sep 17 00:00:00 2001 From: Nicklas Boman Date: Mon, 15 Jul 2024 21:34:15 +0200 Subject: [PATCH] c backend found u64 overflow bug --- lotordb/src/keys.c | 2 ++ lotordb/src/tests/tests.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lotordb/src/keys.c b/lotordb/src/keys.c index 336a956..1da984f 100644 --- a/lotordb/src/keys.c +++ b/lotordb/src/keys.c @@ -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; diff --git a/lotordb/src/tests/tests.c b/lotordb/src/tests/tests.c index 12150cf..f13e911 100644 --- a/lotordb/src/tests/tests.c +++ b/lotordb/src/tests/tests.c @@ -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));