Skip to content

refactor(kms-auth): deploy app proxies through the DstackApp implementation - #1623

Merged
kvinwang merged 2 commits into
nextfrom
refactor/kms-contract-size-2
Nov 19, 2026
Merged

kvinwang merged 2 commits into
nextfrom
refactor/kms-contract-size-2

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

Problem

DstackKms is 24,113 bytes, against the 24,576-byte EIP-170 limit. The test upgrade target DstackKmsV2 has 231 bytes left, so almost any addition to DstackKms fails forge build --sizes. A per-platform TCB policy, for example, needs about 1.9 KB. #1569 already took the cheap wins (custom errors, range-only setters).

The largest single item is deployAndRegisterApp's new ERC1967Proxy(...): it embeds the proxy's creation code (1,007 bytes) and the ERC1967Utils code it pulls in.

Fix

DstackApp gains deployProxy(initData), which runs new ERC1967Proxy(address(this), initData) and refuses to run through a proxy (notDelegated). DstackKms.deployAndRegisterApp calls it on appImplementation. Nothing new is deployed: appImplementation is already a deployed DstackApp, and the app proxies are still OpenZeppelin ERC1967Proxy. Anyone may call deployProxy, but that is the same as deploying a proxy themselves.

Contract Before After
DstackKms 24,113 21,765
DstackKmsV2 24,345 21,988
DstackApp 12,231 14,240

Alternatives measured: optimizer_runs = 1 saves only 265 bytes. via_ir saves about 1.6 KB, but it changes code generation for every contract. An external library or a separate factory adds a deployment step.

Upgrade note

appImplementation must be a current DstackApp. A released one has no deployProxy, so deployAndRegisterApp reverts until it is replaced; nothing else is affected. Upgrade.s.sol:UpgradeKms now deploys a DstackApp and sets it in the same upgradeToAndCall, so the scripted upgrade is still one command. The CHANGELOG and script/README.md describe the manual path.

Verification

  • forge clean && forge test --ffi: 117 passed, including upgrade-safety validation. The new test_ReleasedKmsDeploysAppsOnceItsAppImplementationIsCurrent upgrades a v0.6.0 KMS and checks three things: deployAndRegisterApp reverts while appImplementation is the released app; after setAppImplementation, it deploys a correctly initialized app; and an app proxy refuses deployProxy.
  • Halmos (FOUNDRY_DYNAMIC_TEST_LINKING=false): DstackKmsSymbolicTest 11/11, DstackKmsEpochSymbolicTest 13/13, DstackAppSymbolicTest 5/5.

…tation

Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the refactor/kms-contract-size-2 branch from 2ac2713 to 14aca40 Compare November 19, 2026 05:03
@kvinwang
kvinwang enabled auto-merge November 19, 2026 05:03
@kvinwang
kvinwang merged commit 02d7318 into next Nov 19, 2026
28 checks passed
@kvinwang
kvinwang deleted the refactor/kms-contract-size-2 branch November 19, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant