Skip to content

fix: trim whole zero bytes from the right - #5571

Merged
jxom merged 1 commit into
wevm:mainfrom
yinbowen-dc:codex/fix-5567-trim-zero-bytes
Nov 18, 2026
Merged

jxom merged 1 commit into
wevm:mainfrom
yinbowen-dc:codex/fix-5567-trim-zero-bytes

Conversation

@yinbowen-dc

Copy link
Copy Markdown
Contributor

Fixes #5567.

Right trimming now removes complete 00 bytes, preserving nonzero bytes ending in a zero nibble. For example, 0x10200000 now produces 0x1020 instead of 0x0102. Includes hex/byte parity regressions and a patch changeset.

The existing long right-trim vector also lost a nonzero nibble; its expected result is corrected from 0x01a4e12a45 to 0x1a4e12a450.

Validation: the regression fails on main; all 7 trim tests pass. Biome and production TypeScript check pass. Full pnpm check:types was attempted and is blocked by missing generated test-contract artifacts. No public type signatures changed.

AI assistance: this fix and its tests were prepared with Codex at the account owner's request.

@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@yinbowen-dc is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7003a4e

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

This PR includes changesets to release 1 package
Name Type
viem 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

@erkancamli

Copy link
Copy Markdown
Contributor

Checked this against the bytes path and ox. On viem 2.58.0, the hex branch of trim(..., { dir: 'right' }) trims zero nibbles and then left-pads an odd result, so it returns a different value than the bytes branch whenever the last nonzero byte has a zero low nibble:

input trim(hex) on 2.58.0 trim(bytes) ox Hex.trimRight this PR
0x1230 0x0123 0x1230 0x1230 0x1230
0x10200000 0x0102 0x1020 0x1020 0x1020
0x1a4e…a45000… 0x01a4e12a45 0x1a4e12a450 0x1a4e12a450 0x1a4e12a450
0x0000 0x00 0x00 0x 0x00

I also ran the new right-trim loop against bytesToHex(trim(bytes, { dir: 'right' })) for 200k random 1 to 8 byte inputs weighted towards zero bytes and zero low nibbles: no mismatches, while 2.58.0 differs on about 28% of them. The internal right trims (bytesToString, hexToString) already go through the bytes branch, so this only changes direct callers of trim on hex, and the updated snapshot was the shifted value. The one remaining difference from ox is the all-zero case (0x00 vs 0x), which matches what the bytes branch keeps.

@jxom
jxom merged commit 515d5a5 into wevm:main Nov 18, 2026
53 of 64 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026
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.

trim: dir: 'right' on a hex value removes zero nibbles, not zero bytes

3 participants