policy: Add OP_1 <0x4e73> as a standard output type

These outputs are called anchors, and allow
key-less anchor spends which are vsize-minimized
versus keyed anchors which require larger outputs
when creating and inputs when spending.
This commit is contained in:
Greg Sanders
2023-11-08 14:07:49 -05:00
parent 8754d055c6
commit 455fca86cf
17 changed files with 106 additions and 3 deletions

View File

@@ -128,6 +128,20 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
BOOST_CHECK(solutions[0] == std::vector<unsigned char>{16});
BOOST_CHECK(solutions[1] == ToByteVector(uint256::ONE));
// TxoutType::ANCHOR
std::vector<unsigned char> anchor_bytes{0x4e, 0x73};
s.clear();
s << OP_1 << anchor_bytes;
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::ANCHOR);
BOOST_CHECK(solutions.empty());
// Sanity-check IsPayToAnchor
int version{-1};
std::vector<unsigned char> witness_program;
BOOST_CHECK(s.IsPayToAnchor());
BOOST_CHECK(s.IsWitnessProgram(version, witness_program));
BOOST_CHECK(CScript::IsPayToAnchor(version, witness_program));
// TxoutType::NONSTANDARD
s.clear();
s << OP_9 << OP_ADD << OP_11 << OP_EQUAL;
@@ -186,6 +200,18 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_failure)
s.clear();
s << OP_0 << std::vector<unsigned char>(19, 0x01);
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::NONSTANDARD);
// TxoutType::ANCHOR but wrong witness version
s.clear();
s << OP_2 << std::vector<unsigned char>{0x4e, 0x73};
BOOST_CHECK(!s.IsPayToAnchor());
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN);
// TxoutType::ANCHOR but wrong 2-byte data push
s.clear();
s << OP_1 << std::vector<unsigned char>{0xff, 0xff};
BOOST_CHECK(!s.IsPayToAnchor());
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN);
}
BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)