Skip to content

Commit 49bcce4

Browse files
committed
Begin implementation of BCH_2025_05 and BCH_SPEC
1 parent 4043ae7 commit 49bcce4

File tree

78 files changed

+1024
-2306
lines changed

Some content is hidden

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

78 files changed

+1024
-2306
lines changed

.changeset/sour-ties-allow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@bitauth/libauth': patch
3+
---
4+
5+
Begin implementation of BCH_2025_05 and BCH_SPEC
6+
7+
- Revised `AuthenticationVirtualMachine` to remove `clone` (obviated by wide availability of `structuredClone`) and add `initialize`, allowing VM proposals to add to the program state of an existing VM (in a type-safe way) without duplicating its unchanged logic.
8+
- Clarified documentation around contributing upgrade proposals to Libauth VMs
9+
- Allow usage of any `BCH_SPEC` opcodes in `assembleBytecodeBch`/`disassembleBytecodeBch`

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
"args": ["${file}"],
2626
"outputCapture": "std",
2727
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
28+
},
29+
{
30+
"type": "node",
31+
"request": "launch",
32+
"name": "Debug VMB Test",
33+
"runtimeExecutable": "yarn",
34+
"runtimeArgs": ["run", "test:unit:vmb_test"],
35+
"args": ["bch_spec_standard", "06ty9", "-v"],
36+
"outputCapture": "std",
37+
"console": "integratedTerminal",
38+
"skipFiles": ["<node_internals>/**"],
39+
"preLaunchTask": "npm: build"
40+
},
41+
{
42+
"type": "node",
43+
"request": "launch",
44+
"name": "Debug VMB Test Generation",
45+
"runtimeExecutable": "yarn",
46+
"runtimeArgs": ["run", "gen:vmb_tests"],
47+
"outputCapture": "std",
48+
"console": "integratedTerminal",
49+
"skipFiles": ["<node_internals>/**"],
50+
"preLaunchTask": "npm: build"
2851
}
2952
]
3053
}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"fix": "yarn fix:eslint && yarn fix:prettier",
4545
"fix:prettier": "prettier . --write",
4646
"fix:eslint": "yarn test:eslint --fix",
47-
"gen:vmb-tests": "yarn build && yarn gen:vmb-tests:bch && yarn gen:vmb-tests-prettier",
48-
"gen:vmb-tests-prettier": "prettier 'src/lib/vmb-tests/generated/**/*.json' --write",
49-
"gen:vmb-tests:bch": "node 'build/lib/vmb-tests/bch-vmb-tests.spec.helper.js' 'src/lib/vmb-tests/generated/bch' && yarn run gen:vmb-tests:bch:reasons",
50-
"gen:vmb-tests:bch:reasons": "node 'build/lib/vmb-tests/bch-vmb-tests-invalid.spec.helper.js'",
51-
"wallet": "node 'build/lib/vmb-tests/bch-vmb-tests.live.spec.helper.js'",
47+
"gen:vmb_tests": "yarn build && yarn gen:vmb_tests:bch && yarn gen:vmb_tests-prettier",
48+
"gen:vmb_tests-prettier": "prettier 'src/lib/vmb-tests/generated/**/*.json' --write",
49+
"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",
50+
"gen:vmb_tests:bch:reasons": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-tests-invalid.spec.helper.js'",
51+
"wallet": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-tests.live.spec.helper.js'",
5252
"gen:schema": "yarn gen:schema:wallet-template && yarn gen:schema:bcmr",
5353
"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')\"",
5454
"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')\"",
@@ -69,8 +69,8 @@
6969
"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",
7070
"test:unit:script_tests": "c8 ava --match='*[script_tests]*' --serial",
7171
"test:unit:vmb_tests": "c8 ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial",
72-
"test:unit:vmb_test": "node 'build/lib/vmb-tests/bch-vmb-test.spec.helper.js'",
73-
"dev:vmb_tests": "yarn gen:vmb-tests && yarn build:tsc && ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial --fail-fast",
72+
"test:unit:vmb_test": "node --enable-source-maps 'build/lib/vmb-tests/bch-vmb-test.spec.helper.js'",
73+
"dev:vmb_tests": "yarn gen:vmb_tests && yarn build:tsc && ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial --fail-fast",
7474
"bench": "yarn build && yarn bench:browser-deps && yarn bench:test",
7575
"bench:test": "ava --config .ava.bench.config.js --serial --timeout=2m 2>&1 | tee bench.log",
7676
"bench:browser-deps": "cpy '.yarn/artifacts/*.js' build/bench",

src/lib/compiler/compiler-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type {
2626
import {
2727
generateBytecodeMap,
2828
Opcodes,
29-
OpcodesBch,
29+
OpcodesBchSpec,
3030
OpcodesBtc,
3131
} from '../vm/vm.js';
3232

@@ -258,7 +258,7 @@ export const assembleBytecode = (
258258
* @param disassembledBytecode - the disassembled BCH bytecode to re-assemble
259259
*/
260260
export const assembleBytecodeBch = (disassembledBytecode: string) =>
261-
assembleBytecode(generateBytecodeMap(OpcodesBch), disassembledBytecode);
261+
assembleBytecode(generateBytecodeMap(OpcodesBchSpec), disassembledBytecode);
262262
/**
263263
* @deprecated Alias of `assembleBytecodeBch` for backwards-compatibility.
264264
*/

src/lib/compiler/standard/p2pkh.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ export const walletTemplateP2pkhNonHd: WalletTemplate = {
4343
unlocks: 'lock',
4444
},
4545
},
46-
supported: ['BCH_2020_05', 'BCH_2021_05', 'BCH_2022_05'],
47-
version: 0,
46+
supported: [
47+
'BCH_2020_05',
48+
'BCH_2021_05',
49+
'BCH_2022_05',
50+
'BCH_2023_05',
51+
'BCH_2024_05',
52+
'BCH_2025_05',
53+
'BCH_SPEC',
54+
],
4855
};
4956

5057
/**
@@ -90,6 +97,13 @@ export const walletTemplateP2pkh: WalletTemplate = {
9097
unlocks: 'lock',
9198
},
9299
},
93-
supported: ['BCH_2020_05', 'BCH_2021_05', 'BCH_2022_05'],
94-
version: 0,
100+
supported: [
101+
'BCH_2020_05',
102+
'BCH_2021_05',
103+
'BCH_2022_05',
104+
'BCH_2023_05',
105+
'BCH_2024_05',
106+
'BCH_2025_05',
107+
'BCH_SPEC',
108+
],
95109
};

src/lib/engine/types/template-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ export type AuthenticationVirtualMachineIdentifier =
110110
| 'BCH_2021_05'
111111
| 'BCH_2022_05'
112112
| 'BCH_2023_05'
113+
| 'BCH_2024_05'
114+
| 'BCH_2025_05'
115+
| 'BCH_2026_05'
116+
| 'BCH_2027_05'
117+
| 'BCH_2028_05'
118+
| 'BCH_2029_05'
119+
| 'BCH_2030_05'
113120
| 'BCH_SPEC'
114121
| 'BSV_2020_02'
115122
| 'BSV_SPEC'

src/lib/language/language-utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
authenticationInstructionIsMalformed,
2222
decodeAuthenticationInstructions,
2323
encodeAuthenticationInstructionMalformed,
24+
executionIsActive,
2425
OpcodesBch,
2526
vmNumberToBigInt,
2627
} from '../vm/vm.js';
@@ -702,10 +703,6 @@ export const extractEvaluationSamplesRecursive = <ProgramState>({
702703
};
703704
};
704705

705-
const stateIsExecuting = (
706-
state: AuthenticationProgramStateControlStack<boolean | number>,
707-
) => state.controlStack.every((item) => item !== false);
708-
709706
/**
710707
* Extract an array of ranges that were unused by an evaluation. This is useful
711708
* in development tooling for fading out or hiding code that is unimportant to
@@ -735,7 +732,7 @@ const stateIsExecuting = (
735732
* executing), defaults to `1,1`
736733
*/
737734
export const extractUnexecutedRanges = <
738-
ProgramState extends AuthenticationProgramStateControlStack<boolean | number>,
735+
ProgramState extends AuthenticationProgramStateControlStack,
739736
>(
740737
samples: EvaluationSample<ProgramState>[],
741738
evaluationBegins = '1,1',
@@ -752,10 +749,10 @@ export const extractUnexecutedRanges = <
752749
const precedingStateSkips =
753750
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
754751
precedingStateSkipsByEvaluation[currentEvaluationStartLineAndColumn]!;
755-
const endsWithSkip = !stateIsExecuting(sample.state);
752+
const endsWithSkip = !executionIsActive(sample.state);
756753
const sampleHasNoExecutedInstructions =
757754
endsWithSkip &&
758-
sample.internalStates.every((group) => !stateIsExecuting(group.state));
755+
sample.internalStates.every((group) => !executionIsActive(group.state));
759756
if (precedingStateSkips && sampleHasNoExecutedInstructions) {
760757
return {
761758
precedingStateSkipsByEvaluation: {

src/lib/mappings.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ import {
5959
OpcodeDescriptions,
6060
OpcodeDescriptionsBch,
6161
OpcodeDescriptionsBch2023,
62+
OpcodeDescriptionsBchSpec,
6263
Opcodes,
6364
OpcodesBch,
6465
OpcodesBch2023,
66+
OpcodesBchSpec,
6567
SigningSerializationType,
6668
SigningSerializationTypeBch,
6769
} from './lib.js';
@@ -80,7 +82,9 @@ type TypeTests =
8082
| AssertTypesEqual<TransactionBch, Transaction>
8183
| AssertTypesEqual<TransactionBch, TransactionCommon>
8284
| AssertTypesEqual<typeof ConsensusCommon, typeof ConsensusBch>
85+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
8386
| AssertTypesEqual<typeof OpcodeDescriptionsBch, typeof OpcodeDescriptions>
87+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
8488
| AssertTypesEqual<typeof OpcodesBch, typeof Opcodes>;
8589
/* eslint-enable @typescript-eslint/no-duplicate-type-constituents */
8690

@@ -102,9 +106,9 @@ test('Libauth exposes all expected mappings', (t) => {
102106
t.deepEqual(decodeTransactionUnsafe, decodeTransactionUnsafeBch);
103107
t.deepEqual(encodeTransactionCommon, encodeTransactionBch);
104108
t.deepEqual(encodeTransaction, encodeTransactionBch);
105-
t.deepEqual(OpcodeDescriptionsBch2023, OpcodeDescriptionsBch);
106-
t.deepEqual(OpcodeDescriptionsBch, OpcodeDescriptions);
107-
t.deepEqual(OpcodesBch2023, OpcodesBch);
108-
t.deepEqual(Opcodes, OpcodesBch);
109+
t.deepEqual(OpcodeDescriptionsBch, OpcodeDescriptionsBch2023);
110+
t.deepEqual(OpcodeDescriptions, OpcodeDescriptionsBchSpec);
111+
t.deepEqual(OpcodesBch, OpcodesBch2023);
112+
t.deepEqual(Opcodes, OpcodesBchSpec);
109113
t.deepEqual(SigningSerializationType, SigningSerializationTypeBch);
110114
});

src/lib/schema/ajv/validate-wallet-template.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ const schema22 = {
1111
'BCH_2021_05',
1212
'BCH_2022_05',
1313
'BCH_2023_05',
14+
'BCH_2024_05',
15+
'BCH_2025_05',
16+
'BCH_2026_05',
17+
'BCH_2027_05',
18+
'BCH_2028_05',
19+
'BCH_2029_05',
20+
'BCH_2030_05',
1421
'BCH_SPEC',
1522
'BSV_2020_02',
1623
'BSV_SPEC',
@@ -883,6 +890,13 @@ const schema42 = {
883890
'BCH_2021_05',
884891
'BCH_2022_05',
885892
'BCH_2023_05',
893+
'BCH_2024_05',
894+
'BCH_2025_05',
895+
'BCH_2026_05',
896+
'BCH_2027_05',
897+
'BCH_2028_05',
898+
'BCH_2029_05',
899+
'BCH_2030_05',
886900
'BCH_SPEC',
887901
'BSV_2020_02',
888902
'BSV_SPEC',
@@ -6889,6 +6903,13 @@ function validate21(
68896903
data27 === 'BCH_2021_05' ||
68906904
data27 === 'BCH_2022_05' ||
68916905
data27 === 'BCH_2023_05' ||
6906+
data27 === 'BCH_2024_05' ||
6907+
data27 === 'BCH_2025_05' ||
6908+
data27 === 'BCH_2026_05' ||
6909+
data27 === 'BCH_2027_05' ||
6910+
data27 === 'BCH_2028_05' ||
6911+
data27 === 'BCH_2029_05' ||
6912+
data27 === 'BCH_2030_05' ||
68926913
data27 === 'BCH_SPEC' ||
68936914
data27 === 'BSV_2020_02' ||
68946915
data27 === 'BSV_SPEC' ||

src/lib/schema/wallet-template.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
"BCH_2021_05",
1010
"BCH_2022_05",
1111
"BCH_2023_05",
12+
"BCH_2024_05",
13+
"BCH_2025_05",
14+
"BCH_2026_05",
15+
"BCH_2027_05",
16+
"BCH_2028_05",
17+
"BCH_2029_05",
18+
"BCH_2030_05",
1219
"BCH_SPEC",
1320
"BSV_2020_02",
1421
"BSV_SPEC",

0 commit comments

Comments
 (0)