Skip to content

Commit

Permalink
Remone SPORK_6_NEW_SIGS
Browse files Browse the repository at this point in the history
SPORK_6_NEW_SIGS was only activated in testnet3. Not necessary in mainnet nor in new testnet4.
  • Loading branch information
Krekeler committed Jan 30, 2022
1 parent ed4ce6d commit 394bf89
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 477 deletions.
57 changes: 13 additions & 44 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2018-2022 The Documentchain developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -329,30 +330,15 @@ void CGovernanceObject::SetMasternodeOutpoint(const COutPoint& outpoint)
bool CGovernanceObject::Sign(const CKey& key, const CKeyID& keyID)
{
std::string strError;
std::string strMessage = GetSignatureMessage();
if (!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
LogPrintf("CGovernanceObject::Sign -- SignMessage() failed\n");
return false;
}

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::SignHash(hash, key, vchSig)) {
LogPrintf("CGovernanceObject::Sign -- SignHash() failed\n");
return false;
}

if (!CHashSigner::VerifyHash(hash, keyID, vchSig, strError)) {
LogPrintf("CGovernanceObject::Sign -- VerifyHash() failed, error: %s\n", strError);
return false;
}
} else {
std::string strMessage = GetSignatureMessage();
if (!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
LogPrintf("CGovernanceObject::Sign -- SignMessage() failed\n");
return false;
}

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceObject::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceObject::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false;
}

LogPrint("gobject", "CGovernanceObject::Sign -- pubkey id = %s, masternode = %s\n",
Expand All @@ -364,27 +350,10 @@ bool CGovernanceObject::Sign(const CKey& key, const CKeyID& keyID)
bool CGovernanceObject::CheckSignature(const CKeyID& keyID) const
{
std::string strError;

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::VerifyHash(hash, keyID, vchSig, strError)) {
// could be an old object
std::string strMessage = GetSignatureMessage();

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
// nope, not in old format either
LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
}
} else {
std::string strMessage = GetSignatureMessage();

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
std::string strMessage = GetSignatureMessage();
if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false;
}

return true;
Expand Down
60 changes: 14 additions & 46 deletions src/governance-vote.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2018-2022 The Documentchain developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -148,32 +149,17 @@ uint256 CGovernanceVote::GetSignatureHash() const
bool CGovernanceVote::Sign(const CKey& key, const CKeyID& keyID)
{
std::string strError;
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::to_string(nVoteSignal) + "|" + std::to_string(nVoteOutcome) + "|" + std::to_string(nTime);

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::SignHash(hash, key, vchSig)) {
LogPrintf("CGovernanceVote::Sign -- SignHash() failed\n");
return false;
}

if (!CHashSigner::VerifyHash(hash, keyID, vchSig, strError)) {
LogPrintf("CGovernanceVote::Sign -- VerifyHash() failed, error: %s\n", strError);
return false;
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::to_string(nVoteSignal) + "|" + std::to_string(nVoteOutcome) + "|" + std::to_string(nTime);

if (!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n");
return false;
}
if (!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n");
return false;
}

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false;
}

return true;
Expand All @@ -183,32 +169,14 @@ bool CGovernanceVote::CheckSignature(const CKeyID& keyID) const
{
std::string strError;

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::VerifyHash(hash, keyID, vchSig, strError)) {
// could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::to_string(nVoteSignal) + "|" +
std::to_string(nVoteOutcome) + "|" +
std::to_string(nTime);

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
// nope, not in old format either
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::to_string(nVoteSignal) + "|" +
std::to_string(nVoteOutcome) + "|" +
std::to_string(nTime);

if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
if (!CMessageSigner::VerifyMessage(keyID, vchSig, strMessage, strError)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
return false;
}

return true;
Expand Down
25 changes: 1 addition & 24 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2017 The Dash Core developers
// Copyright (c) 2018-2022 The Documentchain developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -1121,18 +1122,6 @@ bool CTxLockVote::CheckSignature() const
LogPrintf("CTxLockVote::CheckSignature -- VerifyInsecure() failed\n");
return false;
}
} else if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::VerifyHash(hash, infoMn.legacyKeyIDOperator, vchMasternodeSignature, strError)) {
// could be a signature in old format
std::string strMessage = txHash.ToString() + outpoint.ToStringShort();
if (!CMessageSigner::VerifyMessage(infoMn.legacyKeyIDOperator, vchMasternodeSignature, strMessage, strError)) {
// nope, not in old format either
LogPrintf("CTxLockVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false;
}
}
} else {
std::string strMessage = txHash.ToString() + outpoint.ToStringShort();
if (!CMessageSigner::VerifyMessage(infoMn.legacyKeyIDOperator, vchMasternodeSignature, strMessage, strError)) {
Expand All @@ -1156,18 +1145,6 @@ bool CTxLockVote::Sign()
return false;
}
sig.GetBuf(vchMasternodeSignature);
} else if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::SignHash(hash, activeMasternodeInfo.legacyKeyOperator, vchMasternodeSignature)) {
LogPrintf("CTxLockVote::Sign -- SignHash() failed\n");
return false;
}

if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.legacyKeyIDOperator, vchMasternodeSignature, strError)) {
LogPrintf("CTxLockVote::Sign -- VerifyHash() failed, error: %s\n", strError);
return false;
}
} else {
std::string strMessage = txHash.ToString() + outpoint.ToStringShort();

Expand Down
72 changes: 18 additions & 54 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2017 The Dash Core developers
// Copyright (c) 2018-2022 The Documentchain developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -554,33 +555,18 @@ uint256 CMasternodePaymentVote::GetSignatureHash() const
bool CMasternodePaymentVote::Sign()
{
std::string strError;

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if(!CHashSigner::SignHash(hash, activeMasternodeInfo.legacyKeyOperator, vchSig)) {
LogPrintf("CMasternodePaymentVote::%s -- SignHash() failed\n", __func__);
return false;
}

if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.legacyKeyIDOperator, vchSig, strError)) {
LogPrintf("CMasternodePaymentVote::%s -- VerifyHash() failed, error: %s\n", __func__, strError);
return false;
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() +
std::string strMessage = masternodeOutpoint.ToStringShort() +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);

if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternodeInfo.legacyKeyOperator)) {
LogPrintf("CMasternodePaymentVote::%s -- SignMessage() failed\n", __func__);
return false;
}
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternodeInfo.legacyKeyOperator)) {
LogPrintf("CMasternodePaymentVote::%s -- SignMessage() failed\n", __func__);
return false;
}

if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.legacyKeyIDOperator, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePaymentVote::%s -- VerifyMessage() failed, error: %s\n", __func__, strError);
return false;
}
if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.legacyKeyIDOperator, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePaymentVote::%s -- VerifyMessage() failed, error: %s\n", __func__, strError);
return false;
}

return true;
Expand Down Expand Up @@ -1107,41 +1093,19 @@ bool CMasternodePaymentVote::CheckSignature(const CKeyID& keyIDOperator, int nVa
nDos = 0;
std::string strError = "";

if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash();

if (!CHashSigner::VerifyHash(hash, keyIDOperator, vchSig, strError)) {
// could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);
if(!CMessageSigner::VerifyMessage(keyIDOperator, vchSig, strMessage, strError)) {
// nope, not in old format either
// Only ban for future block vote when we are already synced.
// Otherwise it could be the case when MN which signed this vote is using another key now
// and we have no idea about the old one.
if(masternodeSync.IsMasternodeListSynced() && nBlockHeight > nValidationHeight) {
nDos = 20;
}
return error("CMasternodePaymentVote::CheckSignature -- Got bad Masternode payment signature, masternode=%s, error: %s",
masternodeOutpoint.ToStringShort(), strError);
}
}
} else {
std::string strMessage = masternodeOutpoint.ToStringShort() +
std::string strMessage = masternodeOutpoint.ToStringShort() +
std::to_string(nBlockHeight) +
ScriptToAsmStr(payee);

if (!CMessageSigner::VerifyMessage(keyIDOperator, vchSig, strMessage, strError)) {
// Only ban for future block vote when we are already synced.
// Otherwise it could be the case when MN which signed this vote is using another key now
// and we have no idea about the old one.
if(masternodeSync.IsMasternodeListSynced() && nBlockHeight > nValidationHeight) {
nDos = 20;
}
return error("CMasternodePaymentVote::CheckSignature -- Got bad Masternode payment signature, masternode=%s, error: %s",
masternodeOutpoint.ToStringShort(), strError);
if (!CMessageSigner::VerifyMessage(keyIDOperator, vchSig, strMessage, strError)) {
// Only ban for future block vote when we are already synced.
// Otherwise it could be the case when MN which signed this vote is using another key now
// and we have no idea about the old one.
if(masternodeSync.IsMasternodeListSynced() && nBlockHeight > nValidationHeight) {
nDos = 20;
}
return error("CMasternodePaymentVote::CheckSignature -- Got bad Masternode payment signature, masternode=%s, error: %s",
masternodeOutpoint.ToStringShort(), strError);
}

return true;
Expand Down
Loading

0 comments on commit 394bf89

Please sign in to comment.