Skip to content

Commit c42cfb3

Browse files
Cross platform reproducible builds
1 parent a10b893 commit c42cfb3

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

tools/reproduce/Dockerfile

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
# Use a specific version of Rust for reproducibility
2-
# FROM debian:bullseye-slim as builder
3-
FROM debian:bullseye-slim@sha256:f527627d07c18abf87313c341ee8ef1b36f106baa8b6b6dc33f4c872d988b651 AS builder
4-
5-
RUN apt-get update && apt-get install -y \
6-
curl \
7-
build-essential \
8-
git \
9-
libssl-dev \
10-
pkg-config
11-
12-
# version MUST be the same as in /tools/verifier/rust-toolchain.toml
13-
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2025-07-25
14-
ENV PATH="/root/.cargo/bin:${PATH}"
15-
16-
RUN rustup target add riscv32i-unknown-none-elf
17-
RUN rustup component add llvm-tools-preview
18-
RUN rustup component add rust-src
19-
RUN cargo install cargo-binutils
20-
21-
# RUN git clone --depth 1 -b mmzk_0608_reproduce https://github.com/matter-labs/zksync-airbender.git
2+
# Pinning os version and architecture for reproducibility
3+
FROM --platform=linux/amd64 debian:bullseye-slim@sha256:4edd2740ebd41d71ef78eed0081c8979e287e2496c6fca892f5936d1e22adcd3 AS builder
4+
5+
6+
# Freeze APT to a specific point in time (matches base image date)
7+
ARG DEBIAN_SNAPSHOT=20250811T000000Z
8+
9+
# Use snapshot.debian.org and disable Valid-Until
10+
RUN set -eux; \
11+
printf 'Acquire::Check-Valid-Until "false";\n' > /etc/apt/apt.conf.d/99snapshot; \
12+
printf 'Acquire::http::No-Cache "true";\n' > /etc/apt/apt.conf.d/99no-cache; \
13+
echo "deb [check-valid-until=no] http://snapshot.debian.org/archive/debian/${DEBIAN_SNAPSHOT} bullseye main" > /etc/apt/sources.list; \
14+
echo "deb [check-valid-until=no] http://snapshot.debian.org/archive/debian-security/${DEBIAN_SNAPSHOT} bullseye-security main" >> /etc/apt/sources.list; \
15+
apt-get -o Acquire::Check-Valid-Until=false update
16+
17+
# Setting a fixed SOURCE_DATE_EPOCH for reproducible builds
18+
# reproduce.sh will set it based on last commit date
19+
ARG SOURCE_DATE_EPOCH=1700000000
20+
ENV SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
21+
CARGO_INCREMENTAL=0 \
22+
TZ=UTC LANG=C.UTF-8 LC_ALL=C.UTF-8
23+
24+
# Toolchain (paths pinned so absolute paths don’t leak)
25+
ENV CARGO_HOME=/opt/cargo RUSTUP_HOME=/opt/rustup
26+
ENV PATH=/opt/cargo/bin:$PATH
27+
RUN apt-get update && apt-get install -y --no-install-recommends \
28+
ca-certificates curl git build-essential libssl-dev pkg-config \
29+
&& rm -rf /var/lib/apt/lists/*
30+
# version MUST be the same as in /tools/verifier/rust-toolchain.toml
31+
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2025-07-25 --profile minimal
32+
RUN rustup target add riscv32i-unknown-none-elf \
33+
&& cargo install cargo-binutils --locked \
34+
&& rustup component add llvm-tools-preview \
35+
&& rustup component add rust-src
36+
37+
ENV CARGO_TARGET_RISCV32I_UNKNOWN_NONE_ELF_AR=llvm-ar
38+
ENV CARGO_TARGET_RISCV32I_UNKNOWN_NONE_ELF_RANLIB=llvm-ranlib
39+
2240
COPY . zksync-airbender
2341

24-
WORKDIR zksync-airbender/tools/verifier
42+
WORKDIR /zksync-airbender/tools/verifier
2543

26-
RUN ./build.sh
44+
RUN ./build.sh

tools/reproduce/reproduce.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
# Make sure to run from the main zksync-airbender directory.
44

5-
set -e # Exit on any error
5+
set -euo pipefail
6+
7+
# Set source date epoch for reproducible builds
8+
SDE="$(git log -1 --format=%ct || echo 1700000000)"
69

710
export DOCKER_DEFAULT_PLATFORM=linux/amd64
811

912
# create a fresh docker
10-
docker build -t airbender-verifiers -f tools/reproduce/Dockerfile .
13+
docker build \
14+
--build-arg SOURCE_DATE_EPOCH="$SDE" \
15+
--platform linux/amd64 \
16+
-t airbender-verifiers \
17+
-f tools/reproduce/Dockerfile .
1118

12-
docker create --name verifiers airbender-verifiers
19+
cid="$(docker create --platform=linux/amd64 airbender-verifiers)"
1320

1421
FILES=(
1522
base_layer.bin
@@ -35,9 +42,9 @@ FILES=(
3542
)
3643

3744
for FILE in "${FILES[@]}"; do
38-
docker cp verifiers:/zksync-airbender/tools/verifier/$FILE tools/verifier/
45+
docker cp "$cid":/zksync-airbender/tools/verifier/"$FILE" tools/verifier/
3946
md5sum tools/verifier/$FILE
4047
done
4148

4249

43-
docker rm verifiers
50+
docker rm -f "$cid" >/dev/null

tools/verifier/.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ rustflags = [
77
"-C", "link-arg=-Tsrc/lds/link.x",
88
"-C", "link-arg=--save-temps",
99
"-C", "force-frame-pointers",
10+
# reproducibility
11+
"--remap-path-prefix= /=/src",
12+
"-C", "link-arg=--build-id=sha1",
13+
"-C", "codegen-units=1",
1014
]
1115

tools/verifier/rust-toolchain.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# If changed, also change tools/reproduce/Dockerfile
12
[toolchain]
2-
channel = "nightly-2025-07-25"
3+
channel = "nightly-2025-07-25"

0 commit comments

Comments
 (0)