From 3963cf914afae69084059b82483da916d97af65c Mon Sep 17 00:00:00 2001 From: James Cramer Date: Wed, 29 Jul 2020 11:53:29 -0400 Subject: [PATCH] critical update for NFT child genesis validation --- lib/validation.ts | 52 +++++++++++++++++++++++++++++++---------------- package-lock.json | 2 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/validation.ts b/lib/validation.ts index bc9ae2d..cf41d3a 100644 --- a/lib/validation.ts +++ b/lib/validation.ts @@ -346,12 +346,13 @@ export class ValidatorType1 { if (slpmsg.versionType === 0x41) { // An NFT1 parent should be provided at input index 0, // so we check this first before checking the whole parent DAG - const inputTxid = txn.inputs[0].previousTxHash; - const inputTxHex = await this.retrieveRawTransaction(inputTxid); - const inputTx: Transaction = Transaction.parseFromBuffer(inputTxHex); + const inputPrevTxid = txn.inputs[0].previousTxHash; + const inputPrevOut = txn.inputs[0].previousTxOutIndex; + const inputPrevTxHex = await this.retrieveRawTransaction(inputPrevTxid); + const inputPrevTx: Transaction = Transaction.parseFromBuffer(inputPrevTxHex); let inputSlpMsg; try { - inputSlpMsg = Slp.parseSlpOutputScript(inputTx.outputs[0].scriptPubKey); + inputSlpMsg = Slp.parseSlpOutputScript(inputPrevTx.outputs[0].scriptPubKey); } catch (_) {} if (!inputSlpMsg || inputSlpMsg.versionType !== 0x81) { validation.validity = false; @@ -360,23 +361,38 @@ export class ValidatorType1 { return validation.validity!; } // Check that the there is a burned output >0 in the parent txn SLP message - if (inputSlpMsg.transactionType === SlpTransactionType.SEND && - !inputSlpMsg.sendOutputs![1].gt(0)) { - validation.validity = false; - validation.waiting = false; - validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero."; - return validation.validity!; - } else if ((inputSlpMsg.transactionType === SlpTransactionType.GENESIS || - inputSlpMsg.transactionType === SlpTransactionType.MINT) && - !inputSlpMsg.genesisOrMintQuantity!.gt(0)) { - validation.validity = false; - validation.waiting = false; - validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero."; - return validation.validity!; + if (inputSlpMsg.transactionType === SlpTransactionType.SEND) { + if (inputPrevOut > inputSlpMsg.sendOutputs!.length - 1) { + validation.validity = false; + validation.waiting = false; + validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input."; + return validation.validity!; + } + if (! inputSlpMsg.sendOutputs![inputPrevOut].gt(0)) { + validation.validity = false; + validation.waiting = false; + validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero."; + return validation.validity!; + } + } else if (inputSlpMsg.transactionType === SlpTransactionType.GENESIS || + inputSlpMsg.transactionType === SlpTransactionType.MINT) { + if (inputPrevOut !== 1) { + validation.validity = false; + validation.waiting = false; + validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input."; + return validation.validity!; + } + if (!inputSlpMsg.genesisOrMintQuantity!.gt(0)) { + validation.validity = false; + validation.waiting = false; + validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero."; + return validation.validity!; + } } + // Continue to check the NFT1 parent DAG const nft_parent_dag_validity = await this.isValidSlpTxid({ - txid: inputTxid, + txid: inputPrevTxid, tokenIdFilter: undefined, tokenTypeFilter: 0x81 }); diff --git a/package-lock.json b/package-lock.json index 36fda69..2158e80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4087,7 +4087,7 @@ "dev": true }, "slp-unit-test-data": { - "version": "git+https://github.com/simpleledger/slp-unit-test-data.git#be74a6005dbf7dfabce19a9f920b2632b539f73e", + "version": "git+https://github.com/simpleledger/slp-unit-test-data.git#8c942eacfae12686dcf1f3366321445a4fba73e7", "from": "git+https://github.com/simpleledger/slp-unit-test-data.git", "dev": true },