Merge pull request #7344 from ethereum/yul-add-more-blockchain-opcodes

Yul proto fuzzer: Additional blockchain opcodes
This commit is contained in:
chriseth 2019-09-04 19:14:43 +02:00 committed by GitHub
commit 049e950085
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 167 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;
@ -337,6 +343,12 @@ void ProtoConverter::visit(UnaryOp const& _x)
case UnaryOp::EXTCODEHASH:
m_output << "extcodehash";
break;
case UnaryOp::BALANCE:
m_output << "balance";
break;
case UnaryOp::BLOCKHASH:
m_output << "blockhash";
break;
}
m_output << "(";
visit(_x.operand());
@ -385,6 +397,36 @@ void ProtoConverter::visit(NullaryOp const& _x)
case NullaryOp::RETURNDATASIZE:
m_output << "returndatasize()";
break;
case NullaryOp::ADDRESS:
m_output << "address()";
break;
case NullaryOp::ORIGIN:
m_output << "origin()";
break;
case NullaryOp::CALLER:
m_output << "caller()";
break;
case NullaryOp::CALLVALUE:
m_output << "callvalue()";
break;
case NullaryOp::GASPRICE:
m_output << "gasprice()";
break;
case NullaryOp::COINBASE:
m_output << "coinbase()";
break;
case NullaryOp::TIMESTAMP:
m_output << "timestamp()";
break;
case NullaryOp::NUMBER:
m_output << "number()";
break;
case NullaryOp::DIFFICULTY:
m_output << "difficulty()";
break;
case NullaryOp::GASLIMIT:
m_output << "gaslimit()";
break;
}
}
@ -677,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 ";
@ -947,6 +1051,9 @@ void ProtoConverter::visit(Statement const& _x)
if (!m_inForInitScope)
visit(_x.funcdef());
break;
case Statement::kPop:
visit(_x.pop());
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}
@ -1233,6 +1340,13 @@ void ProtoConverter::visit(FunctionDef const& _x)
createFunctionDefAndCall(_x, numInParams, numOutParams);
}
void ProtoConverter::visit(PopStmt const& _x)
{
m_output << "pop(";
visit(_x.expr());
m_output << ")\n";
}
void ProtoConverter::visit(Program const& _x)
{
// Initialize input size

View File

@ -85,6 +85,9 @@ private:
void visit(TerminatingStmt const&);
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;
@ -129,6 +160,8 @@ message UnaryOp {
CALLDATALOAD = 4;
EXTCODESIZE = 5;
EXTCODEHASH = 6;
BALANCE = 7;
BLOCKHASH = 8;
}
required UOp op = 1;
required Expression operand = 2;
@ -172,6 +205,16 @@ message NullaryOp {
CALLDATASIZE = 4;
CODESIZE = 5;
RETURNDATASIZE = 6;
ADDRESS = 7;
ORIGIN = 8;
CALLER = 9;
CALLVALUE = 10;
GASPRICE = 11;
COINBASE = 12;
TIMESTAMP = 13;
NUMBER = 14;
DIFFICULTY = 15;
GASLIMIT = 16;
}
required NOp op = 1;
}
@ -213,6 +256,8 @@ message Expression {
TernaryOp top = 5;
NullaryOp nop = 6;
FunctionCall func_expr = 7;
LowLevelCall lowcall = 8;
Create create = 9;
}
}
@ -287,6 +332,10 @@ message FunctionDef {
required Block block = 3;
}
message PopStmt {
required Expression expr = 1;
}
message Statement {
oneof stmt_oneof {
VarDecl decl = 1;
@ -305,6 +354,7 @@ message Statement {
FunctionCall functioncall = 14;
BoundedForStmt boundedforstmt = 15;
FunctionDef funcdef = 16;
PopStmt pop = 17;
}
}