Skip to content

Instantly share code, notes, and snippets.

@A60AB5450353F40E
Last active August 9, 2022 12:41
Show Gist options
  • Save A60AB5450353F40E/c70e1dc5bc2ead37a90eb0ef7fb553ec to your computer and use it in GitHub Desktop.
Save A60AB5450353F40E/c70e1dc5bc2ead37a90eb0ef7fb553ec to your computer and use it in GitHub Desktop.
slpv1
{
"$schema": "https://ide.bitauth.com/authentication-template-v0.schema.json",
"description": "Proof of concept for a token constructor covenant that enforces SLPv1 specification and metadata format",
"name": "SLPv1 CashTokens Constructor",
"entities": {},
"scripts": {
"unlock_constructor": {
"name": "Unlock",
"script": "<0x0100000001699099d656be426a9618d732fd21e626667361d463ba9cae07d9517fc1768582010000006a47304402205124006ac0df4ada8fe652d2dc20f35b73169fcb174239a65ed70f1b8e4e2c9502202b18e1d9e153c60c0802bb61a851957e6c6b42e11307ded72af0ba0772d5a97041210346864c7bbd25b86932742e6681990f67d180d104f66ba2cdb9dd56c194a32cc6feffffff02a08601000000000017a9144fdad98cb1e567c9868e167212437246e6b14c0f8700000000000000009c6a4c99534c5076311976a914112233445566778899001122334455667788990088ac0040075af075070008034243480c426974636f696e20436173681f68747470733a2f2f626974636f696e2e6f72672f626974636f696e2e70646662313637343139316138386563356364643733336534323430613831383033313035646334313264366336373038643533616239346663323438663466353533171b0100>",
"unlocks": "constructor"
},
"constructor": {
"lockingType": "p2sh20",
"name": "constructor",
"script": "// SLPv1 CashToken Constructor\n// The pre-genesis TX MUST have 1 input.\n// The pre-genesis TX MUST have 2 outputs:\n// output0: this contract (P2SH)\n// output1: OP_RETURN <metadata>\n\n// Verify genesis TX format, 2 in 1 out\nOP_TXINPUTCOUNT <1> OP_EQUALVERIFY // should be <2> but I don't know how to set up TX context\nOP_TXOUTPUTCOUNT <1> OP_EQUALVERIFY\n\n// Verify that my input and prevout indexes are both 0\nOP_INPUTINDEX OP_DUP OP_0 OP_EQUALVERIFY\nOP_OUTPOINTINDEX OP_0 OP_EQUALVERIFY\n\n// Verify category ID and genesis output token structure\n// FT + immutable NFT for the \"baton\" that will hold the supply\n<0> op_outputtokencategory\nOP_INPUTINDEX OP_OUTPOINTTXHASH\n<0x30> OP_CAT\nOP_EQUALVERIFY\n\n// Verify the provided raw TX against prevout's TXID\nOP_DUP OP_HASH256\n// replace this with <0> OP_UTXOOUTPOINTTXID OP_EQUALVERIFY\nOP_DUP OP_EQUALVERIFY\n// Parse version\n<4> OP_SPLIT OP_SWAP OP_DROP\n// Parse input count\n<1> OP_SPLIT OP_SWAP <252> OP_LESSTHANOREQUAL OP_VERIFY\n// Parse outpoint\n<36> OP_SPLIT OP_SWAP OP_DROP\n// Parse unlocking script length\n<1> OP_SPLIT OP_SWAP OP_DUP <252> OP_LESSTHANOREQUAL OP_VERIFY\n// Parse unlocking script\nOP_SPLIT OP_SWAP OP_DROP\n// Parse relative lock-time\n<4> OP_SPLIT OP_SWAP OP_DROP\n// Parse output count\n<1> OP_SPLIT OP_SWAP <252> OP_LESSTHANOREQUAL OP_VERIFY\n// Parse output0 satoshi amount\n<8> OP_SPLIT OP_SWAP OP_DROP\n// Parse output0 locking script length\n<1> OP_SPLIT OP_SWAP OP_DUP <252> OP_LESSTHANOREQUAL OP_VERIFY\n// Parse output0 locking script\nOP_SPLIT OP_SWAP OP_DROP\n// Parse and verify output1 satoshi amount\n<8> OP_SPLIT OP_SWAP OP_BIN2NUM <0> OP_EQUALVERIFY\n// Parse output1 locking script length\n<1> OP_SPLIT OP_SWAP <0x00> OP_CAT OP_BIN2NUM OP_DUP <252> OP_LESSTHANOREQUAL OP_VERIFY\n// Parse output1 locking script\nOP_SPLIT\n// Parse lock-time\nOP_SIZE <4> OP_EQUALVERIFY OP_DROP\n// Leave output1 locking script on the stack\n\n// Verify metadata is according to specification\n // Verify encapsulation format\n <2> OP_SPLIT OP_SWAP <OP_RETURN 0x4c> OP_EQUALVERIFY\n <1> OP_SPLIT OP_SIZE OP_ROT <0x00> OP_CAT OP_BIN2NUM OP_EQUALVERIFY\n // Verify magic bytes\n <5> OP_SPLIT OP_SWAP <\"SLPv1\"> OP_EQUALVERIFY\n\n // Verify first owner\n <1> OP_SPLIT OP_SWAP OP_SPLIT OP_SWAP\n <0> OP_OUTPUTBYTECODE\n OP_DROP OP_DUP // remove later when executed in proper context\n OP_EQUALVERIFY\n\n // Verify initial supply\n <8> OP_SPLIT OP_SWAP OP_BIN2NUM\n <0> OP_OUTPUTVALUE // replace with OP_OUTPUTTOKENAMOUNT\n OP_DROP OP_DUP // remove later when executed in proper context\n OP_EQUALVERIFY\n\n // Verify decimals format\n <1> OP_SPLIT OP_SWAP\n <9> OP_LESSTHANOREQUAL OP_VERIFY\n // Parse ticker\n <1> OP_SPLIT OP_SWAP OP_SPLIT OP_SWAP\n OP_DROP\n // Parse name\n <1> OP_SPLIT OP_SWAP OP_SPLIT OP_SWAP\n OP_DROP\n // Parse document URL\n <1> OP_SPLIT OP_SWAP OP_SPLIT OP_SWAP\n OP_DROP\n // Parse document hash\n OP_SIZE <64> OP_EQUALVERIFY\n OP_DROP\n// Done\nOP_1\n\n<0> OP_UTXOBYTECODE // just for info\nOP_DROP"
},
"op_outputtokencategory": {
"name": "op_outputtokencategory",
"script": "OP_DROP\n<0x010000000000000000000000000000000000000000000000000000000000000030>"
},
"tx_pregenesis": {
"name": "tx_pregenesis",
"script": "// Raw TX builder\n\n// TX version\n<0x01000000>\n// Input count\n<0x01>\n// Input-00\n // Prevout hash\n <0x699099d656be426a9618d732fd21e626667361d463ba9cae07d9517fc1768582>\n // Prevout index\n <0x01000000> \n // Unlocking script length\n <0x6a> \n // Unlocking script\n <0x47304402205124006ac0df4ada8fe652d2dc20f35b73169fcb174239a65ed70f1b8e4e2c9502202b18e1d9e153c60c0802bb61a851957e6c6b42e11307ded72af0ba0772d5a97041210346864c7bbd25b86932742e6681990f67d180d104f66ba2cdb9dd56c194a32cc6>\n // Relative lock-time\n <0xfeffffff>\n// Output count\n<0x02>\n// Output-00\n // Satoshi amount\n <0xa086010000000000>\n // Locking script length\n <0x17>\n // Locking script\n <0xa9144fdad98cb1e567c9868e167212437246e6b14c0f87>\n// Output-01\n // Satoshi amount\n <0x0000000000000000>\n // Locking script length & locking script\n // Built interactively here\n <OP_RETURN>\n <\"SLPv1\">\n // First Owner (variable length)\n <OP_DUP OP_HASH160 <0x1122334455667788990011223344556677889900> OP_EQUALVERIFY OP_CHECKSIG>\n OP_SIZE OP_SWAP OP_CAT\n // Initial Supply (8 bytes)\n <2100000000000000> <8> OP_NUM2BIN\n // Decimals (1 byte)\n <8> <1> OP_NUM2BIN\n // Ticker (variable length)\n <\"BCH\">\n OP_SIZE OP_SWAP OP_CAT\n // Name (variable length)\n <\"Bitcoin Cash\">\n OP_SIZE OP_SWAP OP_CAT\n // Document URL (variable length)\n <\"https://bitcoin.org/bitcoin.pdf\">\n OP_SIZE OP_SWAP OP_CAT\n // Document Hash (64 bytes)\n <\"b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553\">\n OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT\n // Construct OP_PUSHDATA1 metadata_length\n OP_SIZE <1> OP_SPLIT OP_DROP\n <0x4c> OP_SWAP OP_CAT\n OP_SWAP OP_CAT\n OP_CAT\n // Limit locking script length to 1-byte varint\n OP_SIZE OP_DUP <252> OP_LESSTHANOREQUAL OP_VERIFY\n // Append the length before locking script\n <1> OP_SPLIT OP_DROP OP_SWAP OP_CAT\n// Lock-time\n<0x171b0100>\n// Calculate TXID\nOP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT \nOP_CAT OP_CAT OP_CAT OP_CAT\nOP_SIZE // just for info\nOP_DROP\nOP_DUP OP_HASH256 // just for info\nOP_DROP\n// raw TX on the stack"
}
},
"supported": [
"BCH_2022_05",
"BCH_SPEC"
],
"version": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment