Skip to content

Commit f1c87e6

Browse files
committed
Only sporadically verify self-recovered signatures
1 parent b0eae6f commit f1c87e6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/llmq/quorums_signing_shares.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,18 @@ void CSigSharesManager::TryRecoverSig(const CQuorumCPtr& quorum, const uint256&
765765
rs.sig.SetSig(recoveredSig);
766766
rs.UpdateHash();
767767

768-
auto signHash = CLLMQUtils::BuildSignHash(rs);
769-
bool valid = recoveredSig.VerifyInsecure(quorum->qc.quorumPublicKey, signHash);
770-
if (!valid) {
771-
// this should really not happen as we have verified all signature shares before
772-
LogPrintf("CSigSharesManager::%s -- own recovered signature is invalid. id=%s, msgHash=%s\n", __func__,
773-
id.ToString(), msgHash.ToString());
774-
return;
768+
// There should actually be no need to verify the self-recovered signatures are it should always succeed. Let's
769+
// however still verify it from time to time, so that we have a chance to catch bugs. We do only this sporadic
770+
// verification because this is unbatched and thus slow verification that happens here.
771+
if (((recoveredSigsCounter++) % 100) == 0) {
772+
auto signHash = CLLMQUtils::BuildSignHash(rs);
773+
bool valid = recoveredSig.VerifyInsecure(quorum->qc.quorumPublicKey, signHash);
774+
if (!valid) {
775+
// this should really not happen as we have verified all signature shares before
776+
LogPrintf("CSigSharesManager::%s -- own recovered signature is invalid. id=%s, msgHash=%s\n", __func__,
777+
id.ToString(), msgHash.ToString());
778+
return;
779+
}
775780
}
776781

777782
quorumSigningManager->ProcessRecoveredSig(-1, rs, quorum, connman);

src/llmq/quorums_signing_shares.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class CSigSharesManager : public CRecoveredSigsListener
361361
FastRandomContext rnd;
362362

363363
int64_t lastCleanupTime{0};
364+
std::atomic<uint32_t> recoveredSigsCounter{0};
364365

365366
public:
366367
CSigSharesManager();

0 commit comments

Comments
 (0)