From d96b7036fb9a034e883fd005c5756362be22900d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 31 Aug 2016 15:21:36 +1000 Subject: [PATCH 1/3] tests: add BIP62 compliance tests --- package.json | 1 + test/script.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/package.json b/package.json index b8e37f0..2d4ba52 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "bs58": "^2.0.1", "cb-http-client": "^0.2.0", "httpify": "^1.0.0", + "minimaldata": "^1.0.0", "mocha": "^2.2.0", "proxyquire": "^1.4.0", "sinon": "^1.12.2", diff --git a/test/script.js b/test/script.js index e1598cd..e3e7f3f 100644 --- a/test/script.js +++ b/test/script.js @@ -3,6 +3,7 @@ var assert = require('assert') var bcrypto = require('../src/crypto') var bscript = require('../src/script') +var minimalData = require('minimaldata') var ops = require('../src/opcodes') var fixtures = require('./fixtures/script.json') @@ -440,4 +441,37 @@ describe('script', function () { }) }) }) + + describe('SCRIPT_VERIFY_MINIMALDATA policy', function () { + fixtures.valid.forEach(function (f) { + if (f.scriptSigHex) { + it('compliant for ' + f.type + ' scriptSig ' + f.scriptSig, function () { + var script = new Buffer(f.scriptSigHex, 'hex') + + assert(minimalData(script)) + }) + } + + if (f.scriptPubKeyHex) { + it('compliant for ' + f.type + ' scriptPubKey ' + f.scriptPubKey, function () { + var script = new Buffer(f.scriptPubKeyHex, 'hex') + + assert(minimalData(script)) + }) + } + }) + + function testEncodingForSize (i) { + it('compliant for data PUSH of length ' + i, function () { + var buffer = new Buffer(i) + var script = bscript.compile([buffer]) + + assert(minimalData(script), 'Failed for ' + i + ' length script') + }) + } + + for (var i = 0; i < 520; ++i) { + testEncodingForSize(i) + } + }) }) From 1f62235c38ff3d024372c9a9b855c33c5efcf14c Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 31 Aug 2016 13:45:35 +1000 Subject: [PATCH 2/3] tests: add failing script decode --- test/fixtures/script.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/fixtures/script.json b/test/fixtures/script.json index a7649ed..788d807 100644 --- a/test/fixtures/script.json +++ b/test/fixtures/script.json @@ -149,6 +149,11 @@ "redeemScriptSig": "OP_0", "scriptSig": "OP_0 00", "scriptSigHex": "000100" + }, + { + "type": "nonstandard", + "scriptSig": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "scriptSigHex": "4cff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } ], "invalid": { From 17c6ff62a099fb90c8e27ca44d6665e7b31c26ca Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 31 Aug 2016 13:40:11 +1000 Subject: [PATCH 3/3] bufferutils: fix pushDataInt output --- src/bufferutils.js | 4 ++-- test/fixtures/bufferutils.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bufferutils.js b/src/bufferutils.js index 8e6db04..d4f3153 100644 --- a/src/bufferutils.js +++ b/src/bufferutils.js @@ -10,8 +10,8 @@ function verifuint (value, max) { function pushDataSize (i) { return i < opcodes.OP_PUSHDATA1 ? 1 - : i < 0xff ? 2 - : i < 0xffff ? 3 + : i <= 0xff ? 2 + : i <= 0xffff ? 3 : 5 } diff --git a/test/fixtures/bufferutils.json b/test/fixtures/bufferutils.json index baa003f..db1e1da 100644 --- a/test/fixtures/bufferutils.json +++ b/test/fixtures/bufferutils.json @@ -34,7 +34,7 @@ "dec": 255, "hex64": "ff00000000000000", "hexVI": "fdff00", - "hexPD": "4dff00" + "hexPD": "4cff" }, { "dec": 65534, @@ -46,7 +46,7 @@ "dec": 65535, "hex64": "ffff000000000000", "hexVI": "fdffff", - "hexPD": "4effff0000" + "hexPD": "4dffff" }, { "dec": 65536,