Skip to content

Instantly share code, notes, and snippets.

@A60AB5450353F40E
Created February 22, 2022 19:15
Show Gist options
  • Save A60AB5450353F40E/e81d32df9fa36c4fa961e8065e5a01a1 to your computer and use it in GitHub Desktop.
Save A60AB5450353F40E/e81d32df9fa36c4fa961e8065e5a01a1 to your computer and use it in GitHub Desktop.
OTS Baton
{
"$schema": "https://bitauth.com/schemas/authentication-template-v0.schema.json",
"description": "Public P2SH covenant to create an \"one token standard\" native token baton, one that is limited to 1 baton UTXO.\nThe only way to spend from the covenant is to spend the UTXO as a group genesis input matching the required parameters and verifying that exactly 1 baton \"change\" is being created.",
"name": "Genesis from Covenant",
"entities": {},
"scripts": {
"helper_group_genesis_generator": {
"name": "HELPER: GROUP GENESIS GENERATOR",
"script": "// # Poor man's group genesis generator\n// Set prevout and genesis parameters, and then manually roll the nonce\n// until the groupGenType matches.\n\n// Part 1. - genesis input's prevout reference\n // Prevout hash\n <0x699099d656be426a9618d732fd21e626667361d463ba9cae07d9517fc1768582>\n // Prevout index\n <0x00000000> OP_CAT\n OP_HASH256\n// Part 2. - genesis input's prevout\n // Prevout satoshi amount\n <0xa086010000000000> \n // Prevout locking script length\n <0x17> OP_CAT // Pure\n // <0x40> OP_CAT // Grouped\n // Prevout group annotation\n // PFX_GROUP\n // <0xEE> OP_CAT\n // groupID\n // <0x0e83da9144f9d9c45d1b442684c57b7c516ab18fb112da3c31bf8b807ed13c92> OP_CAT\n // groupAmount\n // <0x0123456789ABCDEF> OP_CAT\n // Locking script\n <0xa914730646f5ec71b49808decce63e15c59fa4bf67fb87> OP_CAT\n OP_HASH256\n// Part 3. - genesis input parameters\n // Genesis input index\n <0x00000000>\n // groupGenVersion\n <0x01> OP_CAT\n // groupGenNonce, roll this until line 38 verifies\n <0x008d> OP_CAT\n // groupGenType\n <0x11> OP_DUP OP_TOALTSTACK OP_CAT \n // groupGenAmount\n <0x0100000000000000> OP_CAT\n// Generate groupID preimage\nOP_CAT OP_CAT\n// Generate groupID\nOP_DUP OP_HASH256\n// Verify groupType\n<31> OP_SPLIT OP_FROMALTSTACK OP_EQUALVERIFY\nOP_DROP\n\n// groupID preimage left on the stack"
},
"op_inputindex_0": {
"name": "OP_INPUTINDEX_0",
"script": "OP_0"
},
"op_utxobytecode_dc": {
"name": "OP_UTXOBYTECODE_DC",
"script": "OP_DROP <0xa914d2c802d0d3a2c0061ff11afbdd0a67a5d728d68a87>\n"
},
"op_outputbytecode_opreturn": {
"name": "OP_OUTPUTBYTECODE_OPRETURN",
"script": "OP_DROP\n<OP_RETURN>"
},
"op_outputgroupamount_1": {
"name": "OP_OUTPUTGROUPAMOUNT_1",
"script": "OP_DROP\n<0x0100000000000000>"
},
"op_outputgroupid_nft": {
"name": "OP_OUTPUTGROUPID_NFT",
"script": "OP_DROP\n<0xd5de6dc2a737d8a25ccb5fa23040f84e55f8164139752c5ff15ffcc0c3fa7a11>"
},
"op_equalverify_1": {
"name": "OP_EQUALVERIFY_1",
"script": "OP_2DROP"
},
"op_checksigverify_1": {
"name": "OP_CHECKSIGVERIFY_1",
"script": "OP_2DROP"
},
"op_outputvalue_10k": {
"name": "OP_OUTPUTVALUE_10k",
"script": "OP_DROP\n<0x1027000000000000>"
},
"op_inputgroupgenesis_0": {
"name": "OP_INPUTGROUPGENESIS_0",
"script": "OP_DROP\nOP_0\n"
},
"op_inputgroupgenesis_nft": {
"name": "OP_INPUTGROUPGENESIS_NFT",
"script": "OP_DROP\n<0xe69b80d54c704b204143089c4e00ee86fa5a4f897878fe1ce0e6661fbc4e7067fa151b786164c897ef7f011bdd38fa80fda43022e7c715902c88e6e660c893ba0000000001008d110100000000000000>\n"
},
"op_utxogroupid_0": {
"name": "OP_UTXOGROUPID_0",
"script": "OP_DROP\nOP_0\n"
},
"op_outputbytecode_dc": {
"name": "OP_OUTPUTBYTECODE_DC",
"script": "OP_DROP <0xa914d2c802d0d3a2c0061ff11afbdd0a67a5d728d68a87>"
},
"op_txinputcount_1": {
"name": "OP_TXINPUTCOUNT_1",
"script": "OP_1"
},
"op_txinputcount_2": {
"name": "OP_TXINPUTCOUNT_2",
"script": "OP_2"
},
"op_txinputcount_3": {
"name": "OP_TXINPUTCOUNT_3",
"script": "OP_3"
},
"op_utxobytecode_0": {
"name": "OP_UTXOBYTECODE_0",
"script": "OP_DROP\nOP_0"
},
"minting_baton_genesis_script_nft": {
"name": "MINTING BATON GENESIS (SCRIPT NFT)",
"script": "// # Unlocking Script\n// Next owner PKH\n<0x0011223344556677889900112233445566778899>\n// Redeem Script Raw\n<0x01177E02A9147E0376A9147B7E0388ADAB7E4c5676A9140233BC976DA9A9E30FF18B35195693B938E06EAF88ADABC0D276008791697601447F517F7551887576AA766B011F7F0111887501487F0801000000000000008875C0CE008876CC08102700000000000088CD177EC0C77E3088C351A26300C0876400D200886868C352A26351C0876451D200886868C353A26352C0876452D200886868C353A169517EA97E01877EAA7E7C7EAA7C76CD016A8876D108010000000000000088D088C351A26300C0876400C7C0C78791696868C352A26351C0876451C7C0C78791696868C353A26352C0876452C7C0C78791696868C353A16951>\n\n// # Locking Script\nOP_HASH160\n<0xd2c802d0d3a2c0061ff11afbdd0a67a5d728d68a>\nOP_EQUAL\n\n// # Simulate Redeem Script Execution\nOP_VERIFY\n\n// # Redeem Script\n// ## Verify myself\nop_inputindex_0 op_inputgroupgenesis_baton OP_DUP\n// ### Verify that I'm being spent with the group genesis input directive\nOP_0 OP_EQUAL OP_NOT OP_VERIFY\nOP_DUP\n// ### Verify that I'm creating a native token baton\n<68> OP_SPLIT <1> OP_SPLIT <2> OP_SPLIT <1> OP_SPLIT <7> OP_SPLIT\n// Verify that I'm a baton\n<0x80> OP_AND <0x80> OP_EQUALVERIFY\nOP_DROP\n// Verify that it's a native token group\n<0x11> OP_EQUALVERIFY\nOP_DROP\n// Verify genesis version\n<0x01> OP_EQUALVERIFY\nOP_DROP\n// Calculate groupID\nOP_HASH256\nOP_CODESEPARATOR\n// ----------------- OP_CODESEPARATOR -----------------\n// ## Enforce NFT behavior on the baton and find the baton's \"change\"\n<5> op_txoutputcount_3 OP_GREATERTHANOREQUAL OP_VERIFY\n<0>\nOP_SWAP\nOP_DUP <4> op_outputgroupid_nft op_equal_1 OP_IF\n <4> op_outputgroupamount_baton <7> OP_SPLIT OP_SWAP OP_DROP <0x80> OP_AND <0x80> OP_EQUAL OP_IF\n <4> OP_TOALTSTACK\n OP_SWAP OP_1ADD OP_SWAP\n OP_ENDIF\nOP_ENDIF\nOP_DUP <3> op_outputgroupid_nft OP_EQUAL OP_IF\n <3> op_outputgroupamount_baton <7> OP_SPLIT OP_SWAP OP_DROP <0x80> OP_AND <0x80> OP_EQUAL OP_IF\n <3> OP_TOALTSTACK\n OP_SWAP OP_1ADD OP_SWAP\n OP_ENDIF\nOP_ENDIF\nOP_DUP <2> op_outputgroupid_nft op_equal_1 OP_IF\n <2> op_outputgroupamount_1 <7> OP_SPLIT OP_SWAP OP_DROP <0x80> OP_AND <0x80> OP_EQUAL OP_IF\n <2> OP_TOALTSTACK\n OP_SWAP OP_1ADD OP_SWAP\n OP_ENDIF\nOP_ENDIF\nOP_DUP <1> op_outputgroupid_nft op_equal_1 OP_IF\n <1> op_outputgroupamount_1 <7> OP_SPLIT OP_SWAP OP_DROP <0x80> OP_AND <0x80> OP_EQUAL OP_IF\n <1> OP_TOALTSTACK\n OP_SWAP OP_1ADD OP_SWAP\n OP_ENDIF\nOP_ENDIF\n<0> op_outputgroupid_nft OP_EQUAL OP_IF\n <0> op_outputgroupamount_baton <7> OP_SPLIT OP_SWAP OP_DROP <0x80> OP_AND <0x80> OP_EQUAL OP_IF\n <0> OP_TOALTSTACK\n OP_SWAP OP_1ADD OP_SWAP\n OP_ENDIF\nOP_ENDIF\n<1> OP_EQUALVERIFY\n// ## Enforce the template on the \"change\"\n<OP_HASH160>\n // Owner set by first spender\n <OP_DUP OP_HASH160 0x14>\n OP_ROT OP_CAT\n <OP_CHECKSIGVERIFY 0xC0 0xCE OP_CODESEPARATOR> OP_CAT\n // NFT template fixed part\n <0x00> // OP_ACTIVEBYTECODE\n OP_CAT\n OP_HASH160\nOP_CAT\n<OP_EQUAL> OP_CAT\nOP_FROMALTSTACK op_outputbytecode_dc\nOP_EQUAL"
},
"op_inputgroupgenesis_baton": {
"name": "OP_INPUTGROUPGENESIS_BATON",
"script": "OP_DROP\n<0xe69b80d54c704b204143089c4e00ee86fa5a4f897878fe1ce0e6661fbc4e7067>\n<0xfa151b786164c897ef7f011bdd38fa80fda43022e7c715902c88e6e660c893ba> OP_CAT\n<0x00000000> OP_CAT\n<0x01> OP_CAT\n<0x008d> OP_CAT\n<0x11> OP_CAT\n<0x0000000000000080> OP_CAT"
},
"op_txoutputcount_3": {
"name": "OP_TXOUTPUTCOUNT_3",
"script": "OP_3"
},
"op_equal_1": {
"name": "OP_EQUAL_1",
"script": "OP_2DROP\nOP_1"
},
"op_outputgroupamount_baton": {
"name": "OP_OUTPUTGROUPAMOUNT_BATON",
"script": "OP_DROP\n<0x1122334455667788>"
}
},
"supported": [
"BCH_2020_05"
],
"version": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment