Skip to content

Commit

Permalink
Merge pull request #6627 from ethereum/add-memory-log
Browse files Browse the repository at this point in the history
Proto fuzzer: Add missing memory and log opcodes and fix visitation bug
  • Loading branch information
chriseth authored Apr 30, 2019
2 parents 2bb68e2 + d894ffa commit 18104a0
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
95 changes: 95 additions & 0 deletions test/tools/ossfuzz/protoToYul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ void ProtoConverter::visit(Expression const& _x)
case Expression::kUnop:
visit(_x.unop());
break;
case Expression::kTop:
visit(_x.top());
break;
case Expression::kNop:
visit(_x.nop());
break;
case Expression::EXPR_ONEOF_NOT_SET:
m_output << "1";
break;
Expand Down Expand Up @@ -327,6 +333,89 @@ void ProtoConverter::visit(TernaryOp const& _x)
m_output << ")";
}

void ProtoConverter::visit(NullaryOp const& _x)
{
switch (_x.op())
{
case NullaryOp::PC:
m_output << "pc()";
break;
case NullaryOp::MSIZE:
m_output << "msize()";
break;
case NullaryOp::GAS:
m_output << "gas()";
break;
}
}

void ProtoConverter::visit(LogFunc const& _x)
{
switch (_x.num_topics())
{
case LogFunc::ZERO:
m_output << "log0";
m_output << "(";
visit(_x.pos());
m_output << ", ";
visit(_x.size());
m_output << ")\n";
break;
case LogFunc::ONE:
m_output << "log1";
m_output << "(";
visit(_x.pos());
m_output << ", ";
visit(_x.size());
m_output << ", ";
visit(_x.t1());
m_output << ")\n";
break;
case LogFunc::TWO:
m_output << "log2";
m_output << "(";
visit(_x.pos());
m_output << ", ";
visit(_x.size());
m_output << ", ";
visit(_x.t1());
m_output << ", ";
visit(_x.t2());
m_output << ")\n";
break;
case LogFunc::THREE:
m_output << "log3";
m_output << "(";
visit(_x.pos());
m_output << ", ";
visit(_x.size());
m_output << ", ";
visit(_x.t1());
m_output << ", ";
visit(_x.t2());
m_output << ", ";
visit(_x.t3());
m_output << ")\n";
break;
case LogFunc::FOUR:
m_output << "log4";
m_output << "(";
visit(_x.pos());
m_output << ", ";
visit(_x.size());
m_output << ", ";
visit(_x.t1());
m_output << ", ";
visit(_x.t2());
m_output << ", ";
visit(_x.t3());
m_output << ", ";
visit(_x.t4());
m_output << ")\n";
break;
}
}

void ProtoConverter::visit(AssignmentStatement const& _x)
{
visit(_x.ref_id());
Expand All @@ -353,6 +442,9 @@ void ProtoConverter::visit(StoreFunc const& _x)
case StoreFunc::SSTORE:
m_output << "sstore(";
break;
case StoreFunc::MSTORE8:
m_output << "mstore8(";
break;
}
visit(_x.loc());
m_output << ", ";
Expand Down Expand Up @@ -440,6 +532,9 @@ void ProtoConverter::visit(Statement const& _x)
if (m_inForScope.top())
m_output << "continue\n";
break;
case Statement::kLogFunc:
visit(_x.log_func());
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions test/tools/ossfuzz/protoToYul.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ProtoConverter
void visit(CaseStmt const&);
void visit(SwitchStmt const&);
void visit(TernaryOp const&);
void visit(NullaryOp const&);
void visit(LogFunc const&);
template <class T>
void visit(google::protobuf::RepeatedPtrField<T> const& _repeated_field);

Expand Down
30 changes: 30 additions & 0 deletions test/tools/ossfuzz/yulProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,51 @@ message TernaryOp {
required Expression arg3 = 4;
}

message NullaryOp {
enum NOp {
PC = 1;
MSIZE = 2;
GAS = 3;
}
required NOp op = 1;
}

message StoreFunc {
enum Storage {
MSTORE = 0;
SSTORE = 1;
MSTORE8 = 2;
}
required Expression loc = 1;
required Expression val = 2;
required Storage st = 3;
}

message LogFunc {
enum NumTopics {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
FOUR = 4;
}
required Expression pos = 1;
required Expression size = 2;
required NumTopics num_topics = 3;
required Expression t1 = 4;
required Expression t2 = 5;
required Expression t3 = 6;
required Expression t4 = 7;
}

message Expression {
oneof expr_oneof {
VarRef varref = 1;
Literal cons = 2;
BinaryOp binop = 3;
UnaryOp unop = 4;
TernaryOp top = 5;
NullaryOp nop = 6;
}
}

Expand Down Expand Up @@ -180,6 +209,7 @@ message Statement {
SwitchStmt switchstmt = 7;
BreakStmt breakstmt = 8;
ContinueStmt contstmt = 9;
LogFunc log_func = 10;
}
}

Expand Down

0 comments on commit 18104a0

Please sign in to comment.