argotorg / argotorg/solidity

[Yul Optimizer] Do not move loop invariants that consume a lot of gas

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

Description

This is a weird one.

```
contract C0 {
function f0() external returns (bytes memory o1)
{
assembly
{
for { let i := 0 } lt(i, 1) { i := add(i, 1) }
{
if o1 { break }
o1 := keccak256(0, 12345678912)
}
}
}
}
// ====
// compileViaYul: also
// ----
// f0() -> 0x20, 0
```

fails via Yul.

To repro

```
$ cp test.sol test/libsolidity/semanticTests
$ isoltest -t semanticTests/test --optimize --show-messages
```

Contributor guide

Open the contributing guide

Research direction

Start with the Yul optimizer behavior shown in the assembly example and reproduce it by placing the case in test/libsolidity/semanticTests. Run isoltest -t semanticTests/test --optimize --show-messages and compare the failing result with the expected f0() output. Done means the test passes via Yul without moving the costly loop-invariant operation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.