argotorg / argotorg/solidity

The maximum integer allowed in version pragma is platform-dependent

Open
#13,706 0 comments 0 reactions 0 assignees View on GitHub
bug :bug: low effort low impact must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

The code checking if integers used in `pragma solidity` uses `unsigned int` as the underlying type and relies on its overflow behavior, which means that the range depends on what platform the compiler was built for: [`unsigned` can be 16- or 32-bit long](https://en.cppreference.com/w/cpp/language/types).

For example this pragma may or may not be allowed, depending on the platform:
```solidity
pragma solidity >=0 <=65536;
```

The code using such a pragma would pass source verification on some platforms but not on others.

To fix this we should use a type with a platform-independent size, either `uint16_t` or `uint32_t`.

I think this is a bug, ~though it could also be seen as a breaking change~. EDIT: Actually not breaking if we use `uint32_t` - then all the code that used to compile would still compile.

### Affected code
https://github.com/ethereum/solidity/blob/8df45f5f8632da4817bc7ceb81497518f298d290/liblangutil/SemVerHandler.cpp#L262-L271

Contributor guide

Open the contributing guide

Research direction

Start in liblangutil/SemVerHandler.cpp at lines 262-271, where the version pragma integer range is checked. Inspect the integer type and its overflow behavior, then verify that the accepted range is platform-independent and that existing Solidity compiler tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.