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

Incorect output decoding when returned value matches the function signature. #173

Closed
steffenix opened this issue Aug 19, 2024 · 1 comment

Comments

@steffenix
Copy link
Contributor

steffenix commented Aug 19, 2024

I am currently working with the erc-1271 standard and encountered an issue when calling the isValidSignature function from the contract. The function returns the bytes4 constant internal MAGICVALUE which is 0x1626ba7e. However, it appears that the method signature is 0x1626ba7e. It is being removed from the returned value before decoding, leading to decoding failures.

case ABI.Util.split_method_id(encoded_data) do
{:ok, ^method_id, rest} -> decode_raw(rest, types)

contract ERC1271 {

  // bytes4(keccak256("isValidSignature(bytes32,bytes)")
  bytes4 constant internal MAGICVALUE = 0x1626ba7e;

  function isValidSignature(
    bytes32 _hash, 
    bytes memory _signature)
    public
    view 
    returns (bytes4 magicValue);
}

My current workaround is, could you tell me if that makes sense to you?

    if rem(byte_size(encoded_data), 32) == 0 do
      decode_raw(encoded_data, types)
    else
      case ABI.Util.split_method_id(encoded_data) do
        {:ok, ^method_id, rest} ->
          decode_raw(rest, types)
        _ -> decode_raw(encoded_data, types)
      end
    end

I have made a PR if that is good for you: #174

@ayrat555
Copy link
Collaborator

fixed by #174

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

2 participants