solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Abicode v1 causes inconsistent memory allocation

Open Subway2023 opened this issue 9 months ago • 0 comments

Description

Environment

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

Steps to Reproduce

ABICoder V1

pragma abicoder v1;
contract C0{
    function f0() external pure returns (uint[2] memory) {}
}
contract Test {
    function test() public returns (uint) {
        C0 c0 = new C0();
        c0.f0();
        uint freeMemoryAfter;
        assembly {
            freeMemoryAfter := mload(0x40)
        }
        return freeMemoryAfter;
    }
}

freeMemoryAfter=0xc0

ABICoder V2

contract C0{
    function f0() external pure returns (uint[2] memory) {}
}
contract Test {
    function test() public returns (uint) {
        C0 c0 = new C0();
        c0.f0();
        uint freeMemoryAfter;
        assembly {
            freeMemoryAfter := mload(0x40)
        }
        return freeMemoryAfter;
    }
}

freeMemoryAfter=0x100

Subway2023 avatar May 21 '24 06:05 Subway2023