From d81a43e671d66214f0e3be585fed25d4065ac1c7 Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Tue, 13 Apr 2021 16:00:58 +0200 Subject: [PATCH] Add upto 32 function I/O parameters. --- test/tools/ossfuzz/protoToYul.cpp | 118 ++++++++++++++++++++++++++++++ test/tools/ossfuzz/protoToYul.h | 7 +- test/tools/ossfuzz/yulProto.proto | 28 +++++++ 3 files changed, 151 insertions(+), 2 deletions(-) diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index ef3fe6bec..f61cbbee0 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -875,6 +875,118 @@ void ProtoConverter::visitFunctionInputParams(FunctionCall const& _x, unsigned _ // We reverse the order of function input visits since it helps keep this switch case concise. switch (_numInputParams) { + case 32: + visit(_x.in_param32()); + m_output << ", "; + [[fallthrough]]; + case 31: + visit(_x.in_param31()); + m_output << ", "; + [[fallthrough]]; + case 30: + visit(_x.in_param30()); + m_output << ", "; + [[fallthrough]]; + case 29: + visit(_x.in_param29()); + m_output << ", "; + [[fallthrough]]; + case 28: + visit(_x.in_param28()); + m_output << ", "; + [[fallthrough]]; + case 27: + visit(_x.in_param27()); + m_output << ", "; + [[fallthrough]]; + case 26: + visit(_x.in_param26()); + m_output << ", "; + [[fallthrough]]; + case 25: + visit(_x.in_param25()); + m_output << ", "; + [[fallthrough]]; + case 24: + visit(_x.in_param24()); + m_output << ", "; + [[fallthrough]]; + case 23: + visit(_x.in_param23()); + m_output << ", "; + [[fallthrough]]; + case 22: + visit(_x.in_param22()); + m_output << ", "; + [[fallthrough]]; + case 21: + visit(_x.in_param21()); + m_output << ", "; + [[fallthrough]]; + case 20: + visit(_x.in_param20()); + m_output << ", "; + [[fallthrough]]; + case 19: + visit(_x.in_param19()); + m_output << ", "; + [[fallthrough]]; + case 18: + visit(_x.in_param18()); + m_output << ", "; + [[fallthrough]]; + case 17: + visit(_x.in_param17()); + m_output << ", "; + [[fallthrough]]; + case 16: + visit(_x.in_param16()); + m_output << ", "; + [[fallthrough]]; + case 15: + visit(_x.in_param15()); + m_output << ", "; + [[fallthrough]]; + case 14: + visit(_x.in_param14()); + m_output << ", "; + [[fallthrough]]; + case 13: + visit(_x.in_param13()); + m_output << ", "; + [[fallthrough]]; + case 12: + visit(_x.in_param12()); + m_output << ", "; + [[fallthrough]]; + case 11: + visit(_x.in_param11()); + m_output << ", "; + [[fallthrough]]; + case 10: + visit(_x.in_param10()); + m_output << ", "; + [[fallthrough]]; + case 9: + visit(_x.in_param9()); + m_output << ", "; + [[fallthrough]]; + case 8: + visit(_x.in_param8()); + m_output << ", "; + [[fallthrough]]; + case 7: + visit(_x.in_param7()); + m_output << ", "; + [[fallthrough]]; + case 6: + visit(_x.in_param6()); + m_output << ", "; + [[fallthrough]]; + case 5: + visit(_x.in_param5()); + m_output << ", "; + [[fallthrough]]; case 4: visit(_x.in_param4()); m_output << ", "; @@ -941,6 +1053,9 @@ optional ProtoConverter::functionExists(NumFunctionReturns _numReturns) void ProtoConverter::visit(FunctionCall const& _x, string const& _functionName, bool _expression) { + // Disable recursive calls. + if (_functionName == m_currentFunctionName) + return; yulAssert(m_functionSigMap.count(_functionName), "Proto fuzzer: Invalid function."); auto ret = m_functionSigMap.at(_functionName); unsigned numInParams = ret.first; @@ -1686,6 +1801,8 @@ void ProtoConverter::createFunctionDefAndCall( // Obtain function name yulAssert(m_functionDefMap.count(&_x), "Proto fuzzer: Unregistered function"); string funcName = m_functionDefMap.at(&_x); + string wasFuncName = m_currentFunctionName; + m_currentFunctionName = funcName; vector varsVec = {}; m_output << "function " << funcName << "("; @@ -1730,6 +1847,7 @@ void ProtoConverter::createFunctionDefAndCall( m_inForBodyScope = wasInForBody; m_inFunctionDef = wasInFunctionDef; + m_currentFunctionName = wasFuncName; yulAssert( !m_inForInitScope, diff --git a/test/tools/ossfuzz/protoToYul.h b/test/tools/ossfuzz/protoToYul.h index 30d2bd4e6..b9971e486 100644 --- a/test/tools/ossfuzz/protoToYul.h +++ b/test/tools/ossfuzz/protoToYul.h @@ -63,6 +63,7 @@ public: m_filterUnboundedLoops = _filterUnboundedLoops; m_filterMemoryWrites = _filterMemoryWrites; m_filterLogs = _filterLogs; + m_currentFunctionName = {}; } ProtoConverter(ProtoConverter const&) = delete; ProtoConverter(ProtoConverter&&) = delete; @@ -344,8 +345,8 @@ private: /// Map of object name to list of sub-object namespace(s) in scope std::map> m_objectScope; // mod input/output parameters impose an upper bound on the number of input/output parameters a function may have. - static unsigned constexpr s_modInputParams = 5; - static unsigned constexpr s_modOutputParams = 5; + static unsigned constexpr s_modInputParams = 33; + static unsigned constexpr s_modOutputParams = 33; /// Hard-coded identifier for a Yul object's data block static auto constexpr s_dataIdentifier = "datablock"; /// Predicate to keep track of for body scope. If false, break/continue @@ -391,5 +392,7 @@ private: /// Flag that, if set, stops the converter from generating log /// records. bool m_filterLogs; + /// Name of current function definition + std::string m_currentFunctionName; }; } diff --git a/test/tools/ossfuzz/yulProto.proto b/test/tools/ossfuzz/yulProto.proto index 60f0ea1f6..f47fa1061 100644 --- a/test/tools/ossfuzz/yulProto.proto +++ b/test/tools/ossfuzz/yulProto.proto @@ -62,6 +62,34 @@ message FunctionCall { required Expression in_param2 = 2; required Expression in_param3 = 3; required Expression in_param4 = 4; + required Expression in_param5 = 5; + required Expression in_param6 = 6; + required Expression in_param7 = 7; + required Expression in_param8 = 8; + required Expression in_param9 = 9; + required Expression in_param10 = 10; + required Expression in_param11 = 11; + required Expression in_param12 = 12; + required Expression in_param13 = 13; + required Expression in_param14 = 14; + required Expression in_param15 = 15; + required Expression in_param16 = 16; + required Expression in_param17 = 17; + required Expression in_param18 = 18; + required Expression in_param19 = 19; + required Expression in_param20 = 20; + required Expression in_param21 = 21; + required Expression in_param22 = 22; + required Expression in_param23 = 23; + required Expression in_param24 = 24; + required Expression in_param25 = 25; + required Expression in_param26 = 26; + required Expression in_param27 = 27; + required Expression in_param28 = 28; + required Expression in_param29 = 29; + required Expression in_param30 = 30; + required Expression in_param31 = 31; + required Expression in_param32 = 32; } message TypedVarDecl {