From d753a0c7901727b51ab9b3fa7c84d147275662b2 Mon Sep 17 00:00:00 2001 From: joshuayabut Date: Sun, 9 Jul 2017 15:54:05 -0400 Subject: [PATCH] Revert "Merge pull request #96 from dkaidalov/Fix_replay_protection" This reverts commit a1739f1a411e549285773d1ee1858e656bc85563, reversing changes made to 7348fcce47723062c6e41f8a9fa2b1bc64803a42. --- src/Makefile.am | 4 +-- src/Makefile.gtest.include | 3 +-- src/Makefile.test.include | 3 +-- src/script/interpreter.cpp | 3 +-- src/script/standard.cpp | 55 +++++--------------------------------- src/script/standard.h | 3 +++ 6 files changed, 14 insertions(+), 57 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index cb8d0990..8a7b4aec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -449,8 +449,8 @@ zcash_cli_LDADD = \ # # zcash-tx binary # -zcash_tx_SOURCES = bitcoin-tx.cpp script/standard.cpp -zcash_tx_CPPFLAGS = $(BITCOIN_INCLUDES) -DZCASH_TX +zcash_tx_SOURCES = bitcoin-tx.cpp +zcash_tx_CPPFLAGS = $(BITCOIN_INCLUDES) zcash_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) if TARGET_WINDOWS diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index e37f8b51..5bf0d186 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -5,7 +5,6 @@ noinst_PROGRAMS += zcash-gtest # test_checktransaction.cpp MUST be before # any test that calls SelectParams(). zcash_gtest_SOURCES = \ - script/standard.cpp \ gtest/main.cpp \ gtest/utils.cpp \ gtest/test_checktransaction.cpp \ @@ -42,7 +41,7 @@ zcash_gtest_SOURCES += \ wallet/gtest/test_wallet.cpp endif -zcash_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES) -DZCASH_TX +zcash_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES) zcash_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index ccfc718d..d18f2964 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -40,7 +40,6 @@ RAW_TEST_FILES = test/data/alertTests.raw GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h) BITCOIN_TESTS =\ - script/standard.cpp \ test/arith_uint256_tests.cpp \ test/bignum.h \ test/addrman_tests.cpp \ @@ -100,7 +99,7 @@ BITCOIN_TESTS += \ endif test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) -test_test_bitcoin_CPPFLAGS = -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS) -DZCASH_TX +test_test_bitcoin_CPPFLAGS = -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS) test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) if ENABLE_WALLET diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index bc9cdee3..edc379ba 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -380,8 +380,7 @@ bool EvalScript(vector >& stack, const CScript& script, un } case OP_NOP5: { - // If it is OP_CHECKBLOCKATHEIGHT then there are should be 3 args in stack: 2 params and 1 ret value from the prev opcode - if (stack.size() == 3) { + if (stack.size() == 2) { popstack(stack); popstack(stack); } diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 7939c9a1..8d623895 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -5,7 +5,6 @@ #include "script/standard.h" -#include "main.h" #include "pubkey.h" #include "script/script.h" #include "util.h" @@ -27,9 +26,12 @@ const char* GetTxnOutputType(txnouttype t) { case TX_NONSTANDARD: return "nonstandard"; case TX_PUBKEY: return "pubkey"; + case TX_PUBKEY_REPLAY: return "pubkeyreplay"; case TX_PUBKEYHASH: return "pubkeyhash"; + case TX_PUBKEYHASH_REPLAY: return "pubkeyhashreplay"; case TX_SCRIPTHASH: return "scripthash"; case TX_MULTISIG: return "multisig"; + case TX_MULTISIG_REPLAY: return "multisigreplay"; case TX_NULL_DATA: return "nulldata"; } return NULL; @@ -46,15 +48,15 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector vchBlockHash, vchBlockHeight; - // Scan templates const CScript& script1 = scriptPubKey; BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates) @@ -149,52 +148,10 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector nMaxDatacarrierBytes) break; } - else if (opcode2 == OP_NOP5) - { - // Full-fledged implementation of the OP_CHECKBLOCKATHEIGHT opcode for verification of vout's - -#ifndef ZCASH_TX // This is a workaround. zcash-tx does not have access to chain state so no replay protection is possible - - if (vchBlockHeight.size() == 0 || vchBlockHash.size() == 0) - { - LogPrintf("%s: %s: OP_CHECKBLOCKATHEIGHT verification failed. Bad params.", __FILE__, __func__); - break; - } - - const int32_t nHeight = CScriptNum(vchBlockHeight, true, sizeof(int)).getint(); - - if (nHeight < 0 || nHeight > chainActive.Height()) - { - LogPrintf("%s: %s: OP_CHECKBLOCKATHEIGHT verification failed. Transaction is non-final. Referenced height: %d", __FILE__, __func__, nHeight); - break; - } - - CBlockIndex* pblockindex = chainActive[nHeight]; - - vector vchCompareTo(pblockindex->GetBlockHash().begin(), pblockindex->GetBlockHash().end()); - vchCompareTo.erase(vchCompareTo.begin(), vchCompareTo.end() - vchBlockHash.size()); - - if (vchCompareTo != vchBlockHash) - { - LogPrintf("%s: %s: OP_CHECKBLOCKATHEIGHT verification failed. vout block height: %d", __FILE__, __func__, nHeight); - break; - } -#endif - if (opcode1 != opcode2 || vch1 != vch2) - { - break; - } - } else if (opcode1 != opcode2 || vch1 != vch2) { // Others must match exactly diff --git a/src/script/standard.h b/src/script/standard.h index 6d72bad2..3b82fc2c 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -62,9 +62,12 @@ enum txnouttype TX_NONSTANDARD, // 'standard' transaction types: TX_PUBKEY, + TX_PUBKEY_REPLAY, TX_PUBKEYHASH, + TX_PUBKEYHASH_REPLAY, TX_SCRIPTHASH, TX_MULTISIG, + TX_MULTISIG_REPLAY, TX_NULL_DATA, };