Skip to content

Commit d28e81a

Browse files
committed
add a script to use enclave tool
1 parent b411171 commit d28e81a

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# --- load .env ---
5+
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6+
ENV_FILE="${SCRIPT_DIR}/../.env"
7+
if [[ ! -f "$ENV_FILE" ]]; then
8+
echo "Error: $ENV_FILE not found"; exit 1
9+
fi
10+
# export everything we source
11+
set -a
12+
# shellcheck disable=SC1090
13+
source "$ENV_FILE"
14+
set +a
15+
16+
# Configuration
17+
# NOTE: if loopback doesn't work from inside the enclave, set HOST_IP=host
18+
HOST_IP="${HOST_IP:-127.0.0.1}"
19+
TAG="${TAG:-op-batcher-enclavetool}"
20+
21+
echo "Using HOST_IP: $HOST_IP"
22+
echo "Ports -> L1:$L1_HTTP_PORT L2:$OP_HTTP_PORT Rollup:$ROLLUP_PORT EspressoAPI:$ESPRESSO_SEQUENCER_API_PORT"
23+
24+
# Build enclave-tools if not already built
25+
if [[ ! -f "../op-batcher/bin/enclave-tools" ]]; then
26+
echo "Building enclave-tools..."
27+
cd ../op-batcher
28+
just enclave-tools
29+
cd -
30+
fi
31+
32+
# Batcher arguments for both build and run
33+
BATCHER_ARGS="--l1-eth-rpc=http://$HOST_IP:$L1_HTTP_PORT,--l2-eth-rpc=http://$HOST_IP:$OP_HTTP_PORT,--rollup-rpc=http://$HOST_IP:$ROLLUP_PORT,--espresso-url=http://$HOST_IP:$ESPRESSO_SEQUENCER_API_PORT,--espresso-url=http://$HOST_IP:$ESPRESSO_SEQUENCER_API_PORT,--testing-espresso-batcher-private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80,--mnemonic=test test test test test test test test test test test junk,--hd-path=m/44'/60'/0'/0/0,--throttle-threshold=0,--max-channel-duration=1,--target-num-frames=1,--espresso-light-client-addr=0x703848f4c85f18e3acd8196c8ec91eb0b7bd0797"
34+
35+
# Use enclave-tools to build the image
36+
echo "Building enclave image using enclave-tools..."
37+
BUILD_OUTPUT=$(../op-batcher/bin/enclave-tools build \
38+
--op-root ../ \
39+
--tag "$TAG" \
40+
--args "$BATCHER_ARGS" 2>&1)
41+
42+
if [ $? -ne 0 ]; then
43+
echo "Failed to build enclave image"
44+
exit 1
45+
fi
46+
47+
echo "$BUILD_OUTPUT"
48+
49+
# Extract PCR0 from build output
50+
PCR0=$(echo "$BUILD_OUTPUT" | grep "PCR0:" | sed 's/.*PCR0: //')
51+
52+
# Get batch authenticator address from deployment state
53+
BATCH_AUTHENTICATOR_ADDRESS=$(jq -r '.opChainDeployments[0].batchAuthenticatorAddress' deployment/deployer/state.json)
54+
55+
if [[ -n "$PCR0" && -n "$BATCH_AUTHENTICATOR_ADDRESS" && -n "$OPERATOR_PRIVATE_KEY" ]]; then
56+
echo "Registering PCR0: $PCR0 with authenticator: $BATCH_AUTHENTICATOR_ADDRESS"
57+
../op-batcher/bin/enclave-tools register \
58+
--authenticator "$BATCH_AUTHENTICATOR_ADDRESS" \
59+
--l1-url "http://$HOST_IP:$L1_HTTP_PORT" \
60+
--private-key "$OPERATOR_PRIVATE_KEY" \
61+
--pcr0 "$PCR0"
62+
63+
if [ $? -ne 0 ]; then
64+
echo "Failed to register PCR0, continuing anyway..."
65+
fi
66+
else
67+
echo "Skipping registration - missing PCR0 ($PCR0), BATCH_AUTHENTICATOR_ADDRESS ($BATCH_AUTHENTICATOR_ADDRESS), or OPERATOR_PRIVATE_KEY"
68+
fi
69+
70+
# Run the enclave
71+
echo "Running enclave..."
72+
echo "Command: ../op-batcher/bin/enclave-tools run --image \"$TAG\" --args \"$BATCHER_ARGS\""
73+
../op-batcher/bin/enclave-tools run \
74+
--image "$TAG" \
75+
--args "$BATCHER_ARGS" &

op-batcher/enclave-entrypoint.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
3131
NC_PORT=8337
3232
received_args=()
3333

34-
echo "Starting nc listener on port $NC_PORT (10 second timeout)"
34+
echo "Starting nc listener on port $NC_PORT (60 second timeout)"
3535
{
3636
# Read null-separated arguments until we get \0\0
3737
while IFS= read -r -d '' arg; do
@@ -41,10 +41,10 @@ echo "Starting nc listener on port $NC_PORT (10 second timeout)"
4141
fi
4242
received_args+=("$arg")
4343
done
44-
} < <(nc -l -p "$NC_PORT" -w 10)
44+
} < <(nc -l -p "$NC_PORT" -w 60)
4545

4646
if [ ${#received_args[@]} -eq 0 ]; then
47-
echo "Warning: No arguments received via nc listener within 10 seconds, continuing with existing arguments"
47+
echo "Warning: No arguments received via nc listener within 60 seconds, continuing with existing arguments"
4848
else
4949
echo "Received ${#received_args[@]} arguments via nc, appending to existing arguments"
5050
# Append received arguments to existing positional parameters

0 commit comments

Comments
 (0)