Skip to content

Commit de876da

Browse files
committed
fix: merge
2 parents c6cb42c + 9d8a5d9 commit de876da

13 files changed

Lines changed: 175 additions & 85 deletions

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Run Forge build
3535
run: |
36-
forge build --sizes
36+
forge build --deny warnings --sizes
3737
id: build
3838

3939
- name: Run Forge tests
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+
"

‎src/EspressoNitroTEEVerifier.sol‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ZkCoProcessorType,
1010
VerificationResult
1111
} from "aws-nitro-enclave-attestation/interfaces/INitroEnclaveVerifier.sol";
12-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
1312
import {TEEHelper} from "./TEEHelper.sol";
1413
import {JournalValidation} from "./libraries/JournalValidation.sol";
1514

@@ -19,8 +18,6 @@ import {JournalValidation} from "./libraries/JournalValidation.sol";
1918
* from `automata` to verify the proof.
2019
*/
2120
contract EspressoNitroTEEVerifier is IEspressoNitroTEEVerifier, TEEHelper {
22-
using EnumerableSet for EnumerableSet.AddressSet;
23-
2421
/// @custom:storage-location erc7201:espresso.storage.EspressoNitroTEEVerifier
2522
struct EspressoNitroTEEVerifierStorage {
2623
INitroEnclaveVerifier nitroEnclaveVerifier;

‎src/EspressoSGXTEEVerifier.sol‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from "@automata-network/dcap-attestation/contracts/types/Constants.sol";
1313
import {EnclaveReport} from "@automata-network/dcap-attestation/contracts/types/V3Structs.sol";
1414
import {BytesUtils} from "@automata-network/dcap-attestation/contracts/utils/BytesUtils.sol";
15-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
1615
import {IEspressoSGXTEEVerifier} from "./interface/IEspressoSGXTEEVerifier.sol";
1716
import {ServiceType} from "./types/Types.sol";
1817
import {TEEHelper} from "./TEEHelper.sol";
@@ -26,7 +25,6 @@ import {TEEHelper} from "./TEEHelper.sol";
2625

2726
contract EspressoSGXTEEVerifier is IEspressoSGXTEEVerifier, TEEHelper {
2827
using BytesUtils for bytes;
29-
using EnumerableSet for EnumerableSet.AddressSet;
3028

3129
/// @custom:storage-location erc7201:espresso.storage.EspressoSGXTEEVerifier
3230
struct EspressoSGXTEEVerifierStorage {

‎src/EspressoTEEVerifier.sol‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ contract EspressoTEEVerifier is
4545
_disableInitializers();
4646
}
4747

48+
/**
49+
* @notice Initializes verifier contracts and ownership for this proxy instance.
50+
* @param _owner The owner address that can manage verifier configuration.
51+
* @param _espressoSGXTEEVerifier The SGX verifier used for SGX-based attestations.
52+
* @param _espressoNitroTEEVerifier The Nitro verifier used for Nitro-based attestations.
53+
*/
4854
function initialize(
4955
address _owner,
5056
IEspressoSGXTEEVerifier _espressoSGXTEEVerifier,
@@ -165,8 +171,11 @@ contract EspressoTEEVerifier is
165171
if (address(_espressoSGXTEEVerifier) == address(0)) {
166172
revert InvalidVerifierAddress();
167173
}
168-
169-
_layout().espressoSGXTEEVerifier = _espressoSGXTEEVerifier;
174+
EspressoTEEVerifierStorage storage $ = _layout();
175+
address oldVerifier = address($.espressoSGXTEEVerifier);
176+
address newVerifier = address(_espressoSGXTEEVerifier);
177+
$.espressoSGXTEEVerifier = _espressoSGXTEEVerifier;
178+
emit EspressoSGXTEEVerifierSet(oldVerifier, newVerifier);
170179
}
171180

172181
/**
@@ -180,8 +189,11 @@ contract EspressoTEEVerifier is
180189
if (address(_espressoNitroTEEVerifier) == address(0)) {
181190
revert InvalidVerifierAddress();
182191
}
183-
184-
_layout().espressoNitroTEEVerifier = _espressoNitroTEEVerifier;
192+
EspressoTEEVerifierStorage storage $ = _layout();
193+
address oldVerifier = address($.espressoNitroTEEVerifier);
194+
address newVerifier = address(_espressoNitroTEEVerifier);
195+
$.espressoNitroTEEVerifier = _espressoNitroTEEVerifier;
196+
emit EspressoNitroTEEVerifierSet(oldVerifier, newVerifier);
185197
}
186198

187199
/**

‎src/TEEHelper.sol‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ abstract contract TEEHelper is ITEEHelper, Initializable {
1919
bytes32 internal constant TEE_HELPER_STORAGE_SLOT =
2020
0x6c53fdf1cef7bc567e8d46761d9c42d29c5fad7063be8d47b686412bfc375800;
2121

22+
/**
23+
* @notice Returns the ERC-7201 namespaced storage pointer for TEE helper state.
24+
* @return l Storage reference for TEEHelper state variables.
25+
*/
2226
function _layout() internal pure returns (TEEHelperStorage storage l) {
2327
bytes32 slot = TEE_HELPER_STORAGE_SLOT;
2428
assembly {
@@ -139,6 +143,10 @@ abstract contract TEEHelper is ITEEHelper, Initializable {
139143
}
140144
}
141145

146+
/**
147+
* @notice Updates the authorized TEE verifier address.
148+
* @param newTEEVerifier The new verifier address allowed to manage enclave hashes.
149+
*/
142150
function _setTEEVerifier(address newTEEVerifier) internal {
143151
if (newTEEVerifier == address(0)) {
144152
revert InvalidTEEVerifierAddress();

‎src/interface/IEspressoTEEVerifier.sol‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {ServiceType} from "../types/Types.sol";
77

88
interface IEspressoTEEVerifier {
99
error InvalidVerifierAddress();
10+
event EspressoSGXTEEVerifierSet(address indexed oldVerifier, address indexed newVerifier);
11+
event EspressoNitroTEEVerifierSet(address indexed oldVerifier, address indexed newVerifier);
1012

1113
/**
1214
* @notice This enum is used to specify the type of TEE

‎src/mocks/EspressoNitroTEEVerifierMock.sol‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ contract EspressoNitroTEEVerifierMock {
2020
/**
2121
* @notice Register a signer without verification. In mock, we skip ZK proof verification.
2222
* @param output The public output (ignored in mock, but we extract signer from it)
23-
* @param proofBytes The proof bytes (ignored in mock)
2423
*/
25-
function registerService(bytes calldata output, bytes calldata proofBytes, ServiceType service)
26-
external
27-
{
24+
function registerService(bytes calldata output, bytes calldata, ServiceType service) external {
2825
VerifierJournal memory journal = abi.decode(output, (VerifierJournal));
2926

3027
// The publicKey's first byte 0x04 byte followed which only determine if the public key is compressed or not.

‎src/mocks/EspressoSGXTEEVerifierMock.sol‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ contract EspressoSGXTEEVerifierMock {
2020

2121
/**
2222
* @notice Register a signer without verification. In mock, we skip quote verification.
23-
* @param attestation The attestation (ignored in mock)
2423
* @param data The signer address as bytes (20 bytes)
2524
*/
26-
function registerService(bytes calldata attestation, bytes calldata data, ServiceType service)
27-
external
28-
{
25+
function registerService(bytes calldata, bytes calldata data, ServiceType service) external {
2926
require(data.length == 20, "Invalid data length");
3027

3128
address signer = address(uint160(bytes20(data[:20])));

0 commit comments

Comments
 (0)