Skip to content

fix(react): exact uint64/uint128 maxValue in FheTypesList - #446

Open
Ravan002 wants to merge 1 commit into
FhenixProtocol:masterfrom
Ravan002:fix/react-fhe-types-max-value
Open

Ravan002 wants to merge 1 commit into
FhenixProtocol:masterfrom
Ravan002:fix/react-fhe-types-max-value

Conversation

@Ravan002

Copy link
Copy Markdown

FheTypesList builds its max values as BigInt(2 ** n - 1). The subtraction happens on a float first, and for 64 and 128 bits 2 ** n - 1 isn't representable, so it rounds back up to 2 ** n:

> FheTypesList.find(t => t.value === 'uint64').maxValue
before: 18446744073709551616n   (2^64)
after:  18446744073709551615n   (2^64 - 1)

> FheTypesList.find(t => t.value === 'uint128').maxValue
before: 340282366920938463463374607431768211456n   (2^128)
after:  340282366920938463463374607431768211455n   (2^128 - 1)

CofheEncryptInput validates against this list, so it accepted 2^64 for a uint64 input; the SDK then rejected it at encrypt time. All entries now use bigint math (2n ** 64n - 1n); 8/16/32 bit were already exact and don't change.

Test: packages/react/src/utils/utils.test.ts, which checks every uint type (uint64 and uint128 fail on master). The react suite passes (83).

BigInt(2 ** 64 - 1) evaluates 2 ** 64 - 1 as a float first, which is
exactly 2 ** 64, so uint64 and uint128 got a maxValue one too high.
@changeset-bot

changeset-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e50f9fc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/react Patch
@cofhe/example-react Patch
@cofhe/abi Patch
@cofhe/foundry-plugin Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/mock-contracts Patch
@cofhe/sdk Patch
@cofhe/site Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant