From 10072b093f529e89a5edef393c2545aacc4fa580 Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Wed, 20 Feb 2019 12:56:35 +0000 Subject: [PATCH 1/7] Remove comments referencing to segwit/witness These comments are incorrect --- lib/blockchain/chain.js | 2 +- lib/net/common.js | 4 ++-- lib/primitives/mtx.js | 6 +----- test/address-test.js | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 5baf0f4af..6a35f9191 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -704,7 +704,7 @@ class Chain extends AsyncEmitter { } } - // Count sigops (legacy + scripthash? + witness?) + // Count sigops (legacy + scripthash?) const txSigops = tx.getSigopsCount(view, state.flags); if (txSigops > consensus.MAX_TX_SIGOPS) { diff --git a/lib/net/common.js b/lib/net/common.js index 3c2243da7..ffeb3103a 100644 --- a/lib/net/common.js +++ b/lib/net/common.js @@ -105,7 +105,7 @@ exports.LOCAL_SERVICES = 0 | exports.services.NETWORK; /** - * Required services (network and segwit). + * Required services (network). * @const {Number} * @default */ @@ -122,7 +122,7 @@ exports.REQUIRED_SERVICES = 0 exports.USER_AGENT = `/bcash:${pkg.version}/`; /** - * Max message size (~4mb with segwit, formerly 2mb) + * Max message size for non-block-like type messages. * @const {Number} * @default */ diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index 4b7e72c62..98f040853 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -405,7 +405,7 @@ class MTX extends TX { } /** - * Build input script (or witness) templates (with + * Build input script templates (with * OP_0 in place of signatures). * @param {Number} index - Input index. * @param {Coin|Output} coin @@ -427,10 +427,6 @@ class MTX extends TX { // Get the previous output's script const prev = coin.script; - // This is easily the hardest part about - // building a transaction with segwit: - // figuring out where the redeem script - // and witness redeem scripts go. const sh = prev.getScripthash(); if (sh) { diff --git a/test/address-test.js b/test/address-test.js index dae0652f6..dd35c4f5d 100644 --- a/test/address-test.js +++ b/test/address-test.js @@ -297,7 +297,7 @@ describe('Address', function() { ); }); - it('should handle segwit non-zero padding in 8-to-5 conversion', () => { + it('should handle cashaddr non-zero padding in 8-to-5 conversion', () => { const addr = 'bitcoincash:pruptvpkmxamee0f72sq40gm70wfr624zpu8adj8t6'; assert.throws(() => Address.fromString(addr, 'main')); From 1be7ff38bdaef00a722a0c15c0d86585397b9017 Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Wed, 20 Feb 2019 12:57:12 +0000 Subject: [PATCH 2/7] Remove unused parameter from Script.verify --- lib/primitives/tx.js | 1 - lib/script/script.js | 5 ++--- test/script-test.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 918e52710..e56ed92be 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -639,7 +639,6 @@ class TX { Script.verify( input.script, - null, coin.script, this, index, diff --git a/lib/script/script.js b/lib/script/script.js index cd443ff70..7ce045aaf 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -3054,9 +3054,8 @@ class Script { } /** - * Verify an input and output script, and a witness if present. + * Verify an input and output script * @param {Script} input - * @param {Null} witness * @param {Script} output * @param {TX} tx * @param {Number} index @@ -3065,7 +3064,7 @@ class Script { * @throws {ScriptError} */ - static verify(input, witness, output, tx, index, value, flags) { + static verify(input, output, tx, index, value, flags) { if (flags == null) flags = Script.flags.STANDARD_VERIFY_FLAGS; diff --git a/test/script-test.js b/test/script-test.js index e3d107234..e3351859b 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -327,7 +327,7 @@ describe('Script', function() { let err; try { - Script.verify(input, null, output, tx, 0, value, flags); + Script.verify(input, output, tx, 0, value, flags); } catch (e) { err = e; } From 8164c1d3672f690991748783624a889fc78c21eb Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Wed, 20 Feb 2019 13:14:31 +0000 Subject: [PATCH 3/7] Remove segwit rule from getblocktemplate test This rule does not exist. --- test/node-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/node-test.js b/test/node-test.js index 678a92793..fae8af203 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -636,7 +636,7 @@ describe('Node', function() { const json = await node.rpc.call({ method: 'getblocktemplate', params: [ - {rules: ['segwit']} + {rules: []} ], id: '1' }, {}); From cfe32bf67327c42925a41efca5ceef3daed195e6 Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Wed, 20 Feb 2019 13:30:46 +0000 Subject: [PATCH 4/7] Remove segwit references from tx tests --- test/data/tx-invalid.json | 10 +++------- test/data/tx-valid.json | 7 +++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/test/data/tx-invalid.json b/test/data/tx-invalid.json index f32091ad8..8646593d1 100644 --- a/test/data/tx-invalid.json +++ b/test/data/tx-invalid.json @@ -253,21 +253,17 @@ ["FindAndDelete tests"], ["This is a test of FindAndDelete. The first tx is a spend of normal scriptPubKey and the second tx is a spend of bare P2WSH."], -["The redeemScript/witnessScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."], +["The redeemScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."], ["The signature is <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01> ,"], ["where the pubkey is obtained through key recovery with sig and the wrong sighash."], -["This is to show that FindAndDelete is applied only to non-segwit scripts"], -["To show that the tests are 'correctly wrong', they should pass by modifying OP_CHECKSIG under interpreter.cpp"], -["by replacing (sigversion == SIGVERSION_BASE) with (sigversion != SIGVERSION_BASE)"], -["Non-segwit: wrong sighash (without FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"], +["Wrong sighash (without FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"], [[["f18783ace138abac5d3a7a5cf08e88fe6912f267ef936452e0c27d090621c169", 7000, "HASH160 0x14 0x0c746489e2d83cdbb5b90b432773342ba809c134 EQUAL", 200000]], "010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f1581b0000b64830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e012103b12a1ec8428fc74166926318c15e17408fea82dbb157575e16a8c365f546248f4aad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01ffffffff0101000000000000000000000000", "P2SH"], ["This is multisig version of the FindAndDelete tests"], ["Script is 2 CHECKMULTISIGVERIFY DROP"], ["52af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175"], ["Signature is 0 2 "], -["Should pass by replacing (sigversion == SIGVERSION_BASE) with (sigversion != SIGVERSION_BASE) under OP_CHECKMULTISIG"], -["Non-segwit: wrong sighash (without FindAndDelete) = 4bc6a53e8e16ef508c19e38bba08831daba85228b0211f323d4cb0999cf2a5e8"], +["Wrong sighash (without FindAndDelete) = 4bc6a53e8e16ef508c19e38bba08831daba85228b0211f323d4cb0999cf2a5e8"], [[["9628667ad48219a169b41b020800162287d2c0f713c04157e95c484a8dcb7592", 7000, "HASH160 0x14 0x5748407f5ca5cdca53ba30b79040260770c9ee1b EQUAL", 200000]], "01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a662896581b0000fd6f01004830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c039596015221023fd5dd42b44769c5653cbc5947ff30ab8871f240ad0c0e7432aefe84b5b4ff3421039d52178dbde360b83f19cf348deb04fa8360e1bf5634577be8e50fafc2b0e4ef4c9552af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175ffffffff0101000000000000000000000000", "P2SH"], diff --git a/test/data/tx-valid.json b/test/data/tx-valid.json index a6792e912..f8ea87644 100644 --- a/test/data/tx-valid.json +++ b/test/data/tx-valid.json @@ -328,18 +328,17 @@ ["FindAndDelete tests"], ["This is a test of FindAndDelete. The first tx is a spend of normal P2SH and the second tx is a spend of bare P2WSH."], -["The redeemScript/witnessScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."], +["The redeemScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."], ["The signature is <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01> ,"], ["where the pubkey is obtained through key recovery with sig and correct sighash."], -["This is to show that FindAndDelete is applied only to non-segwit scripts"], -["Non-segwit: correct sighash (with FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"], +["Correct sighash (with FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"], [[["f18783ace138abac5d3a7a5cf08e88fe6912f267ef936452e0c27d090621c169", 7000, "HASH160 0x14 0x0c746489e2d83cdbb5b90b432773342ba809c134 EQUAL", 200000]], "010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f1581b0000b64830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0121037a3fb04bcdb09eba90f69961ba1692a3528e45e67c85b200df820212d7594d334aad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01ffffffff0101000000000000000000000000", "P2SH"], ["This is multisig version of the FindAndDelete tests"], ["Script is 2 CHECKMULTISIGVERIFY DROP"], ["52af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175"], ["Signature is 0 2 "], -["Non-segwit: correct sighash (with FindAndDelete) = 1d50f00ba4db2917b903b0ec5002e017343bb38876398c9510570f5dce099295"], +["Correct sighash (with FindAndDelete) = 1d50f00ba4db2917b903b0ec5002e017343bb38876398c9510570f5dce099295"], [[["9628667ad48219a169b41b020800162287d2c0f713c04157e95c484a8dcb7592", 7000, "HASH160 0x14 0x5748407f5ca5cdca53ba30b79040260770c9ee1b EQUAL", 200000]], "01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a662896581b0000fd6f01004830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c03959601522102cd74a2809ffeeed0092bc124fd79836706e41f048db3f6ae9df8708cefb83a1c2102e615999372426e46fd107b76eaf007156a507584aa2cc21de9eee3bdbd26d36c4c9552af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175ffffffff0101000000000000000000000000", "P2SH"], From 574c3fa3430b87a76cf2017b8dd74f484b01d8cb Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Thu, 21 Feb 2019 08:01:28 +0000 Subject: [PATCH 5/7] Remove unused args in SignResultPacket constructor --- lib/workers/packets.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/workers/packets.js b/lib/workers/packets.js index 5b397a351..9047612d0 100644 --- a/lib/workers/packets.js +++ b/lib/workers/packets.js @@ -470,11 +470,11 @@ class SignPacket extends Packet { */ class SignResultPacket extends Packet { - constructor(total, witness, script) { + constructor() { super(); this.cmd = packetTypes.SIGNRESULT; - this.total = total || 0; - this.script = script || []; + this.total = 0; + this.script = []; } fromTX(tx, total) { From dcf21d1765879d6d24942bbe481687a7cd8d22ef Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Thu, 21 Feb 2019 08:02:40 +0000 Subject: [PATCH 6/7] Remove hasWitness from peer options --- docs/Examples/connect-to-peer.js | 3 --- test/node-test.js | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/Examples/connect-to-peer.js b/docs/Examples/connect-to-peer.js index 3f85169bc..15edf1551 100644 --- a/docs/Examples/connect-to-peer.js +++ b/docs/Examples/connect-to-peer.js @@ -8,9 +8,6 @@ const network = bcoin.Network.get('testnet'); const peer = bcoin.Peer.fromOptions({ network: 'testnet', agent: 'my-subversion', - hasWitness: () => { - return false; - } }); const addr = bcoin.net.NetAddress.fromHostname(process.argv[2], 'testnet'); diff --git a/test/node-test.js b/test/node-test.js index fae8af203..b9013c482 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -776,10 +776,7 @@ describe('Node', function() { const tx1 = TX.fromRaw(rawTX1, 'hex'); const dummyPeer = Peer.fromOptions({ network: 'regtest', - agent: 'my-subversion', - hasWitness: () => { - return false; - } + agent: 'my-subversion' }); const txItem = new InvItem(invTypes.TX, tx1.hash()); await node.sendTX(tx1); // add TX to inventory From 7d34413d3a49d49588d273fdd99543f7dbb4cc2e Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Thu, 21 Feb 2019 08:03:19 +0000 Subject: [PATCH 7/7] Use const instead of txType method The method just wrapped a single const. --- lib/net/peer.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/net/peer.js b/lib/net/peer.js index 6406283a4..da771229e 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -1226,7 +1226,7 @@ class Peer extends EventEmitter { /** * Calculate peer block inv type (filtered, - * compact, witness, or non-witness). + * compact or full block) * @returns {Number} */ @@ -1243,15 +1243,6 @@ class Peer extends EventEmitter { return invTypes.BLOCK; } - /** - * Calculate peer tx inv type (witness or non-witness). - * @returns {Number} - */ - - txType() { - return invTypes.TX; - } - /** * Send `getdata` to peer. * @param {InvItem[]} items @@ -1294,7 +1285,7 @@ class Peer extends EventEmitter { */ getTX(hashes) { - this.getItems(this.txType(), hashes); + this.getItems(invTypes.TX, hashes); } /**