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

Tuple with struct incorrectly parsed - always errors #701

Open
W3stside opened this issue May 20, 2023 · 9 comments
Open

Tuple with struct incorrectly parsed - always errors #701

W3stside opened this issue May 20, 2023 · 9 comments

Comments

@W3stside
Copy link

Description

Struct tuple incorrectly parsed, never passes validation:
image

Example tuple: (whitespace here for legibility)

[
  [{ "token": "0xSomeActualAddress", "id": "1000" }], 
  [{ "token": "0xSomeActualAddress", "id": "4000" }]
]

contract tuple:

StructType {
  address token;
  uint256 id;
}

function someContractFn(
        string memory stringParam,
        uint256[] calldata _unit256ArrayParam,
        StructType[][] calldata _tupleParam
    ) external { ... }

Running this on etherscan works fine. I checked the tests written in this PR, which addresses the original issue opened, but I don't see any tests for struct tuples

Environment

  • Browser: Brave
  • Wallet: Brave wallet
  • Safe:
  • Environment:
    • production (goerli)

Steps to reproduce

For reasons of security on our side I don't want to give our contract, but any other contract requiring a struct tuple as a param will encounter this problem.

Expected result

Passes validation

Obtained result

Invalidated with: format error. details: typeerror: cannot read properties of undefined (reading 'length')

Screenshots

image

Also hi to the Safe team!

@bradyjoestar
Copy link

I have met the following error:
截屏2023-05-24 18 57 03

@DaniSomoza
Copy link
Contributor

Hi @bradyjoestar for that _batchHeader struct defined in this contract 0x91A5D806BA73d0AA4bFA9B318126dDE60582e92a:

you can use a value like this:

[123,"0xAAAAFF", 1234, 1234, "0xAAAAFF", "0xAAAAFF"]

Captura de pantalla 2023-05-24 a las 14 10 56

@DaniSomoza
Copy link
Contributor

DaniSomoza commented May 24, 2023

Hi @W3stside sorry for the late response.

For this tuple

StructType {
  address token;
  uint256 id;
}

You can use a value like this:

["0x57CB13cbef735FbDD65f5f2866638c546464E45F",1]

but in the method someContractFn expects a matrix param like StructType[][] calldata _tupleParam

A basic example of a valid value for that matrix is:

[
 [
    ["0x57CB13cbef735FbDD65f5f2866638c546464E45F", 1]
 ]
] 

Could you provide me the contract address and the method that you want to use?

@W3stside
Copy link
Author

@DaniSomoza will give it a go, thanks!

@bradyjoestar
Copy link

[123,"0xAAAAFF", 1234, 1234, "0xAAAAFF", "0xAAAAFF"]

It worked ! Thank you for your help.

@Berbex
Copy link

Berbex commented Oct 6, 2023

Hellow, in the case when the tuple is more complex, is there a way to match the format?

In my case this is the format:
image

@ElvisKrop
Copy link

Hello @DaniSomoza!
I'm facing a similar issue with the array of tuples: tuple(int64,tuple(string,uint256)[])[], while this test succeed after replacing the abi fragment and expected result with next values:

  • ABI fragment for input:
{
   "name":"s",
   "type":"tuple[]",
   "internalType":"struct Period[]",
   "components":[
      {
         "internalType":"int64",
         "name":"length",
         "type":"int64"
      },
      {
         "name":"c",
         "type":"tuple[]",
         "internalType":"struct Coin[]",
         "components":[
            {
               "internalType":"string",
               "name":"denom",
               "type":"string"
            },
            {
               "internalType":"uint256",
               "name":"amount",
               "type":"uint256"
            }
         ]
      }
   ]
}
  • input value: [[5000,[["random",100]]]]

During interacting with tx-builder the error is thrown at this line. And it looks like the issue is on web3-eth-abi side (web3/web3.js#6307).

Do you have any advice how to use such structures as an argument?
Thanks in advance!

@AlissonRS
Copy link

Given this struct:

StructType {
  address token;
  uint256 id;
}

Block explorers like Etherscan accept the format below for an array of tuples for that struct:

[{ "token": "0x0000000000000000000000000000000000000000", "id": 1 }]

Could we leverage this thread/issue for supporting this format?

@krzysu
Copy link

krzysu commented Oct 7, 2024

I’m not sure if this issue is still relevant, but it looks like updating to the latest version of web3.js should resolve it. The fix was merged in September 2023. See web3/web3.js#6307

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

No branches or pull requests

7 participants