From 1287eaa0d97dbf9bbe05996abe7f6edd03d274b0 Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Tue, 22 Mar 2016 23:06:10 +0100 Subject: [PATCH] QA: Allow setting the fedpeg script with a command line argument - In both default and regtest modes - The script is stored - BaseSignatureChecker is used to pass it to the interpreter Modified by jtimon --- src/chainparams.cpp | 4 ++++ src/consensus/params.h | 2 ++ src/script/bitcoinconsensus.cpp | 2 +- src/script/interpreter.cpp | 2 +- src/script/interpreter.h | 15 +++++++++++++-- src/script/sigcache.h | 2 +- src/test/sigopcount_tests.cpp | 2 +- src/validation.cpp | 2 +- src/wallet/rpcwallet.cpp | 7 ++----- 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f0dfadf8fb..c9cbafb459 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -70,6 +70,9 @@ public: // Default blocksign script for elements defaultSignblockScript = CScript() << OP_2 << ParseHex("03206b45265ae687dfdc602b8faa7dd749d7865b0e51f986e12c532229f0c998be") << ParseHex("02cc276552e180061f64dc16e2a02e7f9ecbcc744dea84eddbe991721824df825c") << ParseHex("0204c6be425356d9200a3303d95f2c39078cc9473ca49619da1e0ec233f27516ca") << OP_3 << OP_CHECKMULTISIG; CScript genesisChallengeScript = StrHexToScriptWithDefault(GetArg("-signblockscript", ""), defaultSignblockScript); + CScript defaultFedpegScript; + defaultFedpegScript = CScript() << OP_2 << ParseHex("02d51090b27ca8f1cc04984614bd749d8bab6f2a3681318d3fd0dd43b2a39dd774") << ParseHex("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << OP_3 << OP_CHECKMULTISIG; + consensus.fedpegScript = StrHexToScriptWithDefault(GetArg("-fedpegscript", ""), defaultFedpegScript); strNetworkID = CHAINPARAMS_ELEMENTS; consensus.nSubsidyHalvingInterval = 210000; @@ -182,6 +185,7 @@ public: CRegTestParams() { const CScript defaultRegtestScript(CScript() << OP_TRUE); CScript genesisChallengeScript = StrHexToScriptWithDefault(GetArg("-signblockscript", ""), defaultRegtestScript); + consensus.fedpegScript = StrHexToScriptWithDefault(GetArg("-fedpegscript", ""), defaultRegtestScript); strNetworkID = CHAINPARAMS_REGTEST; consensus.nSubsidyHalvingInterval = 150; diff --git a/src/consensus/params.h b/src/consensus/params.h index a6d00987ce..959c0bd761 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_CONSENSUS_PARAMS_H #define BITCOIN_CONSENSUS_PARAMS_H +#include "script/script.h" #include "uint256.h" #include #include @@ -63,6 +64,7 @@ struct Params { int64_t nPowTargetTimespan; int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } uint256 nMinimumChainWork; + CScript fedpegScript; uint256 defaultAssumeValid; }; } // namespace Consensus diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index 9e0b2896e7..3cef8122c8 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -99,7 +99,7 @@ static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptP if (amountPreviousInput.IsAmount() && (amountPreviousInput.GetAmount() < -1 || (nIn != 0 && !MoneyRange(amountPreviousInput.GetAmount())))) return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionNoWithdrawsSignatureChecker(&tx, nIn, amount, txdata), NULL); else - return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionSignatureChecker(&tx, nIn, amount, amountPreviousInput, txdata), NULL); + return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionSignatureChecker(&tx, nIn, amount, amountPreviousInput, txdata, CScript()), NULL); } catch (const std::exception&) { return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing } diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 0d9bcb77e4..1699534f2a 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1165,7 +1165,7 @@ bool EvalScript(vector >& stack, const CScript& script, un return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_FORMAT); opcodetype opcodeTmp; - CScript scriptDestination(CScript() << OP_2 << ParseHex("02d51090b27ca8f1cc04984614bd749d8bab6f2a3681318d3fd0dd43b2a39dd774") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << ParseHex("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << OP_3 << OP_CHECKMULTISIG); + CScript scriptDestination = checker.GetFedpegScript(); { CScript::iterator sdpc = scriptDestination.begin(); vector vch; diff --git a/src/script/interpreter.h b/src/script/interpreter.h index f17001c257..37331c7cd7 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -142,6 +142,12 @@ public: return false; } + virtual CScript GetFedpegScript() const + { + CScript fedpegScript(CScript() << OP_FALSE); + return fedpegScript; + } + virtual bool CheckLockTime(const CScriptNum& nLockTime) const { return false; @@ -204,15 +210,20 @@ class TransactionSignatureChecker : public TransactionNoWithdrawsSignatureChecke { private: const CTxOutValue amountPreviousInput; + const CScript fedpegScript; public: - TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn), amountPreviousInput(amountPreviousInputIn) {} - TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn, const PrecomputedTransactionData& txdataIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn, txdataIn), amountPreviousInput(amountPreviousInputIn) {} + TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} + TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amountIn, const CTxOutValue& amountPreviousInputIn, const PrecomputedTransactionData& txdataIn, const CScript& fedpegScriptIn) : TransactionNoWithdrawsSignatureChecker(txToIn, nInIn, amountIn, txdataIn), amountPreviousInput(amountPreviousInputIn), fedpegScript(fedpegScriptIn) {} CTxOut GetOutputOffsetFromCurrent(const int offset) const; COutPoint GetPrevOut() const; CTxOutValue GetValueIn() const; CTxOutValue GetValueInPrevIn() const; bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements) const; + virtual CScript GetFedpegScript() const + { + return fedpegScript; + } }; bool EvalScript(std::vector >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = NULL); diff --git a/src/script/sigcache.h b/src/script/sigcache.h index c742462bc7..00e160a9a6 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -27,7 +27,7 @@ private: bool store; public: - CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amount, const CTxOutValue& amountPreviousInput, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, amountPreviousInput), store(storeIn) {} + CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CTxOutValue& amount, const CTxOutValue& amountPreviousInput, const CScript& scriptFedRedeem, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, amountPreviousInput, scriptFedRedeem), store(storeIn) {} bool VerifySignature(const std::vector& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const; }; diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index 0a1f4304a6..e104c4b524 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -71,7 +71,7 @@ ScriptError VerifyWithFlag(const CTransaction& output, const CMutableTransaction { ScriptError error; CTransaction inputi(input); - bool ret = VerifyScript(inputi.vin[0].scriptSig, output.vout[0].scriptPubKey, &inputi.vin[0].scriptWitness, flags, TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue, -1), &error); + bool ret = VerifyScript(inputi.vin[0].scriptSig, output.vout[0].scriptPubKey, &inputi.vin[0].scriptWitness, flags, TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue, -1, CScript()), &error); BOOST_CHECK((ret == true) == (error == SCRIPT_ERR_OK)); return error; diff --git a/src/validation.cpp b/src/validation.cpp index 6651d953e9..d54769aab4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1691,7 +1691,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight) bool CScriptCheck::operator()() { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness; - if (!VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, amountPreviousInput, cacheStore, *txdata), &error)) { + if (!VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, amountPreviousInput, Params().GetConsensus().fedpegScript, cacheStore, *txdata), &error)) { return false; } return true; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1a733421ab..2b1f912e51 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,9 +38,6 @@ using namespace std; int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; -//Redeemscript template for alpha fedpeg -static const CScript fedRedeemScript(CScript() << OP_2 << ParseHex("02d51090b27ca8f1cc04984614bd749d8bab6f2a3681318d3fd0dd43b2a39dd774") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << ParseHex("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << OP_3 << OP_CHECKMULTISIG); - std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() @@ -3231,7 +3228,7 @@ UniValue getpeginaddress(const JSONRPCRequest& request) unsigned char nonce[16]; memset(nonce, 0, sizeof(nonce)); unsigned char fullcontract[40]; - CBitcoinAddress destAddr(calculate_contract(fedRedeemScript, address, nonce, fullcontract)); + CBitcoinAddress destAddr(calculate_contract(Params().GetConsensus().fedpegScript, address, nonce, fullcontract)); UniValue fundinginfo(UniValue::VOBJ); @@ -3388,7 +3385,7 @@ UniValue claimpegin(const JSONRPCRequest& request) unsigned char nonce[16]; memset(nonce, 0, sizeof(nonce)); unsigned char fullcontract[40]; - CScript mainchain_script = GetScriptForDestination(calculate_contract(fedRedeemScript, sidechainAddress, &nonce[0], fullcontract)); + CScript mainchain_script = GetScriptForDestination(calculate_contract(Params().GetConsensus().fedpegScript, sidechainAddress, &nonce[0], fullcontract)); unsigned int nOut = 0; for (; nOut < txBTC.vout.size(); nOut++)