use 5+27 length for quadrable keys instead of 9+23

- reduces quadrable branching
- increases collision resistance
- good until year 2514
This commit is contained in:
Doug Hoyte
2023-01-25 16:31:31 -05:00
parent 485abee8ed
commit 9e2bc45a46
4 changed files with 7 additions and 4 deletions

2
golpe

Submodule golpe updated: a655f8f5b2...f84f71a2f0

View File

@ -1,3 +1,4 @@
#pragma once
const size_t MAX_SUBID_SIZE = 63;
const size_t MAX_SUBID_SIZE = 63; // Statically allocated size in SubId
const uint64_t MAX_TIMESTAMP = 17179869184; // Safety limit to ensure it can fit in quadrable key. Good until year 2514.

View File

@ -119,7 +119,7 @@ void verifyEventTimestamp(const NostrIndex::Event *flat) {
uint64_t latest = now + cfg().events__rejectEventsNewerThanSeconds;
if (ts < earliest) throw herr("created_at too early");
if (ts > latest) throw herr("created_at too late");
if (ts > latest || ts > MAX_TIMESTAMP) throw herr("created_at too late");
}
void parseAndVerifyEvent(const tao::json::value &origJson, secp256k1_context *secpCtx, bool verifyMsg, bool verifyTime, std::string &flatStr, std::string &jsonStr) {

View File

@ -51,7 +51,9 @@ std::string_view decodeEventPayload(lmdb::txn &txn, Decompressor &decomp, std::s
std::string_view getEventJson(lmdb::txn &txn, Decompressor &decomp, uint64_t levId);
inline quadrable::Key flatEventToQuadrableKey(const NostrIndex::Event *flat) {
return quadrable::Key::fromIntegerAndHash(flat->created_at(), sv(flat->id()).substr(0, 23));
uint64_t timestamp = flat->created_at();
if (timestamp > MAX_TIMESTAMP) throw herr("timestamp is too large to encode in quadrable key");
return quadrable::Key::fromIntegerAndHash(timestamp, sv(flat->id()).substr(0, 27));
}