Comments (10)
Sure, I believe the fix is as simple as changing how functions are encoded, with the knowledge that they should be considered tuples. I'll see if I can take a crack at this shortly.
from abi.
A couple of months ago I re-wrote encoder and decoder of abi n https://github.com/poanetwork/ex_abi . it should be fixed there
from abi.
I believe this relates to confusion around encoding of tuples or raw data parameters. If you instead encode this as a tuple, you'll get what you're looking for.
ABI.encode("dynamicUint((uint[]))", [{[1,2,3,4,5]}]) |> Base.encode16(case: :lower)
"5b8b2e7c0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005"
Thus, I think the bug is likely in function_selector.ex
which tells the encoder that function arguments should be encoded one-by-one instead of as a tuple. I believe that's where we should fix this bug.
Does that make sense?
from abi.
Ah, yes. Thank you! This makes sense, easy enough to work around for now. I'll stay posted for any updates on this.
from abi.
So after a bit of data wrangling, I was able to get the dynamic array to be encoded correctly. But the transaction results in a revert.
I compared the results to my ruby project and determined the source of the problem. The issue becomes that the method id "5b8b2e7c" is incorrect, it should be "5d4e0342" like I had it originally. This is because "dynamicUint((uint[]))" is not a valid function signature because of the extra case of parentheses surrounding "uint[]".
So I thought easy enough, I'll use the old function signature. But that results in this error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for {[1, 2, 3, 4, 5]}.
Which I am assuming is due to encoding the data based on how the function signature is parsed.
Once again, I could manually work around this if I had to, but luckily I'm not in that situation. And thus, it will be best if this bug is fixed here.
from abi.
I did some digging on my own, and I'm noticing some behavior that seems strange to me:
iex(30)> ABI.Parser.parse!("(uint256[])")
%ABI.FunctionSelector{
function: nil,
returns: nil,
types: [tuple: [array: {:uint, 256}]]
}
iex(31)> ABI.Parser.parse!("dynamicUint(uint256[])")
%ABI.FunctionSelector{
function: "dynamicUint",
returns: nil,
types: [array: {:uint, 256}]
}
I feel like the results should be similar.
from abi.
Running into this issue and well to want to give it a
from abi.
For now will use something like this: ABI.encode("dynamicUint((uint[]))", [{[1,2,3,4,5]}]) |> Base.encode16(case: :lower)
from abi.
Hmm, I dont know if this is encoding the function the way I am expecting it to
from abi.
I'm running into this problem as well. Is there any other way to encode dynamic arrays? I'm trying to encode test(bytes32[], uint256[])
in particular
from abi.
Related Issues (12)
- license HOT 1
- Got on_load_function_failed when trying to start release. HOT 6
- Address type as string, not :uint 160 HOT 1
- Invalid encode of string HOT 2
- Invalid encoding of dynamic types HOT 2
- Fail to encode long string HOT 4
- Cannot compile on Mac OSX HOT 2
- Unable to decode int HOT 7
- Parsing input of transaction 0xd4144955be257182665c7be541b573341294c0536d56bb7094b17953374def8c causes memory leak. HOT 1
- encode bytes32 error HOT 3
- Decoding function arguments from data for dynamic types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abi.