Skip to content

Commit 3963cf9

Browse files
committed
critical update for NFT child genesis validation
1 parent 70ec52b commit 3963cf9

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

lib/validation.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,13 @@ export class ValidatorType1 {
346346
if (slpmsg.versionType === 0x41) {
347347
// An NFT1 parent should be provided at input index 0,
348348
// so we check this first before checking the whole parent DAG
349-
const inputTxid = txn.inputs[0].previousTxHash;
350-
const inputTxHex = await this.retrieveRawTransaction(inputTxid);
351-
const inputTx: Transaction = Transaction.parseFromBuffer(inputTxHex);
349+
const inputPrevTxid = txn.inputs[0].previousTxHash;
350+
const inputPrevOut = txn.inputs[0].previousTxOutIndex;
351+
const inputPrevTxHex = await this.retrieveRawTransaction(inputPrevTxid);
352+
const inputPrevTx: Transaction = Transaction.parseFromBuffer(inputPrevTxHex);
352353
let inputSlpMsg;
353354
try {
354-
inputSlpMsg = Slp.parseSlpOutputScript(inputTx.outputs[0].scriptPubKey);
355+
inputSlpMsg = Slp.parseSlpOutputScript(inputPrevTx.outputs[0].scriptPubKey);
355356
} catch (_) {}
356357
if (!inputSlpMsg || inputSlpMsg.versionType !== 0x81) {
357358
validation.validity = false;
@@ -360,23 +361,38 @@ export class ValidatorType1 {
360361
return validation.validity!;
361362
}
362363
// Check that the there is a burned output >0 in the parent txn SLP message
363-
if (inputSlpMsg.transactionType === SlpTransactionType.SEND &&
364-
!inputSlpMsg.sendOutputs![1].gt(0)) {
365-
validation.validity = false;
366-
validation.waiting = false;
367-
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
368-
return validation.validity!;
369-
} else if ((inputSlpMsg.transactionType === SlpTransactionType.GENESIS ||
370-
inputSlpMsg.transactionType === SlpTransactionType.MINT) &&
371-
!inputSlpMsg.genesisOrMintQuantity!.gt(0)) {
372-
validation.validity = false;
373-
validation.waiting = false;
374-
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
375-
return validation.validity!;
364+
if (inputSlpMsg.transactionType === SlpTransactionType.SEND) {
365+
if (inputPrevOut > inputSlpMsg.sendOutputs!.length - 1) {
366+
validation.validity = false;
367+
validation.waiting = false;
368+
validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
369+
return validation.validity!;
370+
}
371+
if (! inputSlpMsg.sendOutputs![inputPrevOut].gt(0)) {
372+
validation.validity = false;
373+
validation.waiting = false;
374+
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
375+
return validation.validity!;
376+
}
377+
} else if (inputSlpMsg.transactionType === SlpTransactionType.GENESIS ||
378+
inputSlpMsg.transactionType === SlpTransactionType.MINT) {
379+
if (inputPrevOut !== 1) {
380+
validation.validity = false;
381+
validation.waiting = false;
382+
validation.invalidReason = "NFT1 child GENESIS does not have a valid NFT1 parent input.";
383+
return validation.validity!;
384+
}
385+
if (!inputSlpMsg.genesisOrMintQuantity!.gt(0)) {
386+
validation.validity = false;
387+
validation.waiting = false;
388+
validation.invalidReason = "NFT1 child's parent has SLP output that is not greater than zero.";
389+
return validation.validity!;
390+
}
376391
}
392+
377393
// Continue to check the NFT1 parent DAG
378394
const nft_parent_dag_validity = await this.isValidSlpTxid({
379-
txid: inputTxid,
395+
txid: inputPrevTxid,
380396
tokenIdFilter: undefined,
381397
tokenTypeFilter: 0x81
382398
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)