From bb1f44f8a636f2b0e377b2e2488ff660be314ce7 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/main.cpp | 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/wallet/rpcwallet.cpp | 7 ++----- 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0e99831028..62176fdd18 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -72,6 +72,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", "", mapArgs), defaultSignblockScript); + CScript defaultFedpegScript; + defaultFedpegScript = CScript() << OP_2 << ParseHex("02d51090b27ca8f1cc04984614bd749d8bab6f2a3681318d3fd0dd43b2a39dd774") << ParseHex("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << OP_3 << OP_CHECKMULTISIG; + consensus.fedpegScript = StrHexToScriptWithDefault(GetArg("-fedpegscript", "", mapArgs), defaultFedpegScript); strNetworkID = CHAINPARAMS_ELEMENTS; consensus.nSubsidyHalvingInterval = 210000; @@ -184,6 +187,7 @@ public: { const CScript defaultRegtestScript(CScript() << OP_TRUE); CScript genesisChallengeScript = StrHexToScriptWithDefault(GetArg("-signblockscript", "", mapArgs), defaultRegtestScript); + consensus.fedpegScript = StrHexToScriptWithDefault(GetArg("-fedpegscript", "", mapArgs), defaultRegtestScript); strNetworkID = CHAINPARAMS_REGTEST; consensus.nSubsidyHalvingInterval = 150; diff --git a/src/consensus/params.h b/src/consensus/params.h index ed295b493b..beb65a1a44 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 @@ -62,6 +63,7 @@ struct Params { int64_t nPowTargetSpacing; int64_t nPowTargetTimespan; int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } + CScript fedpegScript; }; } // namespace Consensus diff --git a/src/main.cpp b/src/main.cpp index f516ed17e6..3046819c5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2263,7 +2263,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight) bool CScriptCheck::operator()() { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; const CScriptWitness *witness = (nIn < ptxTo->wit.vtxinwit.size()) ? &ptxTo->wit.vtxinwit[nIn].scriptWitness : NULL; - 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/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index 2759a798b0..5f266f4f3d 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -89,7 +89,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), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionNoWithdrawsSignatureChecker(&tx, nIn, amount, txdata), NULL); else - return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionSignatureChecker(&tx, nIn, amount, amountPreviousInput), NULL); + return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionSignatureChecker(&tx, nIn, amount, amountPreviousInput, 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 ac8ca4a21b..293ba5996d 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("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << 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 7d7bd16a8d..6fa008cb5e 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 f5f9b7f124..6dfcb9acbd 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -24,7 +24,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 350514a600..89fb3d5c20 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -73,7 +73,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.wit.vtxinwit.size() > 0 ? &inputi.wit.vtxinwit[0].scriptWitness : NULL, flags, TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue, 0), &error); + bool ret = VerifyScript(inputi.vin[0].scriptSig, output.vout[0].scriptPubKey, inputi.wit.vtxinwit.size() > 0 ? &inputi.wit.vtxinwit[0].scriptWitness : NULL, flags, TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue, 0, CScript()), &error); BOOST_CHECK((ret == true) == (error == SCRIPT_ERR_OK)); return error; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 136532ac55..1fffa96bb9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -36,9 +36,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("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << OP_3 << OP_CHECKMULTISIG); - std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() @@ -2815,7 +2812,7 @@ UniValue getpeginaddress(const UniValue& params, bool fHelp) 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); @@ -2970,7 +2967,7 @@ UniValue claimpegin(const UniValue& params, bool fHelp) 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++)