Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consensus: correct verification of transactions pre p2sh-asset activation #1019

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,19 @@ bool Consensus::CheckTxAssets(const CTransaction& tx, CValidationState& state, c
int i = 0;
for (const auto& txout : tx.vout) {
i++;
bool fIsAsset = false;

// Values are subject to change, by isAssetScript a few lines down.
int nType = 0;
int nScriptType = 0;
int nStart = 0;
bool fIsOwner = false;
if (txout.scriptPubKey.IsAssetScript(nType, nScriptType, fIsOwner))
fIsAsset = true;

if (fIsAsset && nScriptType == TX_SCRIPTHASH) {
if (!AreP2SHAssetsAllowed())
return state.DoS(0, false, REJECT_INVALID, "bad-txns-p2sh-assets-not-active");
}
// 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 (assetCache) {
if (fIsAsset && !AreAssetsDeployed())
Expand Down
8 changes: 6 additions & 2 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,15 @@ 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) const
bool CScript::IsAssetScript(int& nType, int& nScriptType, bool& fIsOwner, int& nStartingIndex, bool nP2Active) 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) {
if ( (*this)[0] == OP_HASH160
&& (*this)[1] == 0x14
&& (*this)[22] == OP_EQUAL
&& nP2Active == true
) {

// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) const;
bool IsAssetScript(int& nTXType, int& nScriptType, bool& fIsOwner, int& nStartingIndex, bool nP2Active = true) const;
bool IsP2SHAssetScript() const;
bool IsNewAsset() const;
bool IsOwnerAsset() const;
Expand Down