Repository navigation
refactor(deployments): replace Zone routers by their compiled code, not a release number - #137
Conversation
…ot a release number
👁️ Cyclops Security Review✅ Reviewed f5bcc8b (latest) · Coverage: partial ·
|
| const committedAddresses = Object.fromEntries( | ||
| Object.entries(committed.addresses).filter(([key]) => |
There was a problem hiding this comment.
🔴 Operators who resume from a leftover pending file can get the old router reused, and the record republished with it, even though its code differs from the build. retained only filters the committed record's addresses and actions. cached.outputs and cached.actions from deployment.pending.json are merged back unfiltered at pending.ts:205-206. Fix: also drop cached outputs keyed to a replaced component (via deploymentAddressComponents) and cached actions whose step intent includes one. Keep cached entries for a router already redeployed in this replacement. The old release bump changed deploymentIntentHash, which discarded the cache.
Why this was flagged
A pending file with the same intent hash survives any run that called restorePendingDeployment (pending.ts:208 saves committed addresses such as earnRouter/zoneRouter into outputs) and then stopped before removePendingDeployment (deploy.ts:372). If the router source or compiler later changes, replacedComponents marks zone or zoneRouter. restorePendingDeployment then leaves out only the committed address. cached.outputs.earnRouter and cached.actions['deploy-router'] still survive through the spreads at lines 205-206. reconcile.ts:147 calls step.satisfied with pending.outputs, finds the old router deployed and bound, and does not redeploy it. On base, bumping routerContractRelease changed the pending header's deploymentIntentHash. That made loadPendingDeployment throw, so the catch at line 179 reset the cache and nothing stale was kept. No safeguard here covers cached state for replaced components, because the intent hash no longer changes.
Verification: Trigger: a deployment.pending.json with the same intent hash is still on disk when the router code changes. retained (pending.ts:184-186) only filters committed.actions and committed.addresses. pending.ts:205-206 still merges cached.outputs and cached.actions back unfiltered. Code replacement leaves the intent hash the same, so the stale cache now loads.
There was a problem hiding this comment.
The latest push brings this issue back at deployments/core/pending.ts:206-221:
🔴 Operators who resume a paused router replacement after another router code change keep the first replacement, which is also stale. Hosted chains then hit a creation mismatch on every run; other chains silently record it. replacedAddress and staleReplacedAction treat any cached address or action that differs from the committed one as a current replacement (pending.ts:211, 218-221). They never check its code against this build. Fix: decide staleness of cached outputs by code identity, for example by running the replacedComponents check on the cached addresses too, and drop the dependent actions. A replacement that matches the build must still resume.
Why this was flagged
Router change A lands and Deploy deploys router A. The run then stops at a handoff or is interrupted before the record is rebuilt, so deployment.pending.json holds earnRouter/zoneRouter = A and the matching deploy-router action. Change B (source or solar.lock) lands before the resume. Because A !== C, replacedAddress (pending.ts:206-213) keeps A, and the deep-compare at 218-221 keeps A's action. reconcile.ts:147 step.satisfied accepts A and skips redeploying. On hosted chains, buildDeploymentRecord then calls assertStepCreation (creation.ts:76-88). It compares A's creation code with B's compiled bytecode and throws. Every rerun restores A again, so the deployment stays stuck until the operator deletes the pending file by hand. On the base branch, the release bump for B changed deploymentIntentHash, so loadPendingDeployment threw and the catch at pending.ts:180 reset the cache.
Verification: A is not C, so earnRouter = A and its deploy-router action survive in cachedOutputs/cachedActions. Nothing checks A's code against B. Every run fails the same way until an operator deletes deployment.pending.json by hand. Under base, the documented procedure for B was a release bump. That changed the intent hash, so loadPendingDeployment failed and the cache was reset.
There was a problem hiding this comment.
The latest push brings this issue back at deployments/core/pending.ts:202-223:
🔴 An operator resuming after an interrupted router deploy can still get a router built from superseded code adopted, because only outputs and actions are screened for stale code. ...cached at pending.ts:223 carries latestOutputs through unfiltered, and staleCached never checks it. reconcile.ts:229-237 then adopts those recovered outputs once satisfied passes. Fix: give latestOutputs the same stale-code screen as cached outputs. Either drop its keys for staleCached components, or run replacedComponents over {...outputs, ...latestOutputs} in deploy.ts so recovery cannot bring back an old-build router. [also at: deployments/core/pending.ts:225 - An operator resuming an interrupted Earn router deploy after a further code change can still have the stale router adopted and recorded as current.; deployments/core/deploy.ts:193 - An operator resuming an interrupted first deployment after router code changes gets the stale router recorded as current.]
Why this was flagged
Trigger: the router is being replaced, and a Forge run writes latestOutputs but is interrupted before completeAction strips them (pending.ts:305). Then the router source or compiler changes again before the next Deploy. On that run, replaced flags the component from the committed router. staleCached is computed only from cachedPendingOutputs(...).outputs (deploy.ts:186-193, 780-786), which has no router key, so it comes back empty. restorePendingDeployment keeps latestOutputs via ...cached (pending.ts:223). In reconcile.ts:229-237, readActionOutputs reads latestOutputs, step.satisfied passes for the old-build router, and the step adopts and completes it. On local chains nothing else checks this, so the record is published with a router that is not this checkout's build. On hosted chains assertStepCreation (creation.ts:84) rejects the creation bytes instead, and every run fails until the operator removes the pending file by hand.
Verification: cachedPendingOutputs (deploy.ts:780-786) returns only loadPendingDeployment(...).outputs, and staleCached is computed from that alone (deploy.ts:186-193). latestOutputs comes through ...cached (pending.ts:223) unchanged. reconcile.ts:229-233 reads latestOutputs and adopts the step if step.satisfied passes. On the base, a release bump changed deploymentIntentHash and the whole cache was reset.
| // Immutable periphery built from other code than this checkout's is replaced like changed intent. | ||
| const replaced = committed | ||
| ? await replacedComponents(client, profile, committed, (contract) => | ||
| compiledRuntimeCode(options.root, contract, options.environment), | ||
| ) | ||
| : new Set<IntentComponent>() | ||
| for (const component of replaced) reconciling.add(component) |
There was a problem hiding this comment.
🟣 pre-existing, not blocking: After merging, any router bytecode change makes the next Deploy run silently swap in a new router. The superseded router keeps its Zone Portal role and PropAMM pool admission, and nobody is told. replacedComponents drops the old earnRouter/zoneRouter and re-runs only the grant steps for the new address. No step revokes the old router's roles or flags it for revocation. Fix: when a replaced component's old router still holds Portal roles or pool admission, report it as a blocker or handoff that names the old address (or emit its revoke calls), so replacement never leaves two privileged routers.
A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Trigger: a source, compiler (solar.lock) or metadata-only change to SingleZoneEarnRouter or ZoneRouterFactory/ZoneRouter, then a broadcast Deploy run. At deploy.ts:178-184, replacedComponents (provenance.ts:47-70) flags zone or zoneRouterFactory/zoneRouter. restorePendingDeployment (pending.ts:184-200) then drops the old address. The new router is deployed. Steps such as authorize-router (pool admission, earn/zone-router/steps.ts:134-147) and register-zone-gateway (chain/zone.ts:340) check and grant only the new earnRouter. There is no revoke step for the replaced router. The old immutable, ownerless router therefore stays admitted on the pool and the Portal, and the run reports complete. On the base branch this only happened when someone deliberately bumped routerContractRelease/zoneRouterContractRelease, a reviewed event where an operator could also revoke. Now it happens automatically and more often, so privileged routers pile up unnoticed.
Verification: Pre-existing, made wider by this change. deploy.ts:178-184 adds what replacedComponents returns to reconciling, and pending.ts retained drops the recorded earnRouter/zoneRouter address. authorize-router (earn/zone-router/steps.ts:133-163) then admits only the new address, and no step revokes or reports the old router.
…pies of replaced routers
There was a problem hiding this comment.
The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.
Still open from earlier reviews (2):
- 🔴
deployments/core/pending.ts:200—Operators who resume from a leftover pending file can get the old router reused, and the record republished with it, ev… - Also unresolved: 1 minor or pre-existing.
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
| // A paused replacement may itself predate this checkout's build, so cached contracts are checked too. | ||
| const staleCached = committed | ||
| ? await replacedComponents( | ||
| client, | ||
| profile, | ||
| { addresses: cachedPendingOutputs(options.profilePath, profile) }, | ||
| compile, | ||
| ) | ||
| : new Set<IntentComponent>() |
There was a problem hiding this comment.
Medium: First-deployment resume keeps a router built from an older checkout
The PR now decides router replacement by comparing compiled code and freezes the router intent hashes. However, the cached-output code check runs only when a committed record exists. An interrupted first deployment therefore resumes with a router built by an older checkout.
Full finding
The PR now decides router replacement by comparing compiled code and freezes the router intent hashes. However, the cached-output code check runs only when a committed record exists. An interrupted first deployment therefore resumes with a router built by an older checkout. On hosted chains, record building then fails. On other chains, the record publishes the stale router.
Valid? React with 👍 / 👎.
| // A paused replacement may itself predate this checkout's build, so cached contracts are checked too. | ||
| const staleCached = committed | ||
| ? await replacedComponents( | ||
| client, | ||
| profile, | ||
| { addresses: cachedPendingOutputs(options.profilePath, profile) }, | ||
| compile, | ||
| ) | ||
| : new Set<IntentComponent>() |
There was a problem hiding this comment.
Needs review · unverified: Missing code in disposable cache blocks a valid committed deployment
A formerly mined replacement address can remain in pending outputs after a chain rollback that leaves the committed address intact. If the operator resumes on the committed build with unchanged intent, committed state should override that cache, as it did before this PR.
Full finding
A formerly mined replacement address can remain in pending outputs after a chain rollback that leaves the committed address intact. If the operator resumes on the committed build with unchanged intent, committed state should override that cache, as it did before this PR. Instead, the new cache scan runs before restoration and sends the obsolete cached address to the strict provenance helper. An empty getCode response throws, preventing the valid committed address from being restored. The command continues to fail while the cache remains, without broadcasting or charging additional transaction fees; moving the cache aside recovers the valid committed path. The precondition is a lost cached replacement and surviving committed state; no ability for an unprivileged party to cause that chain state was established. Check only cache entries eligible to be retained, or classify a definite empty-code response as stale for cached addresses only. Keep RPC failures and missing committed code fatal.
Valid? React with 👍 / 👎.
| // A paused replacement may itself predate this checkout's build, so cached contracts are checked too. | ||
| const staleCached = committed | ||
| ? await replacedComponents( | ||
| client, | ||
| profile, | ||
| { addresses: cachedPendingOutputs(options.profilePath, profile) }, | ||
| compile, | ||
| ) | ||
| : new Set<IntentComponent>() | ||
| syncFoundryOutputs(options.root, options.profilePath) |
There was a problem hiding this comment.
Medium (trigger unconfirmed) · unverified: Stale Foundry checkpoints bypass router build reconciliation
On a profile with a committed record, stop after Forge broadcasts an intermediate SingleZoneEarnRouter replacement and writes latestOutputs, but before the lifecycle records the action. Resume from another checkout with a different router build and the same profile. The new cache probe reads only outputs and runs before external staging synchronization; restoration also preserves latestOutputs unchanged.
Full finding
On a profile with a committed record, stop after Forge broadcasts an intermediate SingleZoneEarnRouter replacement and writes latestOutputs, but before the lifecycle records the action. Resume from another checkout with a different router build and the same profile. The new cache probe reads only outputs and runs before external staging synchronization; restoration also preserves latestOutputs unchanged. Reconciliation then overlays the older address from latestOutputs and accepts its bindings before considering a new broadcast. If the old successful receipt is recoverable on a hosted chain, the current initcode check rejects it and retries hit the same checkpoint rather than deploying the current build. On a non-hosted chain that creation check is skipped, so the old build can be reused. This requires an interrupted operator deployment and an intervening build change; no unprivileged trigger or affected live deployment was established. On hosted chains the interruption blocks progress without further transaction spend on each retry; the ordinary successful path needs a replacement broadcast. Synchronize staging first, classify mined latestOutputs independently of materialized outputs, and remove definitively stale checkpoint entries before recovery while preserving current-build checkpoints and receipt validation.
Valid? React with 👍 / 👎.
| from the profile is refused. The immutable Zone routers and the `ZoneRouterFactory` are also replaced, | ||
| with the steps that configure them, when a recorded one's runtime differs from this checkout's build | ||
| (compiler-declared immutable slots aside), so a source or compiler change redeploys them on the next | ||
| deploy without any profile change. The deployment-fixed engine migration mode either permits the operator |
There was a problem hiding this comment.
Low (exposure unconfirmed): Deployment runbook omits named-factory exception to Zone router code replacement
The runbook now says a source or compiler change redeploys the immutable Zone routers on the next deploy without a profile change. A ZoneRouter whose profile names its factory is never compared with the build and never replaced, and every Spend mode must name its factory. First reported at 3939c95; recheck at this head: still present.
Valid? React with 👍 / 👎.
There was a problem hiding this comment.
The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.
Still open from earlier reviews (2):
- 🔴
deployments/core/pending.ts:201—Operators who resume from a leftover pending file can get the old router reused, and the record republished with it, ev… - Also unresolved: 1 minor or pre-existing.
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
What changed
The Zone router slices no longer carry a release number to bump. Reconciliation now decides from the code itself whether a recorded router is current.
FoundryStep.source.replaceOnCodeChange(new): a step declares its contract as immutable periphery identified by this checkout's build. Set fordeploy-router(SingleZoneEarnRouter),deploy-zone-router-factory, anddeploy-zone-router(unless the profile names its own factory, whose routers carry that factory's code).replacedComponents(core/provenance.ts): for each such recorded contract, compares its onchain runtime with the locally compiled runtime, compiler-declared immutable slots zeroed. A mismatch marks the step's intent components as replaced.deployEarnProfiletreats replaced components like changed intent:restorePendingDeploymentdrops their recorded addresses and actions, and any cached pending copies that do not run this build either, so the router and its configuration steps run again; a replacement an interrupted run already deployed with this build is resumed.legacyRouterIntent,legacyModeIntent,legacyComponentIntent), so every existing record keeps its intent hashes and code identity alone decides replacement.deployment.mddocuments the replacement rule.A source or compiler change to these contracts now redeploys them on the next Deploy run, with no number to remember. Any change to their bytecode counts, including metadata-only changes.
Checks
pnpm verifypasses. New tests cover a matching runtime (immutables aside), a replaced runtime, restoring a replaced component, dropping stale pending copies while resuming a deployed replacement, and the step declarations.