1#!/bin/bash -eu
2# Copyright 2020 The Monero Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18export BOOST_ROOT=/src/monero/boost_1_70_0
19export OPENSSL_ROOT_DIR=/src/monero/openssl-1.1.1g
20
21cd monero
22sed -i -e 's/include(FindCcache)/# include(FindCcache)/' CMakeLists.txt
23git submodule init
24git submodule update
25mkdir -p build
26cd build
27export CXXFLAGS="$CXXFLAGS -fPIC"
28cmake -D OSSFUZZ=ON -D STATIC=ON -D BUILD_TESTS=ON -D USE_LTO=OFF -D ARCH="default" ..
29
30TESTS="\
31  base58_fuzz_tests \
32  block_fuzz_tests \
33  transaction_fuzz_tests \
34  load-from-binary_fuzz_tests \
35  load-from-json_fuzz_tests \
36  parse-url_fuzz_tests \
37  http-client_fuzz_tests \
38  levin_fuzz_tests \
39  bulletproof_fuzz_tests \
40  tx-extra_fuzz_tests \
41"
42
43# only libfuzzer can run the slow to start ones
44if test "x$FUZZING_ENGINE" == 'xlibfuzzer'
45then
46  TESTS="$TESTS \
47    signature_fuzz_tests \
48    cold-outputs_fuzz_tests \
49    cold-transaction_fuzz_tests \
50  "
51fi
52
53make -C tests/fuzz $TESTS
54
55cd /src/monero/monero/build/tests/fuzz
56for fuzzer in *_fuzz_tests
57do
58  cp "$fuzzer" "$OUT"
59  base=$(echo $fuzzer | sed -e s/_fuzz_tests//)
60  cd "/src/monero/monero/tests/data/fuzz/$base"
61  rm -f "${OUT}/${fuzzer}_seed_corpus.zip"
62  for f in *
63  do
64    h=$(sha1sum "$f" | awk '{print $1}')
65    cp "$f" "$h"
66    zip "${OUT}/${fuzzer}_seed_corpus.zip" "$h"
67    rm -f "$h"
68  done
69  cd -
70done
71