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

Sync Master <> Dev #2635

Merged
merged 137 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
114dc2e
Fix #2266 where the type of functions when used as RValues was not pr…
DarkaMaul Apr 8, 2024
46d0cb1
Init Cheatcode printer
DarkaMaul Apr 8, 2024
7045cb8
Update Cheatcode Printer
DarkaMaul Apr 8, 2024
7b9f543
Fix test
DarkaMaul Apr 9, 2024
2f0f8cc
Prevent failure when executed with a project not using `Vm`
DarkaMaul Apr 9, 2024
b5766dc
Add cheatcode printer to test files
DarkaMaul Apr 9, 2024
e1b480e
Merge branch 'dev' into fix/ir-assignment-2266
DarkaMaul Apr 26, 2024
90373fb
Upgrade cheatcode printer
DarkaMaul Apr 26, 2024
bb8b108
Merge branch 'dev' into printer-cheatcode
DarkaMaul Apr 26, 2024
ee46cae
Add missing blank line.
DarkaMaul May 1, 2024
9fe27d3
Merge branch 'dev' into fix/ir-assignment-2266
DarkaMaul Jun 5, 2024
f3f4b20
Update tests/e2e/printers/test_printers.py
DarkaMaul Jun 5, 2024
ecca8da
Improve performances of offsets references.
DarkaMaul Jun 11, 2024
eaebe7a
Merge branch 'dev' into fix/ir-assignment-2266
DarkaMaul Jun 11, 2024
8f8bfef
Add instruction for how to upgrade slither in the CLI
CJ42 Jun 26, 2024
1512fb0
chore: fix some comments
withbest Jul 28, 2024
cadcf1e
Update README.md
0xalpharush Aug 23, 2024
7aa0367
Update README.md
0xalpharush Aug 23, 2024
7bfa87a
Add support custom errors in require
smonicas Sep 9, 2024
5d55bc5
Add test
smonicas Sep 9, 2024
109c31a
Add require with error
smonicas Sep 11, 2024
482f92f
Merge pull request #2553 from crytic/master
0xalpharush Sep 11, 2024
12712f2
Merge branch 'dev' into dev-require-error
0xalpharush Sep 11, 2024
7fd0e58
Revisit *Calls API
smonicas Sep 13, 2024
a60bd63
Fix test
smonicas Sep 13, 2024
7b408b2
Lint
smonicas Sep 13, 2024
cee7451
Revert lint
smonicas Sep 13, 2024
13b25e8
Fix solidity calls analysis
smonicas Sep 13, 2024
439010a
Use new *Calls API in detectors
smonicas Sep 13, 2024
2c51629
Lint
smonicas Sep 13, 2024
bf5d6d6
Add assert information for echidna
smonicas Sep 18, 2024
4de824b
Fix function name
smonicas Sep 18, 2024
fdf1db3
Lint
smonicas Sep 18, 2024
584d64c
add event as value member
hamdiallam Sep 25, 2024
29ca19a
Merge pull request #2550 from crytic/dev-require-error
0xalpharush Sep 26, 2024
0cfaa68
fix: mapping to type value lookup with top-level constant
0xalpharush Sep 26, 2024
2075e6f
fmt
0xalpharush Sep 26, 2024
1ed8205
Merge pull request #2569 from crytic/pull/2567/head
montyly Oct 2, 2024
546122a
Merge pull request #2412 from DarkaMaul/fix/ir-assignment-2266
montyly Oct 2, 2024
cca47a1
Merge branch 'dev' into printer-cheatcode
montyly Oct 2, 2024
ad9e8dd
Update test_printers.py
montyly Oct 2, 2024
0a306e6
Merge pull request #2481 from crytic/features/offsets-perf
montyly Oct 2, 2024
d9f114d
Merge branch 'dev' into dev-revisit-calls-api
montyly Oct 2, 2024
162bf0f
Merge remote-tracking branch 'origin/master' into dev-revisit-calls-api
montyly Oct 2, 2024
d1bf27a
Update CI
montyly Oct 2, 2024
7e3f9c5
Update slither/core/cfg/node.py
montyly Oct 2, 2024
e5fe89b
Merge pull request #2571 from crytic/dev-revisit-calls-api-ci
montyly Oct 2, 2024
9113f49
Reduce the number of CI tests on PR
montyly Oct 2, 2024
dfab5ae
Remove windows tests from PR
montyly Oct 2, 2024
3a68886
Fix CI lint
montyly Oct 2, 2024
9122cef
Improvements
montyly Oct 2, 2024
0811cd6
Merge pull request #2572 from crytic/improve-CI
montyly Oct 3, 2024
afac8c4
Improve values extraction
smonicas Oct 4, 2024
d96b87e
Add Optimism deprecation detector
smonicas Oct 4, 2024
088b704
Add Chainlink feed registry detector
smonicas Oct 4, 2024
36bde7d
Update slither/detectors/functions/optimism_deprecation.py
smonicas Oct 4, 2024
6afd281
Update slither/detectors/functions/optimism_deprecation.py
smonicas Oct 4, 2024
909ab51
Update slither/detectors/functions/chainlink_feed_registry.py
smonicas Oct 4, 2024
96c6c94
Only consider if call target is a variable
smonicas Oct 4, 2024
6b503a9
Update optimism_deprecation.py
montyly Oct 4, 2024
48d7d9b
Improve support for type .max/.min and Enums
smonicas Oct 7, 2024
f93b65f
Fix for user defined type and variables defined in another contract
smonicas Oct 7, 2024
607b22a
Handle UnaryOperation from another contract
smonicas Oct 7, 2024
a5e970a
Bump cachix/install-nix-action from V27 to 30
dependabot[bot] Oct 7, 2024
25a4672
Bump pypa/gh-action-pypi-publish from 1.9.0 to 1.10.3
dependabot[bot] Oct 7, 2024
bae46ba
Add Pyth deprecated functions detector
smonicas Oct 8, 2024
f25344c
Add Pyth unchecked confidence detector
smonicas Oct 8, 2024
7e54d41
Add Pyth unchecked publishTime detector
smonicas Oct 8, 2024
24a9d9d
Add Gelato VRF unprotected request detector
smonicas Oct 9, 2024
138b626
Add test
smonicas Oct 9, 2024
2d46a3d
Update CODEOWNERS
0xalpharush Oct 9, 2024
4a9cdce
Add Chronicle unchecked price detector
smonicas Oct 9, 2024
9c9818c
Update tests/e2e/detectors/test_detectors.py
smonicas Oct 9, 2024
1f32855
Add StateVariable location
smonicas Oct 10, 2024
8190a48
Merge pull request #2575 from crytic/dev-optimism-deprecation
montyly Oct 10, 2024
25f6e46
Merge branch 'dev' into dev-pyth-deprecated-functions
montyly Oct 10, 2024
3caad58
Merge pull request #2580 from crytic/dev-pyth-deprecated-functions
montyly Oct 10, 2024
f680cff
Merge pull request #2583 from 0xalpharush/patch-1
montyly Oct 10, 2024
8b226d0
Merge branch 'dev' into dev-chainlink-feed-detector
montyly Oct 10, 2024
570840d
Merge pull request #2585 from crytic/dev-storage-location
montyly Oct 10, 2024
d1d78de
Merge pull request #2576 from crytic/dev-chainlink-feed-detector
montyly Oct 10, 2024
e496570
Merge branch 'dev' into dev-pyth-unchecked-publishtime-conf-detector
montyly Oct 10, 2024
32f3ba5
Merge pull request #2581 from crytic/dev-pyth-unchecked-publishtime-c…
montyly Oct 10, 2024
efc45f0
Merge branch 'dev' into dev-chronicle-price-detector
montyly Oct 10, 2024
e863fbc
Merge pull request #2584 from crytic/dev-chronicle-price-detector
montyly Oct 10, 2024
9ce8302
Update gelato_unprotected_randomness.sol
montyly Oct 10, 2024
1c7f1f3
Merge branch 'dev' into dev-gelato-vrf-detector
montyly Oct 10, 2024
ecc2010
Update tests/e2e/detectors/test_detectors.py
montyly Oct 10, 2024
d10f7eb
Merge pull request #2582 from crytic/dev-gelato-vrf-detector
montyly Oct 10, 2024
3753b40
Merge pull request #2578 from crytic/dependabot/github_actions/dev/ca…
montyly Oct 10, 2024
98af7fd
Merge pull request #2579 from crytic/dependabot/github_actions/dev/py…
montyly Oct 10, 2024
ef03cb7
Improve transient storage support
smonicas Oct 10, 2024
2bf8516
Merge branch 'dev' into docs/update-slither
CJ42 Oct 11, 2024
8abf917
Merge pull request #2498 from CJ42/docs/update-slither
montyly Oct 11, 2024
9e89bbb
Merge pull request #2588 from crytic/dev-support-transient
montyly Oct 11, 2024
4b91acd
Fix IR conversion when an Event selector is accessed
smonicas Oct 11, 2024
1941e91
Improve selector parsing
montyly Oct 17, 2024
1ae2e9e
Remove unused import
montyly Oct 17, 2024
5488d50
Remove commented code
montyly Oct 17, 2024
79619f6
Merge pull request #2589 from crytic/dev-event-selector-ir
montyly Oct 17, 2024
f6b2509
Add try/catch, add tests, refactor guidance/echidna to reduce pylint …
montyly Oct 17, 2024
83e5fca
Merge pull request #2574 from crytic/dev-echidna-values
montyly Oct 17, 2024
e659f54
Merge pull request #2413 from crytic/printer-cheatcode
montyly Oct 24, 2024
80c7e85
Merge pull request #2518 from withbest/master
montyly Oct 24, 2024
d0929a8
Merge pull request #2568 from crytic/fix/mapping-type-identifer-lookup
montyly Oct 24, 2024
38f7136
Merge branch 'dev' into echidna-printer
smonicas Oct 24, 2024
1bbc13b
Use the new API
smonicas Oct 24, 2024
537ee27
Extract multiple assert in a single function
smonicas Oct 24, 2024
89a7d58
Merge pull request #2560 from crytic/echidna-printer
montyly Oct 24, 2024
2aee055
Boxes + horizonal flow makes for more readable call graphs.
DanielVF Nov 12, 2024
191b94b
Update README.md
leopardracer Nov 26, 2024
2c401e6
Fix reorder arguments when a function is overridden with diff param n…
smonicas Dec 3, 2024
c97abac
Update tests/unit/slithir/test_argument_reorder.py
smonicas Dec 3, 2024
638cad3
Merge pull request #2611 from crytic/dev-fix-override-reorder
montyly Dec 4, 2024
730d035
Merge branch 'dev' into horizontal-call-graph
montyly Dec 6, 2024
0f390e9
Merge branch 'dev' into master
montyly Dec 6, 2024
bcd0f83
Merge pull request #2607 from leopardracer/master
montyly Dec 6, 2024
10774d1
Merge branch 'horizontal-call-graph' of github.com:DanielVF/slither i…
montyly Dec 6, 2024
ce496c7
Run black
montyly Dec 6, 2024
7642299
Fix reorder argument edge case
smonicas Dec 6, 2024
c6d56e8
Merge pull request #2613 from crytic/DanielVF-horizontal-call-graph
montyly Dec 6, 2024
8958d3b
Merge pull request #2614 from crytic/fix-reorder-arg
montyly Dec 6, 2024
60ff5b4
Bump pypa/gh-action-pypi-publish from 1.10.3 to 1.12.3
dependabot[bot] Dec 9, 2024
653e821
[mutator] print files to-be-mutated
bohendo Jan 6, 2025
d8ffee7
fix formatting
bohendo Jan 6, 2025
ab28eb1
ensure very_verbose logs are a superset of verbose logs
bohendo Jan 9, 2025
9ea7329
consolidate & clean verbose & very_verbose logs
bohendo Jan 9, 2025
653cda5
Fix infinite loop
smonicas Jan 15, 2025
811d390
Merge pull request #2625 from crytic/features/mutator
smonicas Jan 16, 2025
23074c6
Merge pull request #2628 from crytic/dev-fix-modifier-detector
smonicas Jan 16, 2025
5ce67b7
Fix analysis for named return variables
smonicas Jan 17, 2025
cbb9a5c
Merge pull request #2615 from crytic/dependabot/github_actions/dev/py…
smonicas Jan 17, 2025
e50dd34
Merge pull request #2631 from crytic/dev-fix-analysis
smonicas Jan 17, 2025
a565849
Update README.md
smonicas Jan 17, 2025
7b30e77
Merge pull request #2632 from crytic/dev-update-readme
smonicas Jan 17, 2025
d227b8a
Prepare 0.11.0 release
smonicas Jan 17, 2025
bc8e8f2
Merge pull request #2634 from crytic/prepare-release-0.11.0
smonicas Jan 17, 2025
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
16 changes: 9 additions & 7 deletions .github/workflows/black_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ jobs:
with:
python-version: 3.8

- name: Install Python dependencies
run: pip install .[dev]
- name: Run black
uses: psf/black@stable
with:
options: ""
summary: false
version: "~= 22.3.0"

- name: Run linters
uses: wearerequired/lint-action@v2
- name: Annotate diff changes using reviewdog
uses: reviewdog/action-suggester@v1
with:
auto_fix: true
black: true
black_auto_fix: true
tool_name: blackfmt
23 changes: 3 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-2022"]
os: ${{ (github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]')) || fromJSON('["ubuntu-latest", "windows-2022"]') }}
python: ${{ (github.event_name == 'pull_request' && fromJSON('["3.8", "3.12"]')) || fromJSON('["3.8", "3.9", "3.10", "3.11", "3.12"]') }}
type: ["cli",
"dapp",
"data_dependency",
"path_filtering",
# "embark",
"erc",
# "etherlime",
"etherscan",
"find_paths",
"flat",
"interface",
"kspec",
"printers",
# "prop"
"simil",
"slither_config",
"truffle",
"upgradability"]
type: ${{ (github.event_name == 'pull_request' && fromJSON('["data_dependency", "path_filtering","erc","find_paths","flat","interface", "printers","slither_config","upgradability"]')) || fromJSON('["data_dependency", "path_filtering","erc","find_paths","flat","interface", "printers","slither_config","upgradability", "cli", "dapp", "etherscan", "kspec", "simil", "truffle"]') }}
exclude:
# Requires nix
- os: windows-2022
Expand All @@ -67,7 +50,7 @@ jobs:

- name: Set up nix
if: matrix.type == 'dapp'
uses: cachix/install-nix-action@V27
uses: cachix/install-nix-action@v30

- name: Set up cachix
if: matrix.type == 'dapp'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
path: dist/

- name: publish
uses: pypa/gh-action-pypi-publish@v1.9.0
uses: pypa/gh-action-pypi-publish@v1.12.3

- name: sign
uses: sigstore/[email protected]
Expand Down
3 changes: 1 addition & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
* @montyly @0xalpharush @smonicas
/slither/tools/read_storage/ @0xalpharush
* @montyly @smonicas
/slither/tools/doctor/ @elopez
/slither/slithir/ @montyly
/slither/analyses/ @montyly
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TEST_MODULE := tests
ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \
$(shell find test -name '*.py')

# Optionally overriden by the user, if they're using a virtual environment manager.
# Optionally overridden by the user, if they're using a virtual environment manager.
VENV ?= env

# On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
Expand Down
156 changes: 84 additions & 72 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/ci_test_printers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cd tests/e2e/solc_parsing/test_data/compile/ || exit

# Do not test the evm printer,as it needs a refactoring
ALL_PRINTERS="cfg,constructor-calls,contract-summary,data-dependency,echidna,function-id,function-summary,modifiers,call-graph,halstead,human-summary,inheritance,inheritance-graph,loc,martin,slithir,slithir-ssa,vars-and-auth,require,variable-order,declaration,ck"
ALL_PRINTERS="cfg,constructor-calls,contract-summary,data-dependency,echidna,function-id,function-summary,modifiers,call-graph,halstead,human-summary,inheritance,inheritance-graph,loc,martin,slithir,slithir-ssa,vars-and-auth,require,variable-order,declaration,ck,cheatcode"

# Only test 0.5.17 to limit test time
for file in *0.5.17-compact.zip; do
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
description="Slither is a Solidity and Vyper static analysis framework written in Python 3.",
url="https://github.com/crytic/slither",
author="Trail of Bits",
version="0.10.4",
version="0.11.0",
packages=find_packages(),
python_requires=">=3.8",
install_requires=[
"packaging",
"prettytable>=3.10.2",
"pycryptodome>=3.4.6",
"crytic-compile>=0.3.7,<0.4.0",
"crytic-compile>=0.3.8,<0.4.0",
# "crytic-compile@git+https://github.com/crytic/crytic-compile.git@master#egg=crytic-compile",
"web3>=6.20.2, <7",
"eth-abi>=4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion slither/analyses/write/are_variables_written.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _visit(
lvalue = refs_lvalues

ret: List[Variable] = []
if not node.sons and node.type not in [NodeType.THROW, NodeType.RETURN]:
if not node.sons and node.type is not NodeType.THROW:
ret += [v for v in variables_to_write if v not in variables_written]

# Explore sons if
Expand Down
70 changes: 30 additions & 40 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
if TYPE_CHECKING:
from slither.slithir.variables.variable import SlithIRVariable
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.utils.type_helpers import (
InternalCallType,
HighLevelCallType,
LibraryCallType,
LowLevelCallType,
)
from slither.core.cfg.scope import Scope
from slither.core.scope.scope import FileScope

Expand Down Expand Up @@ -153,11 +147,11 @@ def __init__(
self._ssa_vars_written: List["SlithIRVariable"] = []
self._ssa_vars_read: List["SlithIRVariable"] = []

self._internal_calls: List[Union["Function", "SolidityFunction"]] = []
self._solidity_calls: List[SolidityFunction] = []
self._high_level_calls: List["HighLevelCallType"] = [] # contains library calls
self._library_calls: List["LibraryCallType"] = []
self._low_level_calls: List["LowLevelCallType"] = []
self._internal_calls: List[InternalCall] = [] # contains solidity calls
self._solidity_calls: List[SolidityCall] = []
self._high_level_calls: List[Tuple[Contract, HighLevelCall]] = [] # contains library calls
self._library_calls: List[LibraryCall] = []
self._low_level_calls: List[LowLevelCall] = []
self._external_calls_as_expressions: List[Expression] = []
self._internal_calls_as_expressions: List[Expression] = []
self._irs: List[Operation] = []
Expand Down Expand Up @@ -226,8 +220,9 @@ def type(self, new_type: NodeType) -> None:
@property
def will_return(self) -> bool:
if not self.sons and self.type != NodeType.THROW:
if SolidityFunction("revert()") not in self.solidity_calls:
if SolidityFunction("revert(string)") not in self.solidity_calls:
solidity_calls = [ir.function for ir in self.solidity_calls]
if SolidityFunction("revert()") not in solidity_calls:
if SolidityFunction("revert(string)") not in solidity_calls:
return True
return False

Expand Down Expand Up @@ -373,44 +368,38 @@ def variables_written_as_expression(self, exprs: List[Expression]) -> None:
###################################################################################

@property
def internal_calls(self) -> List["InternalCallType"]:
def internal_calls(self) -> List[InternalCall]:
"""
list(Function or SolidityFunction): List of internal/soldiity function calls
list(InternalCall): List of IR operations with internal/solidity function calls
"""
return list(self._internal_calls)

@property
def solidity_calls(self) -> List[SolidityFunction]:
def solidity_calls(self) -> List[SolidityCall]:
"""
list(SolidityFunction): List of Soldity calls
list(SolidityCall): List of IR operations with solidity calls
"""
return list(self._solidity_calls)

@property
def high_level_calls(self) -> List["HighLevelCallType"]:
def high_level_calls(self) -> List[HighLevelCall]:
"""
list((Contract, Function|Variable)):
List of high level calls (external calls).
A variable is called in case of call to a public state variable
list(HighLevelCall): List of IR operations with high level calls (external calls).
Include library calls
"""
return list(self._high_level_calls)

@property
def library_calls(self) -> List["LibraryCallType"]:
def library_calls(self) -> List[LibraryCall]:
"""
list((Contract, Function)):
Include library calls
list(LibraryCall): List of IR operations with library calls.
"""
return list(self._library_calls)

@property
def low_level_calls(self) -> List["LowLevelCallType"]:
def low_level_calls(self) -> List[LowLevelCall]:
"""
list((Variable|SolidityVariable, str)): List of low_level call
A low level call is defined by
- the variable called
- the name of the function (call/delegatecall/codecall)
list(LowLevelCall): List of IR operations with low_level call
"""
return list(self._low_level_calls)

Expand Down Expand Up @@ -529,8 +518,9 @@ def contains_require_or_assert(self) -> bool:
bool: True if the node has a require or assert call
"""
return any(
c.name in ["require(bool)", "require(bool,string)", "assert(bool)"]
for c in self.internal_calls
ir.function.name
in ["require(bool)", "require(bool,string)", "require(bool,error)", "assert(bool)"]
for ir in self.internal_calls
)

def contains_if(self, include_loop: bool = True) -> bool:
Expand Down Expand Up @@ -894,11 +884,11 @@ def _find_read_write_call(self) -> None: # pylint: disable=too-many-statements
self._vars_written.append(var)

if isinstance(ir, InternalCall):
self._internal_calls.append(ir.function)
self._internal_calls.append(ir)
if isinstance(ir, SolidityCall):
# TODO: consider removing dependancy of solidity_call to internal_call
self._solidity_calls.append(ir.function)
self._internal_calls.append(ir.function)
self._solidity_calls.append(ir)
self._internal_calls.append(ir)
if (
isinstance(ir, SolidityCall)
and ir.function == SolidityFunction("sstore(uint256,uint256)")
Expand All @@ -916,22 +906,22 @@ def _find_read_write_call(self) -> None: # pylint: disable=too-many-statements
self._vars_read.append(ir.arguments[0])
if isinstance(ir, LowLevelCall):
assert isinstance(ir.destination, (Variable, SolidityVariable))
self._low_level_calls.append((ir.destination, str(ir.function_name.value)))
self._low_level_calls.append(ir)
elif isinstance(ir, HighLevelCall) and not isinstance(ir, LibraryCall):
# Todo investigate this if condition
# It does seem right to compare against a contract
# This might need a refactoring
if isinstance(ir.destination.type, Contract):
self._high_level_calls.append((ir.destination.type, ir.function))
self._high_level_calls.append((ir.destination.type, ir))
elif ir.destination == SolidityVariable("this"):
func = self.function
# Can't use this in a top level function
assert isinstance(func, FunctionContract)
self._high_level_calls.append((func.contract, ir.function))
self._high_level_calls.append((func.contract, ir))
else:
try:
# Todo this part needs more tests and documentation
self._high_level_calls.append((ir.destination.type.type, ir.function))
self._high_level_calls.append((ir.destination.type.type, ir))
except AttributeError as error:
# pylint: disable=raise-missing-from
raise SlitherException(
Expand All @@ -940,8 +930,8 @@ def _find_read_write_call(self) -> None: # pylint: disable=too-many-statements
elif isinstance(ir, LibraryCall):
assert isinstance(ir.destination, Contract)
assert isinstance(ir.function, Function)
self._high_level_calls.append((ir.destination, ir.function))
self._library_calls.append((ir.destination, ir.function))
self._high_level_calls.append((ir.destination, ir))
self._library_calls.append(ir)

self._vars_read = list(set(self._vars_read))
self._state_vars_read = [v for v in self._vars_read if isinstance(v, StateVariable)]
Expand Down
60 changes: 40 additions & 20 deletions slither/core/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def __init__(self, core: "SlitherCore", crytic_compilation_unit: CompilationUnit
# Memoize
self._all_state_variables: Optional[Set[StateVariable]] = None

self._storage_layouts: Dict[str, Dict[str, Tuple[int, int]]] = {}
self._persistent_storage_layouts: Dict[str, Dict[str, Tuple[int, int]]] = {}
self._transient_storage_layouts: Dict[str, Dict[str, Tuple[int, int]]] = {}

self._contract_with_missing_inheritance: Set[Contract] = set()

Expand Down Expand Up @@ -297,33 +298,52 @@ def get_scope(self, filename_str: str) -> FileScope:

def compute_storage_layout(self) -> None:
assert self.is_solidity

for contract in self.contracts_derived:
self._storage_layouts[contract.name] = {}

slot = 0
offset = 0
for var in contract.stored_state_variables_ordered:
assert var.type
size, new_slot = var.type.storage_size

if new_slot:
if offset > 0:
slot += 1
offset = 0
elif size + offset > 32:
self._compute_storage_layout(contract.name, contract.storage_variables_ordered, False)
self._compute_storage_layout(contract.name, contract.transient_variables_ordered, True)

def _compute_storage_layout(
self, contract_name: str, state_variables_ordered: List[StateVariable], is_transient: bool
):
if is_transient:
self._transient_storage_layouts[contract_name] = {}
else:
self._persistent_storage_layouts[contract_name] = {}

slot = 0
offset = 0
for var in state_variables_ordered:
assert var.type
size, new_slot = var.type.storage_size

if new_slot:
if offset > 0:
slot += 1
offset = 0
elif size + offset > 32:
slot += 1
offset = 0

self._storage_layouts[contract.name][var.canonical_name] = (
if is_transient:
self._transient_storage_layouts[contract_name][var.canonical_name] = (
slot,
offset,
)
if new_slot:
slot += math.ceil(size / 32)
else:
offset += size
else:
self._persistent_storage_layouts[contract_name][var.canonical_name] = (
slot,
offset,
)

if new_slot:
slot += math.ceil(size / 32)
else:
offset += size

def storage_layout_of(self, contract: Contract, var: StateVariable) -> Tuple[int, int]:
return self._storage_layouts[contract.name][var.canonical_name]
if var.is_stored:
return self._persistent_storage_layouts[contract.name][var.canonical_name]
return self._transient_storage_layouts[contract.name][var.canonical_name]

# endregion
Loading
Loading