Skip to content

Commit

Permalink
[Consensus] Remove Old message format in CMasternodeBroadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Sep 10, 2019
1 parent e815815 commit a1fcd2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
36 changes: 10 additions & 26 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
}

std::string errorMessage = "";
if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetNewStrMessage(), errorMessage)
&& !obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetOldStrMessage(), errorMessage))
if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetStrMessage(), errorMessage))
{
// don't ban for old masternodes, their sigs could be broken because of the bug
nDos = protocolVersion < MIN_PEER_MNANNOUNCE ? 0 : 100;
Expand Down Expand Up @@ -661,11 +660,7 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
std::string errorMessage;
sigTime = GetAdjustedTime();

std::string strMessage;
if(chainActive.Height() < Params().Zerocoin_Block_V2_Start())
strMessage = GetOldStrMessage();
else
strMessage = GetNewStrMessage();
std::string strMessage = GetStrMessage();

if (!obfuScationSigner.SignMessage(strMessage, errorMessage, sig, keyCollateralAddress))
return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage);
Expand All @@ -681,31 +676,20 @@ bool CMasternodeBroadcast::VerifySignature()
{
std::string errorMessage;

if(!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetNewStrMessage(), errorMessage)
&& !obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetOldStrMessage(), errorMessage))
if(!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetStrMessage(), errorMessage))
return error("CMasternodeBroadcast::VerifySignature() - Error: %s", errorMessage);

return true;
}

std::string CMasternodeBroadcast::GetOldStrMessage()
std::string CMasternodeBroadcast::GetStrMessage()
{
std::string strMessage;

std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());
strMessage = addr.ToString() + std::to_string(sigTime) + vchPubKey + vchPubKey2 + std::to_string(protocolVersion);

return strMessage;
}

std:: string CMasternodeBroadcast::GetNewStrMessage()
{
std::string strMessage;

strMessage = addr.ToString() + std::to_string(sigTime) + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + std::to_string(protocolVersion);

return strMessage;
return (addr.ToString() +
std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() +
pubKeyMasternode.GetID().ToString() +
std::to_string(protocolVersion)
);
}

CMasternodePing::CMasternodePing()
Expand Down
3 changes: 1 addition & 2 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ class CMasternodeBroadcast : public CMasternode
bool Sign(CKey& keyCollateralAddress);
bool VerifySignature();
void Relay();
std::string GetOldStrMessage();
std::string GetNewStrMessage();
std::string GetStrMessage();

ADD_SERIALIZE_METHODS;

Expand Down

0 comments on commit a1fcd2a

Please sign in to comment.