more linting

pull/1288/head
noxx 2 years ago committed by noxx
parent 3d690088e3
commit c18b5ae43b
  1. 9
      slither/tools/read_storage/__main__.py
  2. 158
      slither/tools/read_storage/read_storage.py

@ -139,8 +139,7 @@ def main() -> None:
srs.rpc = args.rpc_url
if args.silent:
environ["SILENT"] = "1"
environ["SILENT"] = args.silent
if args.table_storage_layout:
environ["TABLE"] = "1"
@ -148,14 +147,12 @@ def main() -> None:
srs.get_storage_layout()
srs.print_table()
return
if args.table_storage_value:
assert args.rpc_url
environ["TABLE"] = "1"
environ["TABLE_VALUE"] = "1"
srs.get_all_storage_variables()
srs.get_storage_layout()
srs.print_table()
srs.print_table_with_values()
return
if args.layout:

@ -145,7 +145,7 @@ class SlitherReadStorage:
contracts (`Contract`): The contract that contains the given state variable.
**kwargs:
key (str): Key of a mapping or index position if an array.
deep_key (str): Key of a mapping embedded within another mapping or
deep_key (str): Key of a mapping embedded within another mapping or
secondary index if array.
struct_var (str): Structure variable name.
Returns:
@ -261,12 +261,6 @@ class SlitherReadStorage:
def print_table(self) -> None:
if environ.get("TABLE_VALUE") is None:
tabulate_headers = ["slot", "offset", "size", "type", "name"]
else:
tabulate_headers = ["slot", "offset", "size", "type", "name", "value"]
print("Processing, grabbing values from rpc endpoint...")
tabulate_data = []
for _, state_var in self.target_variables:
@ -279,23 +273,7 @@ class SlitherReadStorage:
type_string = info.get("type_string")
struct_var = info.get("struct_var")
if environ.get("TABLE_VALUE") is None:
tabulate_data.append(
[slot, offset, size, type_string, var]
)
else:
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
value = self.convert_value_to_type(hex_bytes, size, offset, type_string)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var,
value
]
)
tabulate_data.append([slot, offset, size, type_string, var])
if is_user_defined_type(type_) and is_struct(type_.type):
tabulate_data.pop()
@ -307,25 +285,85 @@ class SlitherReadStorage:
struct_var = info["elems"][item].get("struct_var")
# doesn't handle deep keys currently
var_name_struct_or_array_var = "{} -> {}".format(var, struct_var)
var_name_struct_or_array_var = f"{var} -> {struct_var}"
tabulate_data.append(
[slot, offset, size, type_string, var_name_struct_or_array_var]
)
if is_array(type_):
tabulate_data.pop()
for item in info["elems"]:
for key in info["elems"][item]:
slot = info["elems"][item][key].get("slot")
offset = info["elems"][item][key].get("offset")
size = info["elems"][item][key].get("size")
type_string = info["elems"][item][key].get("type_string")
struct_var = info["elems"][item][key].get("struct_var")
# doesn't handle deep keys currently
var_name_struct_or_array_var = f"{var}[{item}] -> {struct_var}"
if environ.get("TABLE_VALUE") is None:
tabulate_data.append(
[slot, offset, size, type_string, var_name_struct_or_array_var]
)
else:
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
value = self.convert_value_to_type(hex_bytes, size, offset, type_string)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var_name_struct_or_array_var,
value
]
)
print(
tabulate(
tabulate_data, headers=["slot", "offset", "size", "type", "name"], tablefmt="grid"
)
)
def print_table_with_values(self) -> None:
print("Processing, grabbing values from rpc endpoint...")
tabulate_data = []
for _, state_var in self.target_variables:
type_ = state_var.type
var = state_var.name
info = self.slot_info[var]
slot = info.get("slot")
offset = info.get("offset")
size = info.get("size")
type_string = info.get("type_string")
struct_var = info.get("struct_var")
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var,
self.convert_value_to_type(hex_bytes, size, offset, type_string),
]
)
if is_user_defined_type(type_) and is_struct(type_.type):
tabulate_data.pop()
for item in info["elems"]:
slot = info["elems"][item].get("slot")
offset = info["elems"][item].get("offset")
size = info["elems"][item].get("size")
type_string = info["elems"][item].get("type_string")
struct_var = info["elems"][item].get("struct_var")
# doesn't handle deep keys currently
var_name_struct_or_array_var = f"{var} -> {struct_var}"
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var_name_struct_or_array_var,
self.convert_value_to_type(hex_bytes, size, offset, type_string),
]
)
if is_array(type_):
tabulate_data.pop()
@ -338,27 +376,27 @@ class SlitherReadStorage:
struct_var = info["elems"][item][key].get("struct_var")
# doesn't handle deep keys currently
var_name_struct_or_array_var = "{}[{}] -> {}".format(var, item, struct_var)
if environ.get("TABLE_VALUE") is None:
tabulate_data.append(
[slot, offset, size, type_string, var_name_struct_or_array_var]
)
else:
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
value = self.convert_value_to_type(hex_bytes, size, offset, type_string)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var_name_struct_or_array_var,
value,
]
)
print(tabulate(tabulate_data, headers=tabulate_headers, tablefmt="grid"))
var_name_struct_or_array_var = f"{var}[{item}] -> {struct_var}"
hex_bytes = get_storage_data(self.web3, self.checksum_address, slot)
tabulate_data.append(
[
slot,
offset,
size,
type_string,
var_name_struct_or_array_var,
self.convert_value_to_type(hex_bytes, size, offset, type_string),
]
)
print(
tabulate(
tabulate_data,
headers=["slot", "offset", "size", "type", "name", "value"],
tablefmt="grid",
)
)
@staticmethod
def _find_struct_var_slot(

Loading…
Cancel
Save