Skip to content

abi.calldata.toString output does not match the reference format #210

Description

@memosr

Summary

abi.calldata.toString() produces output that does not match the reference implementation in the genvm repo (runners/genlayer-py-std/src/genlayer/calldata/__init__.py, to_str). There are three separate defects, all in src/abi/calldata/string.ts.

This function is public API, and it also feeds the readable field of decodeTransaction / simplifyTransactionReceipt through calldataToUserFriendlyJson, so the malformed output reaches end users.

Defects

Input genlayer-js v1 Reference to_str
new Uint8Array([0x01, 0x02]) b#12 b#0102
20-byte address of 0x01 addr#11111111111111111111 addr#0101…0101 (40 chars)
{x: true, y: null} {"x":true"y":null} {"x":true,"y":null}
[1, 2, 3] [1,2,3,] [1,2,3]
  1. Hex is not zero padded. Bytes and addresses use toString(16) with no padding, so 0x0a renders as a. This is lossy, not just cosmetic: Uint8Array([0x01, 0x02]) and Uint8Array([0x12]) both render as b#12. Addresses shorter than 40 hex characters are produced whenever any byte is below 0x10.
  2. Map entries have no separator. toStringImplMap never pushes a comma, so the output is not parseable.
  3. Arrays emit a trailing comma. The reference emits none.

Reproduction

import * as calldata from "genlayer-js/abi";

calldata.toString(new Uint8Array([0x01, 0x02])); // "b#12",   expected "b#0102"
calldata.toString({x: true, y: null});           // '{"x":true"y":null}'
calldata.toString([1, 2, 3]);                    // "[1,2,3,]"

Affected branches

Present on v1, v2, v2-dev and main. The file has not been modified since #51.

Environment

genlayer-js 1.1.8, Node 22, macOS.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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