argotorg / argotorg/solidity

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

Open
#15,412 4 comments 0 reactions 0 assignees View on GitHub
waiting for more input
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## 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
```solidity
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
```csv
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'}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the contract with solc 0.8.27 using legacy, IR-based, abicoder v1, and --import-ast codegen, then compare the reported EVM execution results. Trace the compiler entry points for these codegen modes and memory writes; done means the affected modes no longer revert or exhaust gas for this input, matching the successful legacy behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
blockchain, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.