Auto merge of #1017 - ebfull:coinbase-must-be-protected, r=ebfull

Enforce that coinbases must be protected

This PR forces miners to place their funds in the private value transfer system, making "transparent coins" opt-in for users, and increasing privacy for all participants on a systemic level.

Closes #101.
This commit is contained in:
zkbot
2016-06-15 03:06:23 +00:00
8 changed files with 114 additions and 17 deletions

View File

@@ -6,6 +6,9 @@
#include "random.h"
#include "uint256.h"
#include "test/test_bitcoin.h"
#include "consensus/validation.h"
#include "main.h"
#include "undo.h"
#include <vector>
#include <map>
@@ -475,4 +478,48 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
BOOST_CHECK(missed_an_entry);
}
BOOST_AUTO_TEST_CASE(coins_coinbase_spends)
{
CCoinsViewTest base;
CCoinsViewCacheTest cache(&base);
// Create coinbase transaction
CMutableTransaction mtx;
mtx.vin.resize(1);
mtx.vin[0].scriptSig = CScript() << OP_1;
mtx.vin[0].nSequence = 0;
mtx.vout.resize(1);
mtx.vout[0].nValue = 500;
mtx.vout[0].scriptPubKey = CScript() << OP_1;
CTransaction tx(mtx);
BOOST_CHECK(tx.IsCoinBase());
CValidationState state;
UpdateCoins(tx, state, cache, 100);
// Create coinbase spend
CMutableTransaction mtx2;
mtx2.vin.resize(1);
mtx2.vin[0].prevout = COutPoint(tx.GetHash(), 0);
mtx2.vin[0].scriptSig = CScript() << OP_1;
mtx2.vin[0].nSequence = 0;
{
CTransaction tx2(mtx2);
BOOST_CHECK(NonContextualCheckInputs(tx2, state, cache, false, SCRIPT_VERIFY_NONE, false, Params().GetConsensus()));
}
mtx2.vout.resize(1);
mtx2.vout[0].nValue = 500;
mtx2.vout[0].scriptPubKey = CScript() << OP_1;
{
CTransaction tx2(mtx2);
BOOST_CHECK(!NonContextualCheckInputs(tx2, state, cache, false, SCRIPT_VERIFY_NONE, false, Params().GetConsensus()));
BOOST_CHECK(state.GetRejectReason() == "bad-txns-coinbase-spend-has-transparent-outputs");
}
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -147,6 +147,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
LOCK(cs_main);
fCheckpointsEnabled = false;
fCoinbaseEnforcedProtectionEnabled = false;
// We can't make transactions until we have inputs
// Therefore, load 100 blocks :)
@@ -415,6 +416,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
delete tx;
fCheckpointsEnabled = true;
fCoinbaseEnforcedProtectionEnabled = true;
}
BOOST_AUTO_TEST_SUITE_END()