@smartledger/bsv 9.6.0 → 9.8.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.
- package/CHANGELOG.md +204 -0
- package/README.md +19 -19
- package/bsv-gdaf.min.js +29 -29
- package/bsv-ltp.min.js +17 -17
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +30 -30
- package/bsv.d.ts +301 -54
- package/bsv.min.js +28 -28
- package/docs/AUDIT_SCOPE.md +39 -13
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/audit-rfq/cure53.txt +24 -10
- package/docs/audit-rfq/ncc-group.txt +24 -10
- package/docs/audit-rfq/trail-of-bits.txt +24 -10
- 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/preimage.md +151 -87
- package/lib/script/interpreter.js +104 -3
- package/package.json +7 -3
- package/version.js +1 -1
package/docs/preimage.md
CHANGED
|
@@ -1,126 +1,190 @@
|
|
|
1
|
-
|
|
1
|
+
# The BIP-143 sighash preimage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The preimage is the byte string that is double-SHA256'd and then signed. Its layout is
|
|
4
|
+
what makes covenants possible on BSV: a script that can prove it was handed *this*
|
|
5
|
+
transaction's preimage can read the transaction's own fields out of it, which is why
|
|
6
|
+
BSV needs no `OP_TXLOCKTIME` or `OP_INPUTVALUE` opcode.
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Every offset and every script fragment on this page is asserted in
|
|
9
|
+
`test/covenant/preimage_doc.js` against a preimage this library actually produces. If
|
|
10
|
+
you change the layout, that test fails before this page goes stale.
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
> **Two digest algorithms, not one.** BIP-143 with `SIGHASH_FORKID` is what this page
|
|
13
|
+
> describes and what almost everything uses. Chronicle restored the **Original
|
|
14
|
+
> Transaction Digest Algorithm**, selected by `SIGHASH_CHRONICLE` (`0x20`), which has a
|
|
15
|
+
> different layout entirely — see `Signature.SIGHASH_CHRONICLE` and
|
|
16
|
+
> `lib/transaction/sighash.js`. Do not assume a signature is BIP-143 without checking
|
|
17
|
+
> its sighash byte.
|
|
9
18
|
|
|
10
19
|
---
|
|
11
20
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
21
|
+
## Field layout
|
|
22
|
+
|
|
23
|
+
| # | Field | Bytes | Encoding |
|
|
24
|
+
| --: | --- | --: | --- |
|
|
25
|
+
| 1 | `nVersion` | 4 | little-endian int32 |
|
|
26
|
+
| 2 | `hashPrevouts` | 32 | HASH256 digest, as the hash function returns it |
|
|
27
|
+
| 3 | `hashSequence` | 32 | HASH256 digest, as the hash function returns it |
|
|
28
|
+
| 4 | `outpoint` | 36 | 32-byte txid in **serialized order** + 4-byte LE index |
|
|
29
|
+
| 5 | `scriptCode` | varint + N | length prefix then the script |
|
|
30
|
+
| 6 | `amount` | 8 | little-endian **uint64** — satoshis in the output being spent |
|
|
31
|
+
| 7 | `nSequence` | 4 | little-endian **uint32** |
|
|
32
|
+
| 8 | `hashOutputs` | 32 | HASH256 digest, as the hash function returns it |
|
|
33
|
+
| 9 | `nLockTime` | 4 | little-endian **uint32** |
|
|
34
|
+
| 10 | `sighashType` | 4 | little-endian uint32 (`0x41` for `ALL|FORKID`) |
|
|
35
|
+
|
|
36
|
+
**The three 32-byte hashes have no endianness worth naming.** They are the bytes
|
|
37
|
+
`HASH256()` returns, inserted as-is. Calling them "big-endian" invites someone to
|
|
38
|
+
reverse them; the only field in the preimage that is genuinely reversed relative to how
|
|
39
|
+
you normally read it is the **txid inside the outpoint**, which appears here in
|
|
40
|
+
serialized order — the reverse of the string an explorer shows.
|
|
41
|
+
|
|
42
|
+
### Length
|
|
27
43
|
|
|
28
|
-
|
|
44
|
+
```
|
|
45
|
+
4 + 32 + 32 + 36 + 8 + 4 + 32 + 4 + 4 = 156 fixed bytes
|
|
46
|
+
+ varint(len(scriptCode)) + len(scriptCode)
|
|
47
|
+
```
|
|
29
48
|
|
|
30
|
-
|
|
49
|
+
A 25-byte P2PKH `scriptCode` needs a 1-byte length prefix, so the whole preimage is
|
|
50
|
+
**182 bytes** — not ~108, and not 181. There is no "typical" length beyond that,
|
|
51
|
+
because `scriptCode` is whatever locking script is being spent.
|
|
52
|
+
|
|
53
|
+
### Offsets, for a 25-byte scriptCode
|
|
54
|
+
|
|
55
|
+
| Field | From start | From end |
|
|
56
|
+
| --- | --: | --: |
|
|
57
|
+
| `nVersion` | 0 | — |
|
|
58
|
+
| `hashPrevouts` | 4 | — |
|
|
59
|
+
| `hashSequence` | 36 | — |
|
|
60
|
+
| `outpoint` | 68 | — |
|
|
61
|
+
| `scriptCode` (len + data) | 104 | — |
|
|
62
|
+
| `amount` | 130 | **52** |
|
|
63
|
+
| `nSequence` | 138 | **44** |
|
|
64
|
+
| `hashOutputs` | 142 | **40** |
|
|
65
|
+
| `nLockTime` | 174 | **8** |
|
|
66
|
+
| `sighashType` | 178 | **4** |
|
|
67
|
+
|
|
68
|
+
**Use the from-end column in scripts.** Everything before `amount` sits behind a
|
|
69
|
+
variable-length `scriptCode`, so its absolute offset changes with the contract. The
|
|
70
|
+
five tail fields are at fixed distances from the end whatever the script contains,
|
|
71
|
+
which is why every extraction this library ships is written with `OP_RIGHT`.
|
|
31
72
|
|
|
32
|
-
|
|
73
|
+
---
|
|
33
74
|
|
|
34
|
-
|
|
35
|
-
| ----------------------- | ------------- | ------------------------ |
|
|
36
|
-
| nVersion | 4 | `01000000` |
|
|
37
|
-
| hashPrevouts | 32 | `e3...4a` |
|
|
38
|
-
| hashSequence | 32 | `00...00` |
|
|
39
|
-
| outpoint | 36 | `00..00 00000000` |
|
|
40
|
-
| scriptCode (len + data) | 25 | `1976a914...88ac` |
|
|
41
|
-
| amount | 8 | `1027000000000000` |
|
|
42
|
-
| nSequence | 4 | `ffffffff` |
|
|
43
|
-
| hashOutputs | 32 | `d2...1e` |
|
|
44
|
-
| nLockTime | 4 | `e8030000` *(= 1000 LE)* |
|
|
45
|
-
| sighashType | 4 | `41000000` *(= 0x41)* |
|
|
75
|
+
## When the hashes are zero
|
|
46
76
|
|
|
47
|
-
|
|
77
|
+
`hashPrevouts`, `hashSequence` and `hashOutputs` are not always populated. Measured:
|
|
48
78
|
|
|
49
|
-
|
|
79
|
+
| Sighash type | `hashPrevouts` | `hashSequence` | `hashOutputs` |
|
|
80
|
+
| --- | --- | --- | --- |
|
|
81
|
+
| `ALL|FORKID` (`0x41`) | set | set | set |
|
|
82
|
+
| `NONE|FORKID` (`0x42`) | set | **zero** | **zero** |
|
|
83
|
+
| `SINGLE|FORKID` (`0x43`) | set | **zero** | set (the one matching output) |
|
|
84
|
+
| `ALL|ANYONECANPAY|FORKID` (`0xc1`) | **zero** | **zero** | set |
|
|
85
|
+
| `SINGLE|ANYONECANPAY|FORKID` (`0xc3`) | **zero** | **zero** | set |
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
A covenant that reads `hashOutputs` is only meaningful if it *also* pins the sighash
|
|
88
|
+
type — otherwise a spender signs with `NONE` and the field it is checking is 32 zero
|
|
89
|
+
bytes. `PushTx.assertSighashType()` exists for that.
|
|
53
90
|
|
|
54
91
|
---
|
|
55
92
|
|
|
56
|
-
##
|
|
93
|
+
## Reading fields in Script
|
|
57
94
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
95
|
+
`OP_RIGHT n` keeps the last `n` bytes; `OP_LEFT n` keeps the first `n`. Together they
|
|
96
|
+
take a window at a fixed distance from the end. These are the fragments this library
|
|
97
|
+
ships:
|
|
61
98
|
|
|
62
|
-
|
|
99
|
+
| Field | Script |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `sighashType` | `OP_DUP 4 OP_RIGHT` |
|
|
102
|
+
| `nLockTime` | `OP_DUP 8 OP_RIGHT 4 OP_LEFT` |
|
|
103
|
+
| `hashOutputs` | `OP_DUP 40 OP_RIGHT 32 OP_LEFT` |
|
|
104
|
+
| `nSequence` | `OP_DUP 44 OP_RIGHT 4 OP_LEFT` |
|
|
105
|
+
| `amount` | `OP_DUP 52 OP_RIGHT 8 OP_LEFT` |
|
|
106
|
+
| `nVersion` | `OP_DUP 4 OP_LEFT` |
|
|
107
|
+
|
|
108
|
+
`OP_DUP` first, because these consume the preimage and you usually want it back.
|
|
109
|
+
|
|
110
|
+
### `OP_BIN2NUM` will silently corrupt three of these
|
|
63
111
|
|
|
64
|
-
|
|
112
|
+
`amount`, `nSequence` and `nLockTime` are **unsigned**. `OP_BIN2NUM` produces a
|
|
113
|
+
**signed** script number. Feeding a raw field straight into it is wrong, and wrong in
|
|
114
|
+
the direction that fails quietly:
|
|
65
115
|
|
|
66
116
|
```
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
[0064-007e] script length + scriptPubKey (varies)
|
|
73
|
-
[007f-0086] amount (8 LE)
|
|
74
|
-
[0087-008a] nSequence (4 LE)
|
|
75
|
-
[008b-00aa] hashOutputs (32)
|
|
76
|
-
[00ab-00ae] nLockTime (4 LE)
|
|
77
|
-
[00af-00b2] sighashType (4 LE)
|
|
117
|
+
nLockTime e8030000 -> 1000 correct
|
|
118
|
+
ffffff7f -> 2147483647 correct — last value before the sign bit
|
|
119
|
+
00000080 -> 0 WRONG, should be 2147483648 (19 Jan 2038)
|
|
120
|
+
01000080 -> -1 WRONG, should be 2147483649
|
|
121
|
+
ffffffff -> -2147483647 WRONG, should be 4294967295 (year 2106)
|
|
78
122
|
```
|
|
79
123
|
|
|
80
|
-
|
|
124
|
+
A `nLockTime >= deadline` check written this way stops working on **19 January 2038**,
|
|
125
|
+
and a `<=` check starts passing when it should not. The same applies to `amount` above
|
|
126
|
+
2³¹ satoshis (21.47 BSV) and to `nSequence` above `0x7fffffff` — which includes
|
|
127
|
+
`0xffffffff`, the most common value there is.
|
|
81
128
|
|
|
82
|
-
|
|
129
|
+
**Sign-pad with a zero byte first:**
|
|
83
130
|
|
|
84
|
-
|
|
131
|
+
```
|
|
132
|
+
OP_DUP 8 OP_RIGHT 4 OP_LEFT <00> OP_CAT OP_BIN2NUM
|
|
133
|
+
```
|
|
85
134
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
135
|
+
```
|
|
136
|
+
nLockTime 00000080 -> 2147483648 correct
|
|
137
|
+
ffffffff -> 4294967295 correct
|
|
138
|
+
e8030000 -> 1000 correct — OP_BIN2NUM re-minimises the pad
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
That five-byte push is only legal because `OP_BIN2NUM` honours the era's script-number
|
|
142
|
+
width — 4 bytes before Genesis, 750,000 after, 32,000,000 after Chronicle. Verify with
|
|
143
|
+
`Interpreter.mainnetFlags()` or no flags at all; a hand-assembled flag word with no era
|
|
144
|
+
bit applies the 4-byte pre-Genesis cap and rejects the padded value.
|
|
92
145
|
|
|
93
146
|
---
|
|
94
147
|
|
|
95
|
-
##
|
|
148
|
+
## Hashing the preimage does not authenticate it
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
<preimage> OP_HASH256
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
gives you `HASH256(preimage)` and **nothing else**. It does not establish that the
|
|
155
|
+
bytes on the stack are this transaction's preimage. A spender can hand you any
|
|
156
|
+
well-formed 182 bytes, satisfy every field check you wrote, and spend the output on a
|
|
157
|
+
transaction that does something entirely different.
|
|
96
158
|
|
|
97
|
-
The
|
|
98
|
-
|
|
159
|
+
The binding has to come from a signature check. `OP_PUSH_TX` — `lib/covenant/pushtx.js`
|
|
160
|
+
— gets it by constructing a signature *from the preimage hash itself* and verifying it
|
|
161
|
+
with `OP_CHECKSIG` against the generator point:
|
|
99
162
|
|
|
100
163
|
```
|
|
101
|
-
|
|
164
|
+
OP_HASH256 z = HASH256(preimage)
|
|
165
|
+
<reverse to LE> e
|
|
166
|
+
<Gx> OP_ADD <n> OP_MOD s = (e + Gx) mod n
|
|
167
|
+
<assemble DER: r = Gx, s> a signature that is valid for P = G
|
|
168
|
+
only if e is this input's sighash
|
|
169
|
+
<02||Gx> OP_CHECKSIG the node checks it against the REAL sighash
|
|
102
170
|
```
|
|
103
171
|
|
|
104
|
-
|
|
172
|
+
`OP_CHECKSIG` computes the sighash itself, from the transaction being validated. The
|
|
173
|
+
signature only verifies if the `e` derived from the supplied preimage equals it. That
|
|
174
|
+
is the whole trick, and it is the step that makes every field check downstream mean
|
|
175
|
+
something.
|
|
105
176
|
|
|
106
|
-
|
|
107
|
-
|
|
177
|
+
Use `PushTx.pushTxCore()` or `SmartContract.policy()` rather than assembling this by
|
|
178
|
+
hand.
|
|
108
179
|
|
|
109
180
|
---
|
|
110
181
|
|
|
111
|
-
##
|
|
112
|
-
|
|
113
|
-
| Field | Bytes | Endian | Covenant Extraction Example |
|
|
114
|
-
| ------------ | -------- | ------ | ------------------------------------------------------- |
|
|
115
|
-
| nVersion | 4 | LE | `4 OP_SPLIT OP_DROP OP_BIN2NUM` |
|
|
116
|
-
| hashPrevouts | 32 | — | `36 OP_SPLIT ...` |
|
|
117
|
-
| hashSequence | 32 | — | next 32 |
|
|
118
|
-
| outpoint | 36 | mixed | — |
|
|
119
|
-
| scriptCode | variable | — | rarely enforced directly |
|
|
120
|
-
| amount | 8 | LE | `40 OP_SPLIT OP_NIP 8 OP_SPLIT OP_DROP OP_BIN2NUM` |
|
|
121
|
-
| nSequence | 4 | LE | `12 OP_SPLIT OP_NIP 4 OP_SPLIT OP_DROP OP_BIN2NUM` |
|
|
122
|
-
| hashOutputs | 32 | — | — |
|
|
123
|
-
| nLockTime | 4 | LE | `<len-8> OP_SPLIT OP_NIP 4 OP_SPLIT OP_DROP OP_BIN2NUM` |
|
|
124
|
-
| sighashType | 4 | LE | `<len-4> OP_SPLIT OP_NIP OP_BIN2NUM` |
|
|
182
|
+
## `scriptCode` is not "the scriptPubKey"
|
|
125
183
|
|
|
126
|
-
|
|
184
|
+
It is the script the signature commits to. For a plain P2PKH spend that happens to be
|
|
185
|
+
the 25-byte locking script, but nothing in the format requires it: it is
|
|
186
|
+
length-prefixed and variable, `OP_CODESEPARATOR` changes where it starts, and for the
|
|
187
|
+
covenants this library builds it is hundreds of bytes.
|
|
188
|
+
|
|
189
|
+
Any parser that assumes 25 bytes, or that reads fields at absolute offsets past the
|
|
190
|
+
`scriptCode`, breaks on the first real contract. Read from the end.
|
|
@@ -293,6 +293,41 @@ Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS = 750000
|
|
|
293
293
|
Interpreter.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE = 32000000
|
|
294
294
|
Interpreter.MAX_PUBKEYS_PER_MULTISIG_AFTER_GENESIS = 4294967295
|
|
295
295
|
|
|
296
|
+
// Maximum combined size of the main and alt stacks, in ELEMENTS. Pre-Genesis
|
|
297
|
+
// consensus is 1000; post-Genesis BSV removed the element count limit and
|
|
298
|
+
// replaced it with a bound on the memory the two stacks occupy, so that a script
|
|
299
|
+
// is limited by what it actually uses rather than by how it is divided up.
|
|
300
|
+
Interpreter.MAX_STACK_SIZE = 1000
|
|
301
|
+
|
|
302
|
+
// The post-Genesis memory bound, UNLIMITED by default because post-Genesis
|
|
303
|
+
// CONSENSUS is unbounded by default. The node's 100 MB figure is
|
|
304
|
+
// -maxstackmemoryusagepolicy, a RELAY setting, and applying a relay setting here
|
|
305
|
+
// would make this library refuse scripts the network accepts — the same mistake
|
|
306
|
+
// as carrying the 1000-element cap past Genesis, one release later and in the
|
|
307
|
+
// same function. It is also why MINIMALDATA is not in currentConsensusFlags().
|
|
308
|
+
//
|
|
309
|
+
// A caller validating against relay policy, or hardening against untrusted input,
|
|
310
|
+
// assigns STACK_MEMORY_USAGE_POLICY (or any ceiling) to this:
|
|
311
|
+
//
|
|
312
|
+
// Interpreter.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS =
|
|
313
|
+
// Interpreter.STACK_MEMORY_USAGE_POLICY
|
|
314
|
+
//
|
|
315
|
+
// Unbounded means a hostile script can allocate until the process runs out of
|
|
316
|
+
// memory. That is the same trade `useGenesisLimits(max)` documents for element
|
|
317
|
+
// size: consensus does not cap it, so neither do we, and a validator taking
|
|
318
|
+
// scripts from strangers should set a ceiling matched to its workload.
|
|
319
|
+
Interpreter.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS = Interpreter.UNLIMITED
|
|
320
|
+
|
|
321
|
+
/** The node's -maxstackmemoryusagepolicy default. Relay policy, not consensus. */
|
|
322
|
+
Interpreter.STACK_MEMORY_USAGE_POLICY = 100 * 1024 * 1024
|
|
323
|
+
|
|
324
|
+
// Charged per element on top of its bytes, because the container holding an
|
|
325
|
+
// element is not free either — a stack of many small elements costs more than
|
|
326
|
+
// their contents. Only consulted when a caller has set a memory ceiling, since
|
|
327
|
+
// the default is unbounded. 32 is deliberately conservative: a bare
|
|
328
|
+
// std::vector<uint8_t> is 24 bytes on the common 64-bit ABIs.
|
|
329
|
+
Interpreter.STACK_ELEMENT_OVERHEAD = 32
|
|
330
|
+
|
|
296
331
|
Interpreter.LOCKTIME_THRESHOLD = 500000000
|
|
297
332
|
Interpreter.LOCKTIME_THRESHOLD_BN = new BN(Interpreter.LOCKTIME_THRESHOLD)
|
|
298
333
|
|
|
@@ -933,6 +968,66 @@ Interpreter.prototype.maxScriptNumLength = function () {
|
|
|
933
968
|
return Interpreter.MAXIMUM_ELEMENT_SIZE
|
|
934
969
|
}
|
|
935
970
|
|
|
971
|
+
/**
|
|
972
|
+
* How many elements the two stacks may hold between them.
|
|
973
|
+
*
|
|
974
|
+
* Genesis removed this cap, the same way it removed the element size, script
|
|
975
|
+
* size and opcode caps. Leaving it static rejected post-Genesis scripts the
|
|
976
|
+
* network accepts — measured, a witness of 1,001 pushes:
|
|
977
|
+
*
|
|
978
|
+
* before: SCRIPT_ERR_STACK_SIZE
|
|
979
|
+
* node: accepted
|
|
980
|
+
*
|
|
981
|
+
* which is the same shape of bug as the CHECKMULTISIG op count carried over
|
|
982
|
+
* from the pre-Genesis constant.
|
|
983
|
+
*/
|
|
984
|
+
Interpreter.prototype.maxStackSize = function () {
|
|
985
|
+
return this.isAfterGenesis() ? Interpreter.UNLIMITED : Interpreter.MAX_STACK_SIZE
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* What replaced it after Genesis: a bound on the memory the two stacks occupy,
|
|
990
|
+
* rather than on how many pieces that memory is divided into. Before Genesis
|
|
991
|
+
* the element cap is the operative one and this is not consulted.
|
|
992
|
+
*
|
|
993
|
+
* UNLIMITED in both eras by default, since post-Genesis consensus does not cap
|
|
994
|
+
* it. Set `MAX_STACK_MEMORY_USAGE_AFTER_GENESIS` to opt into a ceiling.
|
|
995
|
+
*/
|
|
996
|
+
Interpreter.prototype.maxStackMemoryUsage = function () {
|
|
997
|
+
return this.isAfterGenesis()
|
|
998
|
+
? Interpreter.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS
|
|
999
|
+
: Interpreter.UNLIMITED
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/** Bytes held across both stacks, each element charged its container overhead. */
|
|
1003
|
+
Interpreter.prototype.stackMemoryUsage = function () {
|
|
1004
|
+
const overhead = Interpreter.STACK_ELEMENT_OVERHEAD
|
|
1005
|
+
let total = (this.stack.length + this.altstack.length) * overhead
|
|
1006
|
+
for (let i = 0; i < this.stack.length; i++) total += this.stack[i].length
|
|
1007
|
+
for (let i = 0; i < this.altstack.length; i++) total += this.altstack[i].length
|
|
1008
|
+
return total
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* The stack limits, applied where the node applies them: after EVERY opcode.
|
|
1013
|
+
*
|
|
1014
|
+
* Checking once at the end of the script was a false accept in the direction
|
|
1015
|
+
* that costs money — a script that piles up 1,001 elements and drops back to
|
|
1016
|
+
* one before it finishes passed here and is rejected by the network.
|
|
1017
|
+
*
|
|
1018
|
+
* Returns an error string, or null.
|
|
1019
|
+
*/
|
|
1020
|
+
Interpreter.prototype.checkStackLimits = function () {
|
|
1021
|
+
if (this.stack.length + this.altstack.length > this.maxStackSize()) {
|
|
1022
|
+
return 'SCRIPT_ERR_STACK_SIZE'
|
|
1023
|
+
}
|
|
1024
|
+
const memoryCap = this.maxStackMemoryUsage()
|
|
1025
|
+
if (memoryCap !== Interpreter.UNLIMITED && this.stackMemoryUsage() > memoryCap) {
|
|
1026
|
+
return 'SCRIPT_ERR_STACK_SIZE'
|
|
1027
|
+
}
|
|
1028
|
+
return null
|
|
1029
|
+
}
|
|
1030
|
+
|
|
936
1031
|
/** Genesis raised this rather than removing it: the node caps at UINT32_MAX. */
|
|
937
1032
|
Interpreter.prototype.maxPubKeysPerMultisig = function () {
|
|
938
1033
|
return this.isAfterGenesis()
|
|
@@ -1041,11 +1136,17 @@ Interpreter.prototype.evaluate = function () {
|
|
|
1041
1136
|
// conditional or an invalid opcode beyond this point is not an error.
|
|
1042
1137
|
return true
|
|
1043
1138
|
}
|
|
1139
|
+
// Where the node checks it: after each opcode, not once at the end.
|
|
1140
|
+
const limitErr = this.checkStackLimits()
|
|
1141
|
+
if (limitErr) {
|
|
1142
|
+
this.errstr = limitErr
|
|
1143
|
+
return false
|
|
1144
|
+
}
|
|
1044
1145
|
}
|
|
1045
1146
|
|
|
1046
|
-
|
|
1047
|
-
if (
|
|
1048
|
-
this.errstr =
|
|
1147
|
+
const finalErr = this.checkStackLimits()
|
|
1148
|
+
if (finalErr) {
|
|
1149
|
+
this.errstr = finalErr
|
|
1049
1150
|
return false
|
|
1050
1151
|
}
|
|
1051
1152
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.8.0",
|
|
4
4
|
"description": "Bitcoin SV library with an interpreter-verified script engine: OP_PUSH_TX covenants, BIP-143 preimage tooling, and consensus flags that match what miners actually enforce. Also ships DID:web / W3C VC-JWT credentials and the Legal Token Protocol.",
|
|
5
5
|
"author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
|
|
6
6
|
"homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
|
|
@@ -135,13 +135,17 @@
|
|
|
135
135
|
"test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
|
|
136
136
|
"test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
|
|
137
137
|
"preimage:extract": "node examples/preimage/extract_preimage_bidirectional.js",
|
|
138
|
-
"prepublishOnly": "npm run build-all && npm run check:readme && npm run check:api && npm run check:types",
|
|
138
|
+
"prepublishOnly": "npm run build-all && npm run check:readme && npm run check:api && npm run check:types && npm run check:dts",
|
|
139
139
|
"sync-cdn": "node scripts/sync-cdn-urls.js",
|
|
140
140
|
"version": "node scripts/sync-cdn-urls.js && node scripts/sync-version.js && node scripts/gen-esm-wrapper.js && git add README.md docs version.js index.mjs",
|
|
141
141
|
"test:browser:ci": "node tests/browser-smoke-runner.js",
|
|
142
142
|
"api:snapshot": "node scripts/api-surface.js",
|
|
143
143
|
"check:api": "mocha test/api_surface.js --no-config",
|
|
144
|
-
"check:types": "node scripts/check-types.js"
|
|
144
|
+
"check:types": "node scripts/check-types.js",
|
|
145
|
+
"check:dts": "node scripts/check-dts-coverage.js",
|
|
146
|
+
"check:audit-scope": "node scripts/check-audit-scope.js",
|
|
147
|
+
"check:audit-scope:fix": "node scripts/check-audit-scope.js --fix",
|
|
148
|
+
"check:dts:update": "node scripts/check-dts-coverage.js --update"
|
|
145
149
|
},
|
|
146
150
|
"unpkg": "bsv.min.js",
|
|
147
151
|
"jsdelivr": "bsv.min.js",
|
package/version.js
CHANGED