Skip to content

update typicalMaximumVmNumberByteLength & update conditionals #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/vm/instruction-sets/common/combinators.ts
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion src/lib/vm/instruction-sets/common/format.ts
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@
state,
(nextState, [target]) => {
const minimallyEncoded = bigIntToVmNumber(target);
return minimallyEncoded.length > maximumVmNumberByteLength
return maximumVmNumberByteLength && minimallyEncoded.length > maximumVmNumberByteLength

Check warning on line 146 in src/lib/vm/instruction-sets/common/format.ts

Codecov / codecov/patch

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

Added line #L146 was not covered by tests
? applyError(
nextState,
AuthenticationErrorCommon.exceededMaximumVmNumberByteLength,
10 changes: 7 additions & 3 deletions src/lib/vm/instruction-sets/common/instruction-sets-utils.ts
Original file line number Diff line number Diff line change
@@ -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