Skip to content

Commit c9244d2

Browse files
authored
feat: Add pcr0 gen (#72)
* Add pcr0 output * Fixes and update readme * clean up * rename * readme
1 parent 3837981 commit c9244d2

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This removes the need for the 7-day challenge period, and allows for immediate w
1414
├── <a href="./op-enclave">op-enclave</a>: Stateless transition function, for running in an AWS Nitro TEE
1515
├── <a href="./op-proposer">op-proposer</a>: L2-Output Submitter, communicates with op-enclave and submits proposals to L1
1616
├── <a href="./op-withdrawer">op-withdrawer</a>: Withdrawal utility for submitting withdrawals to L1
17-
├── <a href="./register-signer">register-signer</a>: Registers an enclave signer key from a Nitro attestation with the SystemConfigGlobal contract
17+
├── <a href="./tools">tools</a>: Tools for registering enclave signer keys with SystemConfigGlobal and verifying PCR0s
1818
├── <a href="./testnet">testnet</a>: Dockerized testnet for running the op-enclave stack
1919
</pre>
2020

tools/pcr0-verifier/Dockerfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Build skopeo
2+
FROM golang@sha256:367bb5295d3103981a86a572651d8297d6973f2ec8b62f716b007860e22cbc25 AS skopeo
3+
WORKDIR /app
4+
ENV REPO=https://github.com/containers/skopeo.git
5+
# v1.12.0
6+
ENV COMMIT=a55290973794d93f602a027e795bf510bd3cad01
7+
RUN git init && \
8+
git remote add origin $REPO && \
9+
git fetch --depth=1 origin $COMMIT && \
10+
git reset --hard FETCH_HEAD
11+
RUN CGO_ENABLED=0 DISABLE_DOCS=1 make BUILDTAGS=containers_image_openpgp GO_DYN_FLAGS=
12+
13+
# Build umoci
14+
FROM golang@sha256:367bb5295d3103981a86a572651d8297d6973f2ec8b62f716b007860e22cbc25 AS umoci
15+
WORKDIR /app
16+
ENV REPO=https://github.com/opencontainers/umoci.git
17+
# v0.4.7
18+
ENV COMMIT=17f38511d61846e2fb8ec01a1532f3ef5525e71d
19+
RUN git init && \
20+
git remote add origin $REPO && \
21+
git fetch --depth=1 origin $COMMIT && \
22+
git reset --hard FETCH_HEAD
23+
RUN go build -o bin/umoci ./cmd/umoci
24+
25+
# Get the EIF
26+
FROM golang@sha256:367bb5295d3103981a86a572651d8297d6973f2ec8b62f716b007860e22cbc25 AS op-enclave
27+
WORKDIR /app
28+
COPY --from=skopeo /app/bin/skopeo /app/bin/skopeo
29+
COPY --from=umoci /app/bin/umoci /app/bin/umoci
30+
31+
ENV TAG=v0.0.1-rc5
32+
RUN bin/skopeo --insecure-policy copy docker://ghcr.io/base/op-enclave:$TAG oci:op-enclave:latest
33+
RUN bin/umoci unpack --image op-enclave bundle
34+
35+
# Extract PCR0
36+
FROM amazonlinux:2
37+
RUN amazon-linux-extras enable aws-nitro-enclaves-cli && \
38+
yum clean metadata && \
39+
yum update -y && \
40+
yum install -y aws-nitro-enclaves-cli aws-nitro-enclaves-cli-devel jq && \
41+
yum clean all
42+
43+
COPY --from=op-enclave /app/bundle/rootfs/build/eif.bin /app/eif.bin
44+
COPY extract-pcr0.sh /extract-pcr0.sh
45+
RUN chmod +x /extract-pcr0.sh
46+
47+
ENTRYPOINT ["/extract-pcr0.sh"]

tools/pcr0-verifier/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# PCR0 Extractor
2+
3+
This tool extracts the PCR0 measurement from an op-enclave EIF (Enclave Image Format) file. The PCR0 measurement is a cryptographic hash that represents the initial state of the enclave, which is crucial for attestation and verification purposes.
4+
5+
## Prerequisites
6+
7+
- Docker installed on your system
8+
- [cast](https://book.getfoundry.sh/cast/) (for contract verification)
9+
10+
## Building and Running
11+
12+
1. Build the PCR0 extractor container:
13+
```bash
14+
docker build -t pcr0-extractor .
15+
```
16+
17+
2. Run the container to extract the PCR0:
18+
```bash
19+
docker run --rm pcr0-extractor
20+
```
21+
22+
The tool will:
23+
1. Download the specified op-enclave EIF
24+
2. Extract it using AWS Nitro CLI tools
25+
3. Output the PCR0 measurement
26+
4. Generate a cast command to verify the PCR0 against the SystemConfigGlobal contract
27+
28+
## Verifying PCR0 Against SystemConfigGlobal Contract
29+
30+
The tool will output a `cast` command that you can use to verify if the PCR0 is registered in the SystemConfigGlobal contract. The command will look like:
31+
32+
```bash
33+
export SYSTEM_CONFIG_GLOBAL_ADDRESS=<contract_address>
34+
cast call $SYSTEM_CONFIG_GLOBAL_ADDRESS 'validPCR0s(bytes32)' <keccak256_hash_of_pcr0>
35+
```
36+
37+
Note that the contract stores the keccak256 hash of the PCR0 value, not the raw PCR0 measurement. The tool automatically converts the PCR0 to the correct format for verification.
38+
39+
## How it Works
40+
41+
The tool uses a multi-stage Docker build to:
42+
1. Build required tools (skopeo and umoci)
43+
2. Download and extract the op-enclave EIF
44+
3. Use AWS Nitro CLI tools to extract the PCR0 measurement
45+
4. Convert the PCR0 to a keccak256 hash for contract verification
46+
47+
The output will include both the raw PCR0 measurement and instructions for verifying it against the contract.
48+
49+
## Note
50+
51+
The PCR0 measurement is specific to the version of the op-enclave EIF being examined. The current version being used is specified in the Dockerfile as `TAG=v0.0.1-rc5`.

tools/pcr0-verifier/entrypoint.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
echo "Starting PCR0 extraction..."
4+
echo "Checking if EIF file exists:"
5+
ls -l /app/eif.bin
6+
7+
echo "Command used: nitro-cli describe-eif --eif-path /app/eif.bin"
8+
echo "PCR0 measurement:"
9+
PCR0=$(nitro-cli describe-eif --eif-path /app/eif.bin | tee /dev/stderr | jq -r ".Measurements.PCR0")
10+
PCR0_WITH_PREFIX="0x${PCR0}"
11+
12+
echo -e "\nTo verify against SystemConfigGlobal contract, run:"
13+
echo "# First set your environment variables:"
14+
echo "export SYSTEM_CONFIG_GLOBAL_ADDRESS=<contract_address>"
15+
echo "export RPC_URL=<rpc_url>"
16+
echo -e "\n# Then run these commands to verify:"
17+
echo "# To register a new PCR0 (requires owner access):"
18+
echo "cast send \$SYSTEM_CONFIG_GLOBAL_ADDRESS 'registerPCR0(bytes)' ${PCR0_WITH_PREFIX} --rpc-url \$RPC_URL"
19+
echo -e "\n# To check if a PCR0 is valid:"
20+
echo "cast call \$SYSTEM_CONFIG_GLOBAL_ADDRESS 'validPCR0s(bytes32)' \$(cast keccak ${PCR0_WITH_PREFIX}) --rpc-url \$RPC_URL"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)