Giter Club home page Giter Club logo

Comments (10)

hayesgm avatar hayesgm commented on June 27, 2024 1

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.

ayrat555 avatar ayrat555 commented on June 27, 2024 1

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.

hayesgm avatar hayesgm commented on June 27, 2024

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.

hswick avatar hswick commented on June 27, 2024

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.

hswick avatar hswick commented on June 27, 2024

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.

hswick avatar hswick commented on June 27, 2024

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.

ghbutton avatar ghbutton commented on June 27, 2024

Running into this issue and well to want to give it a 👍

from abi.

ghbutton avatar ghbutton commented on June 27, 2024

For now will use something like this: ABI.encode("dynamicUint((uint[]))", [{[1,2,3,4,5]}]) |> Base.encode16(case: :lower)

from abi.

ghbutton avatar ghbutton commented on June 27, 2024

Hmm, I dont know if this is encoding the function the way I am expecting it to

from abi.

aaroncolaco avatar aaroncolaco commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.