argotorg / argotorg/solidity

Assigning values to bytes causes an ABICoder v1 decoding exception.

Open
#15,604 0 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

Assigning a value to a bytes variable using assembly results in an abnormal return value.

## Environment

- Compiler version: 0.8.28
- Target EVM version (as per compiler settings): None
- Framework/IDE (e.g. Truffle or Remix): Remix
- EVM execution environment / backend / blockchain client: None
- Operating system: None

## Steps to Reproduce
By commenting out **pragma abicoder v1;**, you manually enable or disable ABICoder v1.

```solidity
// pragma abicoder v1;
contract Combined {
function complexFunction() public pure returns (bytes memory, uint, bytes20[] memory, uint) {
(bytes memory a, uint b, bytes20[] memory c, uint d) = simplifiedFunction();
// manipulate memory outputs
assembly {
let ptr := mload(0x40)
a := ptr
}
// optional loop and manipulation
for (uint i = 0; i < c.length; i++) {
if (i == 2) {
continue;
}
c[i] = bytes20(uint160(c[i]) ^ 0xFFFF);
}
return (a, b, c, d);
}
function simplifiedFunction() internal pure returns (bytes memory a, uint b, bytes20[] memory c, uint d) {
a = "ESCAPE\\SEQUENCE\\TEST";
b = type(uint).max;
c = new bytes20[](4);
c[0] = bytes20(uint160(1234));
c[3] = bytes20(uint160(6789));
d = 0x1234;
}
}
```
### Not use ABICoder v1
```
{
"0": "bytes: 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080",
"1": "uint256: 115792089237316195423570985008687907853269984665640564039457584007913129639935",
"2": "bytes20[]: 0x000000000000000000000000000000000000fb2d,0x000000000000000000000000000000000000ffff,0x0000000000000000000000000000000000000000,0x000000000000000000000000000000000000e57a",
"3": "uint256: 4660"
}
```
### use ABICoder v1
```
{
"0": "bytes: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012340000000000000000000000000000000000000000000000000000000000000080",
"1": "uint256: 115792089237316195423570985008687907853269984665640564039457584007913129639935",
"2": "bytes20[]: 0x000000000000000000000000000000000000fb2d,0x000000000000000000000000000000000000ffff,0x0000000000000000000000000000000000000000,0x000000000000000000000000000000000000e57a",
"3": "uint256: 4660"
}
```
The result of the first return value is abnormal. Why do fff and 1234 appear?

Contributor guide

Open the contributing guide

Research direction

Compile and run the supplied Combined contract with and without `pragma abicoder v1;` using Solidity 0.8.28, then compare the first returned bytes value with the reported outputs. Trace how the compiler handles the assembly assignment to `a` and ABI encoding of the return tuple; done means explaining the divergent encoding and adding a regression test if a compiler defect is confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.