solc hangs when compiling with `addmod`
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
solc will hang when compiling a library using `addmod` in a function call. I tested this on Remix, Ubuntu 20.04, Ubuntu 22.04 and it only hangs in:
Ubuntu 22.04 - installed via apt-get. The resulting binary appears to be dynamically linked. Interestingly, Ubuntu 20.04 installs a static binary and it will compile.
## Environment
- Compiler version:0.8.30+commit.73712a01.Linux.g++
- Compilation pipeline (legacy, IR, EOF): legacy (simple just `solc --input-file test.sol`
- Target EVM version (as per compiler settings): prague
- Framework/IDE (e.g. Foundry, Hardhat, Remix): `ethers-rs` / cli
- EVM execution environment / backend / blockchain client:
- Operating system: Ubuntu 22.04
## Steps to Reproduce
Install `0.8.30+commit.73712a01.Linux.g++` via the following steps on UBUNTU 22.04
(from solidity website)
```bash
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
```
Compile the below library
`touch test.sol`
`solc --input-file test.sol`
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
library TestAddmodVariants {
uint256 constant q_mod = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
function simple_add(uint256 a, uint256 b) internal pure returns (uint256) {
return addmod(a, b, q_mod);
}
}
```
This should hang on Ubuntu 22.04, using the dynamically linked compiler.
Ldd info for 22.04
```
ldd $(which solc)
linux-vdso.so.1 (0x00007fff86fc0000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x0000736f6ba00000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x0000736f6c9dd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000736f6b600000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x0000736f6bd19000)
/lib64/ld-linux-x86-64.so.2 (0x0000736f6ca0a000)
```
Would appreciate if someone could reproduce this!
Contributor guide
Research direction
Start by running the reported `solc --input-file test.sol` reproduction with the `addmod` library on Ubuntu 22.04, then compare it with the Ubuntu 20.04 static binary and the dynamically linked binary described by `ldd`. Trace the legacy compilation path to identify why compilation hangs; done means the reproduction no longer hangs and the behavior is covered by an appropriate regression test.
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
- Needs clarification
- Newbie friendliness
- 35/100