mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
lxrPadUint256 wrote a number wider than 32 bytes as b[:32] — its LEADING bytes, not its low ones — so a value one bit over came out as a completely unrelated quantity in the field that says how much to spend. The quote accepted any string and the swap checked only the sign, so nothing stopped one arriving. Two changes, and the boundary one is the real fix. wholeUnits is one parser for every path that takes an amount: a whole number of a token's smallest unit, in decimal, that fits in a uint256 — refused at the edge, where the sentence can say what is wrong with it. And the encoder now keeps the LOW bytes, which is what the EVM does to a uint256, so the failure mode of anything that slips past is truncation rather than a different number entirely. Co-authored-by: Hanzo Dev <[email protected]>