Skip to content

Commit

Permalink
Add support for multiple compilation units (#2444)
Browse files Browse the repository at this point in the history
* Add support for multiple compilation units
See crytic/crytic-compile#167

* update setup.py

* Use crytic-compile@master

* Update setup.py
  • Loading branch information
montyly authored May 10, 2021
1 parent eb4f208 commit 809bc76
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
55 changes: 31 additions & 24 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,36 +270,43 @@ def _compile_through_crytic_compile(filename, contract_name, libraries, crytic_c
else:
crytic_compile = CryticCompile(filename)

if not contract_name:
if len(crytic_compile.contracts_names_without_libraries) > 1:
raise EthereumError(
f"Solidity file must contain exactly one contract or you must select one. Contracts found: {', '.join(crytic_compile.contracts_names)}"
)
contract_name = list(crytic_compile.contracts_names_without_libraries)[0]
if crytic_compile.is_in_multiple_compilation_unit(contract_name):
raise EthereumError(
f"{contract_name} is shared in multiple compilation units, please split the codebase to prevent the duplicate"
)

for compilation_unit in crytic_compile.compilation_units.values():

if not contract_name:
if len(compilation_unit.contracts_names_without_libraries) > 1:
raise EthereumError(
f"Solidity file must contain exactly one contract or you must select one. Contracts found: {', '.join(compilation_unit.contracts_names)}"
)
contract_name = list(compilation_unit.contracts_names_without_libraries)[0]

if contract_name not in crytic_compile.contracts_names:
raise ValueError(f"Specified contract not found: {contract_name}")
if contract_name not in compilation_unit.contracts_names:
raise ValueError(f"Specified contract not found: {contract_name}")

name = contract_name
name = contract_name

libs = crytic_compile.libraries_names(name)
if libraries:
libs = [l for l in libs if l not in libraries]
if libs:
raise DependencyError(libs)
libs = compilation_unit.libraries_names(name)
if libraries:
libs = [l for l in libs if l not in libraries]
if libs:
raise DependencyError(libs)

bytecode = bytes.fromhex(crytic_compile.bytecode_init(name, libraries))
runtime = bytes.fromhex(crytic_compile.bytecode_runtime(name, libraries))
srcmap = crytic_compile.srcmap_init(name)
srcmap_runtime = crytic_compile.srcmap_runtime(name)
hashes = crytic_compile.hashes(name)
abi = crytic_compile.abi(name)
bytecode = bytes.fromhex(compilation_unit.bytecode_init(name, libraries))
runtime = bytes.fromhex(compilation_unit.bytecode_runtime(name, libraries))
srcmap = compilation_unit.srcmap_init(name)
srcmap_runtime = compilation_unit.srcmap_runtime(name)
hashes = compilation_unit.hashes(name)
abi = compilation_unit.abi(name)

filename = crytic_compile.filename_of_contract(name).absolute
with open(filename) as f:
source_code = f.read()
filename = compilation_unit.filename_of_contract(name).absolute
with open(filename) as f:
source_code = f.read()

return name, source_code, bytecode, runtime, srcmap, srcmap_runtime, hashes, abi
return name, source_code, bytecode, runtime, srcmap, srcmap_runtime, hashes, abi

except InvalidCompilation as e:
raise EthereumError(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def rtd_dependent_deps():
"prettytable",
"ply",
"rlp",
"crytic-compile>=0.1.8",
"crytic-compile>=0.2.0",
"wasm",
"dataclasses; python_version < '3.7'",
"pyevmasm>=0.2.3",
Expand Down

0 comments on commit 809bc76

Please sign in to comment.