argotorg / argotorg/solidity

Lack of proper heuristics in the Function Specializer can lead to large contract sizes

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

Description

## Description

I have a smart contract where the majority of the functionality has one private function as entry point, and there are two external entry points. Solidity currently inlines the private function (including everything it calls) into both of the external entry points. I now wanted to add a third external entry point, and solidity inlines the entire private function *yet again*, making the contract blow up by almost 50% and exceeding the blockchain limit.

This happens with via-ir at any optimization run count, even when going down to zero. Turning off optimization is not an option for various reasons, but I also don't want to turn off inlining completely as I have many functions which are designed to be inlined. I would expect the compiler to pay some consideration to the size of the function being inlined and not blow up the contract to almost 3x the necessary size just to avoid a jump.

Is there anything I can do to make the compiler stop inlining this very large function, while still inlining small functions?

## Environment

- Compiler version: 0.8.24
- Target EVM version (as per compiler settings): London
- Operating system: Linux

Contributor guide

Open the contributing guide

Research direction

Begin with the via-ir Function Specializer and reproduce the compiler 0.8.24 example with London as the target EVM and optimization run counts from zero upward. Investigate the inlining heuristic and verify that large shared functions are not duplicated unnecessarily while small functions can still be inlined; done means contract size no longer grows toward three times the necessary size.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
blockchain, compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.