make slither-read-storage dependencies explicit

pull/1743/head
alpharush 2 years ago
parent 829f7eb169
commit 12682c3094
  1. 3
      .github/workflows/read_storage.yml
  2. 3
      setup.py
  3. 31
      slither/tools/read_storage/read_storage.py
  4. 13
      tests/test_read_storage.py

@ -39,8 +39,7 @@ jobs:
- name: Install python dependencies
run: |
pip install ".[dev]"
pip install web3
pip install ".[slither-read-storage]"
solc-select install 0.8.1
solc-select install 0.8.10
solc-select use 0.8.1

@ -30,7 +30,8 @@ setup(
"solc-select>=v1.0.0b1",
"openai",
"pdoc",
]
],
"slither-read-storage": ["solc-select>=v1.0.0b1", "web3>=6.0.0b"],
},
license="AGPL-3.0",
long_description=long_description,

@ -3,20 +3,17 @@ import sys
from math import floor
from typing import Callable, Optional, Tuple, Union, List, Dict, Any
try:
from web3 import Web3
from eth_typing.evm import ChecksumAddress
from eth_abi import decode_single, encode_abi
from eth_utils import keccak
from .utils import (
get_offset_value,
get_storage_data,
coerce_type,
)
except ImportError:
print("ERROR: in order to use slither-read-storage, you need to install web3")
print("$ pip3 install web3 --user\n")
sys.exit(-1)
from web3 import Web3
from eth_typing.evm import ChecksumAddress
from eth_abi import decode, encode
from eth_utils import keccak
from .utils import (
get_offset_value,
get_storage_data,
coerce_type,
)
import dataclasses
from slither.utils.myprettytable import MyPrettyTable
@ -92,7 +89,7 @@ class SlitherReadStorage:
if not self.storage_address:
raise ValueError
if not self._checksum_address:
self._checksum_address = self.web3.toChecksumAddress(self.storage_address)
self._checksum_address = self.web3.to_checksum_address(self.storage_address)
return self._checksum_address
@property
@ -449,7 +446,7 @@ class SlitherReadStorage:
if "int" in key_type: # without this eth_utils encoding fails
key = int(key)
key = coerce_type(key_type, key)
slot = keccak(encode_abi([key_type, "uint256"], [key, decode_single("uint256", slot)]))
slot = keccak(encode([key_type, "uint256"], [key, decode("uint256", slot)]))
if isinstance(target_variable_type.type_to, UserDefinedType) and isinstance(
target_variable_type.type_to.type, Structure
@ -471,7 +468,7 @@ class SlitherReadStorage:
deep_key = int(deep_key)
# If deep map, will be keccak256(abi.encode(key1, keccak256(abi.encode(key0, uint(slot)))))
slot = keccak(encode_abi([key_type, "bytes32"], [deep_key, slot]))
slot = keccak(encode([key_type, "bytes32"], [deep_key, slot]))
# mapping(elem => mapping(elem => elem))
target_variable_type_type_to_type_to = target_variable_type.type_to.type_to

@ -12,13 +12,10 @@ from deepdiff import DeepDiff
from slither import Slither
from slither.tools.read_storage import SlitherReadStorage
try:
from web3 import Web3
from web3.contract import Contract
except ImportError:
print("ERROR: in order to use slither-read-storage, you need to install web3")
print("$ pip3 install web3 --user\n")
sys.exit(-1)
from web3 import Web3
from web3.contract import Contract
SLITHER_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STORAGE_TEST_ROOT = os.path.join(SLITHER_ROOT, "tests", "storage-layout")
@ -98,7 +95,7 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract:
# pylint: disable=too-many-locals
@pytest.mark.usefixtures("web3", "ganache")
def test_read_storage(web3, ganache) -> None:
assert web3.isConnected()
assert web3.is_connected()
bin_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.bin")
abi_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.abi")
bytecode = get_source_file(bin_path)

Loading…
Cancel
Save