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

incorrect usage of types in function selectors #25

Closed
InoMurko opened this issue Mar 23, 2020 · 0 comments · Fixed by #36
Closed

incorrect usage of types in function selectors #25

InoMurko opened this issue Mar 23, 2020 · 0 comments · Fixed by #36

Comments

@InoMurko
Copy link
Contributor

InoMurko commented Mar 23, 2020

Based on:
https://github.com/poanetwork/ex_abi/blob/master/lib/abi/type_decoder.ex#L140
and
https://github.com/poanetwork/ex_abi/blob/master/lib/abi/function_selector.ex#L29

a function selector return types get completely ignored - so even basic function return data doesn't get parsed.
For example:

selector = %ABI.FunctionSelector{
  function: "getVersion",
  input_names: [],
  inputs_indexed: nil,
  method_id: <<13, 142, 110, 44>>,
  returns: [:string],
  type: :function,
  types: []
}

was parsed directly from our solidity contract abi (json):

abi_path
      |> File.read!()
      |> Jason.decode!()
      |> Map.fetch!("abi")
      |> ABI.parse_specification(include_events?: true)
data2 = method_id |> Encoding.to_hex() |> Kernel.<>(data) |> Encoding.from_hex 
ABI.find_and_decode([selector], data2)

where

iex(196)> method_id
<<13, 142, 110, 44>>
iex(197)> data
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d312e302e342b6136396337363300000000000000000000000000000000000000"
iex(198)>

and returns this:

{%ABI.FunctionSelector{
   function: "getVersion",
   input_names: [],
   inputs_indexed: nil,
   method_id: <<13, 142, 110, 44>>,
   returns: [:string],
   type: :function,
   types: []
 }, []}

if we modify the selector to (returns and types were swaped):

selector = %ABI.FunctionSelector{
  function: "getVersion",
  input_names: [],
  inputs_indexed: nil,
  method_id: <<13, 142, 110, 44>>,
  returns: [],
  type: :function,
  types: [:string],
}
ABI.find_and_decode([selector], data2)
{%ABI.FunctionSelector{
   function: "getVersion",
   input_names: [],
   inputs_indexed: nil,
   method_id: <<13, 142, 110, 44>>,
   returns: [],
   type: :function,
   types: [:string]
 }, ["1.0.4+a69c763"]}
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

Successfully merging a pull request may close this issue.

1 participant