Skip to content

Commit

Permalink
Add BCH_2026_05, add VM benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed May 30, 2024
1 parent 1f34ca4 commit 5f3bcfe
Show file tree
Hide file tree
Showing 81 changed files with 17,709 additions and 7,635 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-insects-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bitauth/libauth': patch
---

Add BCH_2026_05, add VM benchmarking
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"regtest",
"reversebytes",
"ripemd",
"rkalis",
"RSHIFT",
"rustup",
"satoshi",
Expand All @@ -172,6 +173,7 @@
"substack",
"templating",
"testnet",
"tinybench",
"TOALTSTACK",
"tprv",
"tpub",
Expand Down
11 changes: 11 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"name": "Debug VMB Test",
"runtimeExecutable": "yarn",
"runtimeArgs": ["run", "test:unit:vmb_test"],
"args": ["bch_spec_standard", "06ty9", "-v"],
"args": ["${input:vmVersion}", "${input:vmbTestShortId}", "-v"],
"outputCapture": "std",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"],
Expand All @@ -49,5 +49,29 @@
"skipFiles": ["<node_internals>/**"],
"preLaunchTask": "npm: build"
}
],
"inputs": [
{
"id": "vmbTestShortId",
"description": "Please enter a VMB test ID",
"default": "vdqk6",
"type": "promptString"
},
{
"id": "vmVersion",
"description": "Please choose a VM version",
"type": "pickString",
"options": [
"bch_2023_standard",
"bch_2023_nonstandard",
"bch_2025_standard",
"bch_2025_nonstandard",
"bch_2026_standard",
"bch_2026_nonstandard",
"bch_spec_standard",
"bch_spec_nonstandard"
],
"default": "bch_spec_standard"
}
]
}
2 changes: 1 addition & 1 deletion .yarn
File renamed without changes.
12 changes: 6 additions & 6 deletions docs/verify-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ if (typeof result === 'string') {
}
```

For examples of the kind of error messages that `vm.verify` might return, see [`bch_vmb_tests_2022_invalid_reasons.json`](../src/lib/vmb-tests/generated/bch/bch_vmb_tests_2022_invalid_reasons.json) and [`bch_vmb_tests_2022_nonstandard_reasons.json`](../src/lib/vmb-tests/generated/bch/bch_vmb_tests_2022_nonstandard_reasons.json)/.
For examples of the kind of error messages that `vm.verify` might return, see [`bch_vmb_tests_2025_invalid_reasons.json`](../src/lib/vmb-tests/generated/bch_vmb_tests_2025_invalid_reasons.json) and [`bch_vmb_tests_2025_nonstandard_reasons.json`](../src/lib/vmb-tests/generated/bch_vmb_tests_2025_nonstandard_reasons.json)/.

## Debugging Evaluations

A complete example of transaction verification and evaluation debugging is available in [`bch-vmb-test.spec.helper.ts`](src/lib/vmb-tests/bch-vmb-test.spec.helper.ts), which is used by the `yarn test:unit:vmb_test` CLI command. E.g.:
A complete example of transaction verification and evaluation debugging is available in [`run-bch-vmb-test.spec.helper.ts`](src/lib/vmb-tests/run-bch-vmb-test.spec.helper.ts), which is used by the `yarn test:unit:vmb_test` CLI command. E.g.:

```sh
❯ yarn test:unit:vmb_test bch_2023_standard dv5k4
❯ yarn test:unit:vmb_test bch_2025_standard dv5k4

VMB test ID: dv5k4
Description: Basic push operations: OP_0 (A.K.A. OP_PUSHBYTES_0, OP_FALSE): zero is represented by an empty stack item (P2SH20)
Test sets: 2022_standard
Test sets: 2025_standard, 2025_standard

Unlocking ASM: OP_0
Redeem (P2SH20) ASM: OP_SIZE <0> OP_EQUAL OP_NIP
Result: Success
Result (VM: bch_2025_standard): Transaction accepted
Evaluation at index 1:

0. OP_0: 0x(0)
Expand All @@ -76,7 +76,7 @@ Evaluation at index 1:

```

For extended debugging information, try the `-v` flag, e.g. `yarn test:unit:vmb_test bch_2023_standard dv5k4 -v`.
For extended debugging information, try the `-v` flag, e.g. `yarn test:unit:vmb_test bch_2025_standard dv5k4 -v`.

For a more advanced example of transaction debugging, including mapping of evaluation results to CashAssembly source positions ([`extractEvaluationSamplesRecursive`](https://libauth.org/functions/extractEvaluationSamplesRecursive.html)), see [Bitauth IDE's `editor-state.ts`](https://github.com/bitauth/bitauth-ide/blob/master/src/editor/editor-state.ts).

Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"fix:eslint": "yarn test:eslint --fix",
"gen:vmb_tests": "yarn build && yarn gen:vmb_tests:bch && yarn gen:vmb_tests-prettier",
"gen:vmb_tests-prettier": "prettier 'src/lib/vmb-tests/generated/**/*.json' --write",
"gen:vmb_tests:bch": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-tests.spec.helper.js' 'src/lib/vmb-tests/generated/bch' && yarn run gen:vmb_tests:bch:reasons",
"gen:vmb_tests:bch:reasons": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-tests-invalid.spec.helper.js'",
"wallet": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-tests.live.spec.helper.js'",
"gen:vmb_tests:bch": "node --enable-source-maps 'build/lib/vmb-tests/write-bch-vmb-tests.spec.helper.js' 'src/lib/vmb-tests/generated' && yarn run gen:vmb_tests:bch:reasons",
"gen:vmb_tests:bch:reasons": "node --enable-source-maps 'build/lib/vmb-tests/write-reasons-bch-vmb-tests.spec.helper.js'",
"wallet": "node --enable-source-maps 'build/lib/vmb-tests/run-live-bch-vmb-test.spec.helper.js'",
"gen:schema": "yarn gen:schema:wallet-template && yarn gen:schema:bcmr",
"gen:schema:wallet-template": "ts-json-schema-generator --no-ref-encode --path 'src/lib/engine/types/template-types.ts' --type 'WalletTemplate' > src/lib/schema/wallet-template.schema.json && prettier 'src/lib/schema/wallet-template.schema.json' --write && ajv compile -s src/lib/schema/wallet-template.schema.json --allowUnionTypes -o src/lib/schema/ajv/validate-wallet-template.js && prettier 'src/lib/schema/ajv/validate-wallet-template.js' --write && node -e \"const fs = require('fs'), path = 'src/lib/schema/ajv/validate-wallet-template.js'; fs.writeFileSync(path, fs.readFileSync(path, 'utf8').replace(/'use strict'[\\s\\S]*module.exports.default =/, 'export default'), 'utf8')\"",
"gen:schema:bcmr": "ts-json-schema-generator --no-ref-encode --path 'src/lib/engine/types/bcmr-types.ts' --type 'MetadataRegistry' > src/lib/schema/bcmr.schema.json && prettier 'src/lib/schema/bcmr.schema.json' --write && ajv compile -s src/lib/schema/bcmr.schema.json --allowUnionTypes -o src/lib/schema/ajv/validate-bcmr.js && prettier 'src/lib/schema/ajv/validate-bcmr.js' --write && node -e \"const fs = require('fs'), path = 'src/lib/schema/ajv/validate-bcmr.js'; fs.writeFileSync(path, fs.readFileSync(path, 'utf8').replace(/'use strict'[\\s\\S]*module.exports.default =/, 'export default'), 'utf8')\"",
Expand All @@ -69,10 +69,11 @@
"test:fast": "echo '\n\nUsage:\n yarn test:fast src/lib/key/bip39.spec.ts # run a single test file \n yarn test:fast --match=\"!*crypto*\" --match=\"!*vmb_tests*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v",
"test:unit:script_tests": "c8 ava --match='*[script_tests]*' --serial",
"test:unit:vmb_tests": "c8 ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial",
"test:unit:vmb_test": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-test.spec.helper.js'",
"test:unit:vmb_test": "node --enable-source-maps 'build/lib/vmb-tests/run-bch-vmb-test.spec.helper.js'",
"dev:vmb_tests": "yarn gen:vmb_tests && yarn build:tsc && ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial --fail-fast",
"bench": "yarn build && yarn bench:browser-deps && yarn bench:test",
"bench:test": "ava --config .ava.bench.config.js --serial --timeout=2m 2>&1 | tee bench.log",
"bench:vmb_tests": "ava src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts --serial",
"bench": "yarn build && yarn bench:browser-deps && yarn bench:vmb_tests && yarn bench:test",
"bench:test": "ava --config config/.ava.bench.config.js --serial --timeout=2m 2>&1 | tee bench.log",
"bench:browser-deps": "cpy '.yarn/artifacts/*.js' build/bench",
"watch": "yarn build -w",
"watch:test": "echo '\n\nUsage:\n yarn watch:test src/lib/key/bip39.spec.ts # watch a single test file \n yarn watch:test --match=\"!*crypto*\" --match=\"!*vmb_tests*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v --watch",
Expand Down Expand Up @@ -135,6 +136,7 @@
"rollup": "^4.9.4",
"secp256k1": "^5.0.0",
"source-map-support": "^0.5.21",
"tinybench": "^2.8.0",
"ts-json-schema-generator": "^1.5.0",
"typedoc": "^0.25.7",
"typescript": "^5.3.3"
Expand Down Expand Up @@ -177,7 +179,7 @@
"overrides": [
{
"files": [
"src/lib/vmb-tests/*bch-vmb-tests*.ts"
"src/lib/vmb-tests/**/*bch-vmb-tests*.ts"
],
"options": {
"printWidth": 400
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test(
errors: [
{
error:
'Both a VM and a createState method are required to reduce evaluations.',
'Both a VM and a createAuthenticationProgram method are required to reduce evaluations.',
range: {
endColumn: 15,
endLineNumber: 1,
Expand All @@ -89,7 +89,7 @@ test(
);

test(
'[BCH compiler] evaluations - requires createState',
'[BCH compiler] evaluations - requires createAuthenticationProgram',
expectCompilationResult,
'$( OP_1 OP_2 )',
{},
Expand All @@ -98,7 +98,7 @@ test(
errors: [
{
error:
'Both a VM and a createState method are required to reduce evaluations.',
'Both a VM and a createAuthenticationProgram method are required to reduce evaluations.',
range: {
endColumn: 15,
endLineNumber: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ test(
errors: [
{
error:
'Both a VM and a createState method are required to reduce evaluations.',
'Both a VM and a createAuthenticationProgram method are required to reduce evaluations.',
range: {
endColumn: 44,
endLineNumber: 1,
Expand Down
Loading

0 comments on commit 5f3bcfe

Please sign in to comment.