From 56656839b3ef6f04530ffdf938e0ebbd2cf9939c Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Sun, 27 Mar 2022 16:13:48 +0200 Subject: [PATCH 1/3] Detect more lightning scripts: - expired htlc - anchor - swept anchor Fix indentation what i messed up in 7565aa7 Add explanation --- .../address-labels.component.ts | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index 75bbe7cba..2ce0ae5a3 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -46,19 +46,36 @@ export class AddressLabelsComponent implements OnInit { return; } + const topElement = this.vin.witness[this.vin.witness.length - 2]; // https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction-outputs if (/^OP_IF OP_PUSHBYTES_33 \w{66} OP_ELSE OP_PUSHBYTES_(1 \w{2}|2 \w{4}) OP_CSV OP_DROP OP_PUSHBYTES_33 \w{66} OP_ENDIF OP_CHECKSIG$/.test(this.vin.inner_witnessscript_asm)) { - if (this.vin.witness[this.vin.witness.length - 2] == '01') { - this.lightning = 'Revoked Force Close'; - } else { - this.lightning = 'Force Close'; - } + if (topElement === '01') { + // top element is '01' to get in the revocation path + this.lightning = 'Revoked Force Close'; + } else { + // top element is '', this is a delayed to_local output + this.lightning = 'Force Close'; + } // https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs } else if (/^OP_DUP OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE OP_PUSHBYTES_33 \w{66} OP_SWAP OP_SIZE OP_PUSHBYTES_1 20 OP_EQUAL OP_NOTIF OP_DROP OP_PUSHNUM_2 OP_SWAP OP_PUSHBYTES_33 \w{66} OP_PUSHNUM_2 OP_CHECKMULTISIG OP_ELSE OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF (OP_PUSHNUM_1 OP_CHECKSEQUENCEVERIFY OP_DROP |)OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) { - if (this.vin.witness[this.vin.witness.length - 2].length == 66) { - this.lightning = 'Revoked HTLC'; + if (topElement.length === 66) { + // top element is a public key + this.lightning = 'Revoked HTLC'; + } else if (topElement) { + // top element is a preimage + this.lightning = 'HTLC'; } else { - this.lightning = 'HTLC'; + // top element is '' to get in the multisig path of the script + this.lightning = 'Expired HTLC'; + } + // https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local_anchor-and-to_remote_anchor-output-option_anchors + } else if (/^OP_PUSHBYTES_33 \w{66} OP_CHECKSIG OP_IFDUP OP_NOTIF OP_PUSHNUM_16 OP_CSV OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) { + if (topElement) { + // top element is a signature + this.lightning = 'Anchor'; + } else { + // top element is '', it has been swept after 16 blocks + this.lightning = 'Swept Anchor'; } } @@ -77,19 +94,19 @@ export class AddressLabelsComponent implements OnInit { return; } const ops = script.split(' '); - if (ops.length < 3 || ops.pop() != 'OP_CHECKMULTISIG') { + if (ops.length < 3 || ops.pop() !== 'OP_CHECKMULTISIG') { return; } const opN = ops.pop(); if (!opN.startsWith('OP_PUSHNUM_')) { return; } - const n = parseInt(opN.match(/[0-9]+/)[0]); + const n = parseInt(opN.match(/[0-9]+/)[0], 10); if (ops.length < n * 2 + 1) { return; } // pop n public keys - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { if (!/^0((2|3)\w{64}|4\w{128})$/.test(ops.pop())) { return; } @@ -101,7 +118,7 @@ export class AddressLabelsComponent implements OnInit { if (!opM.startsWith('OP_PUSHNUM_')) { return; } - const m = parseInt(opM.match(/[0-9]+/)[0]); + const m = parseInt(opM.match(/[0-9]+/)[0], 10); this.multisig = true; this.multisigM = m; From b5ef148b822eadf6871b1c140a6cf8e6555587ef Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Tue, 29 Mar 2022 15:47:48 +0200 Subject: [PATCH 2/3] replace 3 seperate labels with one `AddressLabelsComponent.label?: string` + consistency: move comments in the `if` blocks --- .../address-labels.component.html | 16 +------- .../address-labels.component.ts | 40 ++++++++----------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.html b/frontend/src/app/components/address-labels/address-labels.component.html index 9abfe32da..2f673a8a9 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.html +++ b/frontend/src/app/components/address-labels/address-labels.component.html @@ -1,17 +1,5 @@ multisig {{ multisigM }} of {{ multisigN }} - -Lightning {{ lightning }} - -Liquid {{ liquid }} +>{{ label }} diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index 2ce0ae5a3..4909c4f29 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -14,12 +14,7 @@ export class AddressLabelsComponent implements OnInit { @Input() vin: Vin; @Input() vout: Vout; - multisig = false; - multisigM: number; - multisigN: number; - - lightning = null; - liquid = null; + label?: string; constructor( stateService: StateService, @@ -39,47 +34,46 @@ export class AddressLabelsComponent implements OnInit { if (this.vin.inner_witnessscript_asm) { if (this.vin.inner_witnessscript_asm.indexOf('OP_DEPTH OP_PUSHNUM_12 OP_EQUAL OP_IF OP_PUSHNUM_11') === 0) { if (this.vin.witness.length > 11) { - this.liquid = 'Peg Out'; + this.label = 'Liquid Peg Out'; } else { - this.liquid = 'Emergency Peg Out'; + this.label = 'Emergency Liquid Peg Out'; } return; } const topElement = this.vin.witness[this.vin.witness.length - 2]; - // https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction-outputs if (/^OP_IF OP_PUSHBYTES_33 \w{66} OP_ELSE OP_PUSHBYTES_(1 \w{2}|2 \w{4}) OP_CSV OP_DROP OP_PUSHBYTES_33 \w{66} OP_ENDIF OP_CHECKSIG$/.test(this.vin.inner_witnessscript_asm)) { + // https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction-outputs if (topElement === '01') { // top element is '01' to get in the revocation path - this.lightning = 'Revoked Force Close'; + this.label = 'Revoked Lightning Force Close'; } else { // top element is '', this is a delayed to_local output - this.lightning = 'Force Close'; + this.label = 'Lightning Force Close'; } - // https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs + return; } else if (/^OP_DUP OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE OP_PUSHBYTES_33 \w{66} OP_SWAP OP_SIZE OP_PUSHBYTES_1 20 OP_EQUAL OP_NOTIF OP_DROP OP_PUSHNUM_2 OP_SWAP OP_PUSHBYTES_33 \w{66} OP_PUSHNUM_2 OP_CHECKMULTISIG OP_ELSE OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF (OP_PUSHNUM_1 OP_CHECKSEQUENCEVERIFY OP_DROP |)OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) { + // https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs if (topElement.length === 66) { // top element is a public key - this.lightning = 'Revoked HTLC'; + this.label = 'Revoked Lightning HTLC'; } else if (topElement) { // top element is a preimage - this.lightning = 'HTLC'; + this.label = 'Lightning HTLC'; } else { // top element is '' to get in the multisig path of the script - this.lightning = 'Expired HTLC'; + this.label = 'Expired Lightning HTLC'; } - // https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local_anchor-and-to_remote_anchor-output-option_anchors + return; } else if (/^OP_PUSHBYTES_33 \w{66} OP_CHECKSIG OP_IFDUP OP_NOTIF OP_PUSHNUM_16 OP_CSV OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) { + // https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local_anchor-and-to_remote_anchor-output-option_anchors if (topElement) { // top element is a signature - this.lightning = 'Anchor'; + this.label = 'Lightning Anchor'; } else { // top element is '', it has been swept after 16 blocks - this.lightning = 'Swept Anchor'; + this.label = 'Swept Lightning Anchor'; } - } - - if (this.lightning) { return; } @@ -120,9 +114,7 @@ export class AddressLabelsComponent implements OnInit { } const m = parseInt(opM.match(/[0-9]+/)[0], 10); - this.multisig = true; - this.multisigM = m; - this.multisigN = n; + this.label = `multisig ${m} of ${n}`; } handleVout() { From 493b44d4b9bb894134aa166b51834487b1f40cc8 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Tue, 29 Mar 2022 16:16:20 +0200 Subject: [PATCH 3/3] detect bare multisigs with handleVout --- .../app/components/address-labels/address-labels.component.ts | 1 + .../transactions-list/transactions-list.component.html | 3 +++ 2 files changed, 4 insertions(+) diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index 4909c4f29..ee8e26de6 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -118,5 +118,6 @@ export class AddressLabelsComponent implements OnInit { } handleVout() { + this.detectMultisig(this.vout.scriptpubkey_asm); } } diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.html b/frontend/src/app/components/transactions-list/transactions-list.component.html index 3d9c67b17..72407a405 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.html +++ b/frontend/src/app/components/transactions-list/transactions-list.component.html @@ -155,6 +155,9 @@ {{ vout.scriptpubkey_address | shortenString : 16 }} {{ vout.scriptpubkey_address | shortenString : 35 }} +
+ +
Peg-out to