Skip to content

Decoding bytes parameters longer than 32 bytes doesn't work #3524

@PaulRBerg

Description

@PaulRBerg

Check existing issues

Viem Version

2.23.2

Current Behavior

The following code doesn't work when the 2nd parameter has a length greater than 32 bytes:

const decoded = decodeAbiParameters(
    [
      { name: "success", type: "bool" },
      { name: "response", type: "bytes" },
    ],
    revertData,
  );
  console.log({ decoded });

How to Reproduce

Input

This is a bytes with 128 bytes (notice the 80 at the end of the second EVM word - that's the length).

const revertData = "0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000023ffec2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000";

Actual Output

crash.ts:93 PositionOutOfBoundsError: Position `255` is out of bounds (`0 < position < 192`).

Version: viem@2.23.2
    at Object.assertPosition (cursor.js:23:19)
    at Object.inspectBytes (cursor.js:52:14)
    at Object.readBytes (cursor.js:117:28)
    at decodeBytes (decodeAbiParameters.js:160:29)
    at decodeParameter (decodeAbiParameters.js:62:16)
    at decodeAbiParameters (decodeAbiParameters.js:41:35)
    at decodeRevertData (interact.ts:445:38)
    at safeWrite (interact.ts:423:7)
    at async Object.safeAllowAndWrite (interact.ts:183:20)
    at async onExecuteSafe (lockupCreate.ts:427:11)
    at async onProcess (lockupCreate.ts:481:9)
    at async doProcess (index.tsx:178:11)

Expected Output

[true, '0x00000000000000000000000000000000000000000000000000000000023ffec2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000']

32 Bytes Works

Note that when the bytes parameter has only 32 bytes, it works, e.g.

// this works!
const revertData = "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080";

Output:

[true, '0x0000000000000000000000000000000000000000000000000000000000000080']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions