|
|
|
@ -51,6 +51,7 @@ class Flattening: |
|
|
|
|
compilation_unit: SlitherCompilationUnit, |
|
|
|
|
external_to_public=False, |
|
|
|
|
remove_assert=False, |
|
|
|
|
convert_library_to_internal=False, |
|
|
|
|
private_to_internal=False, |
|
|
|
|
export_path: Optional[str] = None, |
|
|
|
|
pragma_solidity: Optional[str] = None, |
|
|
|
@ -61,6 +62,7 @@ class Flattening: |
|
|
|
|
self._external_to_public = external_to_public |
|
|
|
|
self._remove_assert = remove_assert |
|
|
|
|
self._use_abi_encoder_v2 = False |
|
|
|
|
self._convert_library_to_internal = convert_library_to_internal |
|
|
|
|
self._private_to_internal = private_to_internal |
|
|
|
|
self._pragma_solidity = pragma_solidity |
|
|
|
|
|
|
|
|
@ -146,6 +148,36 @@ class Flattening: |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if self._convert_library_to_internal and contract.is_library: |
|
|
|
|
for f in contract.functions_declared: |
|
|
|
|
visibility = "" |
|
|
|
|
if f.visibility in ["external", "public"]: |
|
|
|
|
visibility = f.visibility |
|
|
|
|
attributes_start = ( |
|
|
|
|
f.parameters_src().source_mapping["start"] |
|
|
|
|
+ f.parameters_src().source_mapping["length"] |
|
|
|
|
) |
|
|
|
|
attributes_end = f.returns_src().source_mapping["start"] |
|
|
|
|
attributes = content[attributes_start:attributes_end] |
|
|
|
|
regex = ( |
|
|
|
|
re.search(r"((\sexternal)\s+)|(\sexternal)$|(\)external)$", attributes) |
|
|
|
|
if visibility == "external" |
|
|
|
|
else re.search(r"((\spublic)\s+)|(\spublic)$|(\)public)$", attributes) |
|
|
|
|
) |
|
|
|
|
if regex: |
|
|
|
|
to_patch.append( |
|
|
|
|
Patch( |
|
|
|
|
attributes_start + regex.span()[0] + 1, |
|
|
|
|
"external_to_internal" |
|
|
|
|
if visibility == "external" |
|
|
|
|
else "public_to_internal", |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
raise SlitherException( |
|
|
|
|
f"{visibility} keyword not found {f.name} {attributes}" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if self._private_to_internal: |
|
|
|
|
for variable in contract.state_variables_declared: |
|
|
|
|
if variable.visibility == "private": |
|
|
|
@ -186,6 +218,10 @@ class Flattening: |
|
|
|
|
index = index - start |
|
|
|
|
if patch_type == "public_to_external": |
|
|
|
|
content = content[:index] + "public" + content[index + len("external") :] |
|
|
|
|
elif patch_type == "external_to_internal": |
|
|
|
|
content = content[:index] + "internal" + content[index + len("external") :] |
|
|
|
|
elif patch_type == "public_to_internal": |
|
|
|
|
content = content[:index] + "internal" + content[index + len("public") :] |
|
|
|
|
elif patch_type == "private_to_internal": |
|
|
|
|
content = content[:index] + "internal" + content[index + len("private") :] |
|
|
|
|
elif patch_type == "calldata_to_memory": |
|
|
|
|