Yul proto fuzzer: Add create and call opcodes

This commit is contained in:
Bhargava Shastry 2019-09-04 16:05:26 +02:00 committed by chriseth
parent 6b27ef8fcb
commit c889e6e015
3 changed files with 103 additions and 0 deletions

View File

@ -152,6 +152,12 @@ void ProtoConverter::visit(Expression const& _x)
else
m_output << dictionaryToken();
break;
case Expression::kLowcall:
visit(_x.lowcall());
break;
case Expression::kCreate:
visit(_x.create());
break;
case Expression::EXPR_ONEOF_NOT_SET:
m_output << dictionaryToken();
break;
@ -713,6 +719,68 @@ void ProtoConverter::visit(FunctionCall const& _x)
}
}
void ProtoConverter::visit(LowLevelCall const& _x)
{
LowLevelCall_Type type = _x.callty();
switch (type)
{
case LowLevelCall::CALL:
m_output << "call(";
break;
case LowLevelCall::CALLCODE:
m_output << "callcode(";
break;
case LowLevelCall::DELEGATECALL:
m_output << "delegatecall(";
break;
case LowLevelCall::STATICCALL:
m_output << "staticcall(";
break;
}
visit(_x.gas());
m_output << ", ";
visit(_x.addr());
m_output << ", ";
if (type == LowLevelCall::CALL || LowLevelCall::CALLCODE)
{
visit(_x.wei());
m_output << ", ";
}
visit(_x.in());
m_output << ", ";
visit(_x.insize());
m_output << ", ";
visit(_x.out());
m_output << ", ";
visit(_x.outsize());
m_output << ")";
}
void ProtoConverter::visit(Create const& _x)
{
Create_Type type = _x.createty();
switch (type)
{
case Create::CREATE:
m_output << "create(";
break;
case Create::CREATE2:
m_output << "create2(";
break;
}
visit(_x.wei());
m_output << ", ";
visit(_x.position());
m_output << ", ";
visit(_x.size());
if (type == Create::CREATE2)
{
m_output << ", ";
visit(_x.value());
}
m_output << ")";
}
void ProtoConverter::visit(IfStmt const& _x)
{
m_output << "if ";

View File

@ -86,6 +86,8 @@ private:
void visit(FunctionCall const&);
void visit(FunctionDef const&);
void visit(PopStmt const&);
void visit(LowLevelCall const&);
void visit(Create const&);
void visit(Program const&);
/// Creates a new scope, and adds @a _funcParams to it if it

View File

@ -21,6 +21,37 @@ message VarDecl {
required Expression expr = 1;
}
message LowLevelCall {
enum Type {
CALL = 0;
CALLCODE = 1;
DELEGATECALL = 2;
STATICCALL = 3;
}
required Type callty = 1;
required Expression gas = 2;
required Expression addr = 3;
// Valid for call and callcode only
required Expression wei = 4;
required Expression in = 5;
required Expression insize = 6;
required Expression out = 7;
required Expression outsize = 8;
}
message Create {
enum Type {
CREATE = 0;
CREATE2 = 1;
}
required Type createty = 1;
required Expression wei = 2;
required Expression position = 3;
required Expression size = 4;
// Valid for create2 only
required Expression value = 5;
}
message FunctionCall {
enum Returns {
ZERO = 1;
@ -225,6 +256,8 @@ message Expression {
TernaryOp top = 5;
NullaryOp nop = 6;
FunctionCall func_expr = 7;
LowLevelCall lowcall = 8;
Create create = 9;
}
}