From ac7bfec2c0308fc5be32989c22961a2ee59b6d6f Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Tue, 26 Mar 2019 10:52:30 +0100 Subject: [PATCH] Support generation of calldata, code, extcode and returndata opcodes --- test/tools/ossfuzz/protoToYul.cpp | 61 +++++++++++++++++++++++++++++++ test/tools/ossfuzz/protoToYul.h | 2 + test/tools/ossfuzz/yulProto.proto | 27 ++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index ff9f5e50d..2f25fb486 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -307,6 +307,15 @@ void ProtoConverter::visit(UnaryOp const& _x) case UnaryOp::ISZERO: m_output << "iszero"; break; + case UnaryOp::CALLDATALOAD: + m_output << "calldataload"; + break; + case UnaryOp::EXTCODESIZE: + m_output << "extcodesize"; + break; + case UnaryOp::EXTCODEHASH: + m_output << "extcodehash"; + break; } m_output << "("; visit(_x.operand()); @@ -346,9 +355,55 @@ void ProtoConverter::visit(NullaryOp const& _x) case NullaryOp::GAS: m_output << "gas()"; break; + case NullaryOp::CALLDATASIZE: + m_output << "calldatasize()"; + break; + case NullaryOp::CODESIZE: + m_output << "codesize()"; + break; + case NullaryOp::RETURNDATASIZE: + m_output << "returndatasize()"; + break; } } +void ProtoConverter::visit(CopyFunc const& _x) +{ + switch (_x.ct()) + { + case CopyFunc::CALLDATA: + m_output << "calldatacopy"; + break; + case CopyFunc::CODE: + m_output << "codecopy"; + break; + case CopyFunc::RETURNDATA: + m_output << "returndatacopy"; + break; + } + m_output << "("; + visit(_x.target()); + m_output << ", "; + visit(_x.source()); + m_output << ", "; + visit(_x.size()); + m_output << ")\n"; +} + +void ProtoConverter::visit(ExtCodeCopy const& _x) +{ + m_output << "extcodecopy"; + m_output << "("; + visit(_x.addr()); + m_output << ", "; + visit(_x.target()); + m_output << ", "; + visit(_x.source()); + m_output << ", "; + visit(_x.size()); + m_output << ")\n"; +} + void ProtoConverter::visit(LogFunc const& _x) { switch (_x.num_topics()) @@ -535,6 +590,12 @@ void ProtoConverter::visit(Statement const& _x) case Statement::kLogFunc: visit(_x.log_func()); break; + case Statement::kCopyFunc: + visit(_x.copy_func()); + break; + case Statement::kExtcodeCopy: + visit(_x.extcode_copy()); + break; case Statement::STMT_ONEOF_NOT_SET: break; } diff --git a/test/tools/ossfuzz/protoToYul.h b/test/tools/ossfuzz/protoToYul.h index 1e8413355..620b0d511 100644 --- a/test/tools/ossfuzz/protoToYul.h +++ b/test/tools/ossfuzz/protoToYul.h @@ -69,6 +69,8 @@ private: void visit(TernaryOp const&); void visit(NullaryOp const&); void visit(LogFunc const&); + void visit(CopyFunc const&); + void visit(ExtCodeCopy const&); template void visit(google::protobuf::RepeatedPtrField const& _repeated_field); diff --git a/test/tools/ossfuzz/yulProto.proto b/test/tools/ossfuzz/yulProto.proto index ff020b42d..3d3fd698f 100644 --- a/test/tools/ossfuzz/yulProto.proto +++ b/test/tools/ossfuzz/yulProto.proto @@ -106,6 +106,9 @@ message UnaryOp { MLOAD = 1; SLOAD = 2; ISZERO = 3; + CALLDATALOAD = 4; + EXTCODESIZE = 5; + EXTCODEHASH = 6; } required UOp op = 1; required Expression operand = 2; @@ -122,11 +125,33 @@ message TernaryOp { required Expression arg3 = 4; } +message CopyFunc { + enum CopyType { + CALLDATA = 0; + CODE = 1; + RETURNDATA = 2; + } + required CopyType ct = 1; + required Expression target = 2; + required Expression source = 3; + required Expression size = 4; +} + +message ExtCodeCopy { + required Expression addr = 1; + required Expression target = 2; + required Expression source = 3; + required Expression size = 4; +} + message NullaryOp { enum NOp { PC = 1; MSIZE = 2; GAS = 3; + CALLDATASIZE = 4; + CODESIZE = 5; + RETURNDATASIZE = 6; } required NOp op = 1; } @@ -210,6 +235,8 @@ message Statement { BreakStmt breakstmt = 8; ContinueStmt contstmt = 9; LogFunc log_func = 10; + CopyFunc copy_func = 11; + ExtCodeCopy extcode_copy = 12; } }