Repository navigation
Conversation
calldata.encode silently accepted: 1. Unsafe integer numbers (outside Number.isSafeInteger range) — BigInt(data) encoded the already-rounded Number 2. Strings with unpaired UTF-16 surrogates — TextEncoder replaced them with U+FFFD, causing decode(encode(value)) !== value and map key collisions Now rejects both with clear error messages, matching the GenVM Python reference encoder behavior. Closes genlayerlabs#229
|
This PR targeted I retargeted it to |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #229:
calldata.encodesilently accepted two JavaScript value classes that cannot be represented losslessly:numbers —Number.isInteger()accepts values outside JavaScript's safe-integer range, thenBigInt(data)encodes the already-rounded Number.TextEncoderreplaces an unpaired surrogate with U+FFFD instead of failing, sodecode(encode(value)) !== valueand distinct map keys can collapse to the same UTF-8 bytes.Changes
src/abi/calldata/encoder.ts: rejectnumbervalues for whichNumber.isSafeInteger(value)is falsesrc/abi/calldata/encoder.ts: reject unpaired UTF-16 surrogates in calldata string values and map keyshasUnpairedSurrogates()helper functiontests/calldata-encoder.test.tsTesting
npx vitest run— clean🤖 Generated with Claude Code
Summary by CodeRabbit
bigintfor large integers.