From f7a3ea9dae003168fea9bda5b8e27c8003c91d15 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Thu, 7 Feb 2019 13:31:19 +0100 Subject: [PATCH 1/4] Fix bug on AcceptBlock when pindex is null Signed-off-by: cevap --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e68c0cae0..425c6f328 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4465,7 +4465,7 @@ bool ContextualCheckZerocoinStake(int nHeight, CStakeInput* stake) return error("%s: failed to get index associated with xION stake checksum", __func__); if (chainActive.Height() - pindexFrom->nHeight < Params().Zerocoin_RequiredStakeDepth()) - return error("%s: xION stake does not have required confirmation depth", __func__); + return error("%s: xION stake does not have required confirmation depth. Current height %d, stakeInput height %d.", __func__, chainActive.Height(), pindexFrom->nHeight); //The checksum needs to be the exact checksum from 200 blocks ago uint256 nCheckpoint200 = chainActive[nHeight - Params().Zerocoin_RequiredStakeDepth()]->nAccumulatorCheckpoint; @@ -4854,7 +4854,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis CheckBlockIndex (); if (!ret) { // Check spamming - if(pfrom && GetBoolArg("-blockspamfilter", DEFAULT_BLOCK_SPAM_FILTER)) { + if(pindex && pfrom && GetBoolArg("-blockspamfilter", DEFAULT_BLOCK_SPAM_FILTER)) { CNodeState *nodestate = State(pfrom->GetId()); if(nodestate != nullptr) { nodestate->nodeBlocks.onBlockReceived(pindex->nHeight); @@ -4873,6 +4873,9 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis } return error("%s : AcceptBlock FAILED", __func__); } + else { + LogPrintf("%s : AccpetBlock PASSED!", __func__); + } } if (!ActivateBestChain(state, pblock, checked)) From b9e5f55132ece98cd079e2c9bf2b15d446b14f64 Mon Sep 17 00:00:00 2001 From: furszy <5377650+furszy@users.noreply.github.com> Date: Thu, 7 Feb 2019 17:52:39 +0100 Subject: [PATCH 2/4] AcceptBlock() block stored log removed Signed-off-by: cevap --- src/main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 425c6f328..01bf396b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4873,9 +4873,6 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis } return error("%s : AcceptBlock FAILED", __func__); } - else { - LogPrintf("%s : AccpetBlock PASSED!", __func__); - } } if (!ActivateBestChain(state, pblock, checked)) From 110aaa81a1ec0a4df5ff515e9cd710b6fdb99fad Mon Sep 17 00:00:00 2001 From: cevap Date: Thu, 7 Feb 2019 19:49:23 +0100 Subject: [PATCH 3/4] AcceptBlock() reject blocks double spending the coin ref: 6a16049dfa27f7aba0bdeae4f35660daa734bf42 --- src/main.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 01bf396b8..2fbac9d94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4561,25 +4561,47 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, CTransaction &stakeTxIn = block.vtx[1]; + // Inputs + std::vector ionInputs; + std::vector xIONInputs; + + for (CTxIn stakeIn : stakeTxIn.vin) { + if(stakeIn.scriptSig.IsZerocoinSpend()){ + xIONInputs.push_back(stakeIn); + }else{ + ionInputs.push_back(stakeIn); + } + } + const bool hasIONInputs = !ionInputs.empty(); + const bool hasXIONInputs = !xIONInputs.empty(); + // ZC started after PoS. // Check for serial double spent on the same block, TODO: Move this to the proper method.. - if(nHeight >= Params().Zerocoin_StartHeight()) { - vector inBlockSerials; - for (CTransaction tx : block.vtx) { - for (CTxIn in: tx.vin) { + vector inBlockSerials; + for (CTransaction tx : block.vtx) { + for (CTxIn in: tx.vin) { + if(nHeight >= Params().Zerocoin_StartHeight()) { if (in.scriptSig.IsZerocoinSpend()) { CoinSpend spend = TxInToZerocoinSpend(in); // Check for serials double spending in the same block - if (std::find(inBlockSerials.begin(), inBlockSerials.end(), spend.getCoinSerialNumber()) != inBlockSerials.end()) { - return state.DoS(100, error("%s: serial double spent on the same block", __func__)); + if (std::find(inBlockSerials.begin(), inBlockSerials.end(), spend.getCoinSerialNumber()) != + inBlockSerials.end()) { } inBlockSerials.push_back(spend.getCoinSerialNumber()); } } + if(tx.IsCoinStake()) continue; + if(hasIONInputs) + // Check if coinstake input is double spent inside the same block + for (CTxIn ionIn : ionInputs){ + if(ionIn.prevout == in.prevout){ + // double spent coinstake input inside block + return error("%s: double spent coinstake input inside block", __func__); + } + } } - inBlockSerials.clear(); } - + inBlockSerials.clear(); // Check whether is a fork or not if (isBlockFromFork) { From 47be94df8f2d87a4730466ac692db39ceb132042 Mon Sep 17 00:00:00 2001 From: furszy <5377650+furszy@users.noreply.github.com> Date: Tue, 5 Feb 2019 22:10:27 +0100 Subject: [PATCH 4/4] AcceptBlock() reject blocks double spending the coin stake input inside the same block Signed-off-by: cevap --- src/main.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2fbac9d94..092c870ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4609,20 +4609,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, // Start at the block we're adding on to CBlockIndex *prev = pindexPrev; - // Inputs - std::vector ionInputs; - std::vector xIONInputs; - - for (CTxIn stakeIn : stakeTxIn.vin) { - if(stakeIn.scriptSig.IsZerocoinSpend()){ - xIONInputs.push_back(stakeIn); - }else{ - ionInputs.push_back(stakeIn); - } - } - const bool hasIONInputs = !ionInputs.empty(); - const bool hasXIONInputs = !xIONInputs.empty(); - int readBlock = 0; vector vBlockSerials; CBlock bl;