solidity
solidity copied to clipboard
IR-base codegen, abicoder v1, Ast import lack of memory protection mechanism
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'}