mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor contract ABI Utils a bit to get it to build with solc ossfuzz. Untested.
This commit is contained in:
@@ -29,6 +29,7 @@ if (OSSFUZZ)
|
||||
../../TestCaseReader.cpp
|
||||
../../EVMHost.cpp
|
||||
SolidityEvmoneInterface.cpp
|
||||
../../libsolidity/util/ContractABIUtils.cpp
|
||||
)
|
||||
target_link_libraries(solc_ossfuzz PRIVATE libsolc evmasm evmc evmone-standalone)
|
||||
set_target_properties(solc_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <range/v3/algorithm/all_of.hpp>
|
||||
#include <range/v3/span.hpp>
|
||||
#include <random>
|
||||
|
||||
using namespace solidity::test::fuzzer;
|
||||
using namespace solidity::frontend;
|
||||
@@ -74,6 +75,20 @@ optional<string> SolidityCompilationFramework::noInputFunction()
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<Json::Value> SolidityCompilationFramework::randomFunction()
|
||||
{
|
||||
Json::Value const& contractABI = m_compiler.contractABI(m_compiler.lastContractName());
|
||||
unsigned numFunctions = contractABI.size();
|
||||
if (numFunctions == 0)
|
||||
return {};
|
||||
else
|
||||
{
|
||||
uniform_int_distribution<unsigned> d(0, contractABI.size());
|
||||
minstd_rand r(contractABI.size());
|
||||
return contractABI[d(r)];
|
||||
}
|
||||
}
|
||||
|
||||
bool EvmoneUtility::zeroWord(uint8_t const* _result, size_t _length)
|
||||
{
|
||||
return _length == 32 &&
|
||||
|
||||
@@ -100,6 +100,9 @@ public:
|
||||
/// @returns name of a public/external method that does not contain
|
||||
/// input parameters in its signature.
|
||||
std::optional<std::string> noInputFunction();
|
||||
/// @returns FunctionABI of a randomly chosen external function in
|
||||
/// current contract.
|
||||
std::optional<Json::Value> randomFunction();
|
||||
/// @returns name of the last contract in source unit.
|
||||
std::string lastContractName()
|
||||
{
|
||||
@@ -178,6 +181,10 @@ public:
|
||||
{
|
||||
return m_compilationFramework.noInputFunction();
|
||||
}
|
||||
std::optional<Json::Value> randomFunction()
|
||||
{
|
||||
return m_compilationFramework.randomFunction();
|
||||
}
|
||||
void optSetting(frontend::OptimiserSettings _opt)
|
||||
{
|
||||
m_compilationFramework.optSetting(_opt);
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include <test/TestCaseReader.h>
|
||||
|
||||
#include <libsolidity/util/ContractABIUtils.h>
|
||||
|
||||
#include <libyul/backends/evm/EVMCodeTransform.h>
|
||||
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
@@ -84,6 +86,8 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
return 0;
|
||||
|
||||
optional<string> noInputFunction = evmoneUtil.noInputFunction();
|
||||
if (auto r = evmoneUtil.randomFunction(); r.has_value())
|
||||
cout << ContractABIUtils{}.functionSignatureFromABI(r.value()) << endl;
|
||||
if (noInputFunction.has_value())
|
||||
evmoneUtil.methodName(noInputFunction.value());
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user