From af710a719559fe4253e0598912638f5212035831 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 10 Dec 2020 17:14:23 +0100 Subject: [PATCH 1/3] bls: Add CBLSWrapper constructor which accepts a byte vecor --- src/bls/bls.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bls/bls.h b/src/bls/bls.h index 17b610ab0910..c1efa3edacf8 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -62,6 +62,10 @@ class CBLSWrapper static NullHash nullHash; cachedHash = nullHash.hash; } + CBLSWrapper(const std::vector& vecBytes) : CBLSWrapper() + { + SetBuf(vecBytes); + } CBLSWrapper(const CBLSWrapper& ref) = default; CBLSWrapper& operator=(const CBLSWrapper& ref) = default; From ce301d28df122b0a663cb575b5f096bd2408cfd5 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 10 Dec 2020 17:24:38 +0100 Subject: [PATCH 2/3] bls: Bring CBLSWrapper::CBLSWrapper in scope of CBLSId, CBLSSecretKey, CBLSPublicKey Allow them to access e.g. the new byte vector consructor. --- src/bls/bls.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bls/bls.h b/src/bls/bls.h index c1efa3edacf8..5b4df18aa22e 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -242,6 +242,7 @@ class CBLSId : public CBLSWrapper using CBLSWrapper::operator=; using CBLSWrapper::operator==; using CBLSWrapper::operator!=; + using CBLSWrapper::CBLSWrapper; CBLSId() {} @@ -258,6 +259,7 @@ class CBLSSecretKey : public CBLSWrapper Date: Thu, 10 Dec 2020 17:19:53 +0100 Subject: [PATCH 3/3] governance|init|privatesend|test: Refactor some BLS instantiations --- src/governance/governance-object.cpp | 4 +--- src/governance/governance-vote.cpp | 5 +---- src/init.cpp | 3 +-- src/privatesend/privatesend.cpp | 12 ++---------- src/test/evo_simplifiedmns_tests.cpp | 9 +++------ 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/governance/governance-object.cpp b/src/governance/governance-object.cpp index ad1e4b6041a4..f48349f767c2 100644 --- a/src/governance/governance-object.cpp +++ b/src/governance/governance-object.cpp @@ -315,9 +315,7 @@ bool CGovernanceObject::Sign(const CBLSSecretKey& key) bool CGovernanceObject::CheckSignature(const CBLSPublicKey& pubKey) const { - CBLSSignature sig; - sig.SetBuf(vchSig); - if (!sig.VerifyInsecure(pubKey, GetSignatureHash())) { + if (!CBLSSignature(vchSig).VerifyInsecure(pubKey, GetSignatureHash())) { LogPrintf("CGovernanceObject::CheckSignature -- VerifyInsecure() failed\n"); return false; } diff --git a/src/governance/governance-vote.cpp b/src/governance/governance-vote.cpp index ea17200539b0..10fa0a2a06b3 100644 --- a/src/governance/governance-vote.cpp +++ b/src/governance/governance-vote.cpp @@ -235,10 +235,7 @@ bool CGovernanceVote::Sign(const CBLSSecretKey& key) bool CGovernanceVote::CheckSignature(const CBLSPublicKey& pubKey) const { - uint256 hash = GetSignatureHash(); - CBLSSignature sig; - sig.SetBuf(vchSig); - if (!sig.VerifyInsecure(pubKey, hash)) { + if (!CBLSSignature(vchSig).VerifyInsecure(pubKey, GetSignatureHash())) { LogPrintf("CGovernanceVote::CheckSignature -- VerifyInsecure() failed\n"); return false; } diff --git a/src/init.cpp b/src/init.cpp index d3fd04a6892b..a0f5a31500c0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2113,8 +2113,7 @@ bool AppInitMain() std::string strMasterNodeBLSPrivKey = gArgs.GetArg("-masternodeblsprivkey", ""); if (!strMasterNodeBLSPrivKey.empty()) { auto binKey = ParseHex(strMasterNodeBLSPrivKey); - CBLSSecretKey keyOperator; - keyOperator.SetBuf(binKey); + CBLSSecretKey keyOperator(binKey); if (!keyOperator.IsValid()) { return InitError(_("Invalid masternodeblsprivkey. Please see documentation.")); } diff --git a/src/privatesend/privatesend.cpp b/src/privatesend/privatesend.cpp index 19b21ac67f96..8cc19cb7f328 100644 --- a/src/privatesend/privatesend.cpp +++ b/src/privatesend/privatesend.cpp @@ -59,11 +59,7 @@ bool CPrivateSendQueue::Sign() bool CPrivateSendQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const { - uint256 hash = GetSignatureHash(); - - CBLSSignature sig; - sig.SetBuf(vchSig); - if (!sig.VerifyInsecure(blsPubKey, hash)) { + if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash())) { LogPrint(BCLog::PRIVATESEND, "CPrivateSendQueue::CheckSignature -- VerifyInsecure() failed\n"); return false; } @@ -109,11 +105,7 @@ bool CPrivateSendBroadcastTx::Sign() bool CPrivateSendBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) const { - uint256 hash = GetSignatureHash(); - - CBLSSignature sig; - sig.SetBuf(vchSig); - if (!sig.VerifyInsecure(blsPubKey, hash)) { + if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash())) { LogPrint(BCLog::PRIVATESEND, "CPrivateSendBroadcastTx::CheckSignature -- VerifyInsecure() failed\n"); return false; } diff --git a/src/test/evo_simplifiedmns_tests.cpp b/src/test/evo_simplifiedmns_tests.cpp index 58cee9682e28..1782c7c4ea90 100644 --- a/src/test/evo_simplifiedmns_tests.cpp +++ b/src/test/evo_simplifiedmns_tests.cpp @@ -23,13 +23,10 @@ BOOST_AUTO_TEST_CASE(simplifiedmns_merkleroots) std::string ip = strprintf("%d.%d.%d.%d", 0, 0, 0, i); Lookup(ip.c_str(), smle.service, i, false); - uint8_t skBuf[CBLSSecretKey::SerSize]; - memset(skBuf, 0, sizeof(skBuf)); - skBuf[0] = (uint8_t)i; - CBLSSecretKey sk; - sk.SetBuf(skBuf, sizeof(skBuf)); + std::vector vecBytes{static_cast(i)}; + vecBytes.resize(CBLSSecretKey::SerSize); - smle.pubKeyOperator.Set(sk.GetPublicKey()); + smle.pubKeyOperator.Set(CBLSSecretKey(vecBytes).GetPublicKey()); smle.keyIDVoting.SetHex(strprintf("%040x", i)); smle.isValid = true;