-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from pessimistic-io/curve-vyper-version-detector
[NEW] Detector for vulnerable Vyper versions
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Curve Readonly Reentrancy | ||
|
||
## Configuration | ||
|
||
- Check: `pess-curve-vyper-reentrancy` | ||
- Severity: `High` | ||
- Confidence: `High` | ||
|
||
## Description | ||
|
||
Finds if the code is compiled with vulnerable Vyper compiler version and contains non-reentrant modifiers. | ||
Details: | ||
- [Curve exploit postmortem](https://hackmd.io/@LlamaRisk/BJzSKHNjn) | ||
- [Postmortem from Vyper team](https://hackmd.io/@vyperlang/HJUgNMhs2) | ||
|
||
## Vulnerable Scenario | ||
|
||
[test scenarios](../../tests/vyper/curve_vyper_reentrancy_test.vy) | ||
|
||
## Related Attacks | ||
|
||
- [Vyper compiler exploits](https://www.halborn.com/blog/post/explained-the-vyper-bug-hack-july-2023) | ||
|
||
## Recomendations | ||
|
||
- Upgrade the version of your Vyper compiler. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
slitherin/detectors/vyper/reentrancy_curve_vyper_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import List | ||
from slither.utils.output import Output | ||
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification | ||
from slither.core.declarations import Function | ||
from slither.slithir.operations.event_call import EventCall | ||
|
||
VULNERABLE_VERSIONS = ['0.2.15', '0.2.16', '0.3.0'] | ||
class CurveVyperReentrancy(AbstractDetector): | ||
ARGUMENT = 'pess-curve-vyper-reentrancy' # slither will launch the detector with slither.py --detect mydetector | ||
HELP = f'Vyper compiler versions {", ".join(VULNERABLE_VERSIONS)} are vulnerable to malfunctioning re-entrancy guards. Upgrade your compiler version.' | ||
IMPACT = DetectorClassification.HIGH | ||
CONFIDENCE = DetectorClassification.HIGH | ||
|
||
WIKI = 'https://github.com/pessimistic-io/slitherin/blob/master/docs/curve_vyper_reentrancy.md' | ||
WIKI_TITLE = 'Vulnerable Vyper version' | ||
WIKI_DESCRIPTION = "Some Vyper versions are vulnerable to malfunctioning re-entrancy guards." | ||
WIKI_EXPLOIT_SCENARIO = 'https://hackmd.io/@LlamaRisk/BJzSKHNjn' | ||
WIKI_RECOMMENDATION = 'Upgrade the version of your Vyper compiler.' | ||
|
||
def _detect(self) -> List[Output]: | ||
res = [] | ||
if not self.compilation_unit.is_vyper: | ||
return res | ||
compiler_version = self.compilation_unit.compiler_version.version | ||
if compiler_version not in VULNERABLE_VERSIONS: | ||
return res | ||
|
||
for contract in self.contracts: | ||
for f in contract.functions_entry_points: | ||
for modifier in f.modifiers: | ||
if modifier.name.startswith("nonreentrant"): | ||
res += ["\t", modifier.name, " in ", f, " function.\n"] | ||
if not res: | ||
return res | ||
return [self.generate_result( | ||
[f"Vyper {compiler_version} compiler version is vulnerable to malfunctioning re-entrancy guards. Found vulnerable usages:\n", | ||
*[x for x in res], | ||
"\n" | ||
] | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# @version =0.2.15 | ||
|
||
@external | ||
@nonreentrant("hello_lock") | ||
def helloWorld() -> String[24]: | ||
return "Hello World!" | ||
|
||
@external | ||
@nonreentrant("another_lock") | ||
def another_reentrant_func() -> uint256: | ||
return 1 | ||
|
||
@external | ||
def normal_func() -> uint256: | ||
return 0 |