| 128 | } |
| 129 | |
| 130 | evmc::Result EvmoneUtility::compileDeployAndExecute(std::string _fuzzIsabelle) |
| 131 | { |
| 132 | std::map<std::string, h160> libraryAddressMap; |
| 133 | // Stage 1: Compile and deploy library if present. |
| 134 | if (!m_libraryName.empty()) |
| 135 | { |
| 136 | m_compilationFramework.contractName(m_libraryName); |
| 137 | auto compilationOutput = m_compilationFramework.compileContract(); |
| 138 | solAssert(compilationOutput.has_value(), "Compiling library failed"); |
| 139 | CompilerOutput cOutput = compilationOutput.value(); |
| 140 | // Deploy contract and signal failure if deploy failed |
| 141 | evmc::Result createResult = deployContract(cOutput.byteCode); |
| 142 | solAssert( |
| 143 | createResult.status_code == EVMC_SUCCESS, |
| 144 | "SolidityEvmoneInterface: Library deployment failed" |
| 145 | ); |
| 146 | libraryAddressMap[m_libraryName] = EVMHost::convertFromEVMC(createResult.create_address); |
| 147 | m_compilationFramework.libraryAddresses(libraryAddressMap); |
| 148 | } |
| 149 | |
| 150 | // Stage 2: Compile, deploy, and execute contract, optionally using library |
| 151 | // address map. |
| 152 | m_compilationFramework.contractName(m_contractName); |
| 153 | auto cOutput = m_compilationFramework.compileContract(); |
| 154 | solAssert(cOutput.has_value(), "Compiling contract failed"); |
| 155 | solAssert( |
| 156 | !cOutput->byteCode.empty() && !cOutput->methodIdentifiersInContract.empty(), |
| 157 | "SolidityEvmoneInterface: Invalid compilation output." |
| 158 | ); |
| 159 | |
| 160 | std::string methodName; |
| 161 | if (!_fuzzIsabelle.empty()) |
| 162 | // TODO: Remove this once a cleaner solution is found for querying |
| 163 | // isabelle test entry point. At the moment, we are sure that the |
| 164 | // entry point is the second method in the contract (hence the ++) |
| 165 | // but not its name. |
| 166 | methodName = (++cOutput->methodIdentifiersInContract.begin())->get<std::string>() + |
| 167 | _fuzzIsabelle.substr(2, _fuzzIsabelle.size()); |
| 168 | else |
| 169 | methodName = cOutput->methodIdentifiersInContract[m_methodName].get<std::string>(); |
| 170 | |
| 171 | return deployAndExecute( |
| 172 | cOutput->byteCode, |
| 173 | methodName |
| 174 | ); |
| 175 | } |
| 176 | |
| 177 | std::optional<CompilerOutput> EvmoneUtility::compileContract() |
| 178 | { |
no test coverage detected