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

Commit a7fcea8

Browse files
authored
feat(docker): Build cannon kona prestates for custom chains (#3118)
This patch adds support for custom chain configurations when invoking the `just cannon` recipe to build cannon kona prestates. This is useful for devnets and unannounced chains to also enjoy reproducible prestate builds. ## Testing - [x] Build canonical prestates of kona-client releases and ensure the hashes are [standard prestates hashes](https://github.com/ethereum-optimism/superchain-registry/blob/17e5b8f2639324402f192d379cba0d09cddd2a6c/validation/standard/standard-prestates.toml). - [x] Verify that custom prestates contain the custom chain configs
1 parent 31679c6 commit a7fcea8

5 files changed

Lines changed: 64 additions & 1 deletion

File tree

crates/protocol/registry/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,20 @@ fn merge_superchain_configs(custom_path: &Path, target_path: &Path) {
198198
for custom in custom_superchains.superchains {
199199
match superchains.entry(custom.name.clone()) {
200200
Entry::Occupied(mut entry) => {
201+
println!(
202+
"cargo:warning=debug: merging custom chains {}: [{}]",
203+
custom.name,
204+
custom.chains.iter().map(|c| c.name.as_str()).collect::<Vec<_>>().join(",")
205+
);
201206
let existing = entry.get_mut();
202207
*existing = merge_superchain_entry(std::mem::take(existing), custom);
203208
}
204209
Entry::Vacant(entry) => {
210+
println!(
211+
"cargo:warning=debug: inserting new custom chain {}: [{}]",
212+
custom.name,
213+
custom.chains.iter().map(|c| c.name.as_str()).collect::<Vec<_>>().join(",")
214+
);
205215
entry.insert(custom);
206216
}
207217
}

docker/docker-bake.hcl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ variable "CLIENT_BIN" {
100100
description = "The kona-client binary to use in the proof prestate targets. Valid options: kona, kona-int"
101101
}
102102

103+
variable "KONA_CUSTOM_CONFIGS" {
104+
// Used to build a kona prestate using custom chain configurations
105+
default = "false"
106+
description = "Enables custom chain configurations to be built into kona artifacts"
107+
}
108+
109+
variable "CUSTOM_CONFIGS_CONTEXT" {
110+
// The build context for custom chain configurations to add to the prestate build
111+
default = ""
112+
description = "The build context for custom chain configurations to add to the prestate build"
113+
}
114+
115+
103116
target "asterisc-builder" {
104117
description = "Rust build environment for bare-metal RISC-V 64-bit IMA (Asterisc FPVM ISA)"
105118
inherits = ["docker-metadata-action"]
@@ -135,10 +148,14 @@ target "kona-cannon-prestate" {
135148
inherits = ["docker-metadata-action"]
136149
context = "."
137150
dockerfile = "docker/fpvm-prestates/cannon-repro.dockerfile"
151+
contexts = {
152+
custom_configs = "${CUSTOM_CONFIGS_CONTEXT}"
153+
}
138154
args = {
139155
CLIENT_BIN = "${CLIENT_BIN}"
140156
CLIENT_TAG = "${GIT_REF_NAME}"
141157
CANNON_TAG = "${CANNON_TAG}"
158+
KONA_CUSTOM_CONFIGS = "${KONA_CUSTOM_CONFIGS}"
142159
}
143160
# Only build on linux/amd64 for a single source of reproducibility.
144161
platforms = ["linux/amd64"]

docker/fpvm-prestates/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ just asterisc <kona|kona-int> <kona_tag> <asterisc_tag>
2525
# Produce the prestate artifacts for `kona-client` running on `cannon` (version specified by `cannon_tag`)
2626
just cannon <kona|kona-int> <kona_tag> <cannon_tag>
2727
```
28+
29+
### `kona-client` + `cannon` prestate artifacts for custom chains
30+
31+
To create a reproducible kona-client prestate build that supports custom or devnet chain configurations that are not in the superchain-registry:
32+
33+
```sh
34+
# Produce the prestate artifacts for `kona-client` running on `cannon` (version specified by `cannon_tag`)
35+
just cannon <kona|kona-int> <kona_tag> <cannon_tag> <artifacts_output_dir> <custom_config_dir>
36+
```
37+

docker/fpvm-prestates/cannon-repro.dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ SHELL ["/bin/bash", "-c"]
3535

3636
ARG CLIENT_BIN
3737
ARG CLIENT_TAG
38+
ARG KONA_CUSTOM_CONFIGS
39+
40+
COPY --from=custom_configs / /usr/local/kona-custom-configs
3841

3942
# Install deps
4043
RUN apt-get update && apt-get install -y --no-install-recommends git
4144

4245
# Clone kona at the specified tag
4346
RUN git clone https://github.com/op-rs/kona
4447

48+
ENV KONA_CUSTOM_CONFIGS=$KONA_CUSTOM_CONFIGS
49+
ENV KONA_CUSTOM_CONFIGS_DIR=/usr/local/kona-custom-configs
50+
4551
# Build kona-client on the selected tag
4652
RUN cd kona && \
4753
git checkout $CLIENT_TAG && \

docker/fpvm-prestates/justfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ build-client-prestate-asterisc-artifacts kona_client_variant kona_tag asterisc_t
6464
kona-asterisc-prestate
6565

6666
# Build the `kona-client` prestate artifacts for the latest release (cannon).
67-
build-client-prestate-cannon-artifacts kona_client_variant kona_tag cannon_tag out='./prestate-artifacts-cannon':
67+
build-client-prestate-cannon-artifacts \
68+
kona_client_variant \
69+
kona_tag cannon_tag \
70+
out='./prestate-artifacts-cannon' \
71+
custom_config_dir='':
6872
#!/bin/bash
6973
OUTPUT_DIR={{out}}
7074

@@ -77,11 +81,27 @@ build-client-prestate-cannon-artifacts kona_client_variant kona_tag cannon_tag o
7781
# Navigate to workspace root
7882
cd ../..
7983

84+
if [[ -n "{{custom_config_dir}}" ]]; then
85+
export KONA_CUSTOM_CONFIGS="true"
86+
export CUSTOM_CONFIGS_CONTEXT="{{custom_config_dir}}"
87+
if [ ! -d "{{custom_config_dir}}" ]; then
88+
echo "Invalid custom config directory: {{custom_config_dir}}"
89+
exit 1
90+
fi
91+
echo "Using custom config directory: {{custom_config_dir}}"
92+
else
93+
# set to an empty directory to satisfy the docker build context requirement
94+
TEMP_DIR=$(mktemp -d)
95+
trap "rm -rf $TEMP_DIR" EXIT
96+
export CUSTOM_CONFIGS_CONTEXT="$TEMP_DIR"
97+
fi
98+
8099
# Create the output directory
81100
mkdir -p $OUTPUT_DIR
82101

83102
echo "Building kona-client (variant: {{kona_client_variant}}) prestate artifacts for the cannon target. 🐚 Kona Tag: {{kona_tag}} | 🔫 Cannon Tag: {{cannon_tag}}"
84103
docker buildx bake \
85104
--set "*.output=$OUTPUT_DIR" \
86105
-f docker/docker-bake.hcl \
106+
--allow fs=${CUSTOM_CONFIGS_CONTEXT} \
87107
kona-cannon-prestate

0 commit comments

Comments
 (0)