argotorg / argotorg/solidity

Optimizer's optimization effectiveness varies for different opcodes.

Open
#15,020 0 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

When handling overflow in **mload**, **keccak256**, the Optimizer can enable the code to run normally. However, when dealing with **mstore**, and **extcodecopy** opcodes, the Optimizer fails to prevent code execution rollback.

## Environment

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

## Steps to Reproduce
Compile with different compilation conditions.

### mload
```solidity
contract C {
function f() public {
assembly {
pop(mload(4294967297))
sstore(0, 1)
}
}
}
```
1. origin: out of gas
2. --optimize: storage: {0:1}
3. --via-ir: storage: {0:1}
4. --optimize and --via-ir: storage: {0:1}

### keccak256
```solidity
contract C {
function f() external{
assembly {
pop(keccak256(999999999999999999999999,43486543872))
sstore(0, 1)
}
}
}
```
1. origin: gas uint64 overflow
2. --optimize: storage: storage: {0:1}
3. --via-ir: storage: storage: {0:1}
4. --optimize and --via-ir: storage: {0:1}

### mstore
```solidity
contract C {
function f() public {
assembly {
pop(mload(4294967297))
sstore(0, 1)
}
}
}
```
1. origin: gas uint64 overflow
2. --optimize: storage: gas uint64 overflow
3. --via-ir: storage: gas uint64 overflow
4. --optimize and --via-ir: storage: {0:1}

### extcodecopy
### mstore
```solidity
contract C {
function f() external{
assembly {
extcodecopy(1, not(1), not(not(1)), not(1))
sstore(0,1)
}
}
}
```
1. origin: gas uint64 overflow
2. --optimize: storage: gas uint64 overflow
3. --via-ir: storage: gas uint64 overflow
4. --optimize and --via-ir: storage: {0:1}

From the above, we can see that the Optimizer's optimization effectiveness varies for different opcodes.

Contributor guide

Open the contributing guide

Research direction

Reproduce the four Solidity assembly cases using compiler 0.8.25 with the origin, --optimize, --via-ir, and combined settings, then compare the reported storage or gas-overflow outcomes. Investigate the optimizer's handling of mload, keccak256, mstore, and extcodecopy; done means the affected opcodes no longer allow execution to continue after the overflow conditions shown.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.