From 4026ea203bdd4a65e56e06043084472ae47d7f19 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 22 Jan 2019 14:12:47 +0100 Subject: [PATCH] Implement VerifyRecoveredSig to allow verifcation of sigs found in P2P messages --- src/llmq/quorums_signing.cpp | 13 +++++++++++++ src/llmq/quorums_signing.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/llmq/quorums_signing.cpp b/src/llmq/quorums_signing.cpp index 1d29890da..08b18f59c 100644 --- a/src/llmq/quorums_signing.cpp +++ b/src/llmq/quorums_signing.cpp @@ -548,4 +548,17 @@ bool CSigningManager::IsConflicting(Consensus::LLMQType llmqType, const uint256& return false; } +bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, const uint256& signedAtTip, const uint256& id, const uint256& msgHash, const CBLSSignature& sig) +{ + auto& llmqParams = Params().GetConsensus().llmqs.at(Params().GetConsensus().llmqTypeForChainLocks); + + auto quorum = quorumManager->SelectQuorum(llmqParams.type, signedAtTip, id); + if (!quorum) { + return false; + } + + uint256 signHash = CLLMQUtils::BuildSignHash(llmqParams.type, quorum->quorumHash, id, msgHash); + return sig.VerifyInsecure(quorum->quorumPublicKey, signHash); +} + } diff --git a/src/llmq/quorums_signing.h b/src/llmq/quorums_signing.h index 33dc16561..e1c4178e1 100644 --- a/src/llmq/quorums_signing.h +++ b/src/llmq/quorums_signing.h @@ -146,6 +146,9 @@ public: bool HasRecoveredSigForId(Consensus::LLMQType llmqType, const uint256& id); bool HasRecoveredSigForSession(const uint256& signHash); bool IsConflicting(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash); + + // Verifies a recovered sig that was signed while the chain tip was at signedAtTip + bool VerifyRecoveredSig(Consensus::LLMQType llmqType, const uint256& signedAtTip, const uint256& id, const uint256& msgHash, const CBLSSignature& sig); }; extern CSigningManager* quorumSigningManager;