Skip to content

Commit 380cb91

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 7da78a3 commit 380cb91

File tree

4 files changed

+242
-1
lines changed

4 files changed

+242
-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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Uses Ubuntu as base
2+
FROM ubuntu:24.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 python3-pip python3-venv && \
34+
rm -rf /var/lib/apt/lists/*
35+
36+
# Installs LLVM and Clang 18
37+
RUN apt-get update && apt-get install -y \
38+
lsb-release wget software-properties-common gnupg && \
39+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
40+
add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" && \
41+
apt-get update && apt-get install -y \
42+
clang-18 clang++-18 && \
43+
ln -sfT /usr/bin/clang++-18 /usr/bin/clang++ && \
44+
ln -sfT /usr/bin/clang-18 /usr/bin/clang && \
45+
rm -rf /var/lib/apt/lists/*
46+
47+
# Installs Boost
48+
RUN apt-get update && apt-get install -y libboost-all-dev && \
49+
rm -rf /var/lib/apt/lists/*
50+
51+
# Configures environment variables
52+
ENV CC=/usr/bin/clang
53+
ENV CXX=/usr/bin/clang++
54+
ENV BOOST_LIB_DIR=/usr/lib/x86_64-linux-gnu/
55+
ENV LDFLAGS="-lsodium"
56+
57+
# Working directory
58+
WORKDIR /app
59+
60+
# Copies the repository
61+
COPY . .
62+
63+
# Creates a virtual environment
64+
RUN python3 -m venv /venv
65+
ENV PATH="/venv/bin:$PATH"
66+
67+
# Installs dependencies for embit
68+
RUN pip install -r modules/embit/requirements.txt
69+
70+
# Installs dependencies for C-lightning
71+
RUN python3 -m pip install --upgrade pip && \
72+
python3 -m pip install mako
73+
RUN git submodule update --init --recursive external/lightning
74+
RUN apt-get update && apt-get install -y \
75+
libsqlite3-dev \
76+
libsodium-dev \
77+
jq \
78+
&& rm -rf /var/lib/apt/lists/*
79+
80+
# Clean cache bitcoin core
81+
RUN rm -rf /app/modules/bitcoin/univalue/build && \
82+
mkdir -p /app/modules/bitcoin/univalue/build && \
83+
cd /app/modules/bitcoin/univalue && \
84+
CXXFLAGS="-fsanitize=address" cmake -B build && \
85+
cmake --build build && \
86+
cd build && \
87+
make univalue
88+
89+
# Copies and gives permission to auto_build.sh
90+
COPY auto_build.sh .
91+
RUN chmod +x auto_build.sh
92+
93+
# CMD requires FUZZ, but FUZZ_RUNS and FUZZ_INPUT are optional
94+
CMD ["bash", "-c", "mkdir -p /app/data/crash && \
95+
./auto_build.sh && \
96+
if [ -z \"$FUZZ\" ]; then \
97+
echo \"Error: FUZZ not defined\"; \
98+
exit 1; \
99+
elif [ -n \"$FUZZ_INPUT\" ]; then \
100+
./bitcoinfuzz -artifact_prefix=/app/data/crash/ \"$FUZZ_INPUT\"; \
101+
elif [ -n \"$FUZZ_RUNS\" ]; then \
102+
./bitcoinfuzz -runs=$FUZZ_RUNS -artifact_prefix=/app/data/crash/ /app/data; \
103+
else \
104+
./bitcoinfuzz -artifact_prefix=/app/data/crash/ /app/data; \
105+
fi"]

docker-compose.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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 -DCLIGHTNING -DCUSTOM_MUTATOR_BOLT11"
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+
addrv2:
99+
build:
100+
context: .
101+
dockerfile: Dockerfile
102+
environment:
103+
<<: *common-env
104+
CXXFLAGS: "-DBITCOIN_CORE -DRUST_BITCOIN -DBTCD"
105+
FUZZ: addrv2
106+
volumes:
107+
- ./docker/addrv2:/app/data
108+
109+
psbt_parse:
110+
build:
111+
context: .
112+
dockerfile: Dockerfile
113+
environment:
114+
<<: *common-env
115+
CXXFLAGS: "-DEMBIT -DRUST_BITCOIN -DBTCD -DBITCOIN_CORE"
116+
FUZZ: psbt_parse
117+
ASAN_OPTIONS: detect_leaks=0
118+
volumes:
119+
- ./docker/psbt_parse:/app/data
120+
121+
deserialize_offer:
122+
build:
123+
context: .
124+
dockerfile: Dockerfile
125+
environment:
126+
<<: *common-env
127+
CXXFLAGS: "-DLDK -DCLIGHTNING"
128+
FUZZ: deserialize_offer
129+
volumes:
130+
- ./docker/deserialize_offer:/app/data

0 commit comments

Comments
 (0)