Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Consensus] New signatures for network messages #1024

Merged
merged 45 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8550898
[Core] Placeholder block height for activation of new signatures
random-zebra Sep 24, 2019
171c56c
[Refactor] Define messageSigner and hashSigner classes
random-zebra Sep 25, 2019
161392c
[Consensus] New signature for CMasternodePaymentWinner
random-zebra Sep 25, 2019
722af5a
[Trivial] MPW: rename SignatureValid() to CheckSignature()
random-zebra Sep 25, 2019
44edf2d
[Consensus] New signature for CMasternodePing
random-zebra Sep 25, 2019
b30da1c
[Consensus] Include blockhash in CMasternodePing hash
random-zebra Sep 25, 2019
0171209
[Consensus] New signature for CBudgetVote
random-zebra Sep 25, 2019
ac517dc
[Trivial] CBudgetVote: rename SignatureValid() to CheckSignature()
random-zebra Sep 25, 2019
61b1824
[Consensus] New signature for CFinalizedBudgetVote
random-zebra Sep 25, 2019
f8966a7
[Trivial] FBV: rename SignatureValid() to CheckSignature()
random-zebra Sep 25, 2019
a4ac445
[Trivial] constructors with arg list for BV and FBV
random-zebra Sep 26, 2019
3916a0c
[Consensus] New signature for CConsensusVote (SwiftX)
random-zebra Sep 25, 2019
3535544
[Trivial] CConsensusVote: rename SignatureValid() to CheckSignature()
random-zebra Sep 25, 2019
567b4b1
[Trivial] Align the format of the log messages
random-zebra Sep 25, 2019
e2a6ae2
[Consensus] New signature for CMasternodeBroadcast
random-zebra Sep 25, 2019
b3bce53
[Trivial] rename mnb: sig --> vchSig, VerifySignature --> CheckSignature
random-zebra Sep 25, 2019
228b783
[Consensus] New signature for CObfuScationRelay
random-zebra Sep 25, 2019
34d59e8
[Consensus] New signature for CSporkMessage
random-zebra Sep 25, 2019
e45836d
[Core] make signatures private variables in their classes
random-zebra Sep 26, 2019
75f24d3
[Refactor] CFinalizedBudget/Broadcast cleanup constructors
random-zebra Sep 26, 2019
4051846
[Core] Add a field 'nMessVersion' to signed messages
random-zebra Sep 26, 2019
c752a96
[Consensus] add nMessVersion to signature hash
random-zebra Sep 26, 2019
95689d4
[Consensus] Reject old message versions for CMasternodePaymentWinner
random-zebra Sep 26, 2019
d091f25
[Consensus] Reject old message versions for CSporkMessage
random-zebra Sep 26, 2019
a4cee54
[Refactor] define CSignedMessage parent class
random-zebra Sep 27, 2019
73bc65f
[Refactor] CSignedMessage parent of CMasternode and CMasternodePing
random-zebra Sep 27, 2019
a36db49
[Refactor] CSignedMessage parent of CMasternodePaymentWinner
random-zebra Sep 27, 2019
37f8629
[Refactor] CSignedMessage parent of CBudgetVote/CFinalizedBudgetVote
random-zebra Sep 27, 2019
d0c1215
[Refactor] Abstract GetPublicKey in CSignedMessage
random-zebra Sep 27, 2019
3b4f2ed
[Refactor] CSignedMessage parent of CConsensusVote
random-zebra Sep 27, 2019
9e77217
[Refactor] CSignedMessage parent of CObfuscationRelay
random-zebra Sep 27, 2019
294ab82
[Refactor] CSignedMessage parent of CSporkMessage
random-zebra Sep 27, 2019
f01e28e
[Consensus] fNewSigs always defaults to false
random-zebra Sep 27, 2019
8d04cd5
[Fix] Double signatures swap in CMasternode
random-zebra Sep 27, 2019
d4b0d9d
[Fix] remove CMasternode explicit constructor from mnb
random-zebra Oct 1, 2019
0c86ed6
[Fix] default public key for mnb
random-zebra Oct 1, 2019
1db4fe2
[Trivial] better log for CHashSigner::VerifyHash failures
random-zebra Oct 1, 2019
9ab844a
[Fix] mnp sigtime and signature check for mnb in CheckAndUpdate
random-zebra Oct 2, 2019
d6eb7a4
[RPC] fix startmasternode "alias/missing" relay
random-zebra Oct 2, 2019
e4099bd
[RPC] Refactor masternode start/broadcast
random-zebra Oct 2, 2019
1d54b41
[Core] mnb: sign the hex representation of the double hash of the data
random-zebra Oct 7, 2019
640c3c1
[Bug] Fix messages serialization for version MESS_VER_STRMESS
random-zebra Oct 9, 2019
d7b8db0
[RPC] decodemasternodebroadcast: add nMessVersion field for MNB and MNP
random-zebra Oct 9, 2019
152d384
[Trivial][Cleanup] fix a few log lines
random-zebra Oct 10, 2019
7f93bd9
[Trivial] Fix error messages: Setkey -> GetKeysFromSecret
random-zebra Oct 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ set(WALLET_SOURCES
./src/masternode-sync.cpp
./src/masternodeconfig.cpp
./src/masternodeman.cpp
./src/messagesigner.cpp
./src/zpiv/mintpool.cpp
./src/wallet/rpcdump.cpp
./src/zpiv/deterministicmint.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ BITCOIN_CORE_H = \
masternodeman.h \
masternodeconfig.h \
merkleblock.h \
messagesigner.h \
miner.h \
mruset.h \
netbase.h \
Expand Down Expand Up @@ -269,6 +270,7 @@ libbitcoin_wallet_a_SOURCES = \
masternode-sync.cpp \
masternodeconfig.cpp \
masternodeman.cpp \
messagesigner.cpp \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
kernel.cpp \
Expand Down
44 changes: 28 additions & 16 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "masternode.h"
#include "masternodeconfig.h"
#include "masternodeman.h"
#include "messagesigner.h"
#include "protocol.h"
#include "spork.h"

Expand Down Expand Up @@ -100,9 +101,8 @@ void CActiveMasternode::ManageStatus()
CPubKey pubKeyMasternode;
CKey keyMasternode;

if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) {
notCapableReason = "Error upon calling SetKey: " + errorMessage;
LogPrintf("Register::ManageStatus() - %s\n", notCapableReason);
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
LogPrintf("%s : Invalid masternode key", __func__);
return;
}

Expand Down Expand Up @@ -162,15 +162,21 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
CPubKey pubKeyMasternode;
CKey keyMasternode;

if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) {
errorMessage = strprintf("Error upon calling SetKey: %s\n", errorMessage);
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
errorMessage = "Error upon calling GetKeysFromSecret.\n";
return false;
}

LogPrintf("CActiveMasternode::SendMasternodePing() - Relay Masternode Ping vin = %s\n", vin.ToString());

bool fNewSigs = false;
{
LOCK(cs_main);
fNewSigs = chainActive.NewSigsActive();
}

CMasternodePing mnp(vin);
if (!mnp.Sign(keyMasternode, pubKeyMasternode)) {
if (!mnp.Sign(keyMasternode, pubKeyMasternode, fNewSigs)) {
errorMessage = "Couldn't sign Masternode Ping";
return false;
}
Expand Down Expand Up @@ -206,12 +212,12 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)

std::string strMessage = service.ToString() + std::to_string(masterNodeSignatureTime) + std::to_string(false);

if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyMasternode)) {
errorMessage = "dseep sign message failed: " + retErrorMessage;
if (!CMessageSigner::SignMessage(strMessage, vchMasterNodeSignature, keyMasternode)) {
errorMessage = "dseep sign message failed.";
return false;
}

if (!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, retErrorMessage)) {
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dseep verify message failed: " + retErrorMessage;
return false;
}
Expand Down Expand Up @@ -250,8 +256,8 @@ bool CActiveMasternode::CreateBroadcast(std::string strService, std::string strK
return false;
}

if (!obfuScationSigner.SetKey(strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode)) {
errorMessage = strprintf("Can't find keys for masternode %s - %s", strService, errorMessage);
if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternode, pubKeyMasternode)) {
errorMessage = strprintf("Can't find keys for masternode %s", strService);
LogPrintf("CActiveMasternode::CreateBroadcast() - %s\n", errorMessage);
return false;
}
Expand All @@ -278,8 +284,14 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol
// wait for reindex and/or import to finish
if (fImporting || fReindex) return false;

bool fNewSigs = false;
{
LOCK(cs_main);
fNewSigs = chainActive.NewSigsActive();
}

CMasternodePing mnp(vin);
if (!mnp.Sign(keyMasternode, pubKeyMasternode)) {
if (!mnp.Sign(keyMasternode, pubKeyMasternode, fNewSigs)) {
errorMessage = strprintf("Failed to sign ping, vin: %s", vin.ToString());
LogPrintf("CActiveMasternode::CreateBroadcast() - %s\n", errorMessage);
mnb = CMasternodeBroadcast();
Expand All @@ -288,7 +300,7 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol

mnb = CMasternodeBroadcast(service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION);
mnb.lastPing = mnp;
if (!mnb.Sign(keyCollateralAddress)) {
if (!mnb.Sign(keyCollateralAddress, pubKeyCollateralAddress, fNewSigs)) {
errorMessage = strprintf("Failed to sign broadcast, vin: %s", vin.ToString());
LogPrintf("CActiveMasternode::CreateBroadcast() - %s\n", errorMessage);
mnb = CMasternodeBroadcast();
Expand All @@ -313,13 +325,13 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol

std::string strMessage = service.ToString() + std::to_string(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + std::to_string(PROTOCOL_VERSION) + donationAddress + std::to_string(donationPercantage);

if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
errorMessage = "dsee sign message failed: " + retErrorMessage;
if (!CMessageSigner::SignMessage(strMessage, vchMasterNodeSignature, keyCollateralAddress)) {
errorMessage = "dsee sign message failed.";
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) {
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dsee verify message failed: " + retErrorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ class CChain

/** Find the last common block between this chain and a block index entry. */
const CBlockIndex* FindFork(const CBlockIndex* pindex) const;

/** Check if new message signatures are active **/
bool NewSigsActive() { return Params().NewSigsActive(Height()); }
};

#endif // BITCOIN_CHAIN_H
9 changes: 9 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class CMainParams : public CChainParams
// Public coin spend enforcement
nPublicZCSpends = 1880000;

// New P2P messages signatures
nBlockEnforceNewMessageSignatures = 2967000;

// Fake Serial Attack
nFakeSerialBlockheightEnd = 1686229;
nSupplyBeforeFakeSerial = 4131563 * COIN; // zerocoin supply at block nFakeSerialBlockheightEnd
Expand Down Expand Up @@ -318,6 +321,9 @@ class CTestNetParams : public CMainParams
// Public coin spend enforcement
nPublicZCSpends = 1106100;

// New P2P messages signatures
nBlockEnforceNewMessageSignatures = 2214000;

// Fake Serial Attack
nFakeSerialBlockheightEnd = -1;
nSupplyBeforeFakeSerial = 0;
Expand Down Expand Up @@ -411,6 +417,9 @@ class CRegTestParams : public CTestNetParams
// Public coin spend enforcement
nPublicZCSpends = 350;

// New P2P messages signatures
nBlockEnforceNewMessageSignatures = 1;

// Fake Serial Attack
nFakeSerialBlockheightEnd = -1;

Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class CChainParams
int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; }
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
bool IsStakeModifierV2(const int nHeight) const { return nHeight >= nBlockStakeModifierlV2; }
int NewSigsActive(const int nHeight) const { return nHeight >= nBlockEnforceNewMessageSignatures; }

// fake serial attack
int Zerocoin_Block_EndFakeSerial() const { return nFakeSerialBlockheightEnd; }
Expand Down Expand Up @@ -223,6 +224,7 @@ class CChainParams
int nBlockDoubleAccumulated;
int nPublicZCSpends;
int nBlockStakeModifierlV2;
int nBlockEnforceNewMessageSignatures;

// fake serial attack
int nFakeSerialBlockheightEnd = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "masternode-payments.h"
#include "masternodeconfig.h"
#include "masternodeman.h"
#include "messagesigner.h"
#include "miner.h"
#include "net.h"
#include "rpc/server.h"
Expand Down Expand Up @@ -1897,7 +1898,7 @@ bool AppInit2()
CKey key;
CPubKey pubkey;

if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, key, pubkey)) {
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, key, pubkey)) {
return InitError(_("Invalid masternodeprivkey. Please see documenation."));
}

Expand Down
Loading