Skip to content
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

Error when decoding a function with two argument of type array or bytes #12

Closed
pthomalla opened this issue Nov 19, 2018 · 3 comments
Closed

Comments

@pthomalla
Copy link
Contributor

example use:

<<_, _, _, _, data::bytes>> =
      [[1, 2, 3, 4], [4, 5, 6]]
      |> ABI.TypeEncoder.encode(%ABI.FunctionSelector{
        function: "baz",
        types: [{:array, {:uint, 32}}, {:array, {:uint, 32}}]
      })
data
    |> ABI.TypeDecoder.decode(%ABI.FunctionSelector{
      function: "baz",
      types: [{:array, {:uint, 32}}, {:array, {:uint, 32}}]
    })

received error:

** (CompileError) iex:1: ABI.FunctionSelector.__struct__/1 is undefined, cannot expand struct ABI.FunctionSelector
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    (stdlib) lists.erl:1355: :lists.mapfoldl/3
    (elixir) expanding macro: Kernel.|>/2
    iex:1: (file)
@zachdaniel
Copy link
Contributor

@pthomalla That error is saying that the ABI.FunctionSelector struct is not defined/compiled. Are you sure that you have included ex_abi (the latest version) into your mix.exs?

@pthomalla
Copy link
Contributor Author

pthomalla commented Nov 19, 2018

@zachdaniel you're right the error is from an older version :/
in master it's use a lot of memory and crash.

Process Information

--------------------------------------------------
=proc:<0.304.0>
State: Scheduled
Spawned as: proc_lib:init_p/5
Current call: 'Elixir.ABI.TypeDecoder':'-decode_data/4-fun-0-'/3
Spawned by: <0.74.0>
Message queue length: 0
Number of heap fragments: 0
Heap fragment data: 0
Link list: [{from,<0.74.0>,#Ref<0.629182156.262147.238297>}]
Dictionary: [{'$ancestors',[<0.74.0>]},{'$initial_call',{'Elixir.IEx.Evaluator',init,4}},{iex_history,#{'__struct__'=>'Elixir.IEx.History',queue=>{[],[]},size=>0,start=>1}},{iex_evaluator,ack}]
Reductions: 1239878306
Stack+heap: 850246556
OldHeap: 0
Heap unused: 59637865
OldHeap unused: 0
BinVHeap: 36
OldBinVHeap: 0
BinVHeap unused: 46386
OldBinVHeap unused: 46422
Memory: 6801973332
Stack dump:
Program counter: 0x00007fda4a9ce7b8 ('Elixir.ABI.TypeDecoder':'-decode_data/4-fun-0-'/3 + 24)
CP: 0x00007fda4a7f93d8 ('Elixir.Enum':reduce_range_inc/4 + 120)
arity = 4
   395303887
   [{uint,32},{uint,32},{uint .....

in function

 defp decode_data(binary_data, {:array, type}, :dynamic, head_data)

trying make value repeated_type of large number of elements.

but i thing that error is in

defp do_decode_raw(binary_data, type, cursor_offset, acc)

current_head_bit_length should be calculated not only from type but allow from current_head_data

@ayrat555
Copy link
Collaborator

resolved by #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants