argotorg / argotorg/solidity

Redundant memory allocation rounding

Open
#16,450 1 comment 0 reactions 1 assignee Claimed by @r0qs View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

Whenever Solidity is allocating memory (bumping the free memory pointer at `0x40`), it rounds the number of allocated bytes up to nearest 32. This happens even on allocations which have the guarantee of trying to allocate a multiple of 32 bytes, like `new uint256[](constexpr)`. The benefits of this design (in any situation) are currently unknown, while it has multiple downsides:
- making the generated bytecode more complicated and difficult to reason about (by both humans and SMT checkers)
- bloating the bytecode by an estimated 37 bytes *per inlined invocation* (for low optimizer runs: 7)
- increasing the gas consumption *of every allocation* by at least 12 gas (for low optimizer runs: 15)
- allocating more memory than needed – its cost scales quadratically with allocated memory; at most 31 excessive bytes are allocated *per allocation*

## Environment

- Compiler version: 0.8.33
- Compilation pipeline (legacy, IR, EOF): IR

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.