2019-05-15 19:09:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-12-04 14:31:32 +00:00
|
|
|
#include <test/EVMHost.h>
|
|
|
|
|
2019-05-15 19:09:44 +00:00
|
|
|
#include <libsolidity/interface/CompilerStack.h>
|
2019-07-16 09:11:20 +00:00
|
|
|
|
2019-05-15 19:09:44 +00:00
|
|
|
#include <libyul/AssemblyStack.h>
|
2019-07-16 09:11:20 +00:00
|
|
|
|
2019-05-15 19:09:44 +00:00
|
|
|
#include <liblangutil/Exceptions.h>
|
|
|
|
#include <liblangutil/SourceReferenceFormatter.h>
|
2019-07-16 09:11:20 +00:00
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/Keccak256.h>
|
2019-05-15 19:09:44 +00:00
|
|
|
|
2020-12-04 14:31:32 +00:00
|
|
|
#include <evmone/evmone.h>
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::test::abiv2fuzzer
|
2019-05-15 19:09:44 +00:00
|
|
|
{
|
|
|
|
class SolidityCompilationFramework
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SolidityCompilationFramework(langutil::EVMVersion _evmVersion = {});
|
|
|
|
|
|
|
|
Json::Value getMethodIdentifiers()
|
|
|
|
{
|
|
|
|
return m_compiler.methodIdentifiers(m_compiler.lastContractName());
|
|
|
|
}
|
2019-12-23 15:50:30 +00:00
|
|
|
bytes compileContract(
|
2019-05-15 19:09:44 +00:00
|
|
|
std::string const& _sourceCode,
|
2020-04-20 12:28:38 +00:00
|
|
|
std::string const& _contractName,
|
|
|
|
std::map<std::string, solidity::util::h160> const& _libraryAddresses = {},
|
|
|
|
frontend::OptimiserSettings _optimization = frontend::OptimiserSettings::minimal()
|
2019-05-15 19:09:44 +00:00
|
|
|
);
|
|
|
|
protected:
|
2019-12-23 15:50:30 +00:00
|
|
|
frontend::CompilerStack m_compiler;
|
2019-05-15 19:09:44 +00:00
|
|
|
langutil::EVMVersion m_evmVersion;
|
|
|
|
};
|
2019-12-23 15:50:30 +00:00
|
|
|
|
2020-12-04 14:31:32 +00:00
|
|
|
struct AbiV2Utility
|
|
|
|
{
|
|
|
|
/// Compares the contents of the memory address pointed to
|
|
|
|
/// by `_result` of `_length` bytes to the expected output.
|
|
|
|
/// Returns true if `_result` matches expected output, false
|
|
|
|
/// otherwise.
|
|
|
|
static bool isOutputExpected(
|
|
|
|
uint8_t const* _result,
|
|
|
|
size_t _length,
|
|
|
|
std::vector<uint8_t> const& _expectedOutput
|
|
|
|
);
|
|
|
|
/// Accepts a reference to a user-specified input and returns an
|
|
|
|
/// evmc_message with all of its fields zero initialized except
|
|
|
|
/// gas and input fields.
|
|
|
|
/// The gas field is set to the maximum permissible value so that we
|
|
|
|
/// don't run into out of gas errors. The input field is copied from
|
|
|
|
/// user input.
|
|
|
|
static evmc_message initializeMessage(bytes const& _input);
|
|
|
|
/// Accepts host context implementation, and keccak256 hash of the function
|
|
|
|
/// to be called at a specified address in the simulated blockchain as
|
|
|
|
/// input and returns the result of the execution of the called function.
|
|
|
|
static evmc::result executeContract(
|
|
|
|
EVMHost& _hostContext,
|
|
|
|
bytes const& _functionHash,
|
|
|
|
evmc_address _deployedAddress
|
|
|
|
);
|
|
|
|
/// Accepts a reference to host context implementation and byte code
|
|
|
|
/// as input and deploys it on the simulated blockchain. Returns the
|
|
|
|
/// result of deployment.
|
|
|
|
static evmc::result deployContract(EVMHost& _hostContext, bytes const& _code);
|
|
|
|
};
|
|
|
|
|
2019-05-15 19:09:44 +00:00
|
|
|
}
|