Skip to content

Commit

Permalink
consensus: exception for special cases p2sh-assets.
Browse files Browse the repository at this point in the history
    Make exceptions for pre-p2sh-asset transactions that match previous checks.
  • Loading branch information
fdoving committed May 13, 2021
1 parent 038da6b commit 9d3fde8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,17 @@ bool Consensus::CheckTxAssets(const CTransaction& tx, CValidationState& state, c
for (const auto& txout : tx.vout) {
i++;
bool fIsAsset = false;
bool fIsSpecial = false;
int nType = 0;
int nScriptType = 0;
bool fIsOwner = false;
if (txout.scriptPubKey.IsAssetScript(nType, nScriptType, fIsOwner))
fIsAsset = true;

if (fIsAsset && nScriptType == TX_SCRIPTHASH) {
if(!AreP2SHAssetsAllowed() && txout.scriptPubKey.IsPreP2SHAssetScript())
fIsSpecial = true;

if (fIsAsset && nScriptType == TX_SCRIPTHASH && !fIsSpecial) {
if (!AreP2SHAssetsAllowed())
return state.DoS(0, false, REJECT_INVALID, "bad-txns-p2sh-assets-not-active");
}
Expand Down
15 changes: 15 additions & 0 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& isOwner) const
return IsAssetScript(nType, nScriptType, isOwner, start);
}

bool CScript::IsPreP2SHAssetScript() const
{
// check for special cases, only active pre-p2sh-asset activation.
if( (*this)[0] == OP_HASH160
&& (*this)[1] == 0x14
&& (*this)[22] == OP_EQUAL
&& (*this)[23] == OP_0
&& (*this)[24] == OP_0
&& (*this)[25] == OP_RVN_ASSET
)
return true;
else
return false;
}

bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner, int& nStartingIndex) const
{
if (this->size() > 31) {
Expand Down
1 change: 1 addition & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ class CScript : public CScriptBase
bool IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner) const;
bool IsAssetScript(int& nTXType, int& nScriptType, bool& fIsOwner, int& nStartingIndex) const;
bool IsP2SHAssetScript() const;
bool IsPreP2SHAssetScript() const;
bool IsNewAsset() const;
bool IsOwnerAsset() const;
bool IsReissueAsset() const;
Expand Down

0 comments on commit 9d3fde8

Please sign in to comment.