mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7607 from ethereum/add-leave
yul proto: Add leave statement
This commit is contained in:
commit
106d8ec3b6
@ -1091,6 +1091,10 @@ void ProtoConverter::visit(Statement const& _x)
|
|||||||
case Statement::kPop:
|
case Statement::kPop:
|
||||||
visit(_x.pop());
|
visit(_x.pop());
|
||||||
break;
|
break;
|
||||||
|
case Statement::kLeave:
|
||||||
|
if (m_inFunctionDef)
|
||||||
|
visit(_x.leave());
|
||||||
|
break;
|
||||||
case Statement::STMT_ONEOF_NOT_SET:
|
case Statement::STMT_ONEOF_NOT_SET:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1384,6 +1388,11 @@ void ProtoConverter::visit(PopStmt const& _x)
|
|||||||
m_output << ")\n";
|
m_output << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProtoConverter::visit(LeaveStmt const&)
|
||||||
|
{
|
||||||
|
m_output << "leave\n";
|
||||||
|
}
|
||||||
|
|
||||||
string ProtoConverter::getObjectIdentifier(ObjectId const& _x)
|
string ProtoConverter::getObjectIdentifier(ObjectId const& _x)
|
||||||
{
|
{
|
||||||
unsigned currentId = currentObjectId();
|
unsigned currentId = currentObjectId();
|
||||||
|
@ -90,6 +90,7 @@ private:
|
|||||||
void visit(FunctionCall const&);
|
void visit(FunctionCall const&);
|
||||||
void visit(FunctionDef const&);
|
void visit(FunctionDef const&);
|
||||||
void visit(PopStmt const&);
|
void visit(PopStmt const&);
|
||||||
|
void visit(LeaveStmt const&);
|
||||||
void visit(LowLevelCall const&);
|
void visit(LowLevelCall const&);
|
||||||
void visit(Create const&);
|
void visit(Create const&);
|
||||||
void visit(UnaryOpData const&);
|
void visit(UnaryOpData const&);
|
||||||
|
@ -78,35 +78,21 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
|||||||
|
|
||||||
ostringstream os1;
|
ostringstream os1;
|
||||||
ostringstream os2;
|
ostringstream os2;
|
||||||
try
|
yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret(
|
||||||
{
|
|
||||||
yulFuzzerUtil::interpret(
|
|
||||||
os1,
|
os1,
|
||||||
stack.parserResult()->code,
|
stack.parserResult()->code,
|
||||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion())
|
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion())
|
||||||
);
|
);
|
||||||
}
|
if (termReason == yulFuzzerUtil::TerminationReason::StepLimitReached)
|
||||||
catch (yul::test::StepLimitReached const&)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
catch (yul::test::InterpreterTerminatedGeneric const&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.optimize();
|
stack.optimize();
|
||||||
try
|
termReason = yulFuzzerUtil::interpret(
|
||||||
{
|
|
||||||
yulFuzzerUtil::interpret(
|
|
||||||
os2,
|
os2,
|
||||||
stack.parserResult()->code,
|
stack.parserResult()->code,
|
||||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion()),
|
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion()),
|
||||||
(yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 1.5)
|
(yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 4)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
catch (yul::test::InterpreterTerminatedGeneric const&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTraceEq = (os1.str() == os2.str());
|
bool isTraceEq = (os1.str() == os2.str());
|
||||||
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");
|
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");
|
||||||
|
@ -20,7 +20,7 @@ using namespace std;
|
|||||||
using namespace yul;
|
using namespace yul;
|
||||||
using namespace yul::test::yul_fuzzer;
|
using namespace yul::test::yul_fuzzer;
|
||||||
|
|
||||||
void yulFuzzerUtil::interpret(
|
yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret(
|
||||||
ostream& _os,
|
ostream& _os,
|
||||||
shared_ptr<yul::Block> _ast,
|
shared_ptr<yul::Block> _ast,
|
||||||
Dialect const& _dialect,
|
Dialect const& _dialect,
|
||||||
@ -44,6 +44,25 @@ void yulFuzzerUtil::interpret(
|
|||||||
0x8e, 0xf3, 0x9b, 0xe4, 0x4f, 0x6c, 0x14, 0xde
|
0x8e, 0xf3, 0x9b, 0xe4, 0x4f, 0x6c, 0x14, 0xde
|
||||||
};
|
};
|
||||||
Interpreter interpreter(state, _dialect);
|
Interpreter interpreter(state, _dialect);
|
||||||
|
|
||||||
|
TerminationReason reason = TerminationReason::None;
|
||||||
|
try
|
||||||
|
{
|
||||||
interpreter(*_ast);
|
interpreter(*_ast);
|
||||||
state.dumpTraceAndState(_os);
|
}
|
||||||
|
catch (StepLimitReached const&)
|
||||||
|
{
|
||||||
|
reason = TerminationReason::StepLimitReached;
|
||||||
|
}
|
||||||
|
catch (TraceLimitReached const&)
|
||||||
|
{
|
||||||
|
reason = TerminationReason::TraceLimitReached;
|
||||||
|
}
|
||||||
|
catch (ExplicitlyTerminated const&)
|
||||||
|
{
|
||||||
|
reason = TerminationReason::ExplicitlyTerminated;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.dumpTraceAndState(_os);
|
||||||
|
return reason;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,15 @@ namespace yul_fuzzer
|
|||||||
{
|
{
|
||||||
struct yulFuzzerUtil
|
struct yulFuzzerUtil
|
||||||
{
|
{
|
||||||
static void interpret(
|
enum class TerminationReason
|
||||||
|
{
|
||||||
|
ExplicitlyTerminated,
|
||||||
|
StepLimitReached,
|
||||||
|
TraceLimitReached,
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
static TerminationReason interpret(
|
||||||
std::ostream& _os,
|
std::ostream& _os,
|
||||||
std::shared_ptr<yul::Block> _ast,
|
std::shared_ptr<yul::Block> _ast,
|
||||||
Dialect const& _dialect,
|
Dialect const& _dialect,
|
||||||
|
@ -359,6 +359,8 @@ message PopStmt {
|
|||||||
required Expression expr = 1;
|
required Expression expr = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message LeaveStmt {}
|
||||||
|
|
||||||
message Statement {
|
message Statement {
|
||||||
oneof stmt_oneof {
|
oneof stmt_oneof {
|
||||||
VarDecl decl = 1;
|
VarDecl decl = 1;
|
||||||
@ -378,6 +380,7 @@ message Statement {
|
|||||||
BoundedForStmt boundedforstmt = 15;
|
BoundedForStmt boundedforstmt = 15;
|
||||||
FunctionDef funcdef = 16;
|
FunctionDef funcdef = 16;
|
||||||
PopStmt pop = 17;
|
PopStmt pop = 17;
|
||||||
|
LeaveStmt leave = 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,6 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
|||||||
of.write(yul_source.data(), yul_source.size());
|
of.write(yul_source.data(), yul_source.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yul_source.size() > 1200)
|
|
||||||
return;
|
|
||||||
|
|
||||||
YulStringRepository::reset();
|
YulStringRepository::reset();
|
||||||
|
|
||||||
// AssemblyStack entry point
|
// AssemblyStack entry point
|
||||||
@ -95,35 +92,22 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
|||||||
|
|
||||||
ostringstream os1;
|
ostringstream os1;
|
||||||
ostringstream os2;
|
ostringstream os2;
|
||||||
try
|
yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret(
|
||||||
{
|
|
||||||
yulFuzzerUtil::interpret(
|
|
||||||
os1,
|
os1,
|
||||||
stack.parserResult()->code,
|
stack.parserResult()->code,
|
||||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion())
|
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion())
|
||||||
);
|
);
|
||||||
}
|
|
||||||
catch (yul::test::StepLimitReached const&)
|
if (termReason == yulFuzzerUtil::TerminationReason::StepLimitReached)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
catch (yul::test::InterpreterTerminatedGeneric const&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.optimize();
|
stack.optimize();
|
||||||
try
|
termReason = yulFuzzerUtil::interpret(
|
||||||
{
|
|
||||||
yulFuzzerUtil::interpret(
|
|
||||||
os2,
|
os2,
|
||||||
stack.parserResult()->code,
|
stack.parserResult()->code,
|
||||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion()),
|
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion()),
|
||||||
(yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 1.5)
|
(yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 4)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
catch (yul::test::InterpreterTerminatedGeneric const&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTraceEq = (os1.str() == os2.str());
|
bool isTraceEq = (os1.str() == os2.str());
|
||||||
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");
|
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");
|
||||||
|
Loading…
Reference in New Issue
Block a user