From 8c16880b1562d4e26e5337dcf8dc7b6e0a92988f Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 19 Dec 2016 22:25:20 -0500 Subject: [PATCH] Fix governance hash (#1208) * Add vinMasternode to governance object hash and bump protocols * Add collateral hash to governance object hash * Added signature to object hash * Revert "Add collateral hash to governance object hash" This reverts commit 2f60c280f3ce1e26cb4ab12f8287424b200aab83. --- src/darksend.h | 2 +- src/governance-object.cpp | 28 +++++++++++++++++++++------- src/governance-object.h | 4 +++- src/governance.cpp | 2 +- src/instantx.h | 2 +- src/masternode-payments.h | 2 +- src/version.h | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/darksend.h b/src/darksend.h index 179aea537..4dba557e8 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -19,7 +19,7 @@ static const int PRIVATESEND_QUEUE_TIMEOUT = 30; static const int PRIVATESEND_SIGNING_TIMEOUT = 15; //! minimum peer version accepted by mixing pool -static const int MIN_PRIVATESEND_PEER_PROTO_VERSION = 70203; +static const int MIN_PRIVATESEND_PEER_PROTO_VERSION = 70204; static const CAmount PRIVATESEND_COLLATERAL = 0.001 * COIN; static const CAmount PRIVATESEND_POOL_MAX = 999.999 * COIN; diff --git a/src/governance-object.cpp b/src/governance-object.cpp index 84a331a83..b6cb95007 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -223,6 +223,19 @@ void CGovernanceObject::ClearMasternodeVotes() } } +std::string CGovernanceObject::GetSignatureMessage() const +{ + LOCK(cs); + std::string strMessage = nHashParent.ToString() + "|" + + boost::lexical_cast(nRevision) + "|" + + boost::lexical_cast(nTime) + "|" + + strData + "|" + + vinMasternode.prevout.ToStringShort() + "|" + + nCollateralHash.ToString(); + + return strMessage; +} + void CGovernanceObject::SetMasternodeInfo(const CTxIn& vin) { vinMasternode = vin; @@ -230,11 +243,10 @@ void CGovernanceObject::SetMasternodeInfo(const CTxIn& vin) bool CGovernanceObject::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) { - LOCK(cs); - std::string strError; - uint256 nHash = GetHash(); - std::string strMessage = nHash.ToString(); + std::string strMessage = GetSignatureMessage(); + + LOCK(cs); if(!darkSendSigner.SignMessage(strMessage, vchSig, keyMasternode)) { LogPrintf("CGovernanceObject::Sign -- SignMessage() failed\n"); @@ -255,11 +267,11 @@ bool CGovernanceObject::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) bool CGovernanceObject::CheckSignature(CPubKey& pubKeyMasternode) { - LOCK(cs); std::string strError; - uint256 nHash = GetHash(); - std::string strMessage = nHash.ToString(); + std::string strMessage = GetSignatureMessage(); + + LOCK(cs); if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError); return false; @@ -286,6 +298,8 @@ uint256 CGovernanceObject::GetHash() const ss << nRevision; ss << nTime; ss << strData; + ss << vinMasternode; + ss << vchSig; // fee_tx is left out on purpose uint256 h1 = ss.GetHash(); diff --git a/src/governance-object.h b/src/governance-object.h index 5b5977fcd..5266938ff 100644 --- a/src/governance-object.h +++ b/src/governance-object.h @@ -35,7 +35,7 @@ class CGovernanceObject; class CGovernanceVote; static const int MAX_GOVERNANCE_OBJECT_DATA_SIZE = 16 * 1024; -static const int MIN_GOVERNANCE_PEER_PROTO_VERSION = 70203; +static const int MIN_GOVERNANCE_PEER_PROTO_VERSION = 70204; static const int GOVERNANCE_OBJECT_UNKNOWN = 0; static const int GOVERNANCE_OBJECT_PROPOSAL = 1; @@ -262,6 +262,8 @@ public: bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); bool CheckSignature(CPubKey& pubKeyMasternode); + std::string GetSignatureMessage() const; + // CORE OBJECT FUNCTIONS bool IsValidLocally(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral); diff --git a/src/governance.cpp b/src/governance.cpp index 2676b75d6..afdf047c7 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -28,7 +28,7 @@ std::map mapAskedForGovernanceObject; int nSubmittedFinalBudget; -const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-5"; +const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-6"; CGovernanceManager::CGovernanceManager() : pCurrentBlockIndex(NULL), diff --git a/src/instantx.h b/src/instantx.h index 5ba53fe2b..29991aaf3 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -28,7 +28,7 @@ static const int INSTANTSEND_SIGNATURES_REQUIRED = 6; static const int INSTANTSEND_SIGNATURES_TOTAL = 10; static const int DEFAULT_INSTANTSEND_DEPTH = 5; -static const int MIN_INSTANTSEND_PROTO_VERSION = 70203; +static const int MIN_INSTANTSEND_PROTO_VERSION = 70204; static const CAmount INSTANTSEND_MIN_FEE = 0.001 * COIN; extern bool fEnableInstantSend; diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 56f0d153a..6a81f25d1 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -24,7 +24,7 @@ static const int MNPAYMENTS_SIGNATURES_TOTAL = 10; // V1 - Last protocol version before update // V2 - Newest protocol version static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103; -static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70203; +static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70204; extern CCriticalSection cs_vecPayees; extern CCriticalSection cs_mapMasternodeBlocks; diff --git a/src/version.h b/src/version.h index 4afb571e9..109ba0ebc 100644 --- a/src/version.h +++ b/src/version.h @@ -10,7 +10,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70203; +static const int PROTOCOL_VERSION = 70204; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209;