11
11
#include " chainparams.h"
12
12
#include " checkpoints.h"
13
13
#include " checkqueue.h"
14
+ #include " consensus/consensus.h"
14
15
#include " consensus/validation.h"
15
16
#include " init.h"
16
17
#include " merkleblock.h"
17
18
#include " net.h"
19
+ #include " policy/policy.h"
18
20
#include " pow.h"
19
21
#include " txdb.h"
20
22
#include " txmempool.h"
@@ -605,76 +607,6 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
605
607
return nEvicted;
606
608
}
607
609
608
-
609
-
610
-
611
-
612
-
613
-
614
- bool IsStandardTx (const CTransaction& tx, string& reason)
615
- {
616
- if (tx.nVersion > CTransaction::CURRENT_VERSION || tx.nVersion < 1 ) {
617
- reason = " version" ;
618
- return false ;
619
- }
620
-
621
- // Extremely large transactions with lots of inputs can cost the network
622
- // almost as much to process as they cost the sender in fees, because
623
- // computing signature hashes is O(ninputs*txsize). Limiting transactions
624
- // to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
625
- unsigned int sz = tx.GetSerializeSize (SER_NETWORK, CTransaction::CURRENT_VERSION);
626
- if (sz >= MAX_STANDARD_TX_SIZE) {
627
- reason = " tx-size" ;
628
- return false ;
629
- }
630
-
631
- BOOST_FOREACH (const CTxIn& txin, tx.vin )
632
- {
633
- // Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed
634
- // keys. (remember the 520 byte limit on redeemScript size) That works
635
- // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627
636
- // bytes of scriptSig, which we round off to 1650 bytes for some minor
637
- // future-proofing. That's also enough to spend a 20-of-20
638
- // CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not
639
- // considered standard)
640
- if (txin.scriptSig .size () > 1650 ) {
641
- reason = " scriptsig-size" ;
642
- return false ;
643
- }
644
- if (!txin.scriptSig .IsPushOnly ()) {
645
- reason = " scriptsig-not-pushonly" ;
646
- return false ;
647
- }
648
- }
649
-
650
- unsigned int nDataOut = 0 ;
651
- txnouttype whichType;
652
- BOOST_FOREACH (const CTxOut& txout, tx.vout ) {
653
- if (!::IsStandard (txout.scriptPubKey , whichType)) {
654
- reason = " scriptpubkey" ;
655
- return false ;
656
- }
657
-
658
- if (whichType == TX_NULL_DATA)
659
- nDataOut++;
660
- else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd )) {
661
- reason = " bare-multisig" ;
662
- return false ;
663
- } else if (txout.IsDust (::minRelayTxFee)) {
664
- reason = " dust" ;
665
- return false ;
666
- }
667
- }
668
-
669
- // only one OP_RETURN txout is permitted
670
- if (nDataOut > 1 ) {
671
- reason = " multi-op-return" ;
672
- return false ;
673
- }
674
-
675
- return true ;
676
- }
677
-
678
610
bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
679
611
{
680
612
if (tx.nLockTime == 0 )
@@ -693,74 +625,6 @@ bool CheckFinalTx(const CTransaction &tx)
693
625
return IsFinalTx (tx, chainActive.Height () + 1 , GetAdjustedTime ());
694
626
}
695
627
696
- /* *
697
- * Check transaction inputs to mitigate two
698
- * potential denial-of-service attacks:
699
- *
700
- * 1. scriptSigs with extra data stuffed into them,
701
- * not consumed by scriptPubKey (or P2SH script)
702
- * 2. P2SH scripts with a crazy number of expensive
703
- * CHECKSIG/CHECKMULTISIG operations
704
- */
705
- bool AreInputsStandard (const CTransaction& tx, const CCoinsViewCache& mapInputs)
706
- {
707
- if (tx.IsCoinBase ())
708
- return true ; // Coinbases don't use vin normally
709
-
710
- for (unsigned int i = 0 ; i < tx.vin .size (); i++)
711
- {
712
- const CTxOut& prev = mapInputs.GetOutputFor (tx.vin [i]);
713
-
714
- vector<vector<unsigned char > > vSolutions;
715
- txnouttype whichType;
716
- // get the scriptPubKey corresponding to this input:
717
- const CScript& prevScript = prev.scriptPubKey ;
718
- if (!Solver (prevScript, whichType, vSolutions))
719
- return false ;
720
- int nArgsExpected = ScriptSigArgsExpected (whichType, vSolutions);
721
- if (nArgsExpected < 0 )
722
- return false ;
723
-
724
- // Transactions with extra stuff in their scriptSigs are
725
- // non-standard. Note that this EvalScript() call will
726
- // be quick, because if there are any operations
727
- // beside "push data" in the scriptSig
728
- // IsStandardTx() will have already returned false
729
- // and this method isn't called.
730
- vector<vector<unsigned char > > stack;
731
- if (!EvalScript (stack, tx.vin [i].scriptSig , SCRIPT_VERIFY_NONE, BaseSignatureChecker ()))
732
- return false ;
733
-
734
- if (whichType == TX_SCRIPTHASH)
735
- {
736
- if (stack.empty ())
737
- return false ;
738
- CScript subscript (stack.back ().begin (), stack.back ().end ());
739
- vector<vector<unsigned char > > vSolutions2;
740
- txnouttype whichType2;
741
- if (Solver (subscript, whichType2, vSolutions2))
742
- {
743
- int tmpExpected = ScriptSigArgsExpected (whichType2, vSolutions2);
744
- if (tmpExpected < 0 )
745
- return false ;
746
- nArgsExpected += tmpExpected;
747
- }
748
- else
749
- {
750
- // Any other Script with less than 15 sigops OK:
751
- unsigned int sigops = subscript.GetSigOpCount (true );
752
- // ... extra data left on the stack after execution is OK, too:
753
- return (sigops <= MAX_P2SH_SIGOPS);
754
- }
755
- }
756
-
757
- if (stack.size () != (unsigned int )nArgsExpected)
758
- return false ;
759
- }
760
-
761
- return true ;
762
- }
763
-
764
628
unsigned int GetLegacySigOpCount (const CTransaction& tx)
765
629
{
766
630
unsigned int nSigOps = 0 ;
0 commit comments