Skip to content

Commit 0cbcb8d

Browse files
committed
Add support for BCH_2025_05
- Update libauth to latest @next release and adapt to changes - Remove opcount checks & update bytesize checks to new limit - Update VM used for debugging to BCH_2025_05 - Update bigint tests to check that ints bigger than 64 bits no longer fail
1 parent e464c4d commit 0cbcb8d

File tree

11 files changed

+30
-33
lines changed

11 files changed

+30
-33
lines changed

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint . --ext .ts --ignore-path ../.eslintignore"
1212
},
1313
"dependencies": {
14-
"@bitauth/libauth": "^3.0.0",
14+
"@bitauth/libauth": "^3.1.0-next.2",
1515
"@types/node": "^12.7.8",
1616
"cashc": "^0.10.5",
1717
"cashscript": "^0.10.5",

examples/testing-suite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
2626
},
2727
"dependencies": {
28+
"@bitauth/libauth": "^3.1.0-next.2",
2829
"cashc": "^0.10.5",
2930
"cashscript": "^0.10.5",
3031
"url-join": "^5.0.0"

packages/cashc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
5050
},
5151
"dependencies": {
52-
"@bitauth/libauth": "^3.0.0",
52+
"@bitauth/libauth": "^3.1.0-next.2",
5353
"@cashscript/utils": "^0.10.5",
5454
"antlr4": "^4.13.1-patch-1",
5555
"commander": "^7.1.0",

packages/cashc/src/cashc-cli.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { program, Option } from 'commander';
1313
import fs from 'fs';
1414
import path from 'path';
1515
import { compileFile, version } from './index.js';
16+
import { MAX_INPUT_BYTESIZE } from './constants.js';
1617

1718
program
1819
.storeOptionsAsProperties(false)
@@ -54,11 +55,8 @@ function run(): void {
5455
const opcount = countOpcodes(script);
5556
const bytesize = calculateBytesize(script);
5657

57-
if (opcount > 201) {
58-
console.warn('Warning: Your contract\'s opcount is over the limit of 201 and will not be accepted by the BCH network');
59-
}
60-
if (bytesize > 520) {
61-
console.warn('Warning: Your contract\'s bytesize is over the limit of 520 and will not be accepted by the BCH network');
58+
if (bytesize > MAX_INPUT_BYTESIZE) {
59+
console.warn(`Warning: Your contract is ${bytesize} bytes, which is over the limit of ${MAX_INPUT_BYTESIZE} bytes and will not be accepted by the BCH network`);
6260
}
6361

6462
if (opts.asm) {

packages/cashc/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MAX_INPUT_BYTESIZE = 1650;

packages/cashscript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
4444
},
4545
"dependencies": {
46-
"@bitauth/libauth": "^3.0.0",
46+
"@bitauth/libauth": "^3.1.0-next.2",
4747
"@cashscript/utils": "^0.10.5",
4848
"@mr-zwets/bchn-api-wrapper": "^1.0.1",
4949
"delay": "^5.0.0",

packages/cashscript/src/debugging.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthenticationErrorCommon, AuthenticationInstruction, AuthenticationProgramCommon, AuthenticationProgramStateBCH, AuthenticationProgramStateCommon, AuthenticationVirtualMachine, ResolvedTransactionCommon, WalletTemplate, binToHex, createCompiler, createVirtualMachineBCH2023, encodeAuthenticationInstruction, walletTemplateToCompilerConfiguration } from '@bitauth/libauth';
1+
import { AuthenticationErrorCommon, AuthenticationInstruction, AuthenticationProgramCommon, AuthenticationProgramStateCommon, AuthenticationVirtualMachine, ResolvedTransactionCommon, WalletTemplate, binToHex, createCompiler, createVirtualMachineBch2025, encodeAuthenticationInstruction, walletTemplateToCompilerConfiguration } from '@bitauth/libauth';
22
import { Artifact, LogEntry, Op, PrimitiveType, StackItem, bytecodeToAsm, decodeBool, decodeInt, decodeString } from '@cashscript/utils';
33
import { findLastIndex, toRegExp } from './utils.js';
44
import { FailedRequireError, FailedTransactionError, FailedTransactionEvaluationError } from './Errors.js';
@@ -53,7 +53,7 @@ export const debugTemplate = (template: WalletTemplate, artifact: Artifact): Deb
5353
// preceding OP_CHECKSIG opcode. The error message is registered in the next instruction, so we need to increment
5454
// the instruction pointer to get the correct error message from the require messages in the artifact.
5555
// Note that we do NOT use this adjusted IP when passing the failing IP into the FailedRequireError
56-
const isNullFail = lastExecutedDebugStep.error === AuthenticationErrorCommon.nonNullSignatureFailure;
56+
const isNullFail = lastExecutedDebugStep.error.includes(AuthenticationErrorCommon.nonNullSignatureFailure);
5757
const requireStatementIp = failingIp + (isNullFail ? 1 : 0);
5858

5959
const requireStatement = (artifact.debug?.requires ?? [])
@@ -110,15 +110,15 @@ export const debugTemplate = (template: WalletTemplate, artifact: Artifact): Deb
110110
type VM = AuthenticationVirtualMachine<
111111
ResolvedTransactionCommon,
112112
AuthenticationProgramCommon,
113-
AuthenticationProgramStateBCH
113+
AuthenticationProgramStateCommon
114114
>;
115115
type Program = AuthenticationProgramCommon;
116116
type CreateProgramResult = { vm: VM, program: Program };
117117

118118
// internal util. instantiates the virtual machine and compiles the template into a program
119119
const createProgram = (template: WalletTemplate): CreateProgramResult => {
120120
const configuration = walletTemplateToCompilerConfiguration(template);
121-
const vm = createVirtualMachineBCH2023();
121+
const vm = createVirtualMachineBch2025();
122122
const compiler = createCompiler(configuration);
123123

124124
const scenarioGeneration = compiler.generateScenario({
@@ -176,8 +176,9 @@ const failedFinalVerify = (evaluationResult: string | true): evaluationResult is
176176
// If any of the following errors occurred, then the final verify failed - any other messages
177177
// indicate other kinds of failures
178178
return toRegExp([
179-
AuthenticationErrorCommon.requiresCleanStack,
180-
AuthenticationErrorCommon.nonEmptyControlStack,
179+
// TODO: Ask Jason to put these back into an enum and replace with the enum value
180+
'The CashAssembly internal evaluation completed with an unexpected number of items on the stack (must be exactly 1).', // AuthenticationErrorCommon.requiresCleanStack,
181+
'The CashAssembly internal evaluation completed with a non-empty control stack.', // AuthenticationErrorCommon.nonEmptyControlStack,
181182
AuthenticationErrorCommon.unsuccessfulEvaluation,
182183
]).test(evaluationResult);
183184
};

packages/cashscript/test/e2e/BigInt.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { AuthenticationErrorCommon } from '@bitauth/libauth';
21
import {
32
Contract,
43
MockNetworkProvider,
54
FailedRequireError,
6-
FailedTransactionError,
75
ElectrumNetworkProvider,
86
Network,
97
} from '../../src/index.js';
@@ -26,7 +24,7 @@ describe('BigInt', () => {
2624
});
2725

2826
describe('proofOfBigInt', () => {
29-
it('should fail when providing a number that fits within 32 bits', async () => {
27+
it('should fail require statement when providing a number that fits within 32 bits', async () => {
3028
// given
3129
const to = bigintContract.address;
3230
const amount = 1000n;
@@ -43,7 +41,7 @@ describe('BigInt', () => {
4341
await expect(txPromise).rejects.toThrow('Failing statement: require(x >= maxInt32PlusOne)');
4442
});
4543

46-
it('should fail when providing numbers that overflow 64 bits when multiplied', async () => {
44+
it('should succeed when providing numbers that are larger than 64 bits when multiplied', async () => {
4745
// given
4846
const to = bigintContract.address;
4947
const amount = 1000n;
@@ -55,11 +53,10 @@ describe('BigInt', () => {
5553
.send();
5654

5755
// then
58-
await expect(txPromise).rejects.toThrow(FailedTransactionError);
59-
await expect(txPromise).rejects.toThrow(AuthenticationErrorCommon.overflowsVmNumberRange);
56+
await expect(txPromise).resolves.not.toThrow();
6057
});
6158

62-
it('should fail when providing a number that does not fit within 64 bits', async () => {
59+
it('should succeed when providing a number that does not fit within 64 bits', async () => {
6360
// given
6461
const to = bigintContract.address;
6562
const amount = 1000n;
@@ -71,8 +68,7 @@ describe('BigInt', () => {
7168
.send();
7269

7370
// then
74-
await expect(txPromise).rejects.toThrow(FailedTransactionError);
75-
await expect(txPromise).rejects.toThrow(AuthenticationErrorCommon.invalidVmNumber);
71+
await expect(txPromise).resolves.not.toThrow();
7672
});
7773

7874
it('should succeed when providing a number within 32b < x < 64b', async () => {

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
4141
},
4242
"dependencies": {
43-
"@bitauth/libauth": "^3.0.0"
43+
"@bitauth/libauth": "^3.1.0-next.2"
4444
},
4545
"devDependencies": {
4646
"@jest/globals": "^29.4.1",

packages/utils/src/script.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {
2-
OpcodesBCH,
2+
OpcodesBch2023,
33
encodeDataPush,
44
hexToBin,
5-
disassembleBytecodeBCH,
5+
disassembleBytecodeBch,
66
flattenBinArray,
77
encodeAuthenticationInstructions,
88
decodeAuthenticationInstructions,
99
} from '@bitauth/libauth';
1010
import { decodeInt, encodeInt } from './data.js';
1111
import OptimisationsEquivFile from './cashproof-optimisations.js';
1212

13-
export const Op = OpcodesBCH;
13+
export const Op = OpcodesBch2023;
1414
export type Op = number;
1515
export type OpOrData = Op | Uint8Array;
1616
export type Script = OpOrData[];
@@ -79,7 +79,7 @@ export function asmToBytecode(asm: string): Uint8Array {
7979

8080
export function bytecodeToAsm(bytecode: Uint8Array): string {
8181
// Convert the bytecode to libauth's ASM format
82-
let asm = disassembleBytecodeBCH(bytecode);
82+
let asm = disassembleBytecodeBch(bytecode);
8383

8484
// COnvert libauth's ASM format to BITBOX's
8585
asm = asm.replace(/OP_PUSHBYTES_[^\s]+/g, '');
@@ -95,7 +95,7 @@ export function bytecodeToAsm(bytecode: Uint8Array): string {
9595
// TODO: If we decide to change the ASM / artifact format, we can remove this function and merge it with bytecodeToAsm
9696
export function bytecodeToBitAuthAsm(bytecode: Uint8Array): string {
9797
// Convert the bytecode to libauth's ASM format
98-
let asm = disassembleBytecodeBCH(bytecode);
98+
let asm = disassembleBytecodeBch(bytecode);
9999

100100
// COnvert libauth's ASM format to BitAuth Script ASM
101101
asm = asm.replace(/OP_PUSHBYTES_[^\s]+/g, '');

0 commit comments

Comments
 (0)