Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABI Coder Fails to validate correctly provided arguments #4583

Closed
KyrylR opened this issue Feb 8, 2024 · 3 comments
Closed

ABI Coder Fails to validate correctly provided arguments #4583

KyrylR opened this issue Feb 8, 2024 · 3 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@KyrylR
Copy link

KyrylR commented Feb 8, 2024

Ethers Version

6.10.0

Search Terms

abi

Describe the Problem

Abi Coder encoded an invalid value without throwing an error for the invalid type

Expected result:

invalid string value (argument="value", value=....)

Actual result:

0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673796d626f6c0000000000000000000000000000000000000000000000000000

It treated the complex object as an empty string

Code Snippet

import hre, { ethers } from "hardhat";

import { TASK_NODE } from "hardhat/builtin-tasks/task-names";

export async function sleep(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

async function main() {
  hre.run(TASK_NODE);

  await sleep(3000)

  const _abi = [
    {
      inputs: [
        {
          internalType: "string",
          name: "name_",
          type: "string",
        },
        {
          internalType: "string",
          name: "symbol_",
          type: "string",
        },
      ],
      stateMutability: "nonpayable",
      type: "constructor",
    },
  ] as const;

  const contractInterface = new ethers.Interface(_abi);

  const someAbi = [
    {
      inputs: [
        {
          internalType: "uint256",
          name: "tokenAmount_",
          type: "uint256",
        },
        {
          internalType: "uint8",
          name: "decimals_",
          type: "uint8",
        },
      ],
      name: "calculateUserVotingPower",
      outputs: [
        {
          internalType: "uint256",
          name: "",
          type: "uint256",
        },
      ],
      stateMutability: "pure",
      type: "function",
    },
    {
      inputs: [
        {
          internalType: "uint256",
          name: "totalSupply_",
          type: "uint256",
        },
        {
          internalType: "uint8",
          name: "decimals_",
          type: "uint8",
        },
      ],
      name: "calculateVotingPowerThreshold",
      outputs: [
        {
          internalType: "uint256",
          name: "",
          type: "uint256",
        },
      ],
      stateMutability: "pure",
      type: "function",
    },
  ] as const;

  const someBytecode =
    "0x6103f761003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c806378f5effe14610045578063c189e4891461006a575b600080fd5b610058610053366004610259565b61007d565b60405190815260200160405180910390f35b610058610078366004610259565b6100ba565b60008061008b83600a610389565b905080841161009e5760009150506100b4565b6100b06100ab828661039f565b6100ed565b9150505b92915050565b6000806100c883600a610389565b90508084116100db5760009150506100b4565b6100b06100e8828661039f565b6101c5565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061012c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310610158576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061017657662386f26fc10000830492506010015b6305f5e100831061018e576305f5e100830492506008015b61271083106101a257612710830492506004015b606483106101b4576064830492506002015b600a83106100b45760010192915050565b600080608083901c156101da57608092831c92015b604083901c156101ec57604092831c92015b602083901c156101fe57602092831c92015b601083901c1561021057601092831c92015b600883901c1561022257600892831c92015b600483901c1561023457600492831c92015b600283901c1561024657600292831c92015b600183901c156100b45760010192915050565b6000806040838503121561026c57600080fd5b82359150602083013560ff8116811461028457600080fd5b809150509250929050565b634e487b7160e01b600052601160045260246000fd5b600181815b808511156102e05781600019048211156102c6576102c661028f565b808516156102d357918102915b93841c93908002906102aa565b509250929050565b6000826102f7575060016100b4565b81610304575060006100b4565b816001811461031a576002811461032457610340565b60019150506100b4565b60ff8411156103355761033561028f565b50506001821b6100b4565b5060208310610133831016604e8410600b8410161715610363575081810a6100b4565b61036d83836102a5565b80600019048211156103815761038161028f565b029392505050565b600061039860ff8416836102e8565b9392505050565b6000826103bc57634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220c9d439b034118e8332267cb8664cfa9b90ce68d1e62225d317196c9f705feaf264736f6c63430008140033";

  const contractFactory = new ethers.ContractFactory(someAbi, someBytecode, await ethers.provider.getSigner());
  const contract = await contractFactory.deploy();

  const coder = new ethers.AbiCoder();

  const encoded = coder.encode(["string", "string"], [contract, "symbol"]);

  console.log(encoded);

  process.exit(0);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Contract ABI

No response

Errors

No response

Environment

Hardhat

Environment (Other)

No response

@KyrylR KyrylR added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Feb 8, 2024
@ricmoo
Copy link
Member

ricmoo commented Feb 8, 2024

Thanks! I'll investigate fist thing in the morning.

@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. bug Verified to be an issue. next-patch Issues scheduled for the next arch release. and removed investigate Under investigation and may be a bug. labels Feb 8, 2024
@ricmoo
Copy link
Member

ricmoo commented Feb 14, 2024

I've verified this is an issue and will go out in the next patch release (hopefully within a few hours). For minimal reproduction, this example is easier to use to reproduce:

const coder = new ethers.AbiCoder();

const encoded = coder.encode([ "string", "string" ], [ { }, "symbol" ]);
console.log(encoded);
console.log(coder.decode([ "string", "string" ], encoded));

@ricmoo
Copy link
Member

ricmoo commented Feb 14, 2024

Fixed in v6.11.1.

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants