Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning values to bytes causes an ABICoder v1 decoding exception. #15604

Open
Subway2023 opened this issue Dec 2, 2024 · 0 comments
Open
Labels

Comments

@Subway2023
Copy link

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.

// 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant