Skip to content

Commit ac3add1

Browse files
build: add Docker support for fuzzing scenarios
Adds Dockerfile and docker-compose.yml to facilitate running fuzzing targets in isolated environments. Supports environment variables FUZZ, CXXFLAGS, FUZZ_RUNS, and FUZZ_INPUT. Corpus data is persisted via volume mounts to the host.
1 parent 20d57a4 commit ac3add1

File tree

4 files changed

+206
-1
lines changed

4 files changed

+206
-1
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.o
2+
*.a
3+
*.so
4+
*.out
5+
*.exe

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ obj/
1111
*.so
1212
__pycache__
1313
main.py
14-
corpus/
14+
corpus/
15+
docker/

Dockerfile

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Uses Ubuntu as base
2+
FROM ubuntu:22.04
3+
4+
# Sets environment variables for installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Installs basic tools
8+
RUN apt-get update && apt-get install -y \
9+
wget curl git build-essential sudo \
10+
libc6-dev libgcc-11-dev libasan6 \
11+
cmake \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Installs Rust
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
16+
ENV PATH="/root/.cargo/bin:${PATH}"
17+
RUN rustup install stable && rustup install nightly
18+
19+
# Installs Go
20+
RUN wget https://golang.org/dl/go1.22.2.linux-amd64.tar.gz && \
21+
tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz && \
22+
rm go1.22.2.linux-amd64.tar.gz
23+
ENV PATH="/usr/local/go/bin:${PATH}"
24+
25+
# Installs .NET SDK 8.0
26+
RUN wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
27+
dpkg -i packages-microsoft-prod.deb && \
28+
rm packages-microsoft-prod.deb && \
29+
apt-get update && apt-get install -y dotnet-sdk-8.0 && \
30+
rm -rf /var/lib/apt/lists/*
31+
32+
# Installs Python 3.11 and pip
33+
RUN apt-get update && apt-get install -y python3.11 python3-pip && \
34+
rm -rf /var/lib/apt/lists/*
35+
RUN python3.11 -m pip install --upgrade pip
36+
37+
# Installs LLVM and Clang 18
38+
RUN apt-get update && apt-get install -y \
39+
lsb-release wget software-properties-common gnupg && \
40+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
41+
add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" && \
42+
apt-get update && apt-get install -y \
43+
clang-18 clang++-18 && \
44+
ln -sfT /usr/bin/clang++-18 /usr/bin/clang++ && \
45+
ln -sfT /usr/bin/clang-18 /usr/bin/clang && \
46+
rm -rf /var/lib/apt/lists/*
47+
48+
# Installs Boost
49+
RUN apt-get update && apt-get install -y libboost-all-dev && \
50+
rm -rf /var/lib/apt/lists/*
51+
52+
# Configures environment variables
53+
ENV CC=/usr/bin/clang
54+
ENV CXX=/usr/bin/clang++
55+
ENV BOOST_LIB_DIR=/usr/lib/x86_64-linux-gnu/
56+
57+
# Working directory
58+
WORKDIR /app
59+
60+
# Copies the repository
61+
COPY . .
62+
63+
# Installs dependencies for embit
64+
RUN pip install -r modules/embit/embit_lib/requirements.txt
65+
66+
# Clean cache bitcoin core
67+
RUN rm -rf /app/modules/bitcoin/univalue/build && \
68+
mkdir -p /app/modules/bitcoin/univalue/build && \
69+
cd /app/modules/bitcoin/univalue && \
70+
CXXFLAGS="-fsanitize=address" cmake -B build && \
71+
cmake --build build && \
72+
cd build && \
73+
make univalue
74+
75+
# Copies and gives permission to auto_build.sh
76+
COPY auto_build.sh .
77+
RUN chmod +x auto_build.sh
78+
79+
# CMD requires FUZZ, but FUZZ_RUNS and FUZZ_INPUT are optional
80+
CMD ["bash", "-c", "mkdir -p /app/data && \
81+
./auto_build.sh && \
82+
if [ -z \"$FUZZ\" ]; then \
83+
echo \"Error: FUZZ not defined\"; \
84+
exit 1; \
85+
elif [ -n \"$FUZZ_INPUT\" ]; then \
86+
./bitcoinfuzz \"$FUZZ_INPUT\"; \
87+
elif [ -n \"$FUZZ_RUNS\" ]; then \
88+
./bitcoinfuzz -runs=$FUZZ_RUNS -artifact_prefix=/app/data/crash- /app/data; \
89+
else \
90+
./bitcoinfuzz -artifact_prefix=/app/data/crash- /app/data; \
91+
fi"]

docker-compose.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
x-common-env:
2+
&common-env
3+
FUZZ_RUNS: ${FUZZ_RUNS}
4+
FUZZ_INPUT: ${FUZZ_INPUT}
5+
6+
services:
7+
script:
8+
build:
9+
context: .
10+
dockerfile: Dockerfile
11+
environment:
12+
<<: *common-env
13+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_BITCOIN"
14+
FUZZ: script
15+
volumes:
16+
- ./docker/script:/app/data
17+
18+
deserialize_block:
19+
build:
20+
context: .
21+
dockerfile: Dockerfile
22+
environment:
23+
<<: *common-env
24+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_BITCOIN -DBTCD"
25+
FUZZ: deserialize_block
26+
volumes:
27+
- ./docker/deserialize_block:/app/data
28+
29+
script_eval:
30+
build:
31+
context: .
32+
dockerfile: Dockerfile
33+
environment:
34+
<<: *common-env
35+
CXXFLAGS: "-DBITCOIN_CORE -DBTCD"
36+
FUZZ: script_eval
37+
volumes:
38+
- ./docker/script_eval:/app/data
39+
40+
descriptor_parse:
41+
build:
42+
context: .
43+
dockerfile: Dockerfile
44+
environment:
45+
<<: *common-env
46+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_MINISCRIPT -DEMBIT"
47+
FUZZ: descriptor_parse
48+
ASAN_OPTIONS: detect_leaks=0
49+
volumes:
50+
- ./docker/descriptor_parse:/app/data
51+
52+
miniscript_parse:
53+
build:
54+
context: .
55+
dockerfile: Dockerfile
56+
environment:
57+
<<: *common-env
58+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_MINISCRIPT -DEMBIT"
59+
FUZZ: miniscript_parse
60+
ASAN_OPTIONS: detect_leaks=0
61+
volumes:
62+
- ./docker/miniscript_parse:/app/data
63+
64+
script_asm:
65+
build:
66+
context: .
67+
dockerfile: Dockerfile
68+
environment:
69+
<<: *common-env
70+
CXXFLAGS: "-DBITCOIN_CORE -DBTCD"
71+
FUZZ: script_asm
72+
volumes:
73+
- ./docker/script_asm:/app/data
74+
75+
deserialize_invoice:
76+
build:
77+
context: .
78+
dockerfile: Dockerfile
79+
environment:
80+
<<: *common-env
81+
CXXFLAGS: "-DLDK -DLND -DNLIGHTNING"
82+
FUZZ: deserialize_invoice
83+
ASAN_OPTIONS: detect_leaks=0
84+
volumes:
85+
- ./docker/deserialize_invoice:/app/data
86+
87+
address_parse:
88+
build:
89+
context: .
90+
dockerfile: Dockerfile
91+
environment:
92+
<<: *common-env
93+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_BITCOIN"
94+
FUZZ: address_parse
95+
volumes:
96+
- ./docker/address_parse:/app/data
97+
98+
psbt_parse:
99+
build:
100+
context: .
101+
dockerfile: Dockerfile
102+
environment:
103+
<<: *common-env
104+
CXXFLAGS: "-DEMBIT -DRUST_BITCOIN -DBTCD"
105+
FUZZ: psbt_parse
106+
ASAN_OPTIONS: detect_leaks=0
107+
volumes:
108+
- ./docker/psbt_parse:/app/data

0 commit comments

Comments
 (0)