From bcc2d8733580e9c042152325836794b090af523a Mon Sep 17 00:00:00 2001 From: Hans Schmidt Date: Mon, 15 Aug 2022 15:14:12 -0500 Subject: [PATCH] Revert "consensus: correct verification of transactions pre p2sh-asset activation (#1019)" This reverts commit 46aad1a25978e732285bad2c2ba96171bdaa5fec. --- src/consensus/tx_verify.cpp | 16 +++++++--------- src/script/script.cpp | 8 ++------ src/script/script.h | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index 6a1788c58a..f396a7af7e 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -653,19 +653,17 @@ bool Consensus::CheckTxAssets(const CTransaction& tx, CValidationState& state, c int i = 0; for (const auto& txout : tx.vout) { i++; - - // Values are subject to change, by isAssetScript a few lines down. + bool fIsAsset = false; int nType = 0; int nScriptType = 0; - int nStart = 0; bool fIsOwner = false; + if (txout.scriptPubKey.IsAssetScript(nType, nScriptType, fIsOwner)) + fIsAsset = true; - // False until BIP9 consensus activates P2SH for Assets. - bool fP2Active = AreP2SHAssetsAllowed(); - - // Returns true if operations on assets are found in the script. - // It will also possibly change the values of the arguments, as they are passed by reference. - bool fIsAsset = txout.scriptPubKey.IsAssetScript(nType, nScriptType, fIsOwner, nStart, fP2Active); + if (fIsAsset && nScriptType == TX_SCRIPTHASH) { + if (!AreP2SHAssetsAllowed()) + return state.DoS(0, false, REJECT_INVALID, "bad-txns-p2sh-assets-not-active"); + } if (assetCache) { if (fIsAsset && !AreAssetsDeployed()) diff --git a/src/script/script.cpp b/src/script/script.cpp index 77388c0419..158ef652e2 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -250,15 +250,11 @@ bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& isOwner) const return IsAssetScript(nType, nScriptType, isOwner, start); } -bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner, int& nStartingIndex, bool nP2Active) const +bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner, int& nStartingIndex) const { if (this->size() > 31) { // Extra-fast test for pay-to-script-hash CScripts: - if ( (*this)[0] == OP_HASH160 - && (*this)[1] == 0x14 - && (*this)[22] == OP_EQUAL - && nP2Active == true - ) { + if ( (*this)[0] == OP_HASH160 && (*this)[1] == 0x14 && (*this)[22] == OP_EQUAL) { // If this is of the P2SH type, we need to return this type so we know how to interact and solve it nScriptType = TX_SCRIPTHASH; diff --git a/src/script/script.h b/src/script/script.h index 1014ffa2db..def6aeed0e 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -667,7 +667,7 @@ class CScript : public CScriptBase bool IsAssetScript() const; bool IsAssetScript(int& nType, bool& fIsOwner) const; bool IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner) const; - bool IsAssetScript(int& nTXType, int& nScriptType, bool& fIsOwner, int& nStartingIndex, bool nP2Active = true) const; + bool IsAssetScript(int& nTXType, int& nScriptType, bool& fIsOwner, int& nStartingIndex) const; bool IsP2SHAssetScript() const; bool IsNewAsset() const; bool IsOwnerAsset() const;