safe-react-apps
safe-react-apps copied to clipboard
Tuple with struct incorrectly parsed - always errors
Description
Struct tuple incorrectly parsed, never passes validation:
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
Also hi to the Safe team!
I have met the following error:
Hi @bradyjoestar for that _batchHeader
struct defined in this contract 0x91A5D806BA73d0AA4bFA9B318126dDE60582e92a
:
you can use a value like this:
[123,"0xAAAAFF", 1234, 1234, "0xAAAAFF", "0xAAAAFF"]
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 will give it a go, thanks!
[123,"0xAAAAFF", 1234, 1234, "0xAAAAFF", "0xAAAAFF"]
It worked ! Thank you for your help.
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:
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!
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?
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