safe-react-apps icon indicating copy to clipboard operation
safe-react-apps copied to clipboard

Tuple with struct incorrectly parsed - always errors

Open W3stside opened this issue 1 year ago • 8 comments

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!

W3stside avatar May 20 '23 11:05 W3stside

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

bradyjoestar avatar May 24 '23 10:05 bradyjoestar

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 avatar May 24 '23 12:05 DaniSomoza

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?

DaniSomoza avatar May 24 '23 12:05 DaniSomoza

@DaniSomoza will give it a go, thanks!

W3stside avatar May 24 '23 20:05 W3stside

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

It worked ! Thank you for your help.

bradyjoestar avatar May 25 '23 07:05 bradyjoestar

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

Berbex avatar Oct 06 '23 13:10 Berbex

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 (https://github.com/web3/web3.js/issues/6307).

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

ElvisKrop avatar Oct 26 '23 12:10 ElvisKrop

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?

AlissonRS avatar Feb 29 '24 04:02 AlissonRS

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 https://github.com/web3/web3.js/issues/6307

krzysu avatar Oct 07 '24 12:10 krzysu