Skip to content

Commit f40d193

Browse files
committed
Merge pull request #4414
a90689f Remove timing-based signature cache unit test (Gavin Andresen)
2 parents 343feec + a90689f commit f40d193

File tree

2 files changed

+1
-88
lines changed

2 files changed

+1
-88
lines changed

src/script.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class CCoins;
2121
class CKeyStore;
2222
class CTransaction;
23-
class CMutableTransaction;
23+
struct CMutableTransaction;
2424

2525
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
2626
static const unsigned int MAX_OP_RETURN_RELAY = 40; // bytes

src/test/DoS_tests.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -231,91 +231,4 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
231231
BOOST_CHECK(mapOrphanTransactionsByPrev.empty());
232232
}
233233

234-
BOOST_AUTO_TEST_CASE(DoS_checkSig)
235-
{
236-
// Test signature caching code (see key.cpp Verify() methods)
237-
238-
CKey key;
239-
key.MakeNewKey(true);
240-
CBasicKeyStore keystore;
241-
keystore.AddKey(key);
242-
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
243-
244-
// 100 orphan transactions:
245-
static const int NPREV=100;
246-
CMutableTransaction orphans[NPREV];
247-
for (int i = 0; i < NPREV; i++)
248-
{
249-
CMutableTransaction& tx = orphans[i];
250-
tx.vin.resize(1);
251-
tx.vin[0].prevout.n = 0;
252-
tx.vin[0].prevout.hash = GetRandHash();
253-
tx.vin[0].scriptSig << OP_1;
254-
tx.vout.resize(1);
255-
tx.vout[0].nValue = 1*CENT;
256-
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
257-
258-
AddOrphanTx(tx);
259-
}
260-
261-
// Create a transaction that depends on orphans:
262-
CMutableTransaction tx;
263-
tx.vout.resize(1);
264-
tx.vout[0].nValue = 1*CENT;
265-
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
266-
tx.vin.resize(NPREV);
267-
for (unsigned int j = 0; j < tx.vin.size(); j++)
268-
{
269-
tx.vin[j].prevout.n = 0;
270-
tx.vin[j].prevout.hash = orphans[j].GetHash();
271-
}
272-
// Creating signatures primes the cache:
273-
boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
274-
for (unsigned int j = 0; j < tx.vin.size(); j++)
275-
BOOST_CHECK(SignSignature(keystore, orphans[j], tx, j));
276-
boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time();
277-
boost::posix_time::time_duration msdiff = mst2 - mst1;
278-
long nOneValidate = msdiff.total_milliseconds();
279-
if (fDebug) printf("DoS_Checksig sign: %ld\n", nOneValidate);
280-
281-
// ... now validating repeatedly should be quick:
282-
// 2.8GHz machine, -g build: Sign takes ~760ms,
283-
// uncached Verify takes ~250ms, cached Verify takes ~50ms
284-
// (for 100 single-signature inputs)
285-
mst1 = boost::posix_time::microsec_clock::local_time();
286-
for (unsigned int i = 0; i < 5; i++)
287-
for (unsigned int j = 0; j < tx.vin.size(); j++)
288-
BOOST_CHECK(VerifySignature(CCoins(orphans[j], MEMPOOL_HEIGHT), tx, j, flags, SIGHASH_ALL));
289-
mst2 = boost::posix_time::microsec_clock::local_time();
290-
msdiff = mst2 - mst1;
291-
long nManyValidate = msdiff.total_milliseconds();
292-
if (fDebug) printf("DoS_Checksig five: %ld\n", nManyValidate);
293-
294-
BOOST_CHECK_MESSAGE(nManyValidate < nOneValidate, "Signature cache timing failed");
295-
296-
// Empty a signature, validation should fail:
297-
CScript save = tx.vin[0].scriptSig;
298-
tx.vin[0].scriptSig = CScript();
299-
BOOST_CHECK(!VerifySignature(CCoins(orphans[0], MEMPOOL_HEIGHT), tx, 0, flags, SIGHASH_ALL));
300-
tx.vin[0].scriptSig = save;
301-
302-
// Swap signatures, validation should fail:
303-
std::swap(tx.vin[0].scriptSig, tx.vin[1].scriptSig);
304-
BOOST_CHECK(!VerifySignature(CCoins(orphans[0], MEMPOOL_HEIGHT), tx, 0, flags, SIGHASH_ALL));
305-
BOOST_CHECK(!VerifySignature(CCoins(orphans[1], MEMPOOL_HEIGHT), tx, 1, flags, SIGHASH_ALL));
306-
std::swap(tx.vin[0].scriptSig, tx.vin[1].scriptSig);
307-
308-
// Exercise -maxsigcachesize code:
309-
mapArgs["-maxsigcachesize"] = "10";
310-
// Generate a new, different signature for vin[0] to trigger cache clear:
311-
CScript oldSig = tx.vin[0].scriptSig;
312-
BOOST_CHECK(SignSignature(keystore, orphans[0], tx, 0));
313-
BOOST_CHECK(tx.vin[0].scriptSig != oldSig);
314-
for (unsigned int j = 0; j < tx.vin.size(); j++)
315-
BOOST_CHECK(VerifySignature(CCoins(orphans[j], MEMPOOL_HEIGHT), tx, j, flags, SIGHASH_ALL));
316-
mapArgs.erase("-maxsigcachesize");
317-
318-
LimitOrphanTxSize(0);
319-
}
320-
321234
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)