Skip to main content

Deploy On-chain KMS Smart Contracts

Deploy the DstackKms smart contract to enforce that only authorized workloads can receive keys. This page covers the full contract deployment workflow, including the recommended Safe + Timelock governance setup for production.

Overview

Note: Safe and Timelock are optional security enhancements, not part of dstack. They are recommended for production but not required for development.

Governance Models

Model A: Direct Admin (Simplest)

  • Admin is a single EOA (externally owned account)
  • No multisig, no timelock
  • Governance actions execute immediately
  • Suitable for development and testing

Model B: Timelock Only

  • Admin is a TimelockController contract
  • Governance actions require a delay before execution
  • Anyone can execute after delay (or restricted to specific executors)
  • Suitable for simple production setups
  • Admin is a Safe multisig wallet
  • Timelock enforces a delay
  • Requires multi-party approval + delay period
  • Maximum security and transparency

Prerequisites

  • Foundry installed (forge, cast)
  • A wallet with funds for deployment gas
    • Testnet: Use a faucet (e.g., Base Sepolia faucet)
    • Mainnet: Sufficient ETH for contract deployment
  • RPC endpoint for the target network

Step 1: Set Up the Project


Step 2: Configure Environment

Create a .env file:
Security: Never commit your private key. Add .env to .gitignore.

Step 3: Deploy DstackKms (Basic, No Timelock)

For development/testing, you can deploy DstackKms with direct EOA admin:
Why ERC1967Proxy? DstackKms uses UUPS upgradeable pattern. You must deploy a proxy to have a working upgradeable instance. The proxy is the actual application address.

Timelock Configuration

The timelock delay depends on your deployment environment:

4.1 Prepare Timelock Configuration

4.2 Deploy All Contracts

4.3 Understanding TimelockController Roles


For production, use a Safe multisig as the proposer/executor:

5.1 Create a Safe

  1. Go to Safe web app
  2. Connect your wallet
  3. Create a new Safe on your target network
  4. Add signers (3-7 addresses recommended)
  5. Set threshold (≥ 2/3 of signers)

5.2 Use Safe Address in Deployment

When deploying the TimelockController, use your Safe address:

5.3 Governance Flow with Safe + Timelock

  1. Draft transaction — Use Safe web interface to create a transaction
  2. Collect signatures — Required signers approve
  3. Schedule in timelock — Safe calls timelock.schedule()
  4. Wait for delay — Wait the configured delay period
  5. Execute — Anyone (or only executor) calls timelock.execute()

Step 6: Verify Deployment

Verify on block explorer:
Check on block explorer:
  • DstackKms owner is set to the TimelockController address
  • TimelockController has correct proposer/executor roles

How to Execute Governance Actions (With Timelock)

Once deployed, all onlyOwner operations must go through the timelock:

Schedule an Operation

Execute After Delay


All Governance-Protected Methods

Once ownership is transferred to timelock, these methods require timelock governance:

Common Issues


Next Steps