Skip to content

Difference in ABI bytes4 compared to solidity #580

Description

@gpersoon

BUG: standard ABI bytes4 is left-aligned and padded on the right.
Core keeps and encodes it right-aligned.
constantValue() returns 0x0000000000000000000000000000000000000000000000000000000011223344

import std.{*};
import std.dispatch.{*};
contract Bytes4AbiAlignment {
  public function constantValue() -> bytes4 { return bytes4(0x11223344); }
}

However the solidity version returns: 0x1122334400000000000000000000000000000000000000000000000000000000

pragma solidity ^0.8.0;
contract Bytes4AbiAlignmentReference {
    function constantValue() public pure returns (bytes4) {
        return 0x11223344;
    }
}

SOLUTION: convert bytes4 at ABI boundaries: ABIEncode must shift the internal value left by 224 bits, and ABIDecode must validate the 28 padding bytes and shift right by 224 bits.
Alternatively, consistently change bytes4's internal representation so its the same as in solidity

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions