-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic array arguments are serialized incorrectly #378
Comments
I would say the encoding is correct. The specification says:
So |
Yes, web3.js makes my contract crash. pyethereum.tester does not. |
Ok, perhaps the offset is correct, because I have another contract function working fine with it. The documentation seems pretty clear that my previous comment should be the behavior, but the documentation could just be wrong. The offsets aren't the only problem with my actual transaction data. My function's signature is
It looks like any arguments that follow dynamic arrays in a function are put in the wrong place. |
I was wrong! Sorry, I didn't know that the head and tail parts of the array encoding are handled differently when encoding arguments versus encoding them individually. |
Consider this test:
It looks like the algorithm for nested dynamic arrays got confused with the one for normal dynamic arrays. A normal dynamic array (
bool[]
) only needs the length of the array to know where the array ends. A nested dynamic array (bool[][3]
, an array of three dynamic arrays of booleans) needs to know the offsets of the three dynamic arrays so the arrays can be indexed without iterating through the dynamic arrays, so the offset of each dynamic array is packed together at the front of the encoded bytes.To access the second of the three dynamic arrays, you look up the second offset (the second
uint256
of the encoded value) and use that as the offset from the beginning. There, you'll find the length of the second dynamic array followed by the values, just like a non-nested dynamic array.In the data from the test, the first 32 bytes are an offset of 32 bytes to get to the array data itself. It would be redundant, so the ABI doesn't work that way.
This is likely the cause of #301.
axic/ethereumjs-abi
also has this bug.The text was updated successfully, but these errors were encountered: