Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.6.0 #129

Merged
merged 61 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7e432a4
added_submodule
Dec 8, 2023
977373f
fixed returncode
Yhtiyar Dec 11, 2023
42f14fc
bump version
Yhtiyar Dec 11, 2023
073b011
Create benchmark.yml
nikolay19 Dec 11, 2023
bb31553
Merge pull request #110 from pessimistic-io/submodule_benchmark-1
nikolay19 Dec 11, 2023
48d53dc
benchmark submodule updates
nikolay19 Dec 11, 2023
4946caf
Update benchmark.yml
nikolay19 Dec 11, 2023
807d4f1
Update benchmark.yml
nikolay19 Dec 11, 2023
0b7142d
Update benchmark.yml
nikolay19 Dec 11, 2023
712bc06
Merge pull request #109 from pessimistic-io/cli-error-status
ndkirillov Dec 13, 2023
1103c43
Merge pull request #112 from pessimistic-io/develop
nikolay19 Dec 13, 2023
95039a8
Update benchmark.yml
nikolay19 Dec 13, 2023
55d05f7
Update benchmark.yml
nikolay19 Dec 13, 2023
f57a6dd
Update benchmark.yml
nikolay19 Dec 13, 2023
9538313
submodule updates
nikolay19 Dec 14, 2023
001bdf8
benchmark updates
nikolay19 Dec 20, 2023
05af4a6
artifact rename&subrepo updates
nikolay19 Dec 28, 2023
b4103a5
add prevrandao/difficulty detector for Arbitrum contracts
olegggatttor Jan 12, 2024
334563e
add check that the function is not a constructor
olegggatttor Jan 12, 2024
86a3057
add test with constructor with arguments
olegggatttor Jan 12, 2024
8488237
exclude oz/uni/balancer FPs from pess-call-forward-to-protected
olegggatttor Jan 12, 2024
e0a49c1
Merge pull request #115 from pessimistic-io/104-fp-external-vs-public…
Yhtiyar Jan 14, 2024
9fcc59e
Merge pull request #116 from pessimistic-io/49-ignore-standard-librar…
Yhtiyar Jan 14, 2024
6b1fc0a
benchmark updates
nikolay19 Jan 15, 2024
8a4bb0b
Merge pull request #113 from pessimistic-io/submodule_benchmark
nikolay19 Jan 15, 2024
93d1985
added 2 new detectors
Yhtiyar Jan 15, 2024
8bc797c
Merge branch 'develop' into arb-block-number
Yhtiyar Jan 15, 2024
ee8b34e
small changes to severity/docs
Yhtiyar Jan 16, 2024
6124893
update of tests
Yhtiyar Jan 16, 2024
1b0da7c
added detector docs
Yhtiyar Jan 16, 2024
a2d9aeb
Merge pull request #118 from pessimistic-io/arb-block-number
Yhtiyar Jan 16, 2024
964018b
update docs
Yhtiyar Jan 16, 2024
ae09548
Merge branch 'arb-block-number' into add-arb-prevrandao-difficulty-de…
Yhtiyar Jan 16, 2024
02893f3
Update benchmark.yml
nikolay19 Jan 16, 2024
0d44445
exclude oz/uni/balancer FPs from pess-call-forward-to-protected
olegggatttor Jan 12, 2024
54d9128
reduce ecrecover fps and add new test
olegggatttor Jan 19, 2024
7df7902
fix test
olegggatttor Jan 19, 2024
d2b67d2
update doc for ecrecover
olegggatttor Jan 19, 2024
7a03c55
Merge pull request #119 from pessimistic-io/submodule_benchmark
ndkirillov Jan 20, 2024
3184552
Merge pull request #120 from pessimistic-io/reduce-fps-ecrecover
ndkirillov Jan 22, 2024
7151098
Merge pull request #114 from pessimistic-io/add-arb-prevrandao-diffic…
ndkirillov Jan 22, 2024
b31a32a
reduce FPs for pess-strange-setter. Detect strange setter if not all …
olegggatttor Jan 26, 2024
621c0e5
update documentation
olegggatttor Jan 26, 2024
0fefdc6
remove prev version and debug logs
olegggatttor Jan 29, 2024
73b4a52
Merge pull request #122 from pessimistic-io/reduce-fps-pess-strange-s…
olegggatttor Jan 30, 2024
50b0473
fix pess-strange-setter failing
olegggatttor Jan 31, 2024
ebcf133
Merge pull request #124 from pessimistic-io/reduce-fps-pess-strange-s…
ndkirillov Feb 1, 2024
ddcf07e
bench updates
nikolay19 Feb 1, 2024
6d00531
Update benchmark.yml
nikolay19 Feb 1, 2024
975dc24
bench update
nikolay19 Feb 1, 2024
77aef38
Merge branch 'master' of https://github.com/pessimistic-io/slitherin …
nikolay19 Feb 2, 2024
d47ac77
bench updates
nikolay19 Feb 2, 2024
c88fa2c
Merge branch 'submodule_benchmark' of https://github.com/pessimistic-…
nikolay19 Feb 2, 2024
2260b80
bench updates&workflow OZ
nikolay19 Feb 2, 2024
58ab4d2
Merge pull request #125 from pessimistic-io/submodule_benchmark
nikolay19 Feb 2, 2024
b319c1f
handle if with reverts
olegggatttor Feb 7, 2024
71768cc
add arithmetic overflow detector
olegggatttor Feb 8, 2024
9a0e3a5
small fix
olegggatttor Feb 8, 2024
04ba8b3
Merge pull request #127 from pessimistic-io/add_arithmetic_overflow_d…
ndkirillov Feb 12, 2024
cdc9f12
version const upd
Feb 15, 2024
5c9409e
Arbitrum Launch README
ndkirillov Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Run Benchmark

on:
pull_request:
branches:
- 'master'
- 'develop'
jobs:
RunBenchmarkMainnet:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install solc-select
run: python -m pip install solc-select
- name: Install Slither
run: python -m pip install slither-analyzer
- name: Install Setuptools
run: python -m pip install setuptools
- name: Install Slitherin
run: python setup.py develop
- name: Configure
run: |
cd slitherin-benchmark/
mv example.config.py config.py
- name: Install node dependencies
run: npm ci
- name: Install benchmark requirements
run: |
cd slitherin-benchmark/
python -m pip install -r requirements.txt
- name: Run Benchmark
run: |
cd slitherin-benchmark/
python runner.py -i contracts/mainnet -o mainnet.csv --limit 7000
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: mainnet
path: slitherin-benchmark/mainnet.csv
RunBenchmarkOZ:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install solc-select
run: python -m pip install solc-select
- name: Install Slither
run: python -m pip install slither-analyzer
- name: Install Setuptools
run: python -m pip install setuptools
- name: Install Slitherin
run: python setup.py develop
- name: Configure
run: |
cd slitherin-benchmark/
mv example.config.py config.py
- name: Install node dependencies
run: npm ci
- name: Install benchmark requirements
run: |
cd slitherin-benchmark/
python -m pip install -r requirements.txt
- name: Run Benchmark
run: |
cd slitherin-benchmark/
python runner.py -i contracts/openzeppelin -o oz.csv -eo oz_extra.csv
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: oz
path: slitherin-benchmark/oz.csv
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: oz_extra
path: slitherin-benchmark/oz_extra.csv

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "slitherin-benchmark"]
path = slitherin-benchmark
url = https://github.com/pessimistic-io/slitherin-benchmark.git
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ slitherin . --slither
```bash
slitherin . --separated
```
* Run Arbitrum-specific Slitherin detectors:
```bash
slitherin . --arbitrum
```
> Keep in mind that Slitherin-cli supports all Slither run options.
### Slither
Slitherin detectors are included into original Slither after the installation. You can use Slither [as usual](https://github.com/crytic/slither#usage).
Expand Down
19 changes: 19 additions & 0 deletions docs/arb_block_number_timestamp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Arbitrum block.number/block.timestamp

## Configuration

- Check: `pess-arb-solidity-version`
- Severity: `Low`
- Confidence: `High`

## Description

`block.number` and `block.timestamp` behave different, than how they behave on Ethereum. For details: [arbitrum docs](https://docs.arbitrum.io/for-devs/concepts/differences-between-arbitrum-ethereum/block-numbers-and-time)

## Vulnerable Scenario

[test scenarios](../tests/arbitrum_block_number_timestamp_test.sol)

## Recommendation

Verify, that contract's logic does not break because of this difference
15 changes: 15 additions & 0 deletions docs/arb_difficulty_randao.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Arbitrum prevRandao/difficulty

## Configuration
* Check: `pess-arb-prevrandao-difficulty`
* Severity: `Medium`
* Confidence: `High`

## Description
The detector sees if an Arbitrum contract contains usages of prevRandao/difficulty block context variables or Yul funciton.

## Vulnerable Scenario
[test scenarios](../tests/arbitrum_prevrandao_difficulty_test.sol)

## Recommendation
Consider removing usage of prevRandao/difficulty inside Arbitrum contracts as they will constantly return `1` in Arbitrum.
19 changes: 19 additions & 0 deletions docs/arb_solidity_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Arbitrum solidity version

## Configuration

- Check: `pess-arb-solidity-version`
- Severity: `High`
- Confidence: `Low`

## Description

Checks that sol version >= 0.8.20 is not used inside an Arbitrum contract. Solidity in these versions will utilize PUSH0 opcode, which is not supported on Arbitrum.

## Vulnerable Scenario

[test scenarios](../tests/arbitrum_prevrandao_solidity_version_test.sol)

## Recommendation

Either, use versions `0.8.19`` and below, or EVM versions below shanghai
3 changes: 2 additions & 1 deletion docs/ecrecover.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

### Potential Improvement

As for now, the detector might not work on asm level.
- As for now, the detector might not work on asm level.
- `ecrecover_negative5` in [test scenarios](../tests/ecrecover.sol) should be found since the result of the check is unused. However, currently such scenarious are not covered.

## Vulnerable Scenario

Expand Down
21 changes: 21 additions & 0 deletions docs/potential_arith_overflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Potential arithmetic overflow

## Configuration
* Check: `pess-potential-arithmetic-overflow`
* Severity: `Medium`
* Confidence: `Medium`

## Description
The detector sees if there are assignments/returns that calculate some arithmetic expressions and if some intermediate calculations
contain a type that is lower than the expected result. Such behavior may lead to unexpected overflow/underflow, e.g., trying to assign the multiplication of two `uint48` variables to `uint256` would look like `uint48 * uint48` and it may overflow (however, the final type would fit such multiplication).

### Potential Improvement
- Handle return statements that return tuples of arithmetic expressions;
- Handle signed integer underflow for subtraction operation e.g. `int256 = int64 - int64` should produce error (`int64` should be cast to `int256`).
- Improve the output of the detector (unroll complex expressions in something readable, not just `...`)

## Vulnerable Scenario
[test scenario](../tests/potential_arith_overflow.sol)

## Recommendation
Use explicit type casting in sub expressions when the assigment to a larger type is performed.
10 changes: 5 additions & 5 deletions docs/strange_setter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* Confidence: `Medium`

## Description
The detector sees if a contract contains a setter (also constructor) that does not change contract storage variables.
Setter functions MUST change the values of storage variables.
Setter functions that do not modify storage variables may lead to contract misfunctions.
The detector sees if a contract contains a setter (also constructor) that does not change contract storage variables or does not perform external calls using provided arguments.
Setter functions MUST change the values of storage variables or perform external calls using provided parameters.
Setter functions that do not use provided variables may lead to contract misfunctions.

### Potential Improvement
Remove highlights of mappings.
Detect shadowing before storage update/external call

## Vulnerable Scenario
[test scenario](../tests/strange_setter_test.sol)

## Recommendation
Make sure that setter functions modify the states of storage variables.
Make sure that setter functions modify the states of storage variables or performs external call using provided arguments.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
packages=find_packages(),
license="AGPL-3.0",
python_requires=">=3.8",
install_requires=["slither-analyzer>=0.9.3"],
install_requires=["slither-analyzer>=0.10.0"],
extras_requires={
"dev": ["twine>=4.0.2"],
},
Expand Down
1 change: 1 addition & 0 deletions slitherin-benchmark
Submodule slitherin-benchmark added at 12792f
16 changes: 15 additions & 1 deletion slitherin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@
from slitherin.detectors.ecrecover import Ecrecover
from slitherin.detectors.public_vs_external import PublicVsExternal
from slitherin.detectors.aave.flashloan_callback import AAVEFlashloanCallbackDetector
from slitherin.detectors.arbitrum.arbitrum_prevrandao_difficulty import (
ArbitrumPrevrandaoDifficulty,
)
from slitherin.detectors.arbitrum.solidity_version import ArbitrumSolidityVersion
from slitherin.detectors.arbitrum.block_number_timestamp import (
ArbitrumBlockNumberTimestamp,
)
from slitherin.detectors.potential_arith_overflow import PotentialArithmOverflow

artbitrum_detectors = [
ArbitrumPrevrandaoDifficulty,
ArbitrumSolidityVersion,
ArbitrumBlockNumberTimestamp,
]

plugin_detectors = [
plugin_detectors = artbitrum_detectors + [
DoubleEntryTokenPossiblity,
UnprotectedSetter,
NftApproveWarning,
Expand All @@ -49,6 +62,7 @@
Ecrecover,
PublicVsExternal,
AAVEFlashloanCallbackDetector,
PotentialArithmOverflow
]
plugin_printers = []

Expand Down
53 changes: 50 additions & 3 deletions slitherin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
import os
import shutil
import pty
import sys
from pathlib import Path
import slitherin
from pkg_resources import iter_entry_points

SLITHERIN_VERSION = "0.5.0"
from .consts import *


def slitherin_detectors_list_as_arguments() -> str:
return ",".join([detector.ARGUMENT for detector in slitherin.plugin_detectors])


def arbitrum_detectors_list_as_arguments() -> str:
return ",".join([detector.ARGUMENT for detector in slitherin.artbitrum_detectors])


logging.basicConfig()
LOGGER = logging.getLogger("slitherinLogger")
LOGGER.setLevel(logging.INFO)
Expand Down Expand Up @@ -47,7 +52,34 @@ def run(
subprocess_cwd,
)

pty.spawn(cmd, read) # this allows to print continuously and with colors
master, slave = pty.openpty()

try:
process = subprocess.Popen(cmd, stdout=slave, stderr=slave, text=False)
os.close(slave)

while True:
try:
output = os.read(master, 1024)
except OSError as e:
if e.errno == 5: # Errno 5 corresponds to Input/output error
break
else:
raise
if not output:
break
decoded_output = output.decode(sys.stdout.encoding, errors="replace")
print(decoded_output, end="")

return_code = process.wait()
if return_code != 0:
raise Exception(
f"Errored out with code: {return_code}, while running slither"
)

except Exception as e:
print(f"Failed to run slither: {str(e)}")
raise e


def handle_list() -> None:
Expand All @@ -61,7 +93,11 @@ def handle_list() -> None:

def handle_parser(args: argparse.Namespace, slither_args) -> None:
slitherin_detectors = slitherin_detectors_list_as_arguments()
slither_with_args = ["slither"] + slither_args
slither_with_args = [
"slither",
"--fail-none",
] + slither_args # using fail-none flag, so slither will return 0 even though there are findings

if args.pess:
run(
slither_with_args + ["--detect", slitherin_detectors],
Expand All @@ -79,6 +115,11 @@ def handle_parser(args: argparse.Namespace, slither_args) -> None:
run(
slither_with_args + ["--ignore-compile", "--detect", slitherin_detectors],
)
elif args.arbitrum:
os.environ["SLITHERIN_ARBITRUM"] = "True"
run(slither_with_args + ["--detect", arbitrum_detectors_list_as_arguments()])
del os.environ["SLITHERIN_ARBITRUM"]

else:
run(slither_with_args)

Expand Down Expand Up @@ -120,6 +161,12 @@ def generate_argument_parser() -> argparse.ArgumentParser:
action="store_true",
help="Run slither detectors, then slitherin",
)

parser.add_argument(
"--arbitrum",
action="store_true",
help="Run arbitrum detectors",
)
return parser


Expand Down
2 changes: 2 additions & 0 deletions slitherin/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ARBITRUM_KEY = "SLITHERIN_ARBITRUM"
SLITHERIN_VERSION = "0.6.0"
Loading
Loading