Skip to content

Commit 4288e91

Browse files
committed
[POLICY] Add OP_TRUE as a standard output type
This will be used in following commits as the flag for ephemeral anchors, allowing dust values, but also requiring the output to be spend in the same relay package.
1 parent 6eab309 commit 4288e91

File tree

12 files changed

+49
-25
lines changed

12 files changed

+49
-25
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ static RPCHelpMan decodescript()
422422
case TxoutType::WITNESS_V1_TAPROOT:
423423
// don't wrap CTV because P2SH CTV is a hash cycle
424424
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
425+
case TxoutType::ANCHOR:
425426
// Should not be wrapped
426427
return false;
427428
} // no default case, so the compiler can warn about missing cases
@@ -466,6 +467,7 @@ static RPCHelpMan decodescript()
466467
case TxoutType::WITNESS_V1_TAPROOT:
467468
// don't wrap CTV because P2SH CTV is a hash cycle
468469
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
470+
case TxoutType::ANCHOR:
469471
// Should not be wrapped
470472
return false;
471473
} // no default case, so the compiler can warn about missing cases

src/script/script.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,19 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
198198
return subscript.GetSigOpCount(true);
199199
}
200200

201+
bool CScript::IsTrue() const
202+
{
203+
return (this->size() == 1 && (*this)[0] == OP_TRUE);
204+
}
205+
201206
bool CScript::IsPayToBareDefaultCheckTemplateVerifyHash() const
202207
{
203208
// Extra-fast test for pay-to-bare-default-check-template-verify-hash CScripts:
204209
return (this->size() == 34 &&
205210
(*this)[0] == 0x20 &&
206211
(*this)[33] == OP_CHECKTEMPLATEVERIFY);
207212
}
213+
208214
bool CScript::IsPayToScriptHash() const
209215
{
210216
// Extra-fast test for pay-to-script-hash CScripts:

src/script/script.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ class CScript : public CScriptBase
532532
unsigned int GetSigOpCount(const CScript& scriptSig) const;
533533

534534
bool IsPayToBareDefaultCheckTemplateVerifyHash() const;
535+
536+
/*
537+
* OP_TRUE
538+
*/
539+
bool IsTrue() const;
540+
535541
bool IsPayToScriptHash() const;
536542
bool IsPayToWitnessScriptHash() const;
537543
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;

src/script/sign.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
297297
case TxoutType::NULL_DATA:
298298
case TxoutType::WITNESS_UNKNOWN:
299299
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
300+
case TxoutType::ANCHOR:
300301
return false;
301302
case TxoutType::PUBKEY:
302303
if (!CreateSig(creator, sigdata, provider, sig, CPubKey(vSolutions[0]), scriptPubKey, sigversion)) return false;

src/script/standard.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std::string GetTxnOutputType(TxoutType t)
5252
case TxoutType::SCRIPTHASH: return "scripthash";
5353
case TxoutType::MULTISIG: return "multisig";
5454
case TxoutType::NULL_DATA: return "nulldata";
55+
case TxoutType::ANCHOR: return "true";
5556
case TxoutType::WITNESS_V0_KEYHASH: return "witness_v0_keyhash";
5657
case TxoutType::WITNESS_V0_SCRIPTHASH: return "witness_v0_scripthash";
5758
case TxoutType::WITNESS_V1_TAPROOT: return "witness_v1_taproot";
@@ -177,6 +178,8 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
177178
std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
178179
vSolutionsRet.push_back(hashBytes);
179180
return TxoutType::SCRIPTHASH;
181+
} else if (scriptPubKey.IsTrue()) {
182+
return TxoutType::ANCHOR;
180183
}
181184

182185
if (scriptPubKey.IsPayToBareDefaultCheckTemplateVerifyHash()) {
@@ -291,6 +294,7 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
291294
case TxoutType::NULL_DATA:
292295
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
293296
case TxoutType::NONSTANDARD:
297+
case TxoutType::ANCHOR:
294298
return false;
295299
} // no default case, so the compiler can warn about missing cases
296300
assert(false);

src/script/standard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
5151
enum class TxoutType {
5252
NONSTANDARD,
5353
// 'standard' transaction types:
54+
ANCHOR, //!< anyonecanspendable script
5455
PUBKEY,
5556
PUBKEYHASH,
5657
SCRIPTHASH,

src/test/transaction_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
781781
CheckIsStandard(t);
782782
g_dust = CFeeRate{DUST_RELAY_TX_FEE};
783783

784-
t.vout[0].scriptPubKey = CScript() << OP_1;
784+
t.vout[0].scriptPubKey = CScript() << OP_2;
785785
CheckIsNotStandard(t, "scriptpubkey");
786786

787787
// MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)

src/wallet/rpc/backup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
911911
case TxoutType::NONSTANDARD:
912912
case TxoutType::WITNESS_UNKNOWN:
913913
case TxoutType::WITNESS_V1_TAPROOT:
914+
case TxoutType::ANCHOR:
914915
return "unrecognized script";
915916
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
916917
return "bare default CheckTemplateVerify hash";

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
104104
case TxoutType::NULL_DATA:
105105
case TxoutType::WITNESS_UNKNOWN:
106106
case TxoutType::WITNESS_V1_TAPROOT:
107+
case TxoutType::ANCHOR:
107108
break;
108109
case TxoutType::PUBKEY:
109110
keyID = CPubKey(vSolutions[0]).GetID();

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_cltv_info(self, *, is_active):
101101

102102
def run_test(self):
103103
peer = self.nodes[0].add_p2p_connection(P2PInterface())
104-
wallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_OP_TRUE)
104+
wallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_OP_2)
105105

106106
self.test_cltv_info(is_active=False)
107107

0 commit comments

Comments
 (0)