Skip to content

eth: reject unsafe EIP-712 numbers - #141

Open
benma-agent wants to merge 1 commit into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/eip712-exact-json-integers
Open

benma-agent wants to merge 1 commit into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/eip712-exact-json-integers

Conversation

@benma-agent

@benma-agent benma-agent commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

EIP-712 numeric values outside the safe integer range can lose precision
when decoded as floating point.

Reject numeric values outside ±(2^53 - 1), requiring decimal strings for
larger integers. Keep integral numeric forms such as 128.0 and 1e3, and
parse JSON floats with round-trip precision at the safe-range boundaries.

Related fixes:

benma-agent added a commit to benma-agent/bitbox-api-ts that referenced this pull request Nov 29, 2026
JavaScript can round integer values before they reach the EIP-712 encoder. Checking only
integrality accepts those rounded values without warning.

Require safe integers for number inputs. Keep decimal strings and bigint inputs for exact
values outside ±(2^53 - 1), and document that converting an already-rounded number cannot
restore the original digits.

Related:

- [bitbox02-api-go #199](BitBoxSwiss/bitbox02-api-go#199)
- [bitbox-api-rs #141](BitBoxSwiss/bitbox-api-rs#141)
@benma-agent
benma-agent force-pushed the benma-agent/eip712-exact-json-integers branch from 5fce867 to 5dcd801 Compare November 29, 2026 08:20
benma-agent added a commit to benma-agent/bitbox02-api-go that referenced this pull request Nov 29, 2026
Decode JSON numbers as exact text so values such as 9007199254740993
are not rounded before encoding. Use math/big's rational parser to accept
integral decimal and exponent forms, rejecting fractions and values
outside the 256-bit range.

Related:

- [Rust BitBoxSwiss#141](BitBoxSwiss/bitbox-api-rs#141)
- [TypeScript BitBoxSwiss#18](BitBoxSwiss/bitbox-api-ts#18)
@benma-agent
benma-agent force-pushed the benma-agent/eip712-exact-json-integers branch 2 times, most recently from 6091e6d to 51d846f Compare November 29, 2026 08:24
benma-agent added a commit to benma-agent/bitbox02-api-go that referenced this pull request Nov 29, 2026
Decode JSON numbers as exact text so values such as 9007199254740993
are not rounded before encoding. Parse integer notation directly with
math/big, rejecting decimal points, exponents, and values outside 256 bits.

Related:

- [Rust BitBoxSwiss#141](BitBoxSwiss/bitbox-api-rs#141)
- [TypeScript BitBoxSwiss#18](BitBoxSwiss/bitbox-api-ts#18)
benma-agent added a commit to benma-agent/bitbox02-api-go that referenced this pull request Nov 29, 2026
Require decoded numeric values to be integers within the JavaScript
safe-integer range, matching the TypeScript client. Decimal and exponent
notation remains accepted when it decodes to a safe integer. Use decimal
strings for larger values.

Related:

- [Rust BitBoxSwiss#141](BitBoxSwiss/bitbox-api-rs#141)
- [TypeScript BitBoxSwiss#18](BitBoxSwiss/bitbox-api-ts#18)
EIP-712 numeric values outside the safe integer range can lose precision
when decoded as floating point.

Reject numeric values outside ±(2^53 - 1), requiring decimal strings for
larger integers. Keep integral numeric forms such as 128.0 and 1e3, and
parse JSON floats with round-trip precision at the safe-range boundaries.

Related fixes:
- Go: BitBoxSwiss/bitbox02-api-go#199
- TypeScript: BitBoxSwiss/bitbox-api-ts#18
@benma-agent
benma-agent force-pushed the benma-agent/eip712-exact-json-integers branch from 51d846f to 154370b Compare November 29, 2026 08:27
@benma-agent benma-agent changed the title eth: preserve exact EIP-712 JSON integers eth: reject unsafe EIP-712 numbers Nov 29, 2026
@benma
benma requested a review from Tomasvrba November 29, 2026 08:29
@benma
benma marked this pull request as ready for review November 29, 2026 08:30

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