Skip to content

Commit 9d8a5d9

Browse files
authored
fix: Update fix to use forge create instead of automata's scripts (#51)
* fix: Update fix to use forge create instead of automata's scripts * fix: add verifier id
1 parent 28c9df8 commit 9d8a5d9

1 file changed

Lines changed: 99 additions & 57 deletions

File tree

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11
#!/usr/bin/env bash
2-
# Deploys the NitroEnclaveVerifier and SP1Verifier contracts
3-
# from the aws-nitro-enclave-attestation submodule.
4-
#
5-
# Usage:
6-
# ./scripts/deploy-nitro-enclave-verifier.sh [--force]
7-
#
8-
# Options:
9-
# --force Deploy even if the submodule already has a deployment record
10-
# for the target chain (temporarily hides the existing record).
11-
#
12-
# Reads RPC_URL, PRIVATE_KEY, CHAIN_ID, and ETHERSCAN_API_KEY from .env in the project root.
13-
142
set -euo pipefail
153

16-
FORCE=false
17-
for arg in "$@"; do
18-
case "$arg" in
19-
--force) FORCE=true ;;
20-
*) echo "Unknown option: $arg"; exit 1 ;;
21-
esac
22-
done
23-
244
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
255
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
266
CONTRACTS_DIR="$PROJECT_ROOT/lib/aws-nitro-enclave-attestation/contracts"
7+
SAMPLES_DIR="$PROJECT_ROOT/lib/aws-nitro-enclave-attestation/samples"
278

28-
# Source .env from project root if it exists
299
if [ -f "$PROJECT_ROOT/.env" ]; then
3010
set -a
3111
source "$PROJECT_ROOT/.env"
3212
set +a
3313
fi
3414

35-
# Validate environment
3615
: "${RPC_URL:?RPC_URL is not set. Add it to .env or export it.}"
3716
: "${PRIVATE_KEY:?PRIVATE_KEY is not set. Add it to .env or export it.}"
3817
: "${CHAIN_ID:?CHAIN_ID is not set. Add it to .env or export it.}"
@@ -46,54 +25,117 @@ fi
4625

4726
cd "$CONTRACTS_DIR"
4827

49-
# Resolve chain ID for the deployment JSON lookup
5028
RESOLVED_CHAIN_ID=$(cast chain-id --rpc-url "$RPC_URL")
5129
if [ "$RESOLVED_CHAIN_ID" != "$CHAIN_ID" ]; then
52-
echo "Warning: CHAIN_ID ($CHAIN_ID) does not match RPC chain ($RESOLVED_CHAIN_ID)"
30+
echo "Error: CHAIN_ID ($CHAIN_ID) does not match RPC chain ($RESOLVED_CHAIN_ID)"
5331
exit 1
5432
fi
55-
DEPLOY_FILE="deployments/${CHAIN_ID}.json"
56-
BACKUP_FILE=""
57-
58-
# If --force, temporarily hide the existing deployment record so the
59-
# Solidity script's needsRedeploy() check doesn't skip deployment.
60-
if $FORCE && [ -f "$DEPLOY_FILE" ]; then
61-
BACKUP_FILE="${DEPLOY_FILE}.bak"
62-
echo "Force mode: temporarily moving $DEPLOY_FILE aside"
63-
mv "$DEPLOY_FILE" "$BACKUP_FILE"
64-
fi
6533

66-
# Restore the deployment file on exit (success or failure)
67-
cleanup() {
68-
if [ -n "$BACKUP_FILE" ] && [ -f "$BACKUP_FILE" ]; then
69-
# If forge created a new deployment file, keep it; otherwise restore.
70-
if [ ! -f "$DEPLOY_FILE" ]; then
71-
mv "$BACKUP_FILE" "$DEPLOY_FILE"
72-
echo "Restored original $DEPLOY_FILE"
73-
else
74-
rm "$BACKUP_FILE"
75-
fi
76-
fi
77-
}
78-
trap cleanup EXIT
79-
80-
echo "=== Deploying NitroEnclaveVerifier (chain ${CHAIN_ID}) ==="
81-
forge script script/NitroEnclaveVerifier.s.sol \
34+
OWNER_ADDRESS=$(cast wallet address --private-key "$PRIVATE_KEY")
35+
echo "Deployer / Owner address: $OWNER_ADDRESS"
36+
37+
# maxTimeDiff from the submodule's deploy-config.json (3 hours = 10800 seconds)
38+
MAX_TIME_DIFF=10800
39+
40+
# ============================================================
41+
# Step 1: Deploy NitroEnclaveVerifier
42+
# ============================================================
43+
echo ""
44+
echo "=== Step 1: Deploying NitroEnclaveVerifier (chain ${CHAIN_ID}) ==="
45+
echo " owner: $OWNER_ADDRESS"
46+
echo " maxTimeDiff: $MAX_TIME_DIFF"
47+
48+
VERIFIER_OUTPUT=$(forge create \
49+
src/NitroEnclaveVerifier.sol:NitroEnclaveVerifier \
8250
--rpc-url "$RPC_URL" \
8351
--private-key "$PRIVATE_KEY" \
8452
--broadcast \
85-
--verify --verifier etherscan --chain "$CHAIN_ID" \
86-
--sig 'deployVerifier()'
53+
--verify --etherscan-api-key "$ETHERSCAN_API_KEY" \
54+
--chain "$CHAIN_ID" \
55+
--constructor-args "$OWNER_ADDRESS" "$MAX_TIME_DIFF" "[]")
56+
57+
VERIFIER_ADDRESS=$(echo "$VERIFIER_OUTPUT" | grep 'Deployed to:' | awk '{print $3}')
58+
echo "NitroEnclaveVerifier deployed at: $VERIFIER_ADDRESS"
8759

60+
# ============================================================
61+
# Step 2: Deploy SP1Verifier
62+
# ============================================================
8863
echo ""
89-
echo "=== Deploying SP1Verifier ==="
90-
forge script script/NitroEnclaveVerifier.s.sol \
64+
echo "=== Step 2: Deploying SP1Verifier (chain ${CHAIN_ID}) ==="
65+
66+
SP1_OUTPUT=$(forge create \
67+
lib/sp1-contracts/contracts/src/v5.0.0/SP1VerifierGroth16.sol:SP1Verifier \
9168
--rpc-url "$RPC_URL" \
9269
--private-key "$PRIVATE_KEY" \
9370
--broadcast \
94-
--verify --verifier etherscan --chain "$CHAIN_ID" \
95-
--sig 'deploySP1Verifier()'
71+
--verify --etherscan-api-key "$ETHERSCAN_API_KEY" \
72+
--chain "$CHAIN_ID")
73+
74+
SP1_ADDRESS=$(echo "$SP1_OUTPUT" | grep 'Deployed to:' | awk '{print $3}')
75+
echo "SP1Verifier deployed at: $SP1_ADDRESS"
76+
77+
# ============================================================
78+
# Step 3: Configure — Set root certificate
79+
# ============================================================
80+
echo ""
81+
echo "=== Step 3: Setting root certificate ==="
82+
83+
ROOT_CERT_FILE="$SAMPLES_DIR/aws_root.der"
84+
if [ ! -f "$ROOT_CERT_FILE" ]; then
85+
echo "Error: AWS root cert not found at $ROOT_CERT_FILE"
86+
exit 1
87+
fi
9688

89+
# The contract uses sha256, not keccak — use openssl
90+
ROOT_CERT_HASH=0x$(openssl dgst -sha256 -binary "$ROOT_CERT_FILE" | xxd -p -c 64)
91+
echo " Root cert SHA-256: $ROOT_CERT_HASH"
92+
93+
cast send "$VERIFIER_ADDRESS" \
94+
"setRootCert(bytes32)" \
95+
"$ROOT_CERT_HASH" \
96+
--rpc-url "$RPC_URL" \
97+
--private-key "$PRIVATE_KEY"
98+
99+
echo "Root certificate set."
100+
101+
# ============================================================
102+
# Step 4: Configure — Set SP1 ZK configuration
103+
# ============================================================
104+
echo ""
105+
echo "=== Step 4: Setting SP1 ZK configuration ==="
106+
107+
# SP1 program IDs from the submodule's sample config
108+
SP1_VERIFIER_ID=$(jq -r '.program_id.verifier_id' "$SAMPLES_DIR/sp1_program_id.json")
109+
SP1_AGGREGATOR_ID=$(jq -r '.program_id.aggregator_id' "$SAMPLES_DIR/sp1_program_id.json")
110+
SP1_VERIFIER_PROOF_ID=$(jq -r '.program_id.verifier_proof_id' "$SAMPLES_DIR/sp1_program_id.json")
111+
112+
echo " SP1 Verifier ID: $SP1_VERIFIER_ID"
113+
echo " SP1 Aggregator ID: $SP1_AGGREGATOR_ID"
114+
echo " SP1 Verifier Proof ID: $SP1_VERIFIER_PROOF_ID"
115+
echo " SP1 Verifier Address: $SP1_ADDRESS"
116+
117+
# ZkCoProcessorType.Succinct = 2 (enum: Unknown=0, RiscZero=1, Succinct=2, Pico=3)
118+
# setZkConfiguration(ZkCoProcessorType, (bytes32 verifierId, bytes32 aggregatorId, address zkVerifier), bytes32 verifierProofId)
119+
cast send "$VERIFIER_ADDRESS" \
120+
"setZkConfiguration(uint8,(bytes32,bytes32,address),bytes32)" \
121+
2 \
122+
"($SP1_VERIFIER_ID,$SP1_AGGREGATOR_ID,$SP1_ADDRESS)" \
123+
"$SP1_VERIFIER_PROOF_ID" \
124+
--rpc-url "$RPC_URL" \
125+
--private-key "$PRIVATE_KEY"
126+
127+
echo "SP1 ZK configuration set."
128+
129+
130+
# ============================================================
131+
# Summary
132+
# ============================================================
97133
echo ""
98134
echo "=== Done ==="
99-
echo "Deployment artifacts saved in: $CONTRACTS_DIR/deployments/"
135+
echo ""
136+
echo "Deployed contracts:"
137+
echo " NitroEnclaveVerifier: $VERIFIER_ADDRESS"
138+
echo " SP1Verifier: $SP1_ADDRESS"
139+
echo ""
140+
141+
"

0 commit comments

Comments
 (0)