Skip to content

Commit 5e41faf

Browse files
authored
Merge pull request #240 from Dstack-TEE/rename-contracts
kms: Rename contracts
2 parents 81bec11 + eccfd35 commit 5e41faf

27 files changed

Lines changed: 473 additions & 466 deletions

docs/deployment.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@ rm -f dstack-${DSTACK_VERSION}.tar.gz
5757
./dstack-vmm -c vmm.toml
5858
```
5959

60-
## Deploy the KmsAuth contract
60+
## Deploy the DstackKms contract
6161

62-
A KMS node requires a KMSAuth contract to be deployed on the Ethereum-compatible network.
62+
A KMS node requires a DstackKms contract to be deployed on the Ethereum-compatible network.
6363

6464
```bash
6565
cd dstack/kms/auth-eth
6666
npm install
6767
npx hardhat compile
6868
PRIVATE_KEY=<your-private-key> npx hardhat kms:deploy --with-app-impl --network phala
6969
```
70-
It will deploy both the AppAuth implementation and KmsAuth contract to the Phala network and print the contract addresses:
70+
It will deploy both the DstackApp implementation and DstackKms contract to the Phala network and print the contract addresses:
7171

7272
```
73-
Step 1: Deploying AppAuth implementation...
74-
AppAuth implementation deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
75-
Step 2: Deploying KmsAuth...
73+
Step 1: Deploying DstackApp implementation...
74+
DstackApp implementation deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
75+
Step 2: Deploying DstackKms...
7676
Deploying proxy...
7777
Waiting for deployment...
78-
KmsAuth Proxy deployed to: 0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875
78+
DstackKms Proxy deployed to: 0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875
7979
Implementation deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
8080
Deployment completed successfully
8181
Transaction hash: 0xd413d01a0640b6193048b0e98afb7c173abe58c74d9cf01f368166bc53f4fefe
8282
✅ Complete KMS setup deployed successfully!
83-
- AppAuth implementation: 0x5FbDB2315678afecb367f032d93F642f64180aa3
84-
- KmsAuth proxy: 0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875
83+
- DstackApp implementation: 0x5FbDB2315678afecb367f032d93F642f64180aa3
84+
- DstackKms proxy: 0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875
8585
🚀 Ready for factory app deployments!
8686
```
8787

@@ -93,7 +93,7 @@ cd dstack/kms/dstack-app/
9393
./deploy-to-vmm.sh
9494
```
9595
It will create a template `.env` file. Edit the `.env` file and set the required variables.
96-
Especially the `KMS_CONTRACT_ADDR` variable set to the address of the KmsAuth Proxy contract deployed in the previous step.
96+
Especially the `KMS_CONTRACT_ADDR` variable set to the address of the DstackKms Proxy contract deployed in the previous step.
9797
The `IMAGE_DOWNLOAD_URL` variable should be set to the URL of the dstack OS image used to verify the os_image_hash.
9898
```
9999
# .env
@@ -169,25 +169,27 @@ npx hardhat kms:add-image --network phala --mr <os-image-hash>
169169
```
170170

171171
### Register dstack-gateway in KMS
172-
As a normal dstack app, it requires the app to be registered in the KmsAuth contract first.
172+
As a normal dstack app, it requires the app to be registered in the DstackKms contract first.
173173

174174
```bash
175175
cd dstack/kms/auth-eth
176-
npx hardhat app:deploy --network phala
176+
npx hardhat kms:create-app --network phala --allow-any-device
177177
```
178178

179-
This will deploy an AppAuth contract in the KmsAuth contract and print the app ID:
179+
This will deploy an DstackApp contract in the DstackKms contract and print the app ID:
180180

181181
```
182-
Deploying proxy...
183-
Waiting for deployment...
184-
AppAuth Proxy deployed to: 0x539D0d59D1742780De41b85b2c3674b24369e292
185-
Implementation deployed to: 0x5aC1671E1Df54994D023F0B05806821d6D84e086
186-
Deployment completed successfully
187-
Transaction hash: 0xceac2ac6d56a40fef903b947d3a05df42ccce66da7f356c5d54afda68277f9a9
188-
Waiting for transaction 0xe144e9007208079e5e82c04f727d2383c58184e74d4f860e62557b5f330ab832 to be confirmed...
189-
App registered in KMS successfully
190-
Registered AppId: 0x31884c4b7775affe4c99735f6c2aff7d7bc6cfcd
182+
Deploying with account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
183+
Account balance: 9999.988063729279315546
184+
Initial device: 0xda2d377e04b7133ec1287a18d465fa44ae9dbb08d929166c6bdb414f38a2acd3
185+
Initial compose hash: none
186+
Using factory method for single-transaction deployment...
187+
Waiting for transaction 0x46cf1959abf309fcde86bcab2518dcf28dd9eec70c74214f0562e7bf847c50de to be confirmed...
188+
✅ App deployed and registered successfully!
189+
Proxy Address (App Id): 0x32467b43BFa67273FC7dDda0999Ee9A12F2AaA08
190+
Owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
191+
Transaction hash: 0x46cf1959abf309fcde86bcab2518dcf28dd9eec70c74214f0562e7bf847c50de
192+
Deployed with 1 initial device and 0 initial compose hash
191193
```
192194

193195
Now go to the `gateway/dstack-app/` directory and run the following command:
@@ -212,7 +214,7 @@ SRV_DOMAIN=test2.dstack.phala.network
212214
# Public IP address
213215
PUBLIC_IP=$(curl -s ifconfig.me)
214216
215-
# Gateway application ID. Register the app in KmsAuth first to get the app ID.
217+
# Gateway application ID. Register the app in DstackKms first to get the app ID.
216218
GATEWAY_APP_ID=0x31884c4b7775affe4c99735f6c2aff7d7bc6cfcd
217219
218220
# Whether to use ACME staging (yes/no)
@@ -262,7 +264,7 @@ GUEST_AGENT_ADDR: 127.0.0.1:9206
262264
Continue? [y/N]
263265
```
264266

265-
Don't press `y` yet. We need to add the compose hash to the AppAuth contract first. Go back to the `kms/auth-eth` directory and run the following command:
267+
Don't press `y` yet. We need to add the compose hash to the DstackApp contract first. Go back to the `kms/auth-eth` directory and run the following command:
266268

267269
```bash
268270
npx hardhat app:add-hash --network phala --app-id 0x31884c4b7775affe4c99735f6c2aff7d7bc6cfcd 0x700a50336df7c07c82457b116e144f526c29f6d8f4a0946b3e88065c9beba0f4
@@ -294,8 +296,8 @@ After the dstack-vmm is ready, you can deploy an app on it following the steps b
294296

295297
The on-chain registration process includes two steps:
296298

297-
1. Deploy an App's control contract AppAuth. Developers can develop their own or choose the reference contract from the Dstack repository. Custom contracts need to implement the IAppAuth interface.
298-
2. Call KmsAuth.registerApp(appAuthAddress) to register the contract.
299+
1. Deploy an App's control contract DstackApp. Developers can develop their own or choose the reference contract from the Dstack repository. Custom contracts need to implement the IAppAuth interface.
300+
2. Call DstackKms.registerApp(appContractAddress) to register the contract.
299301

300302
The Dstack repository provides scripts to complete these two steps:
301303

@@ -320,10 +322,10 @@ Command output:
320322
Deploying with account: 0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199
321323
Account balance: 9999.995278992293365404
322324
App ID: 0xA35b434eE853fdf9c2Bf48Fa1583Ac1332d50255
323-
Starting AppAuth deployment process...
325+
Starting DstackApp deployment process...
324326
Deploying proxy...
325327
Waiting for deployment...
326-
AppAuth deployed to: 0xD4a546B1C7e63CD4CeD314b2C90108e49191A915
328+
DstackApp deployed to: 0xD4a546B1C7e63CD4CeD314b2C90108e49191A915
327329
Implementation deployed to: 0x5aC1671E1Df54994D023F0B05806821d6D84e086
328330
Deployment completed successfully
329331
Transaction hash: 0xceac2ac6d56a40fef903b947d3a05df42ccce66da7f356c5d54afda68277f9a9
@@ -348,7 +350,7 @@ If you need to upgrade the contract in the future, please backup the `.openzeppe
348350

349351
Build app-compose.json and calculate its sha256 to get compose-hash. The compose hash can also be previewed in the dstack-vmm UI.
350352

351-
Call the hardhat command to add it to the whitelist (using AppAuth as an example here; custom AppAuth follows its own custom permission control logic).
353+
Call the hardhat command to add it to the whitelist (using DstackApp as an example here; custom DstackApp follows its own custom permission control logic).
352354

353355
```bash
354356
export PRIVATE_KEY=<your eth private key here>
@@ -360,7 +362,7 @@ npx hardhat app:add-hash --network phala --app-id 0xA35b434eE853fdf9c2Bf48Fa1583
360362
![app deploy](assets/app-deploy.png)
361363
- Select image `dstack-0.4.2`
362364
- Fill in the AppId applied in the contract during deployment
363-
- Currently, test KmsAuth has set a whitelist for Base image, requiring instance memory to be `≥ 3G` or exactly `= 2G`
365+
- Currently, test DstackKms has set a whitelist for Base image, requiring instance memory to be `≥ 3G` or exactly `= 2G`
364366

365367
After the app starts normally, click [Board] to access.
366368

gateway/dstack-app/deploy-to-vmm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ else
5252
# Public IP address
5353
PUBLIC_IP=$(curl -s4 ifconfig.me)
5454
55-
# The dstack-gateway application ID. Register the app in KmsAuth first to get the app ID.
55+
# The dstack-gateway application ID. Register the app in DstackKms first to get the app ID.
5656
# GATEWAY_APP_ID=31884c4b7775affe4c99735f6c2aff7d7bc6cfcd
5757
5858
# Whether to use ACME staging (yes/no)

kms/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ CVMs running in dstack support three boot modes:
4646
2. App control contract check
4747

4848
3. **Authorization Contracts**
49-
- `KmsAuth.sol`
49+
- `DstackKms.sol`
5050
- Maintains a registry for all Applications
5151
- Maintains the allowed KMS Instance MRs
5252
- Maintains the allowed OS Images
5353
- Registers KMS root keys
54-
- `AppAuth.sol`
55-
- Apps can have either a dedicated `AppAuth` contract or share one with multiple apps
54+
- `DstackApp.sol`
55+
- Apps can have either a dedicated `DstackApp` contract or share one with multiple apps
5656
- Controls permissions for individual apps
5757
- Maintains the allowed compose hashes for each app
5858

@@ -93,19 +93,19 @@ During bootstrapping, the KMS node generates two root keys:
9393
1. CA root key: Used to issue x509 certificates for Apps, enabling HTTPS traffic
9494
2. K256 root key: Used to derive Ethereum-compatible keys for Apps
9595

96-
After generating the root keys, their public portions can be obtained along with the corresponding TDX quote and registered in the KmsAuth contract.
96+
After generating the root keys, their public portions can be obtained along with the corresponding TDX quote and registered in the DstackKms contract.
9797

9898
#### KMS Self Replication
9999
When deploying a new KMS instance (`B`) using an existing instance (`A`), the process follows these steps:
100100

101101
1. **Prerequisites**
102-
- Register allowed MRs of instance `B` in the KmsAuth contract
102+
- Register allowed MRs of instance `B` in the DstackKms contract
103103

104104
2. **Replication Flow**
105105
- Configure instance `B` with the URL of existing instance `A`
106106
- Instance `B` sends replication request to instance `A` via RA-TLS based RPC
107107
- Instance `A` validates instance `B`'s TDX quote
108-
- Instance `A` checks KmsAuth contract for permissions
108+
- Instance `A` checks DstackKms contract for permissions
109109
- If approved, instance `A` transfers root keys to instance `B`
110110

111111
After the replication is complete, the KMS node becomes a fully functional KMS node.
@@ -117,7 +117,7 @@ Once onboarded, the KMS node begins listening for app key provisioning requests.
117117

118118
When a KMS node receives a key provisioning request, it:
119119
1. Validates the TDX quote of the requesting App
120-
2. Queries the KmsAuth contract for provisioning allowance
120+
2. Queries the DstackKms contract for provisioning allowance
121121
3. If allowed, generates and sends the keys to the App
122122

123123
### Attestation
@@ -134,7 +134,7 @@ As a simpler approach, an App can verify the signature chain using the KMS root
134134

135135
For example, given a message `M` signed by an App with signature `Sm`, the chain of trust works as follows:
136136

137-
1. The KMS maintains the root key `sK0`, with its corresponding public key `pK0` registered in the KmsAuth contract
137+
1. The KMS maintains the root key `sK0`, with its corresponding public key `pK0` registered in the DstackKms contract
138138
2. The App receives an app-key `sK1` from the KMS, along with signature `S1` (signed by `sK0`)
139139
3. The App derives a purpose-specific key `sK2` from `sK1`, with signature `S2` (signed by `sK1`)
140140
4. The App uses `sK2` to sign message `M`, producing signature `Sm`
@@ -146,7 +146,7 @@ The verification process follows these steps:
146146
1. Recover `pK2` from `Sm` and `M`
147147
2. Recover `pK1` from `S2` and `pK2` + `<purpose-id>`
148148
3. Recover `pK0` from `S1` and `pK1` + `<app-id>`
149-
4. Compare the recovered `pK0` with the registered `pK0` in the KmsAuth contract
149+
4. Compare the recovered `pK0` with the registered `pK0` in the DstackKms contract
150150

151151
## The RPC Interface
152152

0 commit comments

Comments
 (0)