Skip to content

v3.1.1: encodeMethodFromString 不支持在 funcParam 中传递数组类型参数 (uint256[24] 或 uint256[]) #888

@zhanglinchao1

Description

@zhanglinchao1

Issue Title:
v3.1.1: encodeMethodFromString 不支持在 funcParam 中传递数组类型参数 (uint256[24] 或 uint256[])


环境信息

  • WeBASE-Front 版本:v3.1.1
  • 部署模式:单节点 Docker
  • 底层链:FISCO-BCOS 3.x,
  • 浏览器/客户端:调用 Rest API

问题概述

在 WeBASE-Front v3.1.1 的交易处理接口中,funcParam 虽然文档(1.5.5+)中宣称“数组类型也需要以字符串形式包裹”(e.g. ["0x1a","[\"addr1\",\"addr2\"]"]),但实际底层编码工具 encodeMethodFromString 不会对单个字符串做二次 JSON 解析,导致任何数组参数都无法被正确打包,始终返回:

code: 201151  
errorMessage: "cannot encode in encodeMethodFromString with appropriate interface ABI, make sure params match"

复现步骤

  1. ABI 定义(固定长度数组)

    {
      "inputs":[
        { "internalType":"uint256[24]","name":"proof","type":"uint256[24]" },
        { "internalType":"uint256",      "name":"dataHash","type":"uint256"    }
      ],
      "name":"verifyAssetZK",
      "outputs":[ { "internalType":"bool","name":"","type":"bool" } ],
      "stateMutability":"nonpayable",
      "type":"function"
    }
  2. 尝试分步编码 → 发送
    请求 /WeBASE-Front/trans/encodeFunction

    {
      "groupId":"group0",
      "funcName":"verifyAssetZK",
      "contractAbi":[ /* 如上 ABI */ ],
      "funcParam":[
        "[\"0xaaa\",\"0xbbb\",…,\"0xzzz\"]",
        "1234567890"
      ]
    }

    返回(同样直接走 encodeMethodFromString):

    {
      "code":201151,
      "errorMessage":"cannot encode in encodeMethodFromString with appropriate interface ABI, make sure params match"
    }
  3. 尝试改成动态数组 ABI + 拆平

    // 合约 ABI 中把 uint256[24] 改为 uint256[]
    { "internalType":"uint256[]","name":"proof","type":"uint256[]" }

    并将 funcParam 拆成 25 条独立字符串:

    "funcParam":[
      "111111…", "222222…", …, "xxxxxxx…",    // 24 条 proof
      "1234567890"                            // dataHash
    ]

    返回依旧

    { "code":201151, "errorMessage":"cannot encode in encodeMethodFromString with appropriate interface ABI, make sure params match" }

原因分析

encodeMethodFromString 只支持基本类型的单值参数:

“每个 funcParam 元素必须对应一个基本参数,数组类型不再做二次 JSON.parse”。

因此任何 "[\"…\",\"…\"]" 或者拆平的动态数组都不能被识别为数组类型,均触发 201151 编码错误。


建议

  1. 恢复对数组字符串二次解析

    • encodeMethodFromString 中,若 ABI 声明为 T[]T[n],对该参数字符串先做 JSON.parse,再按数组逻辑打包。
  2. 文档更新/明示

    • 若短期无法支持上述特性,需要在文档中说明“当前版本不支持数组类型 funcParam,请使用原生 calldata 绕过”。
  3. 临时替代方案

    • 推荐增加一个新的接口参数 data,允许直接传入完整 ABI calldata(0x…),后端原生工具完成编码;或支持 rawCallData 选项。

感谢团队审阅,希望能尽快修复这一影响多种场景的数组编码问题!

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