Skip to content

Commit e9654ec

Browse files
committed
update typicalMaximumVmNumberByteLength & update conditionals
1 parent 489cac0 commit e9654ec

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/lib/vm/instruction-sets/common/combinators.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export const useSixStackItems = <
165165
),
166166
);
167167

168-
const typicalMaximumVmNumberByteLength = 8;
168+
/**
169+
* Zero means any maximum length checks on VM numbers are disabled.
170+
*/
171+
const typicalMaximumVmNumberByteLength = 0;
169172

170173
export const useOneVmNumber = <
171174
State extends AuthenticationProgramStateError &
@@ -356,7 +359,7 @@ export const pushToStackVmNumberChecked = <
356359
} = {},
357360
) => {
358361
const encoded = bigIntToVmNumber(vmNumber);
359-
if (encoded.length > maximumVmNumberByteLength) {
362+
if (maximumVmNumberByteLength && encoded.length > maximumVmNumberByteLength) {
360363
return applyError(
361364
state,
362365
AuthenticationErrorCommon.overflowsVmNumberRange,

src/lib/vm/instruction-sets/common/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const createOpBin2Num =
143143
state,
144144
(nextState, [target]) => {
145145
const minimallyEncoded = bigIntToVmNumber(target);
146-
return minimallyEncoded.length > maximumVmNumberByteLength
146+
return maximumVmNumberByteLength && minimallyEncoded.length > maximumVmNumberByteLength
147147
? applyError(
148148
nextState,
149149
AuthenticationErrorCommon.exceededMaximumVmNumberByteLength,

src/lib/vm/instruction-sets/common/instruction-sets-utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ export const isVmNumberError = (
482482
): value is VmNumberError =>
483483
value === VmNumberError.outOfRange || value === VmNumberError.requiresMinimal;
484484

485-
const typicalMaximumVmNumberByteLength = 8;
485+
/**
486+
* Zero means any maximum length checks on VM numbers are disabled.
487+
*/
488+
const typicalMaximumVmNumberByteLength = 0;
486489

487490
/**
488491
* This method attempts to decode a VM Number, a format in which numeric values
@@ -512,7 +515,8 @@ export const vmNumberToBigInt = (
512515
requireMinimalEncoding = true,
513516
}: {
514517
/**
515-
* The maximum valid number of bytes in a VM Number.
518+
* The maximum valid number of bytes in a VM Number. Set to `0` to disable
519+
* this check.
516520
*/
517521
maximumVmNumberByteLength?: number;
518522
/**
@@ -528,7 +532,7 @@ export const vmNumberToBigInt = (
528532
if (bytes.length === 0) {
529533
return 0n;
530534
}
531-
if (bytes.length > maximumVmNumberByteLength) {
535+
if (maximumVmNumberByteLength && bytes.length > maximumVmNumberByteLength) {
532536
return VmNumberError.outOfRange;
533537
}
534538
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

0 commit comments

Comments
 (0)