mirror of
https://github.com/trailofbits/manticore.git
synced 2026-10-12 02:23:44 +00:00
Add support for multiple compilation units (#2444)
* Add support for multiple compilation units See https://github.com/crytic/crytic-compile/pull/167 * update setup.py * Use crytic-compile@master * Update setup.py
This commit is contained in:
@@ -270,36 +270,43 @@ class ManticoreEVM(ManticoreBase):
|
||||
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"
|
||||
)
|
||||
|
||||
if contract_name not in crytic_compile.contracts_names:
|
||||
raise ValueError(f"Specified contract not found: {contract_name}")
|
||||
for compilation_unit in crytic_compile.compilation_units.values():
|
||||
|
||||
name = contract_name
|
||||
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]
|
||||
|
||||
libs = crytic_compile.libraries_names(name)
|
||||
if libraries:
|
||||
libs = [l for l in libs if l not in libraries]
|
||||
if libs:
|
||||
raise DependencyError(libs)
|
||||
if contract_name not in compilation_unit.contracts_names:
|
||||
raise ValueError(f"Specified contract not found: {contract_name}")
|
||||
|
||||
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)
|
||||
name = contract_name
|
||||
|
||||
filename = crytic_compile.filename_of_contract(name).absolute
|
||||
with open(filename) as f:
|
||||
source_code = f.read()
|
||||
libs = compilation_unit.libraries_names(name)
|
||||
if libraries:
|
||||
libs = [l for l in libs if l not in libraries]
|
||||
if libs:
|
||||
raise DependencyError(libs)
|
||||
|
||||
return name, source_code, bytecode, runtime, srcmap, srcmap_runtime, hashes, abi
|
||||
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 = 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
|
||||
|
||||
except InvalidCompilation as e:
|
||||
raise EthereumError(
|
||||
|
||||
Reference in New Issue
Block a user