Skip to content

Commit 333cbfa

Browse files
committed
Improve VM perf, support schnorr multisig, expand support for limit, loops, and bigint, expand VMB benchmark tooling and tests
1 parent d0d54b9 commit 333cbfa

File tree

90 files changed

+46509
-31110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+46509
-31110
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"cashaddr",
4040
"CASHTOKENS",
4141
"Chaingraph",
42+
"checkbits",
4243
"CHECKDATASIG",
4344
"CHECKDATASIGVERIFY",
4445
"CHECKLOCKTIMEVERIFY",

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ coverage
1010
report.*.json
1111
scratch
1212
gitignore.*
13+
*.cpuprofile
1314

1415
src/lib/bin/**/*.html
1516
src/lib/bin/**/*.js

.vscode/launch.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,35 @@
2323
"runtimeExecutable": "yarn",
2424
"runtimeArgs": ["run", "ava"],
2525
"args": ["${file}"],
26+
// "args": ["--serial", "${file}"],
2627
"outputCapture": "std",
27-
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
28+
"console": "integratedTerminal",
29+
"skipFiles": ["<node_internals>/**"]
2830
},
2931
{
3032
"type": "node",
3133
"request": "launch",
3234
"name": "Debug VMB Test",
3335
"runtimeExecutable": "yarn",
3436
"runtimeArgs": ["run", "test:unit:vmb_test"],
35-
"args": ["${input:vmVersion}", "${input:vmbTestShortId}", "-v"],
37+
"args": ["${input:vmVersion}", "${input:vmbTestShortId}"],
38+
// "args": ["${input:vmVersion}", "${input:vmbTestShortId}", "-v"],
39+
"outputCapture": "std",
40+
"console": "integratedTerminal",
41+
"skipFiles": ["<node_internals>/**"],
42+
"preLaunchTask": "npm: build"
43+
},
44+
{
45+
"type": "node",
46+
"request": "launch",
47+
"name": "Debug VMB Benchmark",
48+
"runtimeExecutable": "yarn",
49+
"runtimeArgs": ["run", "bench:vmb_tests"],
50+
"env": {
51+
"BENCH_DEBUG_VM": "${input:vmVersion}",
52+
"BENCH_DEBUG_TEST": "${input:vmbTestShortId}",
53+
"BENCH_DEBUG_PROFILE": "${input:collectProfile}"
54+
},
3655
"outputCapture": "std",
3756
"console": "integratedTerminal",
3857
"skipFiles": ["<node_internals>/**"],
@@ -72,6 +91,13 @@
7291
"bch_spec_nonstandard"
7392
],
7493
"default": "bch_spec_standard"
94+
},
95+
{
96+
"id": "collectProfile",
97+
"description": "Collect a CPU profile?",
98+
"type": "pickString",
99+
"options": ["Yes", "No"],
100+
"default": "Yes"
75101
}
76102
]
77103
}

config/.ava.bench.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export default {
22
files: ['build/**/*.bench.js'],
33
workerThreads: false,
4-
verbose: true,
54
};

docs/verify-transactions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const instructionSet = createInstructionSetBch(true);
109109
*/
110110
const opUnRot = <State extends AuthenticationProgramStateStack>(state: State) =>
111111
useThreeStackItems(state, (nextState, [a, b, c]) =>
112-
pushToStack(nextState, c, a, b),
112+
pushToStack(nextState, [c, a, b]),
113113
);
114114

115115
/* We assign "OP_UNROT" at the index held by "OP_RESERVED1" */

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"test:unit:vmb_tests": "c8 ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial",
7272
"test:unit:vmb_test": "node --enable-source-maps 'build/lib/vmb-tests/run-bch-vmb-test.spec.helper.js'",
7373
"dev:vmb_tests": "yarn gen:vmb_tests && yarn build:tsc && ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial --fail-fast",
74+
"dev:vmb_tests:info": "echo 'example: export FILTER_VMB_TESTS=benchmark; export FILTER_VMB_TEST_VM=2025; yarn dev:vmb_tests && say sucess || say failure",
7475
"bench:vmb_tests": "ava --config config/.ava.vmb_bench.config.js src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts --serial",
7576
"bench": "yarn build && yarn bench:browser-deps && yarn bench:vmb_tests && yarn bench:test",
7677
"bench:test": "ava --config config/.ava.bench.config.js --serial --timeout=2m 2>&1 | tee bench.log",
@@ -156,7 +157,7 @@
156157
"SECURITY.md"
157158
],
158159
"ava": {
159-
"timeout": "60s",
160+
"timeout": "120s",
160161
"typescript": {
161162
"compile": false,
162163
"rewritePaths": {
@@ -165,10 +166,11 @@
165166
},
166167
"nodeArguments": [
167168
"--experimental-json-modules",
168-
"--experimental-global-webcrypto",
169-
"# ^ needed for node v18"
169+
"--experimental-global-webcrypto"
170170
],
171-
"files": ["!src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts"]
171+
"files": [
172+
"!src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts"
173+
]
172174
},
173175
"config": {
174176
"commitizen": {

src/lib/compiler/compiler-bch/compiler-bch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test('[BCH compiler] createCompilerBch: generateBytecode', (t) => {
5959
);
6060
});
6161

62-
test('[BCH compiler] createCompilerBch: debug', (t) => {
62+
test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
6363
const compiler = createCompilerBch({
6464
scripts: {
6565
lock: 'OP_DUP OP_HASH160 <$(<a.public_key> OP_HASH160)> OP_EQUALVERIFY OP_CHECKSIG',

src/lib/compiler/compiler-bch/compiler-bch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
} from '../../lib.js';
1818
import { encodeTokenPrefix } from '../../message/message.js';
1919
import {
20-
createVirtualMachineBch,
20+
createVirtualMachineBchSpec,
2121
generateBytecodeMap,
2222
generateSigningSerializationBch,
2323
OpcodesBchSpec,
@@ -40,7 +40,7 @@ import {
4040
} from '../compiler-utils.js';
4141

4242
export type CompilerOperationsKeyBch =
43-
| 'data_signature'
43+
| 'ecdsa_data_signature'
4444
| 'ecdsa_signature'
4545
| 'public_key'
4646
| 'schnorr_data_signature'
@@ -753,7 +753,7 @@ export const createCompilerBch = <
753753
secp256k1: internalSecp256k1,
754754
sha256: internalSha256,
755755
sha512: internalSha512,
756-
vm: configuration.vm ?? createVirtualMachineBch(),
756+
vm: configuration.vm ?? createVirtualMachineBchSpec(),
757757
},
758758
...configuration,
759759
});

src/lib/compiler/compiler-utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
sha256 as internalSha256,
55
sha512 as internalSha512,
66
} from '../crypto/crypto.js';
7+
import { flattenBinArray } from '../format/format.js';
78
import { compileScript } from '../language/language.js';
89
import type {
910
AnyCompilerConfiguration,
@@ -24,6 +25,7 @@ import type {
2425
WalletTemplate,
2526
} from '../lib.js';
2627
import {
28+
encodeDataPush,
2729
generateBytecodeMap,
2830
Opcodes,
2931
OpcodesBchSpec,
@@ -123,6 +125,7 @@ export const compilerConfigurationToCompiler =
123125
compilerConfigurationToCompilerBch;
124126

125127
const nullHashLength = 32;
128+
const maximumValidOpReturnPushLength = 9996;
126129

127130
/**
128131
* A common {@link createAuthenticationProgram} implementation for
@@ -162,7 +165,10 @@ export const createAuthenticationProgramEvaluationCommon = (
162165
locktime: 0,
163166
outputs: [
164167
{
165-
lockingBytecode: Uint8Array.of(),
168+
lockingBytecode: flattenBinArray([
169+
Uint8Array.of(Opcodes.OP_RETURN),
170+
encodeDataPush(new Uint8Array(maximumValidOpReturnPushLength)),
171+
]),
166172
valueSatoshis: 0n,
167173
},
168174
],

src/lib/docs.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ test('verify-transactions.md: add OP_UNROT', (t) => {
734734
state: State,
735735
) =>
736736
useThreeStackItems(state, (nextState, [a, b, c]) =>
737-
pushToStack(nextState, c, a, b),
737+
pushToStack(nextState, [c, a, b]),
738738
);
739739

740740
/* We assign "OP_UNROT" at the index held by "OP_RESERVED1" */

src/lib/language/language-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ export type EvaluationSample<ProgramState> = {
350350
instruction: AuthenticationInstruction;
351351
state: ProgramState;
352352
}[];
353+
/**
354+
* Defined only if an `OP_BEGIN ... OP_UNTIL` loop causes this sample to be
355+
* evaluated more than once; each successive iteration of this sample's
356+
* `instruction` is appended to the `iterations` array. (Note, this array
357+
* excludes the first iteration, which is assigned to the `state` property.)
358+
*/
359+
iterations?: ProgramState[];
353360
/**
354361
* The range over which this sample was defined in the source script.
355362
*/

0 commit comments

Comments
 (0)