Why do standard OP_RETURN outputs also need to be IsPushOnly()?

In src/script/solver.cpp in the Bitcoin Core source we find the following snippet:

// Provably prunable, data-carrying output
//
// So long as script passes the IsUnspendable() test and all but the first
// byte passes the IsPushOnly() test we don't care what exactly is in the
// script.
if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) {
    return TxoutType::NULL_DATA;
}

This is used by IsStandard() in policy.cpp along with -datacarriersize to determine if an OP_RETURN transaction is standard.

Why do we care about IsPushOnly()?

Note that the consensus code, before adding a coin to the UTXO set database, only checks IsUnspendable(), which only checks that the first byte is OP_RETURN.

/**
 * Returns whether the script is guaranteed to fail at execution,
 * regardless of the initial stack. This allows outputs to be pruned
 * instantly when entering the UTXO set.
 */
bool IsUnspendable() const
{
    return (size() > 0 && *begin() == OP_RETURN) || (size() > MAX_SCRIPT_SIZE);
}


from Recent Questions - Bitcoin Stack Exchange https://ift.tt/X0tAc82
via IFTTT

Popular posts from this blog

Bitcoin Mining Could Be Strengthening The Ruble, Russian Central Bank Says

Crypto Exec Warns Tokenization Is Moving Faster Than Expected

Bitwise Clients Pour $69M Into Solana as Bulls Fight to Reclaim $200 Resistance Zone