diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index 742b62d39..03d3facd9 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -19,10 +19,40 @@ #include #include +#include using namespace std; using namespace yul::test::yul_fuzzer; +std::string yul::test::yul_fuzzer::createHex(std::string const& _hexBytes) +{ + std::string tmp{_hexBytes}; + if (!tmp.empty()) + { + boost::range::remove_erase_if(tmp, [=](char c) -> bool { + return !std::isxdigit(c); + }); + tmp = tmp.substr(0, 64); + } + // We need this awkward if case hex literals cannot be empty. + if (tmp.empty()) + tmp = "1"; + return tmp; +} + +std::string yul::test::yul_fuzzer::createAlphaNum(std::string const& _strBytes) +{ + std::string tmp{_strBytes}; + if (!tmp.empty()) + { + boost::range::remove_erase_if(tmp, [=](char c) -> bool { + return !(std::isalpha(c) || std::isdigit(c)); + }); + tmp = tmp.substr(0, 32); + } + return tmp; +} + ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x) { switch (_x.literal_oneof_case()) @@ -30,6 +60,12 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x) case Literal::kIntval: _os << _x.intval(); break; + case Literal::kHexval: + _os << "0x" << createHex(_x.hexval()); + break; + case Literal::kStrval: + _os << "\"" << createAlphaNum(_x.strval()) << "\""; + break; case Literal::LITERAL_ONEOF_NOT_SET: _os << "1"; break; @@ -301,9 +337,7 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Block const& _x) _os << "}\n"; } else - { _os << "{}\n"; - } return _os; } diff --git a/test/tools/ossfuzz/protoToYul.h b/test/tools/ossfuzz/protoToYul.h index 3a427931f..1c06370cc 100644 --- a/test/tools/ossfuzz/protoToYul.h +++ b/test/tools/ossfuzz/protoToYul.h @@ -31,6 +31,8 @@ class Function; std::string functionToString(Function const& input); std::string protoToYul(uint8_t const* data, size_t size); +std::string createHex(std::string const& _hexBytes); +std::string createAlphaNum(std::string const& _strBytes); std::ostream& operator<<(std::ostream& _os, BinaryOp const& _x); std::ostream& operator<<(std::ostream& _os, Block const& _x); std::ostream& operator<<(std::ostream& _os, Literal const& _x); diff --git a/test/tools/ossfuzz/yulProto.proto b/test/tools/ossfuzz/yulProto.proto index 33fd51e13..bd8468d9b 100644 --- a/test/tools/ossfuzz/yulProto.proto +++ b/test/tools/ossfuzz/yulProto.proto @@ -48,6 +48,8 @@ message VarRef { message Literal { oneof literal_oneof { uint64 intval = 1; + string hexval = 2; + string strval = 3; } }