solidity icon indicating copy to clipboard operation
solidity copied to clipboard

mstore(add(mload(0x80), 0x20), xx) cause IR-based codegen execution revert.

Open Subway2023 opened this issue 5 months ago • 0 comments

Description

mstore(add(mload(0x80), 0x20), xx) cause IR-based codegen execution revert. However, legacy codegen can execute successfully.

Environment

  • Compiler version: 0.8.27
  • 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

contract Test {
    bytes public a;
    uint[] public b;
    function f(uint x) public returns (bytes memory) {
        a = "";
        for (uint i = 0; i < x; ++i) {
            a.push() = bytes1(uint8(i));
        }
        return g(a);
    }
    function g(bytes memory input) public returns (bytes memory) {
        uint[2] memory tempStorage;
        tempStorage[0] = 12345;
        tempStorage[1] = 67890;
        assembly {
            let tempMemory := mload(0x80)
            mstore(add(tempMemory, 0x20), 0x12345678)
        }
    }
}

Lecacy codegen

image

IR-based codegen

image

Subway2023 avatar Sep 06 '24 23:09 Subway2023