@smartledger/bsv 7.13.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +38 -38
  3. package/bsv-gdaf.min.js +55 -55
  4. package/bsv-ltp.min.js +39 -39
  5. package/bsv-smartcontract.min.js +1 -1
  6. package/bsv.bundle.js +55 -55
  7. package/bsv.min.js +55 -55
  8. package/docs/AUDIT_SCOPE.md +21 -12
  9. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  10. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  11. package/docs/getting-started/INSTALLATION.md +23 -23
  12. package/docs/getting-started/QUICK_START.md +7 -7
  13. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  14. package/lib/crypto/bn.js +22 -2
  15. package/lib/script/interpreter.js +399 -56
  16. package/lib/transaction/sighash.js +18 -6
  17. package/package.json +4 -1
  18. package/test/consensus/base58-vectors.js +120 -0
  19. package/test/consensus/sv-script-vectors.js +81 -0
  20. package/test/consensus/sv-sighash-vectors.js +51 -0
  21. package/test/consensus/sv-tx-vectors.js +48 -0
  22. package/test/data/bitcoin-sv/README.md +170 -0
  23. package/test/data/bitcoin-sv/base58_encode_decode.json +14 -0
  24. package/test/data/bitcoin-sv/base58_keys_invalid.json +152 -0
  25. package/test/data/bitcoin-sv/base58_keys_valid.json +452 -0
  26. package/test/data/bitcoin-sv/script_tests.json +2591 -0
  27. package/test/data/bitcoin-sv/sighash.json +1003 -0
  28. package/test/data/bitcoin-sv/tx_invalid.json +285 -0
  29. package/test/data/bitcoin-sv/tx_valid.json +367 -0
  30. package/test/regressions.js +35 -0
  31. package/test/script/chronicle.js +170 -25
  32. package/test/script/defaults.js +93 -0
  33. package/test/script/genesis_limits.js +62 -6
  34. package/test/script/interpreter.js +24 -8
  35. package/test/transaction/sighash.js +21 -1
  36. package/version.js +1 -1
@@ -168,15 +168,27 @@ var sighashPreimage = function sighashPreimage (transaction, sighashType, inputN
168
168
  // only took effect when FORKID was absent could never select OTDA in practice, and
169
169
  // the flag would mean nothing.
170
170
  //
171
- // Gated on SCRIPT_ENABLE_CHRONICLE, which is off by default: before the upgrade the
172
- // 0x20 bit means nothing, so BIP-143 signatures already exist whose type byte happens
173
- // to set it. Honouring it unconditionally would reinterpret those as OTDA.
171
+ // Routed on the bit alone, not on whether Chronicle is enabled, which is what
172
+ // the node does:
173
+ //
174
+ // if(enabledSighashForkid && sigHashType.hasForkId() && !sigHashType.hasChronicle())
175
+ // return SignatureHashBIP143(...);
176
+ // return SignatureHashOriginal(...);
177
+ //
178
+ // The concern that made this gated is real — before the upgrade the 0x20 bit
179
+ // meant nothing, so BIP-143 signatures exist whose type byte happens to set
180
+ // it, and reinterpreting those as OTDA would be a disaster. The node answers
181
+ // it in a different place: CheckSignatureEncoding rejects a signature
182
+ // carrying the bit outside Chronicle as SCRIPT_ERR_ILLEGAL_CHRONICLE, so
183
+ // such a signature never reaches this function. Gating here instead made 260
184
+ // of the node's 1000 digest vectors disagree, because the digest for a given
185
+ // transaction and hash type then depends on a flag the node does not consult.
174
186
  //
175
187
  // Note the sighash type byte is committed INSIDE the preimage either way, so setting
176
188
  // this bit changes the digest even where it does not change the algorithm.
177
- if ((sighashType & Signature.SIGHASH_CHRONICLE) && (flags & Interpreter.SCRIPT_ENABLE_CHRONICLE)) {
178
- // fall through to the original algorithm
179
- } else if ((sighashType & Signature.SIGHASH_FORKID) && (flags & Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID)) {
189
+ if ((sighashType & Signature.SIGHASH_FORKID) &&
190
+ !(sighashType & Signature.SIGHASH_CHRONICLE) &&
191
+ (flags & Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID)) {
180
192
  return sighashPreimageForForkId(txcopy, sighashType, inputNumber, subscript, satoshisBN)
181
193
  }
182
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "7.13.0",
3
+ "version": "8.0.0",
4
4
  "description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, DeFi, smart contracts, and secure Bitcoin applications.",
5
5
  "author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
6
6
  "homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
@@ -60,6 +60,9 @@
60
60
  "lint": "standard",
61
61
  "check:load-order": "node scripts/check-address-load-order.js",
62
62
  "conformance": "node conformance/verify.js",
63
+ "vectors:sv": "node tools/sv-vector-report.js",
64
+ "vectors:sv-tx": "node tools/sv-tx-report.js",
65
+ "vectors:sv-sighash": "node tools/sv-sighash-report.js",
63
66
  "conformance:generate": "node conformance/generate.js",
64
67
  "lint:ratchet": "node scripts/lint-ratchet.js",
65
68
  "lint:ratchet:update": "node scripts/lint-ratchet.js --update",
@@ -0,0 +1,120 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Base58 and Base58Check vectors from SV Node v1.2.0.
5
+ *
6
+ * `base58_encode_decode.json` had no counterpart in the inherited bitcoind
7
+ * corpus and nothing else here exercises it. It is small, but it is the only
8
+ * place the raw codec is pinned against the node in both directions, and it
9
+ * carries the two cases an implementation gets wrong: the empty input, and
10
+ * leading zero bytes, which base58 encodes as leading '1's rather than as part
11
+ * of a number.
12
+ *
13
+ * The key vectors are content-identical to the bitcoind copies that
14
+ * test/address.js and test/privatekey.js already use — same 50 rows, different
15
+ * whitespace. They are run here against the SV copies regardless, so that the
16
+ * corpus under test/data/bitcoin-sv is the one this library is measured
17
+ * against. That directory is the declared specification, and re-copying it
18
+ * from a newer node tag should move these tests with it.
19
+ */
20
+
21
+ require('chai').should()
22
+ const bsv = require('../..')
23
+ const Base58 = bsv.encoding.Base58
24
+ const Base58Check = bsv.encoding.Base58Check
25
+ const Address = bsv.Address
26
+ const PrivateKey = bsv.PrivateKey
27
+
28
+ const encodeDecode = require('../data/bitcoin-sv/base58_encode_decode.json')
29
+ const keysValid = require('../data/bitcoin-sv/base58_keys_valid.json')
30
+ const keysInvalid = require('../data/bitcoin-sv/base58_keys_invalid.json')
31
+
32
+ describe('base58 vectors (SV Node v1.2.0)', function () {
33
+ describe('the raw codec', function () {
34
+ it('encodes every vector to the recorded string', function () {
35
+ encodeDecode.forEach(function (v, i) {
36
+ Base58.encode(Buffer.from(v[0], 'hex'))
37
+ .should.equal(v[1], 'encoding row ' + i + ' (' + v[0] + ')')
38
+ })
39
+ })
40
+
41
+ it('decodes every vector back to the recorded bytes', function () {
42
+ encodeDecode.forEach(function (v, i) {
43
+ Base58.decode(v[1]).toString('hex')
44
+ .should.equal(v[0], 'decoding row ' + i + ' (' + JSON.stringify(v[1]) + ')')
45
+ })
46
+ })
47
+
48
+ it('keeps leading zero bytes as leading ones', function () {
49
+ // Ten zero bytes encode as ten '1's. An implementation that treats the
50
+ // input purely as a number loses them, and every address starting 1
51
+ // depends on this.
52
+ Base58.encode(Buffer.alloc(10)).should.equal('1111111111')
53
+ Base58.decode('1111111111').should.deep.equal(Buffer.alloc(10))
54
+ })
55
+
56
+ it('round-trips the empty input', function () {
57
+ Base58.encode(Buffer.alloc(0)).should.equal('')
58
+ Base58.decode('').length.should.equal(0)
59
+ })
60
+ })
61
+
62
+ describe('keys and addresses', function () {
63
+ it('accepts every valid key vector', function () {
64
+ let addresses = 0
65
+ let privkeys = 0
66
+ keysValid.forEach(function (v, i) {
67
+ const str = v[0]
68
+ const meta = v[2]
69
+ if (meta.isPrivkey) {
70
+ const key = PrivateKey.fromWIF(str)
71
+ key.toWIF().should.equal(str, 'WIF round trip at ' + i)
72
+ privkeys++
73
+ } else {
74
+ const network = meta.isTestnet ? 'testnet' : 'livenet'
75
+ const address = Address.fromString(str, network)
76
+ address.toString().should.equal(str, 'address round trip at ' + i)
77
+ address.hashBuffer.toString('hex')
78
+ .should.equal(v[1], 'hash at ' + i)
79
+ address.type.should.equal(
80
+ meta.addrType === 'script' ? Address.PayToScriptHash : Address.PayToPublicKeyHash,
81
+ 'type at ' + i)
82
+ addresses++
83
+ }
84
+ })
85
+ // Both kinds must actually have been reached.
86
+ addresses.should.be.above(0)
87
+ privkeys.should.be.above(0)
88
+ })
89
+
90
+ it('rejects every invalid key vector, as neither address nor key', function () {
91
+ // The claim these vectors make is that the string is not a valid address
92
+ // and not a valid WIF — not that it fails Base58Check. Several of them
93
+ // carry a perfectly good checksum and are simply the wrong length or
94
+ // version, so the checksum layer accepts them and the layer above is
95
+ // what has to refuse. Asserting the stronger thing would be asserting
96
+ // something the corpus does not say.
97
+ let checksumOk = 0
98
+ keysInvalid.forEach(function (v, i) {
99
+ const str = v[0]
100
+ Address.isValid(str).should.equal(false, 'Address accepted row ' + i)
101
+
102
+ let isKey = true
103
+ try {
104
+ PrivateKey.fromWIF(str)
105
+ } catch (e) {
106
+ isKey = false
107
+ }
108
+ isKey.should.equal(false, 'PrivateKey accepted row ' + i)
109
+
110
+ try {
111
+ Base58Check.decode(str)
112
+ checksumOk++
113
+ } catch (e) { /* a bad checksum is one way to be invalid, not the only one */ }
114
+ })
115
+ // Guards the reasoning above: if none of them had a valid checksum, this
116
+ // test would be weaker than it looks and Base58Check could be asserted.
117
+ checksumOk.should.be.above(0)
118
+ })
119
+ })
120
+ })
@@ -0,0 +1,81 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Consensus ratchet over the SV Node script vectors.
5
+ *
6
+ * A report tells you where you are; this stops you going backwards. Both read
7
+ * the same harness, so the progress figure and the gate cannot disagree.
8
+ *
9
+ * False accepts are held at zero outright rather than through an allowlist,
10
+ * because accepting a script the network rejects is the direction that can
11
+ * cost money. False rejects are held at zero too — the corpus passes
12
+ * completely, so there is nothing to exempt and no list to maintain.
13
+ */
14
+
15
+ require('chai').should()
16
+ const harness = require('../../tools/sv-vector-harness')
17
+
18
+ describe('SV Node script vectors', function () {
19
+ this.timeout(120000)
20
+
21
+ let results = null
22
+
23
+ before(function () {
24
+ results = harness.runAll()
25
+ })
26
+
27
+ it('runs the whole corpus', function () {
28
+ results.length.should.equal(1483)
29
+ })
30
+
31
+ it('uses no flag the harness does not recognise', function () {
32
+ // An unrecognised flag means vectors run under the wrong rules, and any
33
+ // pass among them means nothing.
34
+ const unknown = new Set()
35
+ results.forEach(r => r.unknownFlags.forEach(f => unknown.add(f)))
36
+ Array.from(unknown).should.deep.equal([])
37
+ })
38
+
39
+ it('accepts nothing the node rejects', function () {
40
+ const accepts = results.filter(r => r.direction === 'accept')
41
+ const detail = accepts.map(r =>
42
+ '\n ' + r.id + ' ' + r.reason + '\n ' + harness.describe(r.row)).join('')
43
+ accepts.length.should.equal(0, 'false accepts must stay at zero:' + detail)
44
+ })
45
+
46
+ it('rejects nothing the node accepts', function () {
47
+ const rejects = results.filter(r => r.direction === 'reject')
48
+ const detail = rejects.map(r =>
49
+ '\n ' + r.id + ' ' + r.reason + '\n ' + harness.describe(r.row)).join('')
50
+ rejects.length.should.equal(0, 'false rejects must stay at zero:' + detail)
51
+ })
52
+
53
+ it('fails for the reason the node gives', function () {
54
+ // Matching the outcome is not the same as matching the reason, and the gap
55
+ // hid three real bugs — see ERROR_CODE_ALIASES in the harness. Each left
56
+ // the script failing, so the two tests above stayed green throughout.
57
+ const wrong = results.filter(r => r.codeMatches === false)
58
+ const detail = wrong.map(r =>
59
+ '\n ' + r.id + ' expected ' + r.expectedCode + ', reported ' + r.gotCode +
60
+ '\n ' + harness.describe(r.row)).join('')
61
+ wrong.length.should.equal(0,
62
+ wrong.length + ' vector(s) fail for the wrong reason:' + detail)
63
+ })
64
+
65
+ it('compares a code on every vector the node rejects', function () {
66
+ // Guards the test above: if `comparable` ever narrowed, it would pass by
67
+ // checking nothing.
68
+ const rejected = results.filter(r => r.row.expected !== 'OK' && r.passed)
69
+ rejected.length.should.equal(600)
70
+ rejected.every(r => r.codeMatches !== null).should.equal(true)
71
+ })
72
+
73
+ it('uses every alias it grants', function () {
74
+ // The ratchet's other direction. An alias no vector produces any more is
75
+ // an exemption outliving its reason, and should be deleted rather than
76
+ // left to cover something later.
77
+ const produced = new Set(results.filter(r => r.gotCode).map(r => r.gotCode))
78
+ const unused = Object.keys(harness.ERROR_CODE_ALIASES).filter(a => !produced.has(a))
79
+ unused.should.deep.equal([], 'alias(es) no vector produces; remove them')
80
+ })
81
+ })
@@ -0,0 +1,51 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Transaction digest vectors from SV Node v1.2.0 — the regression gate.
5
+ *
6
+ * The work is in tools/sv-sighash-harness.js, which npm run vectors:sv-sighash
7
+ * also uses, so the progress report and this gate cannot disagree about what
8
+ * passes. That file documents the corpus layout and the node's routing.
9
+ *
10
+ * Unlike the script and transaction vectors, this one carries no known-failure
11
+ * list. It has never had a failing row and there is no reason it should: a
12
+ * digest is a pure function of a transaction and a hash type, with no era to
13
+ * negotiate.
14
+ */
15
+
16
+ require('chai').should()
17
+ const harness = require('../../tools/sv-sighash-harness')
18
+
19
+ describe('SV Node sighash vectors', function () {
20
+ this.timeout(120000)
21
+
22
+ const results = harness.runAll()
23
+
24
+ it('covers the whole corpus', function () {
25
+ results.length.should.equal(1000)
26
+ })
27
+
28
+ it('matches the node on both digest columns', function () {
29
+ const failures = results.filter(r => !r.passed)
30
+ .map(r => '#' + r.index + ' ' + r.reason)
31
+ failures.slice(0, 8).should.deep.equal([],
32
+ failures.length + ' of ' + results.length + ' rows disagree with the node')
33
+ })
34
+
35
+ it('routes every Chronicle-bit row to the original digest', function () {
36
+ // Stated separately so a routing regression reads as one rather than as
37
+ // hundreds of unexplained hash mismatches.
38
+ const withBit = harness.chronicleRows()
39
+ withBit.length.should.equal(511)
40
+ withBit.forEach(v => v[4].should.equal(v[5]))
41
+ results.filter(r => r.chronicleBit)
42
+ .forEach(r => r.algorithm.should.equal('OTDA'))
43
+ })
44
+
45
+ it('still exercises both algorithms', function () {
46
+ // Guards the test above: if the routing collapsed to OTDA everywhere it
47
+ // would pass, and this is what would notice.
48
+ results.filter(r => r.algorithm === 'BIP143').length.should.be.above(0)
49
+ results.filter(r => r.algorithm === 'OTDA').length.should.be.above(0)
50
+ })
51
+ })
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Consensus ratchet over the SV Node transaction vectors.
5
+ *
6
+ * These reach a level the script corpus cannot. A script vector evaluates one
7
+ * unlocking script against one locking script; these deserialise a whole
8
+ * transaction, resolve each input against the output it claims to spend, and
9
+ * require every one to verify, with locktimes and sequence numbers in play.
10
+ *
11
+ * That level earned itself immediately: it found that Genesis reverts
12
+ * OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY to upgradable NOPs, which
13
+ * this library did not implement and no script vector can reach — the
14
+ * behaviour only appears once a real nLockTime and sequence number exist.
15
+ */
16
+
17
+ require('chai').should()
18
+ const harness = require('../../tools/sv-tx-harness')
19
+
20
+ describe('SV Node transaction vectors', function () {
21
+ this.timeout(120000)
22
+
23
+ let results = null
24
+
25
+ before(function () {
26
+ results = harness.runAll()
27
+ })
28
+
29
+ it('runs both files', function () {
30
+ results.length.should.equal(161)
31
+ results.filter(r => r.expected).length.should.equal(93)
32
+ results.filter(r => !r.expected).length.should.equal(68)
33
+ })
34
+
35
+ it('accepts no transaction the node rejects', function () {
36
+ const accepts = results.filter(r => r.direction === 'accept')
37
+ const detail = accepts.map(r =>
38
+ '\n ' + r.id + ' ' + r.reason + '\n ' + harness.describe(r)).join('')
39
+ accepts.length.should.equal(0, 'false accepts must stay at zero:' + detail)
40
+ })
41
+
42
+ it('rejects no transaction the node accepts', function () {
43
+ const rejects = results.filter(r => r.direction === 'reject')
44
+ const detail = rejects.map(r =>
45
+ '\n ' + r.id + ' ' + r.reason + '\n ' + harness.describe(r)).join('')
46
+ rejects.length.should.equal(0, 'false rejects must stay at zero:' + detail)
47
+ })
48
+ })
@@ -0,0 +1,170 @@
1
+ # SV Node consensus vectors
2
+
3
+ Consensus test vectors copied verbatim from the reference node implementation.
4
+ These are the specification this library is measured against — do not hand-edit
5
+ them. To update, re-copy from a node tag and record the new provenance here.
6
+
7
+ | field | value |
8
+ | --- | --- |
9
+ | source | [`bitcoin-sv/bitcoin-sv`](https://github.com/bitcoin-sv/bitcoin-sv) `src/test/data` |
10
+ | tag | `v1.2.0` (Chronicle); byte-identical in `v1.2.2`, the current release |
11
+ | commit | `60dc6a3f2547eeaaa3a605e5a69a9fc8686b0a25` |
12
+ | retrieved | 2026-08-11 |
13
+ | licence | MIT (same as this library) |
14
+
15
+ Genesis activated at block **620,538** on **2020-02-04**; Chronicle at block
16
+ **943,816** on **2026-04-07**.
17
+
18
+ ## Files
19
+
20
+ | file | rows run | covers | gate |
21
+ | --- | --- | --- | --- |
22
+ | `script_tests.json` | 1483 | script evaluation, including Genesis and Chronicle rules | `test/consensus/sv-script-vectors.js` |
23
+ | `sighash.json` | 1000 | transaction digest algorithm | `test/consensus/sv-sighash-vectors.js` |
24
+ | `tx_valid.json` | 93 | transactions that must validate | `test/consensus/sv-tx-vectors.js` |
25
+ | `tx_invalid.json` | 68 | transactions that must be rejected | `test/consensus/sv-tx-vectors.js` |
26
+ | `base58_keys_valid.json` | 50 | address and WIF encoding | `test/consensus/base58-vectors.js` |
27
+ | `base58_keys_invalid.json` | 50 | malformed address rejection | `test/consensus/base58-vectors.js` |
28
+ | `base58_encode_decode.json` | 12 | raw base58 round-trips | `test/consensus/base58-vectors.js` |
29
+
30
+ Every one of these is exercised, and every one passes completely. There is no
31
+ known-failure list and nothing is exempted, so any list added later should read
32
+ as a decision someone made rather than as inherited debt.
33
+
34
+ These supersede the older pre-Genesis vectors in `test/data/bitcoind`, which are
35
+ inherited from the upstream fork and encode consensus rules the network
36
+ abandoned in 2020. Those are retained for now so the two can be diffed, but
37
+ they are **not** a valid consensus reference. Where they disagree with these,
38
+ these win.
39
+
40
+ ## Measuring the gap
41
+
42
+ npm run vectors:sv # script vectors
43
+ npm run vectors:sv-tx # transaction vectors
44
+ npm run vectors:sv-sighash # transaction digest vectors
45
+
46
+ Each takes `-- --verbose` for the full failing list. Every report shares its
47
+ harness with the corresponding gate under `test/consensus`, so the progress
48
+ figure and the regression gate cannot disagree about what passes.
49
+
50
+ The script and transaction reports separate the two directions of failure. A
51
+ **false accept** — accepting a script the node rejects — is the direction that
52
+ can cost money, and is held at zero outright. A false reject only costs a
53
+ transaction. The digest report makes no such distinction: a wrong digest is
54
+ equally bad either way, since it both makes valid signatures unverifiable and
55
+ signs something other than what the caller was shown.
56
+
57
+ ## Row layout, and two columns that are easy to get wrong
58
+
59
+ Defined by `script_json_test` in the node's `src/test/script_tests.cpp`:
60
+
61
+ [ [nValue]?, txnVersion, scriptSig, scriptPubKey, flags, expected, comment? ]
62
+
63
+ - **`nValue`** is present only when a row needs an input amount, and it is
64
+ wrapped in an **array**. It states whole coins; the transaction carries
65
+ satoshis, so multiply by 1e8 (the node's `AmountFromValue`).
66
+ - **`txnVersion`** is the *spending* transaction's version, and is present on
67
+ every row. Chronicle gates its malleability relaxations on version > 1, so
68
+ this column is consensus-relevant — it is not padding, and it is not an
69
+ amount. Mistaking it for one changes the crediting transaction's value, which
70
+ changes its txid, which changes the sighash, which silently breaks every
71
+ signature-checking vector in the corpus.
72
+
73
+ The crediting transaction is always version 1; only the spending transaction
74
+ carries the version under test. Both use locktime 0 and a final sequence, and
75
+ the crediting input's scriptSig is `OP_0 OP_0`.
76
+
77
+ ## Flags, and one place this fork differs
78
+
79
+ Flags are mapped by **name**, never by value. This library assigns
80
+ `MONOLITH_OPCODES` and `MAGNETIC_OPCODES` to bits `1<<18` and `1<<19`, which
81
+ are the bits the node uses for `SCRIPT_GENESIS` and `SCRIPT_UTXO_AFTER_GENESIS`
82
+ — mapping by value would quietly run vectors under the wrong rules while
83
+ appearing to pass.
84
+
85
+ The corpus never names `MONOLITH` or `MAGNETIC`, because the node has no such
86
+ flags: those opcodes were restored on BSV in 2018 and are simply enabled. This
87
+ library still gates them, so the harness enables them for every row; otherwise
88
+ the report would be dominated by that one difference rather than by consensus.
89
+ The gating is itself a divergence from BSV and is worth removing. It is
90
+ compensated for here rather than hidden, so that the figures mean what they
91
+ say.
92
+
93
+ ## Transaction vectors
94
+
95
+ `tx_valid.json` and `tx_invalid.json` go a level above the script corpus: a
96
+ whole transaction is deserialised, each input resolved against the output it
97
+ claims to spend, and every one required to verify — with locktimes, sequence
98
+ numbers and multiple inputs in play.
99
+
100
+ That level is worth having. It found a Genesis rule the script corpus cannot
101
+ reach: `OP_CHECKLOCKTIMEVERIFY` and `OP_CHECKSEQUENCEVERIFY` revert to
102
+ upgradable NOPs after Genesis, and without that, four transactions the network
103
+ accepts were being rejected. The behaviour only appears once a real nLockTime
104
+ and sequence exist, so no single-script vector exercises it.
105
+
106
+ ## Digest vectors
107
+
108
+ Each row of `sighash.json` carries **two** expected digests for the same inputs
109
+ — one with forkid enabled and one without — which pins the routing in
110
+ `SignatureHash()` rather than one branch of it.
111
+
112
+ That second column earned its keep. It found 260 rows where this library
113
+ honoured `SIGHASH_CHRONICLE` only when `SCRIPT_ENABLE_CHRONICLE` was also set,
114
+ where the node routes on the bit alone and instead rejects a signature carrying
115
+ that bit outside Chronicle in `CheckSignatureEncoding`, as
116
+ `SCRIPT_ERR_ILLEGAL_CHRONICLE`. Rejected, not reinterpreted.
117
+
118
+ For a row whose hash type sets `0x20`, both columns are identical — the
119
+ original algorithm is taken either way. 511 of the 1000 rows are of that kind,
120
+ so a gate checking only one column would be blind to half the corpus.
121
+
122
+ ## Base58
123
+
124
+ The key vectors are content-identical to the bitcoind copies already used by
125
+ `test/address.js` and `test/privatekey.js` — same 50 rows, different whitespace
126
+ — but `base58_encode_decode.json` has no counterpart there, and nothing else
127
+ pins the raw codec against the node in both directions.
128
+
129
+ Note what the invalid-key vectors actually claim: that a string is neither a
130
+ valid address nor a valid WIF. Several carry a perfectly good checksum and are
131
+ simply the wrong length or version, so `Base58Check` accepts them and the layer
132
+ above is what refuses. A test asserting the checksum layer rejects them would
133
+ be asserting something the corpus does not say.
134
+
135
+ ## Result codes
136
+
137
+ Matching the node's accept/reject outcome is not the same as failing for the
138
+ node's *reason*, and the gap between the two is where bugs live. Comparing the
139
+ result code of all 600 rejected vectors found four, each of which left the
140
+ script failing — so the outcome check stayed green through every one:
141
+
142
+ - a div-by-zero guard comparing a `BN` against the number `0`, so it never
143
+ fired and bn.js asserted instead
144
+ - script number decoding throwing past the evaluator into a generic catch,
145
+ which is what 78 of the four hundred were
146
+ - a truncated `PUSHDATA` doing the same
147
+ - `OP_NUM2BIN` checking only the upper bound of its size argument, so a
148
+ negative size reported the wrong failure
149
+
150
+ All 600 now match: 491 exactly, and 109 through `ERROR_CODE_ALIASES` in
151
+ `tools/sv-vector-harness.js` — names this library reports more narrowly than
152
+ the node, such as `EVAL_FALSE_IN_STACK` for `EVAL_FALSE`. That table is a short
153
+ statement of intent rather than a list of exempted vectors, and it ratchets
154
+ both ways: an unlisted mismatch fails, and so does an alias no vector produces
155
+ any more, so an exemption cannot outlive its reason. Anything added to it
156
+ should be a name that says *more* than the node's, never a different failure
157
+ wearing its label.
158
+
159
+ ## What the vectors cannot reach
160
+
161
+ Passing this corpus completely is not the same as matching the node. Reading
162
+ the code alongside it found `OP_CAT` capping its result at the static 520-byte
163
+ element size rather than the era-derived one, so after Genesis it rejected
164
+ concatenations the network accepts — built from two 300-byte halves that are
165
+ each legal on their own. It is the one opcode that can grow an element past the
166
+ cap without ever pushing an oversized element, which is why no vector here
167
+ covers it. `test/script/genesis_limits.js` holds it instead.
168
+
169
+ Where a rule has no vector, the test that holds it belongs somewhere that says
170
+ so.
@@ -0,0 +1,14 @@
1
+ [
2
+ ["", ""],
3
+ ["61", "2g"],
4
+ ["626262", "a3gV"],
5
+ ["636363", "aPEr"],
6
+ ["73696d706c792061206c6f6e6720737472696e67", "2cFupjhnEsSn59qHXstmK2ffpLv2"],
7
+ ["00eb15231dfceb60925886b67d065299925915aeb172c06647", "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"],
8
+ ["516b6fcd0f", "ABnLTmg"],
9
+ ["bf4f89001e670274dd", "3SEo3LWLoPntC"],
10
+ ["572e4794", "3EFU7m"],
11
+ ["ecac89cad93923c02321", "EJDM8drfXA6uyA"],
12
+ ["10c8511e", "Rt5zm"],
13
+ ["00000000000000000000", "1111111111"]
14
+ ]