Skip to content

Commit

Permalink
Merge pull request #67 from ethereum-optimism/tei/prestate-CI
Browse files Browse the repository at this point in the history
Reproducible absolute prestate of op-program
  • Loading branch information
ImTei authored Jun 19, 2024
2 parents 36d7355 + e8ffc2e commit 9c2c49a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
41 changes: 40 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ workflows:
requires: ["asterisc-prestate"]
- op-e2e-asterisc-tests:
requires: ["devnet-allocs-including-asterisc"]
- prestate-reproducibility:
matrix:
parameters:
version: ["1.1.0", "1.2.0"]

jobs:
pnpm-monorepo:
Expand Down Expand Up @@ -359,4 +363,39 @@ jobs:
path: /testlogs
when: always
- store_test_results:
path: /tmp/test-results
path: /tmp/test-results

prestate-reproducibility:
docker:
- image: <<pipeline.parameters.ci_builder_image>>
parameters:
version:
type: string
steps:
- checkout
- setup_remote_docker
- run:
name: Fetch submodules for asterisc
command: git submodule update --init
- run:
name: Switch to tag
command: |
cd rvsol/lib/optimism
git fetch
git checkout "op-program/v<<parameters.version>>"
git submodule update --init --recursive
- run:
name: Build prestate
command: make reproducible-prestate
- run:
name: Verify prestate
command: |
EXPECTED_PRESTATE_HASH=$(jq -r '.["op-program"]["<<parameters.version>>"]' ./prestates.json)
ACTUAL=$(jq -r .pre ./bin/prestate-proof.json)
echo "Expected: ${EXPECTED_PRESTATE_HASH}"
echo "Actual: ${ACTUAL}"
if [[ "${EXPECTED_PRESTATE_HASH}" != "${ACTUAL}" ]]
then
echo "Prestate did not match expected"
exit 1
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin

rvgo/bin
rvgo/scripts/go-ffi/go-ffi
rvgo/test/testdata
Expand Down
51 changes: 51 additions & 0 deletions Dockerfile.repro
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM golang:1.21.3-alpine3.18 as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN echo "go mod cache: $(go env GOMODCACHE)"
RUN echo "go build cache: $(go env GOCACHE)"

RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go mod download

COPY . /app

# We avoid copying the full .git dir into the build for just some metadata.
# Instead, specify:
# --build-arg GIT_COMMIT=$(git rev-parse HEAD)
# --build-arg GIT_DATE=$(git show -s --format='%ct')
ARG GIT_COMMIT
ARG GIT_DATE

ARG ASTERISC_VERSION=v0.0.0
ARG OP_PROGRAM_VERSION=v0.0.0

ARG TARGETOS TARGETARCH

# Build the asterisc, op-program, and op-program-client-riscv.elf binaries.
RUN --mount=type=cache,target=/root/.cache/go-build cd rvgo && make build \
GOOS=$TARGETOS GOARCH=$TARGETARCH GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE VERSION="ASTERISC_VERSION"
RUN --mount=type=cache,target=/root/.cache/go-build cd rvsol/lib/optimism/op-program && make op-program-host \
GOOS=$TARGETOS GOARCH=$TARGETARCH GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE VERSION="$OP_PROGRAM_VERSION"
RUN --mount=type=cache,target=/root/.cache/go-build cd rvsol/lib/optimism/op-program && make op-program-client-riscv \
GOOS=linux GOARCH=mips GOMIPS=softfloat GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE VERSION="$OP_PROGRAM_VERSION"

# Run the op-program-client-riscv.elf binary directly through asterisc's load-elf subcommand.
RUN /app/rvgo/bin/asterisc load-elf --path /app/rvsol/lib/optimism/op-program/bin/op-program-client-riscv.elf --out /app/prestate.json --meta ""

# Generate the prestate proof containing the absolute pre-state hash.
RUN /app/rvgo/bin/asterisc run --proof-at '=0' --stop-at '=1' --input /app/prestate.json --meta "" --proof-fmt '/app/%d.json' --output ""
RUN mv /app/0.json /app/prestate-proof.json

# Exports files to the specified output location.
# Writing files to host requires buildkit to be enabled.
# e.g. `BUILDKIT=1 docker build ...`
FROM scratch AS export-stage
COPY --from=builder /app/rvsol/lib/optimism/op-program/bin/op-program .
COPY --from=builder /app/rvsol/lib/optimism/op-program/bin/op-program-client-riscv.elf .
COPY --from=builder /app/prestate.json .
COPY --from=builder /app/prestate-proof.json .
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ devnet-clean:
rm -rf packages/contracts-bedrock/deployments
rm -rf packages/contracts-bedrock/deploy-config
.PHONY: devnet-clean

reproducible-prestate:
@docker build --output ./bin/ --progress plain -f Dockerfile.repro .
@echo "Absolute prestate hash:"
@cat ./bin/prestate-proof.json | jq -r .pre
.PHONY: reproducible-prestate
6 changes: 6 additions & 0 deletions prestates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"op-program": {
"1.1.0": "0x0338dc64405def7e3b9ce8f5076b422a846d831832617d227f13baf219cb5406",
"1.2.0": "0x0399525587d7ffb173aaa43f35e21b78f807a0bd3dc80ea6527f407732726351"
}
}

0 comments on commit 9c2c49a

Please sign in to comment.