From e9654eca6c1b1df1bbda2e8dc8b4f207e60dcae6 Mon Sep 17 00:00:00 2001 From: Mathieu Geukens Date: Mon, 3 Mar 2025 15:29:47 +0100 Subject: [PATCH] update typicalMaximumVmNumberByteLength & update conditionals --- src/lib/vm/instruction-sets/common/combinators.ts | 7 +++++-- src/lib/vm/instruction-sets/common/format.ts | 2 +- .../instruction-sets/common/instruction-sets-utils.ts | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/vm/instruction-sets/common/combinators.ts b/src/lib/vm/instruction-sets/common/combinators.ts index 084f1444..491a251c 100644 --- a/src/lib/vm/instruction-sets/common/combinators.ts +++ b/src/lib/vm/instruction-sets/common/combinators.ts @@ -165,7 +165,10 @@ export const useSixStackItems = < ), ); -const typicalMaximumVmNumberByteLength = 8; +/** + * Zero means any maximum length checks on VM numbers are disabled. + */ +const typicalMaximumVmNumberByteLength = 0; export const useOneVmNumber = < State extends AuthenticationProgramStateError & @@ -356,7 +359,7 @@ export const pushToStackVmNumberChecked = < } = {}, ) => { const encoded = bigIntToVmNumber(vmNumber); - if (encoded.length > maximumVmNumberByteLength) { + if (maximumVmNumberByteLength && encoded.length > maximumVmNumberByteLength) { return applyError( state, AuthenticationErrorCommon.overflowsVmNumberRange, diff --git a/src/lib/vm/instruction-sets/common/format.ts b/src/lib/vm/instruction-sets/common/format.ts index 73d81851..010bdddb 100644 --- a/src/lib/vm/instruction-sets/common/format.ts +++ b/src/lib/vm/instruction-sets/common/format.ts @@ -143,7 +143,7 @@ export const createOpBin2Num = state, (nextState, [target]) => { const minimallyEncoded = bigIntToVmNumber(target); - return minimallyEncoded.length > maximumVmNumberByteLength + return maximumVmNumberByteLength && minimallyEncoded.length > maximumVmNumberByteLength ? applyError( nextState, AuthenticationErrorCommon.exceededMaximumVmNumberByteLength, diff --git a/src/lib/vm/instruction-sets/common/instruction-sets-utils.ts b/src/lib/vm/instruction-sets/common/instruction-sets-utils.ts index 649e8b05..33658653 100644 --- a/src/lib/vm/instruction-sets/common/instruction-sets-utils.ts +++ b/src/lib/vm/instruction-sets/common/instruction-sets-utils.ts @@ -482,7 +482,10 @@ export const isVmNumberError = ( ): value is VmNumberError => value === VmNumberError.outOfRange || value === VmNumberError.requiresMinimal; -const typicalMaximumVmNumberByteLength = 8; +/** + * Zero means any maximum length checks on VM numbers are disabled. + */ +const typicalMaximumVmNumberByteLength = 0; /** * This method attempts to decode a VM Number, a format in which numeric values @@ -512,7 +515,8 @@ export const vmNumberToBigInt = ( requireMinimalEncoding = true, }: { /** - * The maximum valid number of bytes in a VM Number. + * The maximum valid number of bytes in a VM Number. Set to `0` to disable + * this check. */ maximumVmNumberByteLength?: number; /** @@ -528,7 +532,7 @@ export const vmNumberToBigInt = ( if (bytes.length === 0) { return 0n; } - if (bytes.length > maximumVmNumberByteLength) { + if (maximumVmNumberByteLength && bytes.length > maximumVmNumberByteLength) { return VmNumberError.outOfRange; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion