mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add Solidity generators
This commit is contained in:
parent
38d1ec3efe
commit
cbbefce443
@ -297,6 +297,10 @@ bool CompilerStack::parse()
|
||||
|
||||
storeContractDefinitions();
|
||||
|
||||
if (!m_hasError)
|
||||
std::cout << "Fuzzer: Parsing successful" << std::endl;
|
||||
else
|
||||
std::cout << "Fuzzer: Parsing failure" << std::endl;
|
||||
return !m_hasError;
|
||||
}
|
||||
|
||||
@ -478,6 +482,11 @@ bool CompilerStack::analyze()
|
||||
if (!noErrors)
|
||||
m_hasError = true;
|
||||
|
||||
if (!m_hasError)
|
||||
std::cout << "Fuzzer: Analysis successful" << std::endl;
|
||||
else
|
||||
std::cout << "Fuzzer: Analysis failure" << std::endl;
|
||||
|
||||
return !m_hasError;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <libsolc/libsolc.h>
|
||||
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/SourceReferenceFormatter.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -81,7 +82,7 @@ void FuzzerUtil::forceSMT(StringMap& _input)
|
||||
sourceUnit.second += smtPragma;
|
||||
}
|
||||
|
||||
void FuzzerUtil::testCompiler(StringMap& _input, bool _optimize, unsigned _rand, bool _forceSMT)
|
||||
FuzzerUtil::Error FuzzerUtil::testCompiler(StringMap& _input, bool _optimize, unsigned _rand, bool _forceSMT)
|
||||
{
|
||||
frontend::CompilerStack compiler;
|
||||
EVMVersion evmVersion = s_evmVersions[_rand % s_evmVersions.size()];
|
||||
@ -100,19 +101,35 @@ void FuzzerUtil::testCompiler(StringMap& _input, bool _optimize, unsigned _rand,
|
||||
compiler.setOptimiserSettings(optimiserSettings);
|
||||
try
|
||||
{
|
||||
compiler.compile();
|
||||
if (!compiler.compile())
|
||||
{
|
||||
langutil::SourceReferenceFormatter formatter(std::cerr, false, false);
|
||||
|
||||
for (auto const& error: compiler.errors())
|
||||
formatter.printExceptionInformation(
|
||||
*error,
|
||||
formatter.formatErrorInformation(*error)
|
||||
);
|
||||
return Error::FAILURE;
|
||||
}
|
||||
else
|
||||
return Error::SUCCESS;
|
||||
}
|
||||
catch (Error const&)
|
||||
{
|
||||
return Error::EXCEPTION;
|
||||
}
|
||||
catch (FatalError const&)
|
||||
{
|
||||
return Error::EXCEPTION;
|
||||
}
|
||||
catch (UnimplementedFeatureError const&)
|
||||
{
|
||||
return Error::EXCEPTION;
|
||||
}
|
||||
catch (StackTooDeepError const&)
|
||||
{
|
||||
return Error::EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,12 @@
|
||||
*/
|
||||
struct FuzzerUtil
|
||||
{
|
||||
enum class Error
|
||||
{
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
EXCEPTION
|
||||
};
|
||||
static void runCompiler(std::string const& _input, bool _quiet);
|
||||
static void testCompilerJsonInterface(std::string const& _input, bool _optimize, bool _quiet);
|
||||
static void testConstantOptimizer(std::string const& _input, bool _quiet);
|
||||
@ -37,7 +43,7 @@ struct FuzzerUtil
|
||||
/// version to be compiled for, and bool @param _forceSMT that, if true,
|
||||
/// adds the experimental SMTChecker pragma to each source file in the
|
||||
/// source map.
|
||||
static void testCompiler(
|
||||
static Error testCompiler(
|
||||
solidity::StringMap& _input,
|
||||
bool _optimize,
|
||||
unsigned _rand,
|
||||
|
@ -41,6 +41,20 @@
|
||||
*
|
||||
*/
|
||||
#define GENERATORLIST(MACRO, SEP, ENDSEP) \
|
||||
MACRO(ConstantVariableDeclaration) SEP \
|
||||
MACRO(ContractDefinitionGenerator) SEP \
|
||||
MACRO(EnumDeclaration) SEP \
|
||||
MACRO(ExpressionGenerator) SEP \
|
||||
MACRO(FunctionDefinitionGenerator) SEP \
|
||||
MACRO(ImportGenerator) SEP \
|
||||
MACRO(LocationGenerator) SEP \
|
||||
MACRO(NatSpecGenerator) SEP \
|
||||
MACRO(ParameterListGenerator) SEP \
|
||||
MACRO(PragmaGenerator) SEP \
|
||||
MACRO(SimpleVarDeclGenerator) SEP \
|
||||
MACRO(SourceUnitGenerator) SEP \
|
||||
MACRO(TestCaseGenerator) ENDSEP
|
||||
MACRO(StatementGenerator) SEP \
|
||||
MACRO(StateVariableDeclarationGenerator) SEP \
|
||||
MACRO(TestCaseGenerator) SEP \
|
||||
MACRO(VariableDeclarationGenerator) ENDSEP
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
56
test/tools/ossfuzz/Types.h
Normal file
56
test/tools/ossfuzz/Types.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
/**
|
||||
* Convenience macros for Solidity type declarations.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/preprocessor.hpp>
|
||||
|
||||
#define BYTES_ENUM_ELEM(z, n, unused) BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) BOOST_PP_IF(BOOST_PP_NOT(BOOST_PP_EQUAL(n, 33)), BOOST_PP_CAT(BYTES, n), BYTES)
|
||||
#define INTEGER_ENUM_ELEM(z, n, typeString) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(typeString, BOOST_PP_MUL(BOOST_PP_INC(n), 8))
|
||||
|
||||
#define ENUM_SWITCH_CASE(r, data, elem) \
|
||||
case data::elem: \
|
||||
return boost::algorithm::to_lower_copy(std::string(BOOST_PP_STRINGIZE(elem)));
|
||||
|
||||
#define TYPE_ENUM_DECLS(typeName, ...) \
|
||||
enum class typeName: size_t \
|
||||
{ \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
static std::string toString(typeName e) \
|
||||
{ \
|
||||
switch(e) \
|
||||
{ \
|
||||
BOOST_PP_SEQ_FOR_EACH( \
|
||||
ENUM_SWITCH_CASE, \
|
||||
typeName, \
|
||||
BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
|
||||
) \
|
||||
} \
|
||||
} \
|
||||
static std::pair<typeName, std::string> BOOST_PP_CAT(indexed, BOOST_PP_CAT(typeName, Type))(size_t _index) \
|
||||
{ \
|
||||
auto t = typeName(_index); \
|
||||
return std::pair(t, toString(t)); \
|
||||
} \
|
||||
static std::pair<typeName, std::string> BOOST_PP_CAT(random, BOOST_PP_CAT(typeName, Type))();
|
||||
|
@ -30,7 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size <= 600)
|
||||
if (_size <= 10240)
|
||||
{
|
||||
string input(reinterpret_cast<char const*>(_data), _size);
|
||||
map<string, string> sourceCode;
|
||||
@ -43,12 +43,18 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
FuzzerUtil::testCompiler(
|
||||
auto e = FuzzerUtil::testCompiler(
|
||||
sourceCode,
|
||||
/*optimize=*/false,
|
||||
/*_rand=*/static_cast<unsigned>(_size),
|
||||
/*forceSMT=*/true
|
||||
);
|
||||
if (e == FuzzerUtil::Error::SUCCESS)
|
||||
std::cout << "Compiler: Success" << std::endl;
|
||||
else if (e == FuzzerUtil::Error::FAILURE)
|
||||
std::cout << "Compiler: Failure" << std::endl;
|
||||
else
|
||||
std::cout << "Compiler: Exception" << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user