Skip to content

Commit 7f6d8e2

Browse files
committed
wip
1 parent 3c2081e commit 7f6d8e2

File tree

5 files changed

+44
-46
lines changed

5 files changed

+44
-46
lines changed

.cargo/config.toml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/release-tee.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
docker build \
7575
-f reproducible.Dockerfile \
7676
-t katana-reproducible:${{ needs.prepare.outputs.tag_name }} \
77+
--build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) \
7778
--no-cache \
7879
.
7980

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ crates/contracts/build/
4141
**/.claude/settings.local.json
4242

4343
vendor
44+
katana-tee

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ SCARB_VERSION := 2.8.4
2626

2727
.DEFAULT_GOAL := usage
2828
.SILENT: clean
29-
.PHONY: usage help check-llvm native-deps native-deps-macos native-deps-linux native-deps-windows build-explorer contracts clean deps install-scarb test-artifacts snos-artifacts db-compat-artifacts install-pyenv
29+
.PHONY: usage help check-llvm native-deps native-deps-macos native-deps-linux native-deps-windows build-explorer contracts clean deps install-scarb test-artifacts snos-artifacts db-compat-artifacts install-pyenv build-tee
3030

3131
usage help:
3232
@echo "Usage:"
3333
@echo " deps: Install all required dependencies for building Katana with all features (incl. tests)."
3434
@echo " snos-deps: Install SNOS test dependencies (pyenv, Python 3.9.15)."
3535
@echo " build-explorer: Build the explorer."
36+
@echo " build-tee: Build reproducible TEE binary (requires Docker)."
3637
@echo " contracts: Build the contracts."
3738
@echo " test-artifacts: Prepare tests artifacts (including test database)."
3839
@echo " snos-artifacts: Prepare SNOS tests artifacts."
@@ -71,6 +72,21 @@ build-explorer:
7172

7273
contracts: $(CONTRACTS_BUILD_DIR)
7374

75+
build-tee: contracts
76+
@which docker >/dev/null 2>&1 || { echo "Error: docker is required but not installed."; exit 1; }
77+
@echo "Building reproducible TEE binary..."
78+
@docker build \
79+
-f reproducible.Dockerfile \
80+
--build-arg SOURCE_DATE_EPOCH=$$(git log -1 --format=%ct) \
81+
-t katana-reproducible \
82+
.
83+
@echo "Extracting binary..."
84+
@docker create --name katana-tee-extract katana-reproducible >/dev/null
85+
@docker cp katana-tee-extract:/katana ./katana-tee
86+
@docker rm katana-tee-extract >/dev/null
87+
@echo "Reproducible TEE binary built: ./katana-tee"
88+
@echo "SHA-384: $$(sha384sum ./katana-tee | cut -d ' ' -f 1)"
89+
7490
# Generate the list of sources dynamically to make sure Make can track all files in all nested subdirs
7591
$(CONTRACTS_BUILD_DIR): $(shell find $(CONTRACTS_DIR) -type f)
7692
@echo "Building contracts..."
@@ -180,5 +196,5 @@ snos-deps-macos: install-pyenv
180196

181197
clean:
182198
echo "Cleaning up generated files..."
183-
-rm -rf $(SNOS_DB_DIR) $(COMPATIBILITY_DB_DIR) $(SNOS_OUTPUT) $(EXPLORER_UI_DIST) $(CONTRACTS_BUILD_DIR)
199+
-rm -rf $(SNOS_DB_DIR) $(COMPATIBILITY_DB_DIR) $(SNOS_OUTPUT) $(EXPLORER_UI_DIST) $(CONTRACTS_BUILD_DIR) katana-tee
184200
echo "Clean complete."

reproducible.Dockerfile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
# Reproducible build Dockerfile for Katana TEE
22
#
33
# Produces bit-for-bit identical builds across different machines.
4+
# Uses a two-stage build: first stage vendors dependencies, second builds offline.
45
#
56
# Usage:
6-
# docker build -f reproducible.Dockerfile -t katana-reproducible .
7+
# docker build -f reproducible.Dockerfile \
8+
# --build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) \
9+
# -t katana-reproducible .
710
# docker create --name extract katana-reproducible
811
# docker cp extract:/katana ./katana-reproducible
912
# docker rm extract
1013

14+
# Stage 1: Vendor dependencies
1115
# Pin Rust image by digest (rust:1.86.0-slim-bookworm for amd64)
16+
FROM rust@sha256:a044f7ab9a762f95be2ee7eb2c49e4d4a4ec60011210de9f7da01d552cae3a55 AS vendorer
17+
18+
WORKDIR /src
19+
20+
# Copy everything needed for vendoring
21+
COPY . .
22+
23+
# Generate vendor directory and cargo config
24+
RUN mkdir -p .cargo && cargo vendor vendor/ > .cargo/config.toml
25+
26+
# Stage 2: Build
1227
FROM rust@sha256:a044f7ab9a762f95be2ee7eb2c49e4d4a4ec60011210de9f7da01d552cae3a55 AS builder
1328

1429
# Install musl toolchain for static linking
@@ -21,17 +36,22 @@ RUN rustup target add x86_64-unknown-linux-musl
2136

2237
WORKDIR /build
2338

39+
# SOURCE_DATE_EPOCH should be passed as build arg (e.g., git commit timestamp)
40+
# Use: docker build --build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) ...
41+
ARG SOURCE_DATE_EPOCH
42+
RUN test -n "$SOURCE_DATE_EPOCH" || (echo "ERROR: SOURCE_DATE_EPOCH build arg is required" && exit 1)
43+
2444
# Reproducibility environment variables
2545
# Added -C link-arg=-s to strip symbols for bit-for-bit identity
26-
ENV SOURCE_DATE_EPOCH=1735689600 \
46+
ENV SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
2747
RUSTFLAGS="--remap-path-prefix=/build=/build --remap-path-prefix=/cargo=/cargo -C target-feature=+crt-static -C link-arg=-s" \
2848
CARGO_HOME=/cargo \
2949
LANG=C.UTF-8 \
3050
LC_ALL=C.UTF-8 \
3151
TZ=UTC
3252

33-
# Copy everything (including the 'vendor' folder and '.cargo/config.toml')
34-
COPY . .
53+
# Copy source and vendored deps from stage 1
54+
COPY --from=vendorer /src .
3555

3656
# Build using the vendored dependencies (--offline)
3757
# and your custom performance profile

0 commit comments

Comments
 (0)