When using assembly statements to assign a value that exceeds the array range to an array, AbiCoder v1 fails to encode the return value correctly when returning the array. However, AbiCoder v2 does not have this issue.
Environment
Compiler version: 0.8.25
Target EVM version (as per compiler settings): No restrictions
# If you comment out this line, AbiCoder v2 will be used by default.
pragma abicoder v1;
contract test {
function f() external returns (uint8[] memory) {
uint8[] memory x = new uint8[](1);
assembly {
mstore(add(x, 0x20), 0x1ff)
}
return x;
}
}
1. Build EVM
git clone git@github.com:ethereum/go-ethereum.git
make all
We can observe that after encoding with AbiCoder v1, the elements in the array are 1ff, whereas after encoding with AbiCoder v2, the array elements are ff
Basically abicoder v1 does not clean the dirty bits in the first element of the array upon returning but abicoder v2 does. Also reproduced using 0.8.19+commit.7dd6d404.
Description
When using assembly statements to assign a value that exceeds the array range to an array, AbiCoder v1 fails to encode the return value correctly when returning the array. However, AbiCoder v2 does not have this issue.
Environment
Steps to Reproduce
1. Build EVM
2. Get function Signatures
3. Get bin-runtime
4. Run in the EVM
5. Compare output
output from pragma abicoder v1
output from pragma abicoder v2
We can observe that after encoding with AbiCoder v1, the elements in the array are 1ff, whereas after encoding with AbiCoder v2, the array elements are ff