@smartledger/bsv 9.0.0 → 9.1.1
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.
- package/CHANGELOG.md +164 -0
- package/README.md +152 -1041
- package/STABILITY.md +134 -0
- package/bsv-gdaf.min.js +53 -48
- package/bsv-ltp.min.js +23 -18
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +53 -48
- package/bsv.min.js +53 -48
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/docs/proposals/10.0.0-package-split.md +131 -0
- package/index.js +5 -0
- package/lib/block/merkleblock.js +53 -9
- package/lib/hdprivatekey.js +15 -0
- package/lib/script/interpreter.js +109 -1
- package/lib/smart_contract/builder.js +14 -0
- package/lib/util/deprecate.js +159 -0
- package/package.json +19 -82
- package/version.js +1 -1
- package/.mocharc.json +0 -5
- package/test/address.js +0 -629
- package/test/block/block.js +0 -239
- package/test/block/blockheader.js +0 -270
- package/test/block/merkleblock.js +0 -207
- package/test/build/bundle_crypto_shim.js +0 -104
- package/test/build/bundle_externals.js +0 -125
- package/test/build/bundle_smoke.js +0 -55
- package/test/build/esbuild_main.js +0 -65
- package/test/build/esm_wrapper.js +0 -97
- package/test/build/exports_resolution.js +0 -84
- package/test/build/version_sync.js +0 -14
- package/test/cli/smoke.js +0 -261
- package/test/consensus/base58-vectors.js +0 -120
- package/test/consensus/sv-script-vectors.js +0 -81
- package/test/consensus/sv-sighash-vectors.js +0 -51
- package/test/consensus/sv-tx-vectors.js +0 -48
- package/test/credentials-test.js +0 -332
- package/test/crypto/backend_selection.js +0 -126
- package/test/crypto/bn.js +0 -168
- package/test/crypto/ecdsa.js +0 -426
- package/test/crypto/elliptic-fixed.js +0 -61
- package/test/crypto/hash.browser.js +0 -121
- package/test/crypto/hash.js +0 -122
- package/test/crypto/point.js +0 -193
- package/test/crypto/random.js +0 -105
- package/test/crypto/security.js +0 -176
- package/test/crypto/shamir.js +0 -177
- package/test/crypto/shamir_rngcap.js +0 -29
- package/test/crypto/signature.js +0 -399
- package/test/data/bip69.json +0 -215
- package/test/data/bitcoin-sv/README.md +0 -170
- package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
- package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
- package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
- package/test/data/bitcoin-sv/script_tests.json +0 -2591
- package/test/data/bitcoin-sv/sighash.json +0 -1003
- package/test/data/bitcoin-sv/tx_invalid.json +0 -285
- package/test/data/bitcoin-sv/tx_valid.json +0 -367
- package/test/data/bitcoind/base58_keys_invalid.json +0 -152
- package/test/data/bitcoind/base58_keys_valid.json +0 -452
- package/test/data/bitcoind/blocks.json +0 -27
- package/test/data/bitcoind/script_tests.json +0 -2244
- package/test/data/bitcoind/sig_canonical.json +0 -7
- package/test/data/bitcoind/sig_noncanonical.json +0 -22
- package/test/data/bitcoind/tx_invalid.json +0 -177
- package/test/data/bitcoind/tx_valid.json +0 -224
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +0 -12
- package/test/data/blk86756-testnet.json +0 -684
- package/test/data/brc220-batch-vector.json +0 -129
- package/test/data/ecdsa.json +0 -230
- package/test/data/merkleblocks.js +0 -486
- package/test/data/messages.json +0 -22
- package/test/data/sighash.json +0 -1004
- package/test/data/tx_creation.json +0 -85
- package/test/didweb/relationships.js +0 -144
- package/test/ecies/bitcore-ecies.js +0 -178
- package/test/ecies/electrum-ecies.js +0 -206
- package/test/encoding/base58.js +0 -131
- package/test/encoding/base58check.js +0 -145
- package/test/encoding/bufferreader.js +0 -328
- package/test/encoding/bufferwriter.js +0 -160
- package/test/encoding/varint.js +0 -104
- package/test/gdaf/anchor_no_key_leak.js +0 -146
- package/test/gdaf/anchor_spv.js +0 -163
- package/test/gdaf/canonicalization.js +0 -106
- package/test/gdaf/canonicalize.js +0 -140
- package/test/gdaf/zk_prover.js +0 -204
- package/test/hdkeys.js +0 -365
- package/test/hdprivatekey.js +0 -339
- package/test/hdpublickey.js +0 -293
- package/test/index.js +0 -16
- package/test/ltp/ids.js +0 -74
- package/test/ltp/right.js +0 -198
- package/test/ltp/verify_failclosed.js +0 -134
- package/test/message/message.js +0 -190
- package/test/mnemonic/data/fixtures.json +0 -300
- package/test/mnemonic/mnemonic.js +0 -277
- package/test/mnemonic/mocha.opts +0 -1
- package/test/mnemonic/pbkdf2.test.js +0 -43
- package/test/networks.js +0 -207
- package/test/notaryhash/batch_leaf.js +0 -140
- package/test/notaryhash/batch_vector.js +0 -282
- package/test/notaryhash/certificate.js +0 -249
- package/test/notaryhash/encoding.js +0 -186
- package/test/notaryhash/interop.js +0 -112
- package/test/notaryhash/merkle.js +0 -181
- package/test/notaryhash/script.js +0 -270
- package/test/notaryhash/verify.js +0 -342
- package/test/opcode.js +0 -186
- package/test/ordinals/bsv20.js +0 -337
- package/test/ordinals/inscription.js +0 -329
- package/test/ordinals/ordlock.js +0 -567
- package/test/privatekey.js +0 -540
- package/test/publickey.js +0 -411
- package/test/regressions.js +0 -215
- package/test/script/chronicle.js +0 -543
- package/test/script/defaults.js +0 -160
- package/test/script/genesis_limits.js +0 -203
- package/test/script/interpreter.js +0 -776
- package/test/script/script.js +0 -1259
- package/test/script/string_ops.js +0 -88
- package/test/security/fail_closed_contracts.js +0 -104
- package/test/security/threat_model_coverage.js +0 -31
- package/test/smart_contract/covenants.js +0 -207
- package/test/smart_contract/dsl_debugger.js +0 -92
- package/test/smart_contract/extract_field.js +0 -61
- package/test/smart_contract/nonenforcing_guard.js +0 -44
- package/test/smart_contract/ordinal_transfer.js +0 -71
- package/test/smart_contract/preimage.js +0 -98
- package/test/smart_contract/sighash_marketplace.js +0 -98
- package/test/smart_contract/token_generalized.js +0 -175
- package/test/spv/headerchain.js +0 -86
- package/test/spv/merkleproof.js +0 -133
- package/test/statuslist/failclosed.js +0 -78
- package/test/transaction/deserialize.js +0 -33
- package/test/transaction/input/input.js +0 -92
- package/test/transaction/input/multisig.js +0 -174
- package/test/transaction/input/multisigscripthash.js +0 -111
- package/test/transaction/input/publickey.js +0 -68
- package/test/transaction/input/publickeyhash.js +0 -59
- package/test/transaction/output.js +0 -185
- package/test/transaction/sighash.js +0 -91
- package/test/transaction/signature.js +0 -127
- package/test/transaction/transaction.js +0 -1299
- package/test/transaction/unspentoutput.js +0 -97
- package/test/types/dts_drift.js +0 -124
- package/test/types/surface_honesty.js +0 -102
- package/test/util/id.js +0 -72
- package/test/util/js.js +0 -76
- package/test/util/preconditions.js +0 -79
- package/test/vcjwt/interop.js +0 -126
package/test/script/defaults.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// `verify()` describes BSV mainnet as it is today when the caller says nothing.
|
|
6
|
-
//
|
|
7
|
-
// Until 8.0.0 it defaulted to `0` — no rules at all. That is the wrong direction to be
|
|
8
|
-
// wrong in: a validator looser than consensus accepts scripts the network rejects, and
|
|
9
|
-
// nothing that tests this library against itself can see it. The node vectors found 21
|
|
10
|
-
// such cases the first time they were run.
|
|
11
|
-
//
|
|
12
|
-
// The set is not assembled by judgement. It mirrors what tools/sv-vector-harness.js
|
|
13
|
-
// applies, including the MONOLITH/MAGNETIC pair — BSV restored those opcodes in 2018 and
|
|
14
|
-
// the node does not gate them, so omitting them here would make the default STRICTER
|
|
15
|
-
// than consensus.
|
|
16
|
-
|
|
17
|
-
require('chai').should()
|
|
18
|
-
var bsv = require('../..')
|
|
19
|
-
var Script = bsv.Script
|
|
20
|
-
var Interpreter = Script.Interpreter
|
|
21
|
-
var Opcode = bsv.Opcode
|
|
22
|
-
var BN = bsv.crypto.BN
|
|
23
|
-
|
|
24
|
-
describe('verify() consensus defaults', function () {
|
|
25
|
-
var FLAGS = Interpreter.currentConsensusFlags()
|
|
26
|
-
|
|
27
|
-
it('includes both era pairs, for the spend and the output being spent', function () {
|
|
28
|
-
;[
|
|
29
|
-
'SCRIPT_GENESIS', 'SCRIPT_UTXO_AFTER_GENESIS',
|
|
30
|
-
'SCRIPT_ENABLE_CHRONICLE', 'SCRIPT_UTXO_AFTER_CHRONICLE'
|
|
31
|
-
].forEach(function (name) {
|
|
32
|
-
(FLAGS & Interpreter[name]).should.equal(Interpreter[name], name + ' missing from the default')
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
// Omitting these would make the library stricter than the node, which is the error
|
|
37
|
-
// #112 fixed in mainnetFlags(). The harness sets the same pair for every vector.
|
|
38
|
-
it('enables the opcode groups the node does not gate', function () {
|
|
39
|
-
(FLAGS & Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES)
|
|
40
|
-
.should.equal(Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES)
|
|
41
|
-
;(FLAGS & Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES)
|
|
42
|
-
.should.equal(Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('does not enable the pre-Genesis timelock flags', function () {
|
|
46
|
-
// Genesis reverted CLTV/CSV to upgradable NOPs; carrying their flags made
|
|
47
|
-
// mainnetFlags() report timelocked outputs unspendable. See #112.
|
|
48
|
-
;(FLAGS & Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY).should.equal(0)
|
|
49
|
-
;(FLAGS & Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY).should.equal(0)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe('applied by verify()', function () {
|
|
53
|
-
function evaluate (build, args) {
|
|
54
|
-
var script = new Script()
|
|
55
|
-
build(script)
|
|
56
|
-
var interp = new Interpreter()
|
|
57
|
-
var verified = interp.verify.apply(interp, [new Script(), script].concat(args || []))
|
|
58
|
-
return { verified: verified, errstr: interp.errstr || '' }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// OP_VER is a Chronicle opcode. Reaching it without BAD_OPCODE proves the default
|
|
62
|
-
// enabled Chronicle rather than merely exposing a constant.
|
|
63
|
-
it('evaluates a Chronicle opcode with no flags argument', function () {
|
|
64
|
-
var r = evaluate(function (s) { s.add(Opcode.OP_VER) }, [new bsv.Transaction(), 0])
|
|
65
|
-
r.errstr.should.not.match(/BAD_OPCODE/)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('still lets the caller select older rules explicitly', function () {
|
|
69
|
-
var r = evaluate(function (s) { s.add(Opcode.OP_VER) }, [new bsv.Transaction(), 0, 0])
|
|
70
|
-
r.verified.should.equal(false)
|
|
71
|
-
r.errstr.should.match(/BAD_OPCODE/)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
// FORKID changes the sighash algorithm and cannot be applied without the input
|
|
75
|
-
// amount — verify() rejects that combination outright. Rather than forcing every
|
|
76
|
-
// caller to supply satoshis for scripts containing no signature check, the flag is
|
|
77
|
-
// dropped when there is nothing for it to act on. A FORKID-signed input without the
|
|
78
|
-
// amount then fails to verify, which is a false negative, never a false positive.
|
|
79
|
-
it('drops FORKID when no input amount is supplied, instead of throwing', function () {
|
|
80
|
-
;(function () {
|
|
81
|
-
evaluate(function (s) { s.add(Opcode.OP_1) }, [new bsv.Transaction(), 0])
|
|
82
|
-
}).should.not.throw()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('keeps FORKID when the input amount is supplied', function () {
|
|
86
|
-
var interp = new Interpreter()
|
|
87
|
-
var script = new Script().add(Opcode.OP_1)
|
|
88
|
-
interp.verify(new Script(), script, new bsv.Transaction(), 0, undefined, new BN(1000))
|
|
89
|
-
;(interp.flags & Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID)
|
|
90
|
-
.should.equal(Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID)
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
// The script-number bound is era-derived, not a process-wide static.
|
|
96
|
-
//
|
|
97
|
-
// `mainnetFlags()` omitted every era flag except SCRIPT_ENABLE_CHRONICLE, so
|
|
98
|
-
// `maxScriptNumLength()` fell back to the pre-Genesis 4 for a validator built from the
|
|
99
|
-
// helper named after mainnet — while post-Genesis is 750,000 and post-Chronicle
|
|
100
|
-
// 32,000,000. An earlier fix pinned MAXIMUM_ELEMENT_SIZE to stop useGenesisLimits()
|
|
101
|
-
// raising it to 0x7fffffff and making Chronicle's shift-overflow check unreachable; that
|
|
102
|
-
// treated the symptom rather than the missing flags.
|
|
103
|
-
//
|
|
104
|
-
// The node's vectors settle the pre-Genesis value at 4 and are silent above it: all 22
|
|
105
|
-
// SCRIPTNUM_OVERFLOW rows carry P2SH,STRICTENC and no era flag, and raising the static
|
|
106
|
-
// bound to 8 turns 15 of them into false accepts.
|
|
107
|
-
describe('script-number bound follows the era', function () {
|
|
108
|
-
function boundFor (flags) {
|
|
109
|
-
var i = new Interpreter()
|
|
110
|
-
i.set({ flags: flags })
|
|
111
|
-
return i.maxScriptNumLength()
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
it('is 4 before Genesis, which the node vectors pin', function () {
|
|
115
|
-
boundFor(0).should.equal(4)
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('is the post-Genesis figure when only Genesis is asked for', function () {
|
|
119
|
-
boundFor(Interpreter.mainnetFlags({ afterChronicle: false }))
|
|
120
|
-
.should.equal(Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('is the post-Chronicle figure under mainnetFlags() and the default', function () {
|
|
124
|
-
boundFor(Interpreter.mainnetFlags())
|
|
125
|
-
.should.equal(Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE)
|
|
126
|
-
boundFor(Interpreter.currentConsensusFlags())
|
|
127
|
-
.should.equal(Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// Genesis activated in 2020 and nothing still spendable predates it in a way that
|
|
131
|
-
// makes a mainnet helper want the older limits, so it is not opt-out-able here.
|
|
132
|
-
it('carries the Genesis era flags in mainnetFlags(), both variants', function () {
|
|
133
|
-
;[Interpreter.mainnetFlags(), Interpreter.mainnetFlags({ afterChronicle: false })].forEach(function (f) {
|
|
134
|
-
(f & Interpreter.SCRIPT_GENESIS).should.equal(Interpreter.SCRIPT_GENESIS)
|
|
135
|
-
;(f & Interpreter.SCRIPT_UTXO_AFTER_GENESIS).should.equal(Interpreter.SCRIPT_UTXO_AFTER_GENESIS)
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
it('drops only the Chronicle pair for a pre-activation UTXO', function () {
|
|
140
|
-
var pre = Interpreter.mainnetFlags({ afterChronicle: false })
|
|
141
|
-
;(pre & Interpreter.SCRIPT_ENABLE_CHRONICLE).should.equal(0)
|
|
142
|
-
;(pre & Interpreter.SCRIPT_UTXO_AFTER_CHRONICLE).should.equal(0)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
// useMainnetConsensus() must no longer pin the static; the flags carry the bound.
|
|
146
|
-
//
|
|
147
|
-
// The limits are process-wide statics, so this saves and restores them. Without the
|
|
148
|
-
// restore the raised caps leak into every later test in the same mocha process — 24 of
|
|
149
|
-
// them, when this was first written, including the inherited pre-Genesis bitcoind
|
|
150
|
-
// vectors. The same trap #114 hit and documented.
|
|
151
|
-
it('is not overridden by useMainnetConsensus()', function () {
|
|
152
|
-
var saved = Interpreter.getLimits()
|
|
153
|
-
try {
|
|
154
|
-
var flags = Interpreter.useMainnetConsensus()
|
|
155
|
-
boundFor(flags).should.equal(Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE)
|
|
156
|
-
} finally {
|
|
157
|
-
Interpreter.setLimits(saved)
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
})
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it, beforeEach, afterEach */
|
|
4
|
-
var should = require('chai').should()
|
|
5
|
-
var bsv = require('../..')
|
|
6
|
-
var BN = bsv.crypto.BN
|
|
7
|
-
var Interpreter = bsv.Script.Interpreter
|
|
8
|
-
var Script = bsv.Script
|
|
9
|
-
var Opcode = bsv.Opcode
|
|
10
|
-
var Transaction = bsv.Transaction
|
|
11
|
-
|
|
12
|
-
// Post-Genesis BSV removed the pre-Genesis script limits (520-byte element,
|
|
13
|
-
// 4-byte script number, 201 opcodes). These are now configurable so modern
|
|
14
|
-
// covenants (e.g. OP_PUSH_TX) can be evaluated. Defaults are unchanged.
|
|
15
|
-
describe('Interpreter post-Genesis limits', function () {
|
|
16
|
-
var saved
|
|
17
|
-
|
|
18
|
-
beforeEach(function () {
|
|
19
|
-
saved = Interpreter.getLimits()
|
|
20
|
-
})
|
|
21
|
-
afterEach(function () {
|
|
22
|
-
Interpreter.setLimits(saved)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('keeps pre-Genesis defaults out of the box', function () {
|
|
26
|
-
Interpreter.MAX_SCRIPT_ELEMENT_SIZE.should.equal(520)
|
|
27
|
-
Interpreter.MAXIMUM_ELEMENT_SIZE.should.equal(4)
|
|
28
|
-
// 500, not Core's 201: BSV raised the limit before Genesis removed it.
|
|
29
|
-
Interpreter.MAX_OPS_PER_SCRIPT.should.equal(500)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// MAXIMUM_ELEMENT_SIZE is no longer among them. It is CScriptNum's max_length, and
|
|
33
|
-
// since the limits became era-derived it is only the PRE-Genesis fallback — raising it
|
|
34
|
-
// could not enable post-Genesis arithmetic, only corrupt pre-Genesis validation.
|
|
35
|
-
it('useGenesisLimits() lifts the size caps but not the script-number bound', function () {
|
|
36
|
-
Interpreter.useGenesisLimits()
|
|
37
|
-
Interpreter.MAX_SCRIPT_ELEMENT_SIZE.should.equal(0x7fffffff)
|
|
38
|
-
Interpreter.MAX_OPS_PER_SCRIPT.should.equal(0x7fffffff)
|
|
39
|
-
Interpreter.MAXIMUM_ELEMENT_SIZE.should.equal(4)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// The reason it must not be raised, stated as a test: a 5-byte operand is an overflow
|
|
43
|
-
// before Genesis, and no process-wide call may turn that into an accept.
|
|
44
|
-
it('cannot be made to accept a pre-Genesis script-number overflow', function () {
|
|
45
|
-
var overflow = new Script()
|
|
46
|
-
.add(Buffer.from('1234567890', 'hex'))
|
|
47
|
-
.add(Buffer.from([2]))
|
|
48
|
-
.add(Opcode.OP_MUL)
|
|
49
|
-
var flags = Interpreter.SCRIPT_VERIFY_P2SH | Interpreter.SCRIPT_VERIFY_STRICTENC |
|
|
50
|
-
Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES | Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES
|
|
51
|
-
Interpreter.useGenesisLimits()
|
|
52
|
-
var interp = new Interpreter()
|
|
53
|
-
interp.verify(new Script(), overflow, new bsv.Transaction(), 0, flags, new BN(0))
|
|
54
|
-
.should.equal(false)
|
|
55
|
-
interp.errstr.should.equal('SCRIPT_ERR_SCRIPTNUM_OVERFLOW')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// <2^32> <2^32> OP_ADD <2^33> OP_NUMEQUAL — operands exceed the 4-byte cap.
|
|
59
|
-
var bigAdd = new Script()
|
|
60
|
-
.add(Buffer.from('0000000001', 'hex')) // 2^32, little-endian, 5 bytes
|
|
61
|
-
.add(Buffer.from('0000000001', 'hex'))
|
|
62
|
-
.add(Opcode.OP_ADD)
|
|
63
|
-
.add(Buffer.from('0000000002', 'hex')) // 2^33
|
|
64
|
-
.add(Opcode.OP_NUMEQUAL)
|
|
65
|
-
|
|
66
|
-
function run (lock) {
|
|
67
|
-
var interp = new Interpreter()
|
|
68
|
-
var ok
|
|
69
|
-
try { ok = interp.verify(new Script(), lock, new Transaction(), 0, 0) } catch (e) { ok = false }
|
|
70
|
-
return ok
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
it('rejects >4-byte arithmetic under default limits', function () {
|
|
74
|
-
run(bigAdd).should.equal(false)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
// Post-Genesis arithmetic is reached through the ERA, not through the static. Before
|
|
78
|
-
// the limits became era-derived, useGenesisLimits() was the only route; it no longer
|
|
79
|
-
// is, and using it for this would corrupt pre-Genesis validation elsewhere.
|
|
80
|
-
it('allows >4-byte arithmetic when the post-Genesis era is asked for', function () {
|
|
81
|
-
var interp = new Interpreter()
|
|
82
|
-
interp.verify(new Script(), bigAdd, new bsv.Transaction(), 0,
|
|
83
|
-
Interpreter.mainnetFlags(), new BN(0)).should.equal(true)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('still rejects it under pre-Genesis rules, whatever the statics say', function () {
|
|
87
|
-
Interpreter.useGenesisLimits()
|
|
88
|
-
run(bigAdd).should.equal(false)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
// 220 OP_NOPs then OP_1 — more non-push opcodes than the 201 cap allows.
|
|
92
|
-
// Over BSV's pre-Genesis limit of 500. It used to be 220, which is over
|
|
93
|
-
// Core's 201 but comfortably inside what BSV allowed.
|
|
94
|
-
var manyOps = new Script()
|
|
95
|
-
for (var i = 0; i < 520; i++) manyOps.add(Opcode.OP_NOP)
|
|
96
|
-
manyOps.add(Opcode.OP_1)
|
|
97
|
-
|
|
98
|
-
it('rejects more opcodes than the pre-Genesis limit allows', function () {
|
|
99
|
-
run(manyOps).should.equal(false)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('allows them after useGenesisLimits()', function () {
|
|
103
|
-
Interpreter.useGenesisLimits()
|
|
104
|
-
run(manyOps).should.equal(true)
|
|
105
|
-
})
|
|
106
|
-
// Total script size was a hard-coded 10,000 in evaluate(), so useGenesisLimits()
|
|
107
|
-
// could not lift it: any script over 10 KB failed SCRIPT_ERR_SCRIPT_SIZE regardless
|
|
108
|
-
// of what the caller asked for. That put every sizeable 1Sat Ordinals inscription
|
|
109
|
-
// out of reach of the interpreter entirely.
|
|
110
|
-
function scriptOfSize (bytes) {
|
|
111
|
-
// OP_DROP a single large push, then OP_1 — trivially true, but big.
|
|
112
|
-
return new Script()
|
|
113
|
-
.add(Buffer.alloc(bytes))
|
|
114
|
-
.add(Opcode.OP_DROP)
|
|
115
|
-
.add(Opcode.OP_1)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
it('exposes the total script size cap as a constant, defaulting to pre-Genesis', function () {
|
|
119
|
-
Interpreter.MAX_SCRIPT_SIZE.should.equal(10000)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
// Intent inverted in 8.0.0. verify() now defaults to current mainnet, where Genesis
|
|
123
|
-
// removed the size cap, so a 20 KB script is accepted unless the caller asks for the
|
|
124
|
-
// pre-Genesis era. The cap is still enforced — it just has to be selected, which is
|
|
125
|
-
// what the following test asserts.
|
|
126
|
-
it('accepts a >10 KB script under the default (post-Genesis) rules', function () {
|
|
127
|
-
Interpreter.useGenesisLimits()
|
|
128
|
-
Interpreter.MAX_SCRIPT_SIZE = 10000 // the static cap is irrelevant post-Genesis
|
|
129
|
-
var interp = new Interpreter()
|
|
130
|
-
interp.verify(new Script(), scriptOfSize(20 * 1024)).should.equal(true)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('rejects a >10 KB script when the pre-Genesis era is asked for', function () {
|
|
134
|
-
Interpreter.useGenesisLimits() // lift element/ops caps so SIZE is what is under test
|
|
135
|
-
Interpreter.MAX_SCRIPT_SIZE = 10000 // ...but keep the pre-Genesis size cap
|
|
136
|
-
var interp = new Interpreter()
|
|
137
|
-
// Flags omitted would mean post-Genesis; 0 selects the older rules explicitly.
|
|
138
|
-
interp.verify(new Script(), scriptOfSize(20 * 1024), new bsv.Transaction(), 0, 0).should.equal(false)
|
|
139
|
-
interp.errstr.should.equal('SCRIPT_ERR_SCRIPT_SIZE')
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('allows a >10 KB script after useGenesisLimits()', function () {
|
|
143
|
-
Interpreter.useGenesisLimits()
|
|
144
|
-
run(scriptOfSize(20 * 1024)).should.equal(true)
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
// Genesis lifted the 520-byte element cap, and OP_CAT is where an
|
|
148
|
-
// implementation is most likely to keep enforcing it: it is the one opcode
|
|
149
|
-
// that can grow an element past the limit from two legal halves. This read
|
|
150
|
-
// the static constant rather than the era-derived size, so it stayed capped
|
|
151
|
-
// at 520 after Genesis and rejected concatenations the network accepts.
|
|
152
|
-
//
|
|
153
|
-
// No vector in the SV corpus covers it, so the corpus passes completely
|
|
154
|
-
// either way. It is held here instead.
|
|
155
|
-
describe('OP_CAT and the element size cap', function () {
|
|
156
|
-
var MONOLITH = Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES
|
|
157
|
-
|
|
158
|
-
// Two 300-byte pushes: each is legal pre-Genesis, their concatenation is
|
|
159
|
-
// not. Nothing but the cap distinguishes the two cases below.
|
|
160
|
-
var cat = new Script()
|
|
161
|
-
.add(Buffer.alloc(300, 1))
|
|
162
|
-
.add(Buffer.alloc(300, 1))
|
|
163
|
-
.add(Opcode.OP_CAT)
|
|
164
|
-
|
|
165
|
-
function runWith (flags) {
|
|
166
|
-
var interp = new Interpreter()
|
|
167
|
-
var ok
|
|
168
|
-
try {
|
|
169
|
-
ok = interp.verify(new Script(), cat, new Transaction(), 0, flags)
|
|
170
|
-
} catch (e) {
|
|
171
|
-
ok = false
|
|
172
|
-
}
|
|
173
|
-
return { ok: ok, errstr: interp.errstr }
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
it('rejects a 600-byte concatenation before Genesis', function () {
|
|
177
|
-
var got = runWith(MONOLITH)
|
|
178
|
-
got.ok.should.equal(false)
|
|
179
|
-
got.errstr.should.equal('SCRIPT_ERR_PUSH_SIZE')
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('allows it after Genesis', function () {
|
|
183
|
-
var got = runWith(MONOLITH | Interpreter.SCRIPT_UTXO_AFTER_GENESIS)
|
|
184
|
-
got.ok.should.equal(true, 'rejected with ' + got.errstr)
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('useGenesisLimits raises the size caps, and getLimits/setLimits round-trip', function () {
|
|
189
|
-
var before = Interpreter.getLimits()
|
|
190
|
-
before.maxScriptSize.should.equal(10000)
|
|
191
|
-
Interpreter.useGenesisLimits(64 * 1024)
|
|
192
|
-
var after = Interpreter.getLimits()
|
|
193
|
-
after.maxScriptElementSize.should.equal(64 * 1024)
|
|
194
|
-
after.maxOpsPerScript.should.equal(64 * 1024)
|
|
195
|
-
// Not raised — see the note on useGenesisLimits. setLimits() can still set it
|
|
196
|
-
// explicitly, which is what the round-trip below checks.
|
|
197
|
-
after.maximumElementSize.should.equal(4)
|
|
198
|
-
after.maxScriptSize.should.equal(64 * 1024)
|
|
199
|
-
Interpreter.setLimits(before)
|
|
200
|
-
Interpreter.getLimits().maxScriptSize.should.equal(10000)
|
|
201
|
-
Interpreter.MAX_SCRIPT_ELEMENT_SIZE.should.equal(520)
|
|
202
|
-
})
|
|
203
|
-
})
|