Merge pull request #773 from gavinandresen/p2shSigOpCount
authorGavin Andresen <gavinandresen@gmail.com>
Wed, 25 Jan 2012 13:21:20 +0000 (05:21 -0800)
committerGavin Andresen <gavinandresen@gmail.com>
Wed, 25 Jan 2012 13:21:20 +0000 (05:21 -0800)
Simplify counting of P2SH sigops to match BIP 16

1  2 
src/main.cpp
src/main.h

diff --cc src/main.cpp
@@@ -500,11 -500,14 +500,14 @@@ bool CTransaction::AcceptToMemoryPool(C
          }
  
          // Check for non-standard pay-to-script-hash in inputs
 -        if (!AreInputsStandard(mapInputs))
 +        if (!AreInputsStandard(mapInputs) && !fTestNet)
              return error("AcceptToMemoryPool() : nonstandard transaction input");
  
+         // Note: if you modify this code to accept non-standard transactions, then
+         // you should add code here to check that the transaction does a
+         // reasonable number of ECDSA signature verifications.
          int64 nFees = GetValueIn(mapInputs)-GetValueOut();
-         int nSigOps = GetSigOpCount(mapInputs);
          unsigned int nSize = ::GetSerializeSize(*this, SER_NETWORK);
  
          // Don't accept it if it can't get into a block
@@@ -1212,17 -1198,18 +1207,19 @@@ bool CBlock::ConnectBlock(CTxDB& txdb, 
          MapPrevTx mapInputs;
          if (!tx.IsCoinBase())
          {
 -            if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs))
 +            bool fInvalid;
 +            if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs, fInvalid))
                  return false;
  
-             int nTxOps = tx.GetSigOpCount(mapInputs);
-             nSigOps += nTxOps;
-             if (nSigOps > MAX_BLOCK_SIGOPS)
-                 return DoS(100, error("ConnectBlock() : too many sigops"));
-             // There is a different MAX_BLOCK_SIGOPS check in AcceptBlock();
-             // a block must satisfy both to make it into the best-chain
-             // (AcceptBlock() is always called before ConnectBlock())
+             if (fStrictPayToScriptHash)
+             {
+                 // Add in sigops done by pay-to-script-hash inputs;
+                 // this is to prevent a "rogue miner" from creating
+                 // an incredibly-expensive-to-validate block.
+                 nSigOps += tx.GetP2SHSigOpCount(mapInputs);
+                 if (nSigOps > MAX_BLOCK_SIGOPS)
+                     return DoS(100, error("ConnectBlock() : too many sigops"));
+             }
  
              nFees += tx.GetValueIn(mapInputs)-tx.GetValueOut();
  
diff --cc src/main.h
Simple merge