Repository navigation
eth: reject unsafe EIP-712 number inputs - #18
benma-agent wants to merge 1 commit into
Conversation
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)
90a23fe to
21e449e
Compare
Converting JSON numbers through f64 can round large integers or turn fractional values into integers before EIP-712 signing. Preserve the JSON digits and convert integral decimal and exponent forms exactly, including values beyond u64. Reject fractions without rounding, and bound exponent expansion to the 256-bit integer range. Related fixes: - Go: BitBoxSwiss/bitbox02-api-go#199 - TypeScript: BitBoxSwiss/bitbox-api-ts#18
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)
Converting JSON numbers through f64 can round large integers or turn fractional values into integers before EIP-712 signing. Parse JSON numbers with BigDecimal and convert integral values exactly, including decimal and exponent notation and integers beyond u64. Reject fractions without rounding and bound values before integer conversion. Related fixes: - Go: BitBoxSwiss/bitbox02-api-go#199 - TypeScript: BitBoxSwiss/bitbox-api-ts#18
Converting JSON numbers through f64 can round large integers or turn fractional values into integers before EIP-712 signing. Preserve exact JSON integer tokens and parse them directly into big integers up to 256 bits. Numeric inputs now require integer notation; decimal and exponent forms such as 128.0 and 1e3 are rejected. Related fixes: - Go: BitBoxSwiss/bitbox02-api-go#199 - TypeScript: BitBoxSwiss/bitbox-api-ts#18
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)
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
Tomasvrba
left a comment
There was a problem hiding this comment.
Same concern as go and rust api PRs, but in the TS case, doesn't seem like anything is gained at all?
| if (typeof value === 'number') { | ||
| if (!Number.isInteger(value) || value < 0) { | ||
| throw new TypedMessageError('Number is not an uint'); | ||
| if (!Number.isSafeInteger(value) || value < 0) { |
There was a problem hiding this comment.
Same concern as the go and rust apis
Switching from Number.isInteger to Number.isSafeInteger rejects exact large round numbers like 1e18 (1 ETH in wei) that @metamask/eth-sig-util (used by Rabby and MetaMask) and viem accept.
Because the BitBox02 always displays the exact number it signs on the device screen, there isn't a blind-signing security issue here, rejecting > 2^53 - 1 mostly causes dApps sending { amount: 1e18 } to fail on BitBox02 while continuing to work in MetaMask and Rabby's software wallet. Unless we specifically want to break compatibility with those dApps, I'd lean toward keeping Number.isInteger here and closing this PR.
There was a problem hiding this comment.
Closing this PR and retaining Number.isInteger. Callers needing exact large integers should supply decimal strings or bigint.
Decode typed-message numbers without converting them to float64 so large integers retain every digit. Accept integral decimal and exponent forms, including 128.0 and 1e18, and reject fractional values instead of rounding them. Integer strings keep their existing parsing behavior. Related: - [Rust BitBoxSwiss#141](BitBoxSwiss/bitbox-api-rs#141) - [TypeScript BitBoxSwiss#18](BitBoxSwiss/bitbox-api-ts#18)
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: