diff --git a/test/tools/ossfuzz/CMakeLists.txt b/test/tools/ossfuzz/CMakeLists.txt index 399eada46..74787f5fd 100644 --- a/test/tools/ossfuzz/CMakeLists.txt +++ b/test/tools/ossfuzz/CMakeLists.txt @@ -5,6 +5,8 @@ add_dependencies(ossfuzz solc_noopt_ossfuzz const_opt_ossfuzz strictasm_diff_ossfuzz + strictasm_opt_ossfuzz + strictasm_assembly_ossfuzz ) add_custom_target(ossfuzz_proto) @@ -23,6 +25,12 @@ target_link_libraries(const_opt_ossfuzz PRIVATE libsolc evmasm FuzzingEngine.a) add_executable(strictasm_diff_ossfuzz strictasm_diff_ossfuzz.cpp yulFuzzerCommon.cpp) target_link_libraries(strictasm_diff_ossfuzz PRIVATE libsolc evmasm yulInterpreter FuzzingEngine.a) +add_executable(strictasm_opt_ossfuzz strictasm_opt_ossfuzz.cpp) +target_link_libraries(strictasm_opt_ossfuzz PRIVATE yul FuzzingEngine.a) + +add_executable(strictasm_assembly_ossfuzz strictasm_assembly_ossfuzz.cpp) +target_link_libraries(strictasm_assembly_ossfuzz PRIVATE yul FuzzingEngine.a) + add_executable(yul_proto_ossfuzz yulProtoFuzzer.cpp protoToYul.cpp yulProto.pb.cc) target_include_directories(yul_proto_ossfuzz PRIVATE /src/libprotobuf-mutator /src/LPM/external.protobuf/include) target_link_libraries(yul_proto_ossfuzz PRIVATE yul evmasm diff --git a/test/tools/ossfuzz/config/strict_assembly.dict b/test/tools/ossfuzz/config/strict_assembly.dict new file mode 100644 index 000000000..4415c87f4 --- /dev/null +++ b/test/tools/ossfuzz/config/strict_assembly.dict @@ -0,0 +1,91 @@ +" -> " +" := " +" address() " +" calldatasize() " +" caller() " +" callvalue() " +" codesize() " +" coinbase() " +" difficulty() " +" gas() " +" gaslimit() " +" gasprice() " +" invalid() " +" number() " +" origin() " +" pc() " +" returndatasize() " +" stop() " +" timestamp() " +"(" +")" +", " +"0x42" +"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" +":" +"add(" +"addmod(" +"and(" +"balance(" +"blockhash(" +"byte(" +"call(" +"callcode(" +"calldatacopy(" +"calldataload(" +"case " +"codecopy(" +"create(" +"create2(" +"default " +"delegatecall(" +"div(" +"eq(" +"exp(" +"extcodecopy(" +"extcodehash(" +"extcodesize(" +"for " +"function " +"gt(" +"hello" +"if " +"iszero(" +"keccak256(" +"let " +"log0(" +"log1(" +"log2(" +"log3(" +"log4(" +"lt(" +"mload(" +"mod(" +"msize" +"mstore(" +"mstore8(" +"mul(" +"mulmod(" +"not(" +"or(" +"pop(" +"return(" +"returndatacopy(" +"revert(" +"sar(" +"sdiv(" +"selfdestruct(" +"sgt(" +"shl(" +"shr(" +"signextend(" +"sload(" +"slt(" +"smod(" +"sstore(" +"staticcall(" +"sub(" +"switch " +"xor(" +"{" +"}" diff --git a/test/tools/ossfuzz/config/strictasm_assembly_ossfuzz.options b/test/tools/ossfuzz/config/strictasm_assembly_ossfuzz.options new file mode 100644 index 000000000..c6170959f --- /dev/null +++ b/test/tools/ossfuzz/config/strictasm_assembly_ossfuzz.options @@ -0,0 +1,2 @@ +[libfuzzer] +dict = strict_assembly.dict diff --git a/test/tools/ossfuzz/config/strictasm_opt_ossfuzz.options b/test/tools/ossfuzz/config/strictasm_opt_ossfuzz.options new file mode 100644 index 000000000..c6170959f --- /dev/null +++ b/test/tools/ossfuzz/config/strictasm_opt_ossfuzz.options @@ -0,0 +1,2 @@ +[libfuzzer] +dict = strict_assembly.dict diff --git a/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp new file mode 100644 index 000000000..b3b11426a --- /dev/null +++ b/test/tools/ossfuzz/strictasm_assembly_ossfuzz.cpp @@ -0,0 +1,47 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ + +#include +#include +#include + +using namespace yul; +using namespace std; + +extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) +{ + if (_size > 600) + return 0; + + string input(reinterpret_cast(_data), _size); + AssemblyStack stack(langutil::EVMVersion(), AssemblyStack::Language::StrictAssembly); + + if (!stack.parseAndAnalyze("source", input)) + return 0; + + try + { + MachineAssemblyObject obj = stack.assemble(AssemblyStack::Machine::EVM); + solAssert(obj.bytecode, ""); + } + catch (StackTooDeepError const&) + { + + } + + return 0; +} diff --git a/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp new file mode 100644 index 000000000..05e70e8ab --- /dev/null +++ b/test/tools/ossfuzz/strictasm_opt_ossfuzz.cpp @@ -0,0 +1,37 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ + +#include +#include + +using namespace yul; +using namespace std; + +extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) +{ + if (_size > 600) + return 0; + + string input(reinterpret_cast(_data), _size); + AssemblyStack stack(langutil::EVMVersion(), AssemblyStack::Language::StrictAssembly); + + if (!stack.parseAndAnalyze("source", input)) + return 0; + + stack.optimize(); + return 0; +}