Vyper struct ABI encoding vs Solidity caller interoperability
0 reputation · 03 Jan 2025, 07:27 UTC
Goal
I need a Vyper external function to return a struct that a Solidity caller decodes with abi.decode on a live chain. Tests may pass locally when both contracts are compiled with the same Vyper version, but production uses a Solidity consumer.
Constraints
Vyper 0.2.x and 0.3.x encode structs in a tightly packed format that omits padding between elements. Solidity's default ABI inserts padding to align dynamic types. Returning a uint128 followed by an address can therefore shift subsequent fields in a Solidity decoder, producing incorrect data or a revert. It is unclear whether Vyper will adopt Solidity-compatible struct alignment, and a future compiler release could change the layout without a major version bump.
Questions
- Does Vyper's current struct ABI encoding match Solidity alignment for external return values?
- Should the Solidity caller manually pad the decoded layout, or is there a Vyper compiler option to enable Solidity-compatible struct encoding?
- Which Vyper version range should production deployments pin to prevent silent decoding failures if the encoding changes?