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

IR-base codegen, abicoder v1, Ast import lack of memory protection mechanism #15412

Open
Subway2023 opened this issue Sep 7, 2024 · 0 comments
Labels

Comments

@Subway2023
Copy link

Description

When writing a large number to memory, the legacy codegen successfully optimizes out the mstore statement without causing the program to revert. However, the IR-based codegen, abicoder v1, and Ast import will cause the program to revert.

Environment

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

Steps to Reproduce

contract C{
    function test() public returns (bool) {
        assembly {
            let x := calldataload(0)
            let y := sload(x)
            let ax := x
            let bx := mload(ax)
            mstore(ax, bx)
        }
        return true;
    }

}

Get bin

AST import

solc C.sol --combined-json ast >> C.json
solc  --bin --import-ast C.json --metadata-hash none

Abicoder v1

add pragma abicoder v1; in solidity program

solc --bin C.sol

IR-based codegen

solc --bin --via-ir C.sol

Legacy codegen

solc --bin C.sol

origin

solc --bin C.sol

Run in evm

typeName,originOutput,memory
Legacy codegen,"{'output': '0x1', 'gasUsed': '0x94'}","{'128': '1', '64': '128'}"
Legacy codegen + optimized,"{'output': '0x1', 'gasUsed': '0x94'}","{'64': '128', '128': '1'}"
IR-based codegen,"{'output': '', 'gasUsed': '0x5f52d91', 'error': 'gas uint64 overflow'}",{'64': '128'}
IR-based codegen + optimize,"{'output': '0x1', 'gasUsed': '0x82'}","{'64': '128', '128': '1'}"
ASTImport,"{'output': '', 'gasUsed': '0x5f56b81', 'error': 'gas uint64 overflow'}",{'64': '128'}
abicoderv1,"{'output': '', 'gasUsed': '0x5f56d11', 'error': 'gas uint64 overflow'}",{'64': '128'}
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