Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Commit b822ff5

Browse files
committed
fix: keep enclave signing key out of image builds (#694)
* fix: keep enclave signing key out of image builds * fix: support GCP Secret Manager enclave key * chore: update mainnet SGX verifier addresses * chore: update gaiko submodule verifier config * chore: update internal devnet chain spec * fix: align devnet SGX verifier addresses * fix: restore devnet verifier config * fix: align gaiko embedded chain specs * fix: remove invalid shasta chain spec forks * fix: unblock enclave key CI build
1 parent 107afa8 commit b822ff5

9 files changed

Lines changed: 102 additions & 65 deletions

File tree

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
!/Cargo.toml
77
!/config.json
88
!/docker/entrypoint.sh
9-
!/docker/enclave-key.pem
109
!/docker/cargo-config.toml
1110
!/.env
1211
!/lib

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SP1_BATCH_VK_HASH=4e8ed79204df0fec11c3bacb3c517e0f33783f9626cb2b6e0e1e46b519ae09
1616
SP1_SHASTA_AGGREGATION_VK_HASH=69640eee59d46fae18ecadf92189b4b20b63eb206bf4034d5aaf2bcf68a8b53b
1717

1818
# SGX MRENCLAVE
19-
SGX_MRENCLAVE=cc28d7121684a5141435a4eb660a2f44ad3fdd67c44f0c351e6c1c2d1c043a8f
19+
SGX_MRENCLAVE=72258d3cae0e9901d0efc1f630064f1c44f11950bd25fee0b62ec8df84532da2
2020

2121
# SGXGETH MRENCLAVE
22-
SGXGETH_MRENCLAVE=d8395bb1ae83b13c2a9d8430f09137ec179a424926aee9c0639cda70936305b9
22+
SGXGETH_MRENCLAVE=398be8424f27802b38e6e8d3413bf6a0b187349e68522a218f5bfc00279006ac

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ perf.data.old
6363
.vscode/
6464

6565
log.build.*
66+
docker/enclave-key.pem
6667

6768
# Python
6869
# -----------------------------------------------------------------------------------------

Dockerfile

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ RUN ego-go build -o gaiko-ego ./cmd/gaiko
1212

1313
# Sign with our enclave config and private key
1414
COPY gaiko/ego/enclave.json .
15-
COPY docker/enclave-key.pem private.pem
16-
RUN ego sign && ego bundle gaiko-ego gaiko
15+
ARG ENCLAVE_KEY_PUBLIC_SHA256
16+
# CI/local compose builds use a throwaway key; release builds pass a secret and hash.
17+
RUN --mount=type=secret,id=enclave_key,target=/run/secrets/enclave-key.pem \
18+
set -e; \
19+
trap 'rm -f private.pem' EXIT; \
20+
if [ -s /run/secrets/enclave-key.pem ]; then \
21+
if [ -n "${ENCLAVE_KEY_PUBLIC_SHA256}" ]; then \
22+
test "$(openssl rsa -in /run/secrets/enclave-key.pem -pubout 2>/dev/null | openssl sha256 | awk '{print $2}')" = "${ENCLAVE_KEY_PUBLIC_SHA256}"; \
23+
fi; \
24+
cp /run/secrets/enclave-key.pem private.pem; \
25+
else \
26+
test -z "${ENCLAVE_KEY_PUBLIC_SHA256}"; \
27+
openssl genrsa -3 -out private.pem 3072; \
28+
fi; \
29+
ego sign && \
30+
ego bundle gaiko-ego gaiko
1731
RUN ego uniqueid gaiko-ego 2>&1 | tee /tmp/gaiko_uniqueid.log
1832
RUN ego signerid gaiko-ego
1933

@@ -87,13 +101,26 @@ COPY --from=builder /opt/raiko/host/config/chain_spec_list_devnet.json /etc/raik
87101
COPY --from=builder /opt/raiko/target/release/sgx-guest ./bin/
88102
COPY --from=builder /opt/raiko/target/release/raiko-host ./bin/
89103
COPY --from=builder /opt/raiko/target/release/raiko-setup ./bin/
90-
COPY --from=builder /opt/raiko/docker/enclave-key.pem /root/.config/gramine/enclave-key.pem
91104

92105
ARG EDMM=0
106+
ARG ENCLAVE_KEY_PUBLIC_SHA256
93107
ENV EDMM=${EDMM}
94108
WORKDIR /opt/raiko/bin
95-
RUN gramine-manifest -Dlog_level=error -Ddirect_mode=0 -Darch_libdir=/lib/x86_64-linux-gnu/ ../provers/sgx/config/sgx-guest.local.manifest.template sgx-guest.manifest && \
96-
gramine-sgx-sign --manifest sgx-guest.manifest --output sgx-guest.manifest.sgx && \
109+
RUN --mount=type=secret,id=enclave_key,target=/run/secrets/enclave-key.pem \
110+
set -e; \
111+
enclave_key_path=/tmp/enclave-key.pem; \
112+
trap 'rm -f "$enclave_key_path"' EXIT; \
113+
if [ -s /run/secrets/enclave-key.pem ]; then \
114+
if [ -n "${ENCLAVE_KEY_PUBLIC_SHA256}" ]; then \
115+
test "$(openssl rsa -in /run/secrets/enclave-key.pem -pubout 2>/dev/null | openssl sha256 | awk '{print $2}')" = "${ENCLAVE_KEY_PUBLIC_SHA256}"; \
116+
fi; \
117+
cp /run/secrets/enclave-key.pem "$enclave_key_path"; \
118+
else \
119+
test -z "${ENCLAVE_KEY_PUBLIC_SHA256}"; \
120+
openssl genrsa -3 -out "$enclave_key_path" 3072; \
121+
fi; \
122+
gramine-manifest -Dlog_level=error -Ddirect_mode=0 -Darch_libdir=/lib/x86_64-linux-gnu/ ../provers/sgx/config/sgx-guest.local.manifest.template sgx-guest.manifest && \
123+
gramine-sgx-sign --key "$enclave_key_path" --manifest sgx-guest.manifest --output sgx-guest.manifest.sgx && \
97124
gramine-sgx-sigstruct-view "sgx-guest.sig" 2>&1 | tee /tmp/sgx_sigstruct.log
98125

99126

docker/enclave-key.pem

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

gaiko

host/config/chain_spec_list_default.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@
9797
"beacon_rpc": null,
9898
"verifier_address_forks": {
9999
"SHASTA": {
100-
"SGX": "0xa1018Ba2e22139076f91dA2A856B2CAB22d968F6",
100+
"SGX": "0x9D3C595BFf6Ff7D2b2CbdEcF94aD917eB2fCFFd8",
101101
"RISC0": "0x059dAF31F571da48Ab4e74Ae12F64f907681Cd8b",
102102
"SP1": "0x96337327648dcFA22b014009cf10A2D5E2F305f6",
103-
"SGXGETH": "0x08568Df252ecf37D6C3eFD24f6ca3688118697F1"
103+
"SGXGETH": "0x41e79EB4F03aBB5DF8716B759528dc5d8f6a84Ee"
104104
}
105105
},
106106
"genesis_time": 0,
@@ -173,4 +173,4 @@
173173
"seconds_per_slot": 1,
174174
"is_taiko": true
175175
}
176-
]
176+
]

host/config/chain_spec_list_devnet.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"RISC0": null
3232
}
3333
},
34-
"genesis_time": 1769395300,
34+
"genesis_time": 1782220308,
3535
"seconds_per_slot": 12,
3636
"is_taiko": false
3737
},
@@ -50,7 +50,7 @@
5050
"Block": 0
5151
},
5252
"SHASTA": {
53-
"Timestamp": 1769396301
53+
"Timestamp": 0
5454
},
5555
"CANCUN": "TBD"
5656
},
@@ -61,28 +61,21 @@
6161
"elasticity_multiplier": "0x2"
6262
},
6363
"l1_contract": {
64-
"PACAYA": "0x3b37a799290950fef954dfF547608baC52A12571",
65-
"SHASTA": "0x12100faa7b157e9947340B44409fC7E27EC0ABef"
64+
"SHASTA": "0xb432bbe475e569B2ADef4830Ae43D587932F139C"
6665
},
6766
"l2_contract": "0x1670010000000000000000000000000000010001",
6867
"rpc": "https://rpc.internal.taiko.xyz",
6968
"beacon_rpc": null,
7069
"verifier_address_forks": {
71-
"PACAYA": {
72-
"SGX": "0x9D351F6E72e3095F24dD854c9B8CA69F99A2C538",
73-
"SP1": "0xCb2D625BF8C2187B180646aF4738AF5F1413Fb70",
74-
"RISC0": "0x48940F7ab2C674Aa66C09eDa71614aD704E9d007",
75-
"SGXGETH": "0x6B455442C8C4cAC2e09c40409E8bf7FfcdB1Fc50"
76-
},
7770
"SHASTA": {
78-
"SGX": "0x9D351F6E72e3095F24dD854c9B8CA69F99A2C538",
71+
"SGX": "0x6fF4A33Fe3766D08251247Daab78F7ebEAD7Db72",
7972
"SP1": "0xCb2D625BF8C2187B180646aF4738AF5F1413Fb70",
8073
"RISC0": "0x48940F7ab2C674Aa66C09eDa71614aD704E9d007",
81-
"SGXGETH": "0x6B455442C8C4cAC2e09c40409E8bf7FfcdB1Fc50"
74+
"SGXGETH": "0xb31e61a8b6Fb5A9573dC1a0B328b1BD184dca98E"
8275
}
8376
},
8477
"genesis_time": 0,
8578
"seconds_per_slot": 1,
8679
"is_taiko": true
8780
}
88-
]
81+
]

script/publish-image.sh

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,67 @@ case "$proof_type" in
5353
esac
5454

5555
echo "Build and push $image_name:$tag..."
56-
docker buildx build . \
56+
build_secret_args=()
57+
tmp_enclave_key_path=""
58+
cleanup_tmp_enclave_key() {
59+
if [[ -n "$tmp_enclave_key_path" ]]; then
60+
rm -f "$tmp_enclave_key_path"
61+
fi
62+
}
63+
trap cleanup_tmp_enclave_key EXIT
64+
65+
if [ "$proof_type" = "0" ] || [ "$proof_type" = "tee" ]; then
66+
if [[ -n "${GCP_ENCLAVE_KEY_SECRET:-}" ]]; then
67+
if ! command -v gcloud >/dev/null 2>&1; then
68+
echo "❌ gcloud is required when GCP_ENCLAVE_KEY_SECRET is set."
69+
exit 1
70+
fi
71+
72+
tmp_enclave_key_path="$(mktemp)"
73+
gcloud_secret_version="${GCP_ENCLAVE_KEY_VERSION:-latest}"
74+
gcloud_secret_args=(
75+
secrets versions access "$gcloud_secret_version"
76+
--secret "$GCP_ENCLAVE_KEY_SECRET"
77+
--out-file "$tmp_enclave_key_path"
78+
)
79+
if [[ -n "${GCP_ENCLAVE_KEY_PROJECT:-}" ]]; then
80+
gcloud_secret_args+=(--project "$GCP_ENCLAVE_KEY_PROJECT")
81+
fi
82+
83+
echo "Fetching enclave signing key from GCP Secret Manager: $GCP_ENCLAVE_KEY_SECRET version $gcloud_secret_version"
84+
case "$-" in
85+
*x*) xtrace_was_on=1 ;;
86+
*) xtrace_was_on=0 ;;
87+
esac
88+
set +x
89+
gcloud "${gcloud_secret_args[@]}"
90+
if [[ "$xtrace_was_on" = "1" ]]; then
91+
set -x
92+
fi
93+
chmod 0600 "$tmp_enclave_key_path"
94+
enclave_key_path="$tmp_enclave_key_path"
95+
else
96+
enclave_key_path="${ENCLAVE_KEY_PATH:-docker/enclave-key.pem}"
97+
fi
98+
99+
if [ ! -s "$enclave_key_path" ]; then
100+
echo "❌ Missing enclave signing key: $enclave_key_path"
101+
echo "Set GCP_ENCLAVE_KEY_SECRET=<secret-name>, ENCLAVE_KEY_PATH=/path/to/enclave-key.pem, or provide docker/enclave-key.pem locally."
102+
exit 1
103+
fi
104+
enclave_key_public_sha256="$(openssl rsa -in "$enclave_key_path" -pubout 2>/dev/null | openssl sha256 | awk '{print $2}')"
105+
build_secret_args=(
106+
--secret "id=enclave_key,src=$enclave_key_path"
107+
--build-arg "ENCLAVE_KEY_PUBLIC_SHA256=$enclave_key_public_sha256"
108+
)
109+
fi
110+
111+
DOCKER_BUILDKIT=1 docker buildx build . \
57112
-f $target_dockerfile \
58113
--load \
59114
--platform linux/amd64 \
60115
-t $image_name:latest \
116+
"${build_secret_args[@]}" \
61117
$build_flags \
62118
--build-arg TARGETPLATFORM=linux/amd64 \
63119
--progress=plain \

0 commit comments

Comments
 (0)