Skip to content

Migrate to Foundry#252

Open
h4x3rotab wants to merge 1 commit into
masterfrom
foundry
Open

Migrate to Foundry#252
h4x3rotab wants to merge 1 commit into
masterfrom
foundry

Conversation

@h4x3rotab
Copy link
Copy Markdown
Contributor

@h4x3rotab h4x3rotab commented Jul 23, 2025

What

Migrates kms/auth-eth/ from Hardhat to Foundry, preserving on-chain compatibility with the four live UUPS proxies on Phala mainnet. Contract source is functionally identical to master (pragma ^0.8.22 → ^0.8.24, forge fmt applied) — same ABI, same storage layout, same events.

Beyond the migration

Operator scripts. script/Upgrade.s.sol previously only had UpgradeKmsToV2 / UpgradeAppToV2 targeting test-only mocks; running them against live proxies would have replaced the impl with scaffolding. Added UpgradeKms / UpgradeApp against the production source. script/Manage.s.sol::DeployApp was silently forcing requireTcbUpToDate=false; now reads REQUIRE_TCB_UP_TO_DATE and uses the 6-arg deployAndRegisterApp.

Security hardening. Both contracts switched to Ownable2StepUpgradeable — eliminates the typo-bricks-contract risk on transferOwnership. ERC-7201 namespaced storage means no slot collision on upgrade.

Related PR

Formal verification (Slither + Halmos + specification) was isolated to #689, which targets this branch as its base. Merge this PR first.

How to review

The branch is one commit. CI is fully green (17/17 including CodeQL across all 5 languages). Local verification: forge test --ffi (46/46), npx jest (4/4 server tests).

🤖 Generated with Claude Code

@h4x3rotab h4x3rotab marked this pull request as draft July 23, 2025 10:34
@Leechael Leechael mentioned this pull request Jul 28, 2025
Comment thread kms/auth-eth/contracts/DstackApp.sol Outdated
Comment thread kms/auth-eth/contracts/DstackKms.sol Outdated
Comment thread kms/auth-eth/contracts/test-utils/DstackKmsV1.sol Outdated
Comment thread kms/auth-eth/contracts/test-utils/DstackAppV1.sol Outdated
Comment thread .github/workflows/foundry-test.yml Fixed
Comment thread kms/auth-eth/coverage/lcov-report/sorter.js Fixed
@h4x3rotab h4x3rotab force-pushed the foundry branch 5 times, most recently from 40dd9c1 to 5f944b5 Compare May 19, 2026 07:22
Migrates the KMS authorization smart contracts and bootAuth server from
Hardhat to Foundry. The Solidity sources are functionally identical to
master (pragma bumped ^0.8.22 → ^0.8.24 for OpenZeppelin 5.x, forge fmt
applied); the ABI, events, and storage layout are byte-compatible with
the live UUPS proxies on Phala mainnet.

Stack changes:
- Hardhat dependencies and config removed (hardhat.config.ts, typechain
  types, jest.integration config, all hardhat-bound .test.ts files,
  scripts/{deploy,upgrade,verify}.ts).
- Foundry stack added: foundry.toml, three lib/ submodules pinned at
  forge-std v1.9.7, openzeppelin-contracts-upgradeable v5.4.0, and
  openzeppelin-foundry-upgrades v0.4.0; a Foundry .t.sol test suite
  (46 unit tests covering TCB toggle, factory deploy, upgrade paths,
  and storage compatibility from legacy 5-arg initializers); production
  deployment / management / query / upgrade scripts under script/.
- BootAuth Fastify server retained byte-identical except src/ethereum.ts,
  which swaps typechain for a 4-method hand-written ABI (same struct,
  same selectors, functionally identical).
- .openzeppelin/unknown-2035.json (proxy registry for the four live
  Phala-mainnet proxies) restored for historical reference.

Operator-script fixes surfaced during a post-rebase audit:
- script/Upgrade.s.sol previously only had UpgradeKmsToV2 /
  UpgradeAppToV2 pointing at test-only mock contracts. Added UpgradeKms
  / UpgradeApp scripts that upgrade live proxies to the current
  production source.
- script/Manage.s.sol::DeployApp was calling the legacy 5-arg
  deployAndRegisterApp, silently forcing requireTcbUpToDate=false. Now
  reads REQUIRE_TCB_UP_TO_DATE env var and uses the 6-arg overload to
  match master's hardhat-task semantics.

Security hardening:
- Both contracts switched from OwnableUpgradeable to
  Ownable2StepUpgradeable. ERC-7201 namespaced storage means no slot
  collision on upgrade; transferOwnership now stages a pending owner
  who must acceptOwnership, eliminating the typo-bricks-contract risk.
- registerApp's permissionless-by-design intent documented inline in
  natspec (any non-zero address can be registered by anyone; the
  downstream allowedOsImages whitelist + delegated isAppAllowed gate
  authorization).
- Slither static analysis configured in slither.config.json with
  per-line suppression comments + justifications on the four
  noise-detector hits (factory reentrancy-benign, unused-return on the
  named-return forward pattern, two unindexed-event-address for
  backward-compatible log indexers). Baseline: 0 findings.
- Inherited Prek hooks (trailing-whitespace, end-of-file-fixer,
  shellcheck) cleaned up across the anvil helper scripts that came in
  with the original migration.

Verification: forge fmt --check, forge build, forge test --ffi (46/46),
slither (0 findings), npx jest (4/4 server tests), npx tsc --noEmit
all clean.
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.

2 participants