Merge pull request #9388 from ethereum/develop

Merge develop into breaking.
This commit is contained in:
chriseth
2020-07-13 14:55:21 +02:00
committed by GitHub
52 changed files with 467 additions and 229 deletions
+6
View File
@@ -8,6 +8,7 @@ add_dependencies(ossfuzz
strictasm_assembly_ossfuzz
)
if (OSSFUZZ)
add_custom_target(ossfuzz_proto)
add_dependencies(ossfuzz_proto
@@ -54,6 +55,7 @@ if (OSSFUZZ)
protobuf.a
)
set_target_properties(yul_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
add_executable(yul_proto_diff_ossfuzz yulProto_diff_ossfuzz.cpp yulFuzzerCommon.cpp protoToYul.cpp yulProto.pb.cc)
target_include_directories(yul_proto_diff_ossfuzz PRIVATE /usr/include/libprotobuf-mutator)
@@ -64,6 +66,7 @@ if (OSSFUZZ)
protobuf.a
)
set_target_properties(yul_proto_diff_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(yul_proto_diff_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
add_executable(yul_proto_diff_custom_mutate_ossfuzz
yulProto_diff_ossfuzz.cpp
@@ -80,6 +83,7 @@ if (OSSFUZZ)
protobuf.a
)
set_target_properties(yul_proto_diff_custom_mutate_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(yul_proto_diff_custom_mutate_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
add_executable(abiv2_proto_ossfuzz
../../EVMHost.cpp
@@ -99,6 +103,7 @@ if (OSSFUZZ)
protobuf.a
)
set_target_properties(abiv2_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
add_executable(sol_proto_ossfuzz
solProtoFuzzer.cpp
@@ -118,6 +123,7 @@ if (OSSFUZZ)
protobuf.a
)
set_target_properties(sol_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
else()
add_library(solc_opt_ossfuzz
solc_opt_ossfuzz.cpp
+2 -2
View File
@@ -192,13 +192,13 @@ void ProtoConverter::visit(VarRef const& _x)
{
// Ensure that there is at least one variable declaration to reference in function scope.
yulAssert(m_currentFuncVars.size() > 0, "Proto fuzzer: No variables to reference.");
m_output << *m_currentFuncVars[_x.varnum() % m_currentFuncVars.size()];
m_output << *m_currentFuncVars[static_cast<size_t>(_x.varnum()) % m_currentFuncVars.size()];
}
else
{
// Ensure that there is at least one variable declaration to reference in nested scopes.
yulAssert(m_currentGlobalVars.size() > 0, "Proto fuzzer: No global variables to reference.");
m_output << *m_currentGlobalVars[_x.varnum() % m_currentGlobalVars.size()];
m_output << *m_currentGlobalVars[static_cast<size_t>(_x.varnum()) % m_currentGlobalVars.size()];
}
}
+1 -1
View File
@@ -202,7 +202,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(sol_source.data(), sol_source.size());
of.write(sol_source.data(), static_cast<streamsize>(sol_source.size()));
}
if (char const* dump_path = getenv("SOL_DEBUG_FILE"))
+1 -1
View File
@@ -43,7 +43,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(yul_source.data(), yul_source.size());
of.write(yul_source.data(), static_cast<streamsize>(yul_source.size()));
}
if (yul_source.size() > 1200)
+1 -1
View File
@@ -64,7 +64,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(yul_source.data(), yul_source.size());
of.write(yul_source.data(), static_cast<streamsize>(yul_source.size()));
}
YulStringRepository::reset();
@@ -51,8 +51,9 @@ void copyZeroExtended(
_target[_targetOffset + i] = _sourceOffset + i < _source.size() ? _source[_sourceOffset + i] : 0;
}
/// Count leading zeros for uint64
uint64_t clz(uint64_t _v)
/// Count leading zeros for uint64. Following WebAssembly rules, it returns 64 for @a _v being zero.
/// NOTE: the clz builtin of the compiler may or may not do this
uint64_t clz64(uint64_t _v)
{
if (_v == 0)
return 64;
@@ -133,7 +134,11 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(YulString _fun, vector<u256> const& _a
accessMemory(arg[0], 4);
return readMemoryHalfWord(arg[0]);
}
else if (_fun == "i32.clz"_yulstring)
// NOTE: the clz implementation assumes 64-bit inputs, hence the adjustment
return clz64(arg[0] & uint32_t(-1)) - 32;
else if (_fun == "i64.clz"_yulstring)
return clz64(arg[0]);
string prefix = _fun.str();
string suffix;
@@ -202,8 +207,6 @@ u256 EwasmBuiltinInterpreter::evalWasmBuiltin(string const& _fun, vector<Word> c
return arg[0] != arg[1] ? 1 : 0;
else if (_fun == "eqz")
return arg[0] == 0 ? 1 : 0;
else if (_fun == "clz")
return clz(arg[0]);
else if (_fun == "lt_u")
return arg[0] < arg[1] ? 1 : 0;
else if (_fun == "gt_u")