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
BUG: standard ABI bytes4 is left-aligned and padded on the right.
Core keeps and encodes it right-aligned.
constantValue() returns 0x0000000000000000000000000000000000000000000000000000000011223344
However the solidity version returns: 0x1122334400000000000000000000000000000000000000000000000000000000
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