Difference in ABI bytes4 compared to solidity
- Dominant language
- Haskell
- Stars
- 113
- Forks
- 9
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 1
Description
BUG: standard ABI bytes4 is left-aligned and padded on the right.
Core keeps and encodes it right-aligned.
constantValue() returns 0x0000000000000000000000000000000000000000000000000000000011223344
```soldity
import std.{*};
import std.dispatch.{*};
contract Bytes4AbiAlignment {
public function constantValue() -> bytes4 { return bytes4(0x11223344); }
}
```
However the solidity version returns: 0x1122334400000000000000000000000000000000000000000000000000000000
```solidity
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
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the compiler's ABIEncode and ABIDecode paths and reproduce constantValue() using the supplied bytes4 examples. Done means Solidity-compatible left-aligned output, validation of the 28 padding bytes during decoding, and matching round-trip behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, solidity
- Domain
- backend-api-design, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100