Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix encoding of nested static tuples in dynamic tuple (#220)
Fixed #202 This PR fixes the "head length" calculation for nested static tuples. This would cause offsets of dynamic data (such as dynamic arrays) to be incorrectly computed in certain cases (such as encoding a dynamic array within a tuple including nested static tuples). If you consider data of: ``` Tuple( // dynamic Tuple( // static Tuple( Bool, U256, ), Array(U256), ) ``` The static tuple was incorrectly computing its "head length" to be 32 instead of 64 - in other words, nested static tuples weren't correctly being flattened. This caused the encoded offset of the dynamic array to be off by 32 bytes, and cause decoding failure described in the linked case. ### Test Plan Added a new unit test to verify encoding is correct. We can use Ethers.js as a reference implementation: ``` > ethers.utils.defaultAbiCoder.encode(["(((bool,uint256)),uint256[])"], [[[[false, 0x777]],[0x42,0x1337]]]) 0x 0000000000000000000000000000000000000000000000000000000000000020 // offset to start of dynamic tuple data 0000000000000000000000000000000000000000000000000000000000000000 // nested static tuple bool value 0000000000000000000000000000000000000000000000000000000000000777 // nested static tuple uint value 0000000000000000000000000000000000000000000000000000000000000060 // offset to start of dynamic array *within* dynamic tuple "tail" 0000000000000000000000000000000000000000000000000000000000000002 // dynamic array length 0000000000000000000000000000000000000000000000000000000000000042 // first array value 0000000000000000000000000000000000000000000000000000000000001337 // second array value ```
- Loading branch information