diff --git a/test/tools/ossfuzz/YulToEvmDifferentialFuzzer.cpp b/test/tools/ossfuzz/YulToEvmDifferentialFuzzer.cpp index d0ae00fbe..8e3b71779 100644 --- a/test/tools/ossfuzz/YulToEvmDifferentialFuzzer.cpp +++ b/test/tools/ossfuzz/YulToEvmDifferentialFuzzer.cpp @@ -106,11 +106,14 @@ DEFINE_PROTO_FUZZER(Program const& _input) } solidity::frontend::OptimiserSettings settings = solidity::frontend::OptimiserSettings::none(); + // Stack evader requires stack allocation to be done. + settings.optimizeStackAllocation = true; AssemblyStack stackUnoptimized(version, AssemblyStack::Language::StrictAssembly, settings); solAssert( stackUnoptimized.parseAndAnalyze("source", yulSubObject), "Parsing fuzzer generated input failed." ); + stackUnoptimized.optimize(); ostringstream unoptimizedState; yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret( unoptimizedState, @@ -121,11 +124,12 @@ DEFINE_PROTO_FUZZER(Program const& _input) if (yulFuzzerUtil::resourceLimitsExceeded(termReason)) return; - AssemblyStack stackOptimized; + AssemblyStack stackOptimized(version, AssemblyStack::Language::StrictAssembly, settings); solAssert( stackOptimized.parseAndAnalyze("source", yulSubObject), "Parsing fuzzer generated input failed." ); + stackOptimized.optimize(); YulOptimizerTestCommon optimizerTest( stackOptimized.parserResult(), EVMDialect::strictAssemblyForEVMObjects(version) @@ -150,6 +154,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) )") ("fuzzerInput", AsmPrinter{}(*astBlock)) .render(); + cout << AsmPrinter{}(*astBlock) << endl; bytes optimisedByteCode; optimisedByteCode = YulAssembler{version, settings, optimisedProgram}.assemble(); diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index 0a423c5ec..d58eb0333 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -233,7 +233,10 @@ void ProtoConverter::visit(Expression const& _x) m_output << dictionaryToken(); break; case Expression::kLowcall: - visit(_x.lowcall()); + if (!m_filterStatefulInstructions) + visit(_x.lowcall()); + else + m_output << dictionaryToken(); break; case Expression::kCreate: // Create and create2 return address of created contract which @@ -263,8 +266,9 @@ void ProtoConverter::visit(BinaryOp const& _x) { BinaryOp_BOp op = _x.op(); - if ((op == BinaryOp::SHL || op == BinaryOp::SHR || op == BinaryOp::SAR) && - !m_evmVersion.hasBitwiseShifting()) + if (((op == BinaryOp::SHL || op == BinaryOp::SHR || op == BinaryOp::SAR) && !m_evmVersion.hasBitwiseShifting()) || + (m_filterStatefulInstructions && op == BinaryOp::KECCAK) + ) { m_output << dictionaryToken(); return; @@ -1282,7 +1286,8 @@ void ProtoConverter::visit(TerminatingStmt const& _x) switch (_x.term_oneof_case()) { case TerminatingStmt::kStopInvalid: - visit(_x.stop_invalid()); + if (!m_filterStatefulInstructions) + visit(_x.stop_invalid()); break; case TerminatingStmt::kRetRev: visit(_x.ret_rev()); diff --git a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp index 83f54c4c7..92582ffe7 100644 --- a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp +++ b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp @@ -464,7 +464,7 @@ u256 EVMInstructionInterpreter::evalBuiltin( } else if (fun == "memoryguard") { - return _evaluatedArguments.at(0); + return u256(std::get(_arguments.at(0)).value.str()); } else yulAssert(false, "Unknown builtin: " + fun);