diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -76,7 +76,7 @@ test/rpc_tests.cpp \ test/sanity_tests.cpp \ test/scheduler_tests.cpp \ - test/script_antireplay_tests.cpp \ + test/script_commitment_tests.cpp \ test/script_P2SH_tests.cpp \ test/script_tests.cpp \ test/script_sighashtype_tests.cpp \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -14,15 +14,6 @@ #include "chainparamsseeds.h" -// Far into the future. -static const std::string ANTI_REPLAY_COMMITMENT = - "Bitcoin: A Peer-to-Peer Electronic Cash System"; - -static std::vector GetAntiReplayCommitment() { - return std::vector(std::begin(ANTI_REPLAY_COMMITMENT), - std::end(ANTI_REPLAY_COMMITMENT)); -} - static CBlock CreateGenesisBlock(const char *pszTimestamp, const CScript &genesisOutputScript, uint32_t nTime, uint32_t nNonce, @@ -106,8 +97,6 @@ consensus.BIP65Height = 388381; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931 consensus.BIP66Height = 363725; - consensus.antiReplayOpReturnSunsetHeight = 530000; - consensus.antiReplayOpReturnCommitment = GetAntiReplayCommitment(); consensus.powLimit = uint256S( "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // two weeks @@ -283,8 +272,6 @@ consensus.BIP65Height = 581885; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182 consensus.BIP66Height = 330776; - consensus.antiReplayOpReturnSunsetHeight = 1250000; - consensus.antiReplayOpReturnCommitment = GetAntiReplayCommitment(); consensus.powLimit = uint256S( "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // two weeks @@ -422,8 +409,6 @@ consensus.BIP65Height = 1351; // BIP66 activated on regtest (Used in rpc activation tests) consensus.BIP66Height = 1251; - consensus.antiReplayOpReturnSunsetHeight = 530000; - consensus.antiReplayOpReturnCommitment = GetAntiReplayCommitment(); consensus.powLimit = uint256S( "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // two weeks diff --git a/src/consensus/params.h b/src/consensus/params.h --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -56,10 +56,6 @@ int monolithActivationTime; /** Unix time used for MTP activation of Nov 15 2018, hardfork */ int magneticAnomalyActivationTime; - /** Block height at which OP_RETURN replay protection stops */ - int antiReplayOpReturnSunsetHeight; - /** Committed OP_RETURN value for replay protection */ - std::vector antiReplayOpReturnCommitment; /** * Minimum blocks including miner confirmation of the total of 2016 blocks * in a retargeting period, (nPowTargetTimespan / nPowTargetSpacing) which diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -91,7 +91,7 @@ rpc_tests.cpp sanity_tests.cpp scheduler_tests.cpp - script_antireplay_tests.cpp + script_commitment_tests.cpp script_P2SH_tests.cpp script_tests.cpp script_sighashtype_tests.cpp diff --git a/src/test/script_antireplay_tests.cpp b/src/test/script_antireplay_tests.cpp deleted file mode 100644 --- a/src/test/script_antireplay_tests.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2017 The Bitcoin developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "script/script.h" -#include "test/test_bitcoin.h" - -#include "chainparams.h" -#include "config.h" -#include "consensus/validation.h" -#include "validation.h" - -#include - -#include -#include - -BOOST_FIXTURE_TEST_SUITE(script_antireplay_tests, BasicTestingSetup) - -BOOST_AUTO_TEST_CASE(test_is_commitment) { - std::vector data{}; - - // Empty commitment. - auto s = CScript() << OP_RETURN << data; - BOOST_CHECK(s.IsCommitment(data)); - - // Commitment to a value of the wrong size. - data.push_back(42); - BOOST_CHECK(!s.IsCommitment(data)); - - // Not a commitment. - s = CScript() << data; - BOOST_CHECK(!s.IsCommitment(data)); - - // Non empty commitment. - s = CScript() << OP_RETURN << data; - BOOST_CHECK(s.IsCommitment(data)); - - // Commitment to the wrong value. - data[0] = 0x42; - BOOST_CHECK(!s.IsCommitment(data)); - - // Commitment to a larger value. - std::string str = "Bitcoin: A peer-to-peer Electronic Cash System"; - data = std::vector(str.begin(), str.end()); - BOOST_CHECK(!s.IsCommitment(data)); - - s = CScript() << OP_RETURN << data; - BOOST_CHECK(s.IsCommitment(data)); - - // 64 bytes commitment, still valid. - data.resize(64); - s = CScript() << OP_RETURN << data; - BOOST_CHECK(s.IsCommitment(data)); - - // Commitment is too large. - data.push_back(23); - s = CScript() << OP_RETURN << data; - BOOST_CHECK(!s.IsCommitment(data)); - - // Check with the actual replay commitment we are going to use. - SelectParams(CBaseChainParams::MAIN); - const Consensus::Params ¶ms = Params().GetConsensus(); - s = CScript() << OP_RETURN << params.antiReplayOpReturnCommitment; - BOOST_CHECK(s.IsCommitment(params.antiReplayOpReturnCommitment)); -} - -BOOST_AUTO_TEST_CASE(test_antireplay) { - SelectParams(CBaseChainParams::MAIN); - - GlobalConfig config; - const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); - - // The anti replay rule start at uahfHeight and stops at - // antiReplayOpReturnSunsetHeight. - const int nUAHFHeight = params.uahfHeight; - const int nSunsetHeight = params.antiReplayOpReturnSunsetHeight; - - const int64_t nUAHFStartTime = 123456; - - CMutableTransaction tx; - tx.nVersion = 1; - tx.vin.resize(1); - tx.vin[0].prevout = COutPoint(InsecureRand256(), 0); - tx.vin[0].scriptSig = CScript(); - tx.vout.resize(1); - tx.vout[0].nValue = Amount(1); - tx.vout[0].scriptPubKey = CScript(); - - { - // Base transaction is valid. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, CTransaction(tx), state, - nSunsetHeight, nUAHFStartTime)); - } - - { - // Base transaction is still valid after sunset. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, CTransaction(tx), state, - nSunsetHeight + 1, - nUAHFStartTime)); - } - - { - // Base transaction is valid before the fork. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, CTransaction(tx), state, - nUAHFHeight - 1, - nUAHFStartTime - 1)); - } - - tx.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_0; - - { - // Wrong commitment, still valid. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, CTransaction(tx), state, - nSunsetHeight, nUAHFStartTime)); - } - - tx.vout[0].scriptPubKey = CScript() << OP_RETURN - << params.antiReplayOpReturnCommitment; - - { - // Anti replay commitment, not valid anymore. - CValidationState state; - BOOST_CHECK(!ContextualCheckTransaction(config, CTransaction(tx), state, - nUAHFHeight, nUAHFStartTime)); - BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txn-replay"); - } - - { - // Anti replay commitment, not valid anymore. - CValidationState state; - BOOST_CHECK(!ContextualCheckTransaction(config, CTransaction(tx), state, - nSunsetHeight, nUAHFStartTime)); - BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txn-replay"); - } - - { - // Anti replay commitment, disabled before start time. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction( - config, CTransaction(tx), state, nUAHFHeight - 1, nUAHFStartTime)); - } - - { - // Anti replay commitment, disabled after sunset. - CValidationState state; - BOOST_CHECK(ContextualCheckTransaction(config, CTransaction(tx), state, - nSunsetHeight + 1, - nUAHFStartTime)); - } -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/script_commitment_tests.cpp b/src/test/script_commitment_tests.cpp new file mode 100644 --- /dev/null +++ b/src/test/script_commitment_tests.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2017 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "script/script.h" +#include "test/test_bitcoin.h" + +#include "chainparams.h" +#include "config.h" +#include "consensus/validation.h" +#include "validation.h" + +#include + +#include +#include + +BOOST_FIXTURE_TEST_SUITE(script_commitmenet_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(test_is_commitment) { + std::vector data{}; + + // Empty commitment. + auto s = CScript() << OP_RETURN << data; + BOOST_CHECK(s.IsCommitment(data)); + + // Commitment to a value of the wrong size. + data.push_back(42); + BOOST_CHECK(!s.IsCommitment(data)); + + // Not a commitment. + s = CScript() << data; + BOOST_CHECK(!s.IsCommitment(data)); + + // Non empty commitment. + s = CScript() << OP_RETURN << data; + BOOST_CHECK(s.IsCommitment(data)); + + // Commitment to the wrong value. + data[0] = 0x42; + BOOST_CHECK(!s.IsCommitment(data)); + + // Commitment to a larger value. + std::string str = "Bitcoin: A peer-to-peer Electronic Cash System"; + data = std::vector(str.begin(), str.end()); + BOOST_CHECK(!s.IsCommitment(data)); + + s = CScript() << OP_RETURN << data; + BOOST_CHECK(s.IsCommitment(data)); + + // 64 bytes commitment, still valid. + data.resize(64); + s = CScript() << OP_RETURN << data; + BOOST_CHECK(s.IsCommitment(data)); + + // Commitment is too large. + data.push_back(23); + s = CScript() << OP_RETURN << data; + BOOST_CHECK(!s.IsCommitment(data)); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3622,20 +3622,6 @@ "non-final transaction"); } - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); - - if (IsUAHFenabled(config, nHeight) && - nHeight <= consensusParams.antiReplayOpReturnSunsetHeight) { - for (const CTxOut &o : tx.vout) { - if (o.scriptPubKey.IsCommitment( - consensusParams.antiReplayOpReturnCommitment)) { - return state.DoS(10, false, REJECT_INVALID, "bad-txn-replay", - false, "non playable transaction"); - } - } - } - return true; }