Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.
This repository was archived by the owner on May 26, 2023. It is now read-only.

Upcoming changes in CryticCompile #417

@montyly

Description

@montyly

Hi,

We are about to change CryticCompile to add the support for multiple compilation units (crytic/crytic-compile#167). The reason is that it's a feature that we are seeing more and more in hardhat projects.

As a result, this will not work with the next crytic-compile release:

def _extract_bin_obj(self, com: CryticCompile):
return [(com.contracts_filenames[name].absolute + ':' + name, com.bytecode_runtime(name)) for name in com.contracts_names if com.bytecode_runtime(name)]
def _compile_solidity(self):
try:
options = []
if self.allow_paths:
options.append(F"--allow-paths {self.allow_paths}")
com = CryticCompile(self.source, solc_remaps=self.remap, solc_args=' '.join(options))
contracts = self._extract_bin_obj(com)
libs = com.contracts_names.difference(com.contracts_names_without_libraries)
if libs:
return self._link_libraries(self.source, libs)
return contracts

_extract_bin_obj can be replaced by

    def _extract_bin_obj(self, com: CryticCompile):
        ret = []
        for compilation_unit in com.compilation_units.values():
            ret += [
                (
                    compilation_unit.contracts_filenames[name].absolute + ":" + name,
                    compilation_unit.bytecode_runtime(name),
                )
                for name in compilation_unit.contracts_names
                if compilation_unit.bytecode_runtime(name)
            ]
        return ret

However, the way oyente deals with libraries is fragile and won't work well here (additionally it only works with direct solc compilation, and won't work with truffle/hardhat etc). I would recommend giving the libraries to bytecode_runtime, which can take an optional libraries parameter: a dictionary from name to address, and let crytic-compile patch the bytecode with the librairies' addresses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions