Closed ryandotsmith closed 1 year ago
@ryandotsmith I guess when in doubt, compile the example in Solidity.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
contract Contract {
struct NestedTuple {
uint8 a;
bytes b;
}
struct Tuple {
uint8 _a;
NestedTuple _nt;
}
uint8 a = 42;
uint8 _a = 43;
bytes b = "foo";
NestedTuple _nt = NestedTuple(_a, b);
function encodeTuple() public view returns (bytes memory) {
return abi.encode(Tuple(a, _nt));
}
}
Compiling the above in remix using the latest Solidity version 0.8.17
yields the same result as the eth-abi result
I'm going to close this but if you believe there's something I've missed and it should be re-opened, don't hesitate to ask to re-open. Best of luck.
Good call on the solidity example! Thanks for the quick reply.
I think I see where I got confused. My assumption was that I was encoding: tuple(uint8, tuple(uint8, bytes))
. But when you call abi.encode, the arguments are coalesced into a tuple so the result looks like this: tuple(tuple(uint8, tuple(uint8, bytes)))
What was wrong?
It's likely that I'm not fully understanding the ABI spec, but given a nested tuple where the outer tuple contains a static field and a dynamic nested tuple, I would expect for the outer tuple's static field to not be offset.
Code that produced the error
Expected Result
Environment