From de646890858f06a30fe72ed2ec97e53c5e27e590 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 14:45:34 +0800 Subject: [PATCH 1/4] fix rewards minrelease validation --- src/cc/rewards.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 73f723453..129cbc47f 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -258,11 +258,11 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); + if ( reward == 0 ) + return eval->Invalid("no elegible rewards"); if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( reward == 0 ) - return eval->Invalid("unlock recover no rewards"); - else if ( tx.vout[1].nValue != 10000 ) + if ( tx.vout[1].nValue != 10000 ) return eval->Invalid("wrong marker vour value"); else if ( tx.vout[1].scriptPubKey != tx.vout[0].scriptPubKey ) return eval->Invalid("unlock recover tx vout.1 mismatched scriptPubKey"); From 87b039a2673ad0f0758c5f9c18a23da5084be8b1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 14:56:51 +0800 Subject: [PATCH 2/4] fix --- src/cc/rewards.cpp | 3 +-- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 129cbc47f..152842bbd 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -263,7 +263,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( tx.vout[1].nValue != 10000 ) - return eval->Invalid("wrong marker vour value"); + return eval->Invalid("wrong marker vout value"); else if ( tx.vout[1].scriptPubKey != tx.vout[0].scriptPubKey ) return eval->Invalid("unlock recover tx vout.1 mismatched scriptPubKey"); else if ( tx.vout[0].scriptPubKey != vinTx.vout[1].scriptPubKey ) @@ -285,7 +285,6 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else if ( tx.vout[1].scriptPubKey != vinTx.vout[1].scriptPubKey ) return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; - reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) diff --git a/src/main.cpp b/src/main.cpp index e520ad83f..019507c55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1383,7 +1383,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio } } if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) - return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); + return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-opret-too-big"); nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) return state.DoS(100, error("CheckTransaction(): txout total out of range"), From 394b00366e05193a4e98cc0d1c8f79acfa091f5a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 20:34:55 +0800 Subject: [PATCH 3/4] fixed! --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 152842bbd..bc9464fb8 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -257,9 +257,10 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); + amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); if ( reward == 0 ) - return eval->Invalid("no elegible rewards"); + return eval->Invalid("no eligible rewards"); if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( tx.vout[1].nValue != 10000 ) @@ -284,7 +285,6 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 is CC output"); else if ( tx.vout[1].scriptPubKey != vinTx.vout[1].scriptPubKey ) return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); - amount = vinTx.vout[0].nValue; if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) From fa309e5b0e84c9287556234784d3abce1198c713 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 2 Apr 2019 19:14:51 +0800 Subject: [PATCH 4/4] Add context flag to stop checking twice --- src/chain.h | 5 ++++- src/main.cpp | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/chain.h b/src/chain.h index ee56c7662..d810ed4cb 100644 --- a/src/chain.h +++ b/src/chain.h @@ -102,6 +102,9 @@ enum BlockStatus: uint32_t { //! Scripts & signatures ok. Implies all parents are also at least SCRIPTS. BLOCK_VALID_SCRIPTS = 5, + // flag to check if contextual check block has passed in Accept block, if it has not check at connect block. + BLOCK_VALID_CONTEXT = 6, + //! All validity bits. BLOCK_VALID_MASK = BLOCK_VALID_HEADER | BLOCK_VALID_TREE | BLOCK_VALID_TRANSACTIONS | BLOCK_VALID_CHAIN | BLOCK_VALID_SCRIPTS, @@ -115,7 +118,7 @@ enum BlockStatus: uint32_t { BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, BLOCK_ACTIVATES_UPGRADE = 128, //! block activates a network upgrade - BLOCK_IN_TMPFILE = 256 + BLOCK_IN_TMPFILE = 256 }; //! Short-hand for the highest consensus validity we implement. diff --git a/src/main.cpp b/src/main.cpp index 20a963287..e8fe3810c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3274,14 +3274,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - // check pindex->CONTEXT_VALIDATED flag - if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 + if ( fCheckPOW != 0 && (pindex->nStatus & BLOCK_VALID_CONTEXT) != BLOCK_VALID_CONTEXT ) // Activate Jan 15th, 2019 { - fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); - if ( pindex->nTime > 1547510400 ) - return false; - fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); + if ( !ContextualCheckBlock(block, state, pindex->pprev) ) + { + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); + if ( pindex->nTime > 1547510400 ) + return false; + fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); + } else pindex->nStatus |= BLOCK_VALID_CONTEXT; } + // Do this here before the block is moved to the main block files. if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 ) { @@ -5340,7 +5343,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); - if ((!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) + bool fContextualCheckBlock = ContextualCheckBlock(block, state, pindex->pprev); + if ( (!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !fContextualCheckBlock ) { static int32_t saplinght = -1; CBlockIndex *tmpptr; @@ -5365,6 +5369,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C return false; } } + if ( fContextualCheckBlock ) + pindex->nStatus |= BLOCK_VALID_CONTEXT; int nHeight = pindex->GetHeight(); // Temp File fix. LABS has been using this for ages with no bad effects.