Skip to content

fix(deployments): revoke pool admission and Portal roles from replaced routers - #140

Closed
Slokh wants to merge 2 commits into
mainfrom
fix/revoke-replaced-routers
Closed

Slokh wants to merge 2 commits into
mainfrom
fix/revoke-replaced-routers

Conversation

@Slokh

@Slokh Slokh commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

A replaced Zone router (see the code-identity replacement) kept the PropAMM pool admission and Zone Portal roles its activation granted, so two privileged routers stayed live. Deploy now revokes them.

  • When reconciliation redeploys a router (its code or its intent changed), deployEarnProfile records the previous address, and a stale paused replacement's, in pending state under retired.<output>.<address> keys (retiredOutputKey). They are never written to the deployment record, and loading or saving pending state rejects a key whose address differs from its value.
  • New activation steps, registered after the grant steps so the successor is admitted first:
    • revoke-retired-router-pool and revoke-retired-zone-router-pool: the pool owner (the deployer, directly or through its rebalance controller) calls setTakerAllowed(router, false) and setRecipientAllowed(router, false) for each retired router still admitted.
    • revoke-retired-router-gateway and revoke-retired-zone-router-gateway: the Zone Portal administrator calls setGateway(router, false) and setAllowedAccount(router, false) for each role a retired router still holds.
    • Each is satisfied when nothing is retired or every retired router holds nothing, and otherwise hands off to its authority with the exact calls, so the profile stays short of complete until revocation lands. A revoke step acts only once the live router holds every grant (pool admission and Portal callback and deposit admission), so a pending handoff for the successor never leaves no working router; the live router is never treated as retired.
  • portalRoleRevokeCalls (chain/zone.ts) builds the Portal revoke calls for the roles an account holds.
  • Docs: the step tables in deployment.md and the Earn router page, the ZoneRouter deployment steps, and the replacement paragraph.

Checks

pnpm verify passes. New tests cover Portal and pool revocation calls, no calls when nothing is held, satisfaction and handoff text, and pending round-trips of retired entries.

@tempoxyz-bot

tempoxyz-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

👁️ Cyclops Security Review

✅ Reviewed 44dda3a (latest) · Coverage: partial · ⚠️ 4 open, 1 not rechecked findings · report
⚠️ Not checked: The repository shows that deployment consumes local or restored pending bytes, but does not establish a path for a less-trusted actor to modify the pending file consumed by a privileged run.
ℹ️ Not verifiable from the source alone (needs running code or deployed state): Actual GitHub Actions cache retention and eviction for deploy-resume keys, and typical Zone admin / pool owner handoff latency. To verify it: Cache usage and eviction records for the tempoxyz/contract (1 more in the report)
⏸️ The review of 44dda3a did not recheck 1 earlier finding, so whether it still applies is unknown

# Severity Finding Introduced Status
1 🟢 Low Retired-router revocation obligation lives only in ephemeral pending state; losing it marks the profile complete while the replaced router keeps pool and Portal roles 44dda3a 🟠 Open
2 🟢 Low Retirement checks the successor's grant targets instead of the predecessor's 44dda3a 🟠 Open
3 🟡 Medium Publishing a replacement can strand revocations in disposable resume state 44dda3a 🟠 Open
4 🟡 Medium A predecessor can lose admission while the successor cannot return funds 44dda3a 🟠 Open
5 ⚪ Informational Pending loader accepts retired entries whose key names a different address 97554b1 ⏸️ Not rechecked since 97554b1

Comment thread deployments/modules/index.ts Resolved
Comment thread deployments/core/deploy.ts Resolved
Comment on lines +214 to +219
// Replaced contracts keep what activation granted them until the revoke steps remove it.
const retired = retiredContracts(profile, committed.addresses, replaced, cached, staleCached)
if (Object.keys(retired).length > 0) {
pending = { ...pending, outputs: { ...pending.outputs, ...retired } }
savePendingDeployment(options.profilePath, profile, pending)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 pre-existing, not blocking: A replaced router can keep its pool admission and Portal roles while deploy reports complete, once the gitignored pending file is lost or reset. The retired addresses live only in deployment.pending.json, but the record pointing at the successor is published before activation runs. Fix: keep the retired addresses in durable state, such as the published record or something derived from record history, so later runs and verify still see them; or hold back publishing the successor record until both revoke steps are satisfied.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

The retired entries are written only into pending outputs (deploy.ts:215-218). buildDeploymentRecord leaves them out of the record, and publishProfileDeploymentRecord (deploy.ts:302) commits the successor router before the activation loop (deploy.ts:343). Suppose a revoke step hands off and the operator resumes from another checkout or CI (pending is gitignored as **/deployment.pending.json). Or suppose the profile is edited and loadPendingDeployment throws on the intent-hash check, which restorePendingDeployment swallows at pending.ts:184-186 and then overwrites. Either way the committed record already has the new router, so replaced is empty and retiredContracts returns nothing. revokeRetired*Pool/Gateway then see retiredOutputs(...) as [] and report satisfied, and deploy returns complete while the old router stays a pool taker/recipient and Portal gateway. The verify path (reconcile.ts:476) checks record addresses only, so it also misses the leftover authority.

Verification: The base never revoked anything. Trigger: a run publishes the successor record and then stops at an activation handoff, and on the next run the pending file is missing or cannot be loaded. The retired addresses exist only in pending outputs (deploy.ts:215-218). poolRoutersRevoked and portalRoutersRevoked call .every on an empty list, which is true. The deploy ends complete.

Comment on lines +214 to +219
// Replaced contracts keep what activation granted them until the revoke steps remove it.
const retired = retiredContracts(committed.addresses, reconciling, cached, staleCached)
if (Object.keys(retired).length > 0) {
pending = { ...pending, outputs: { ...pending.outputs, ...retired } }
savePendingDeployment(options.profilePath, profile, pending)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low (trigger unconfirmed) · unverified: Retired-router revocation obligation lives only in ephemeral pending state; losing it marks…

Mechanism: when a router is replaced, deployEarnProfile records the old address under retired.<output>.<address> only in deployment.pending.json (deploy.ts:214-219). That file is gitignored (.gitignore) and is never written to deployment.json. The same run publishes the deployment record naming the successor before the activation and revoke steps run (deploy.ts:281-302 vs 339-344).

Full finding

Retired-router revocation obligation lives only in ephemeral pending state; losing it marks the profile complete while the replaced router keeps pool and Portal roles

Mechanism: when a router is replaced, deployEarnProfile records the old address under retired.<output>.<address> only in deployment.pending.json (deploy.ts:214-219). That file is gitignored (.gitignore) and is never written to deployment.json. The same run publishes the deployment record naming the successor before the activation and revoke steps run (deploy.ts:281-302 vs 339-344). From the next run on, committed.addresses holds the successor, so reconciling is empty and retiredContracts (deploy.ts:787-805) cannot rebuild the retired entry. The pending file is the only copy of the obligation.

How the obligation is lost:
(a) In hosted CI (deploy.yml:104-114), the pending file survives only through actions/cache. That cache is best-effort: entries are evicted after about 7 days without access or under the repository size cap. Revoke steps are external-authority handoffs (Zone administrator, pool owner) that can easily outlast that.
(b) Any profile edit that changes deploymentIntentHash makes loadPendingDeployment throw (pending.ts:88-94). restorePendingDeployment then silently starts from empty outputs (pending.ts:181-186).
(c) A fresh checkout or another operator machine has no pending file at all.

In each case, retiredOutputs(outputs, 'earnRouter' | 'zoneRouter') returns []. poolRoutersRevoked and portalRoutersRevoked return true for the empty list (earn/zone-router/steps.ts:269-276, 341-350), so all four revoke steps are satisfied. The deploy reaches 'complete', calls removePendingDeployment, and reports success.

Impact: the replaced router still holds PropAMM taker/recipient admission and Portal callback-gateway and allowed-account roles. Two privileged routers stay live, which is the condition this PR exists to remove. The lifecycle also gives a false 'complete' signal, so nobody is prompted to revoke.

Preconditions: a router replacement whose revoke handoff does not land in the same run, followed by loss or discard of deployment.pending.json before the authority acts.

Missing evidence: GitHub cache retention for this repository and the real authority turnaround times. Whether the old router's leftover roles are exploitable depends on that contract's code; at minimum, it remains a privileged admitted taker/recipient and gateway.

Remediation: persist the retired set durably. Options: write retired addresses into the published deployment record, or a committed sidecar, until revocation is verified. Or derive retired routers from on-chain or record history, such as previous records' router addresses or role-grant events. Do not let an empty pending-derived list satisfy the revoke steps. At least, have restorePendingDeployment carry retired.* keys forward when it discards a mismatched pending file.

Valid? React with 👍 / 👎.

Comment on lines +797 to +802
const previous = [
step.intent.some((component) => reconciling.has(component)) ? recorded[output] : undefined,
step.intent.some((component) => staleCached.has(component)) ? cached[output] : undefined,
]
for (const address of previous)
if (address) retired[retiredOutputKey(output, address)] = address

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low (exposure and trigger unconfirmed) · unverified: Retirement checks the successor's grant targets instead of the predecessor's

Retirement must remove grants where they were issued. The new journal stores only the router address, while both router implementations use the successor's configured pool and discovered Portal for verification, writes, and handoffs. Same-chain target changes are expressly allowed during reconciliation.

Full finding

Retirement must remove grants where they were issued. The new journal stores only the router address, while both router implementations use the successor's configured pool and discovered Portal for verification, writes, and handoffs. Same-chain target changes are expressly allowed during reconciliation. For example, if router A was admitted on pool P and its successor uses pool Q, the check can find no permission for A on Q and report success while both flags remain on P. If the successor has no conversion pool, the step is disabled instead. A Zone move has the same problem for roles on the old Portal. Deployment can therefore report complete with the predecessor still authorized on its former infrastructure. This needs a supported profile migration and a previously granted router, not an attacker prerequisite; no affected live migration was established. Persist the original chain, pool, Portal, and Zone identity for each retirement before replacing the record, and verify and route revocations against those historical targets.

Valid? React with 👍 / 👎.

Comment on lines +214 to +219
// Replaced contracts keep what activation granted them until the revoke steps remove it.
const retired = retiredContracts(committed.addresses, reconciling, cached, staleCached)
if (Object.keys(retired).length > 0) {
pending = { ...pending, outputs: { ...pending.outputs, ...retired } }
savePendingDeployment(options.profilePath, profile, pending)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium (trigger unconfirmed) · unverified: Publishing a replacement can strand revocations in disposable resume state

Once a replacement is published, unfinished revocations must remain discoverable on subsequent deploys. The command saves the predecessor only in pending outputs, publishes the successor before activation, and excludes the predecessor and cleanup obligations from the published record.

Full finding

Once a replacement is published, unfinished revocations must remain discoverable on subsequent deploys. The command saves the predecessor only in pending outputs, publishes the successor before activation, and excludes the predecessor and cleanup obligations from the published record. If revocation then requires a handoff and the pending file is absent on the next run, or a later periphery edit invalidates its intent hash, restore starts without the predecessor. The new record contains only the successor, so retirement detection cannot reconstruct the missing obligation. An empty retirement list satisfies cleanup, allowing complete while old grants remain. This can occur without an attacker; the workflow handles the pending cache and published record separately. No actual cache miss or affected live deployment was established. Persist unresolved retirements in durable, verified state before publishing the successor, carry them across allowed intent changes, and remove them only after checking the historical grants onchain.

Valid? React with 👍 / 👎.

Comment on lines +416 to +423
const [admission, gateway, deposits] = await Promise.all([
pool ? poolAdmission(client, pool, router) : undefined,
zoneCallbackGatewayRegistered(client, portal, router),
zoneGatewayDepositsAdmitted(client, portal, router),
])
const admitted =
!admission ||
(admission.taker && admission.recipient && getAddress(admission.resolved) === router)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium (exposure and trigger unconfirmed) · unverified: A predecessor can lose admission while the successor cannot return funds

Retirement is intended to leave a usable successor. Both readiness predicates check pool admission and Portal account or gateway status, but omit whether the successor's return tokens are usable. Earlier token activation checks enablement only, not active deposits, and inspection blockers appear as handoff text rather than preventing the signed revoke path.

Full finding

Retirement is intended to leave a usable successor. Both readiness predicates check pool admission and Portal account or gateway status, but omit whether the successor's return tokens are usable. Earlier token activation checks enablement only, not active deposits, and inspection blockers appear as handoff text rather than preventing the signed revoke path. For example, on a restricted Portal an intent change can replace a router using private asset A with one returning private asset B. If deposits for A are active but B is enabled with deposits paused, the successor can pass every grant check. Revoking the predecessor's gateway role then takes the working route out of service while the successor's redeem callback still reverts when returning B. No attacker or sustained traffic is required: the normal authorized cutover incurs the revoke transaction and the affected route remains unavailable until deposits resume or the predecessor is readmitted. No live instance, outage duration, or transaction fee was measured. Require active deposits for the successor's required return tokens as a revocation precondition, and use that same check in the manual handoff.

Valid? React with 👍 / 👎.

@tempoxyz-bot

Copy link
Copy Markdown

Informational: Pending loader accepts retired entries whose key names a different address

loadPendingDeployment accepts an outputs entry keyed retired.<output>.<A> whose value is a different address B, because it checks key syntax and value shape separately. savePendingDeployment rejects the same entry, so the loader returns state the writer refuses, and pnpm earn status prints it. First reported at 97554b1; recheck at this head: still present.

Valid? React with 👍 / 👎.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open from earlier reviews (1):

  • Unresolved: 1 minor or pre-existing.

zoneRouterConstructorArgs(zoneRouterMode(profile, outputs)),
// A router from a factory the profile names carries that factory's code, not this checkout's.
replaceOnCodeChange: (profile) => !namesFactory(profile),
retireOnReplace: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Other programs that share a ZoneRouter can lose service when this profile edits its mode. The deployer strips that shared router's Portal roles and pool admission. The factory deploys one router per mode with CREATE2, so a Bridge program or another deployer using the same mode gets the same address. retireOnReplace (steps.ts:165) and retiredContracts (deploy.ts:798) retire it on any zoneRouter intent change, and the revoke steps run with the local admin key. Fix: retire a ZoneRouter only when this deployment is its only user, or emit a handoff instead of revoking it automatically.

Why this was flagged

The trigger is a ZoneRouter mode that another consumer also deploys. The comment at zone-router/steps.ts:170-171 says Bridge's spend script can list the same spender, and docs/zone/zone-router.md:38 says one router per Zone can serve several programs. Suppose an operator edits zoneRouter.ops or spenders on a committed profile. Because deployZoneRouter's source sets retireOnReplace: true, retiredContracts (deploy.ts:793-800) writes retired.zoneRouter.<R1>. Once the new router holds its grants, revoke-retired-zone-router-gateway and revoke-retired-zone-router-pool call setGateway/setAllowedAccount(R1,false) and setTakerAllowed/setRecipientAllowed(R1,false) as ZONE_ADMIN_PRIVATE_KEY / DEPLOYER_PRIVATE_KEY. Every other program still routing through R1 then has its callbacks and conversions fail. On the base, R1 kept its grants. retiredOutputs filters out only this profile's live router.

Verification: Severity: normal. deployZoneRouter.source.retireOnReplace: true (zone-router/steps.ts:165). revokeRetiredZoneRouterGateway runs on ZONE_ADMIN_PRIVATE_KEY && proven. Unlike the grant steps, it has no !namesFactory restriction. Against the base: before this change a replaced router kept its roles, so the other consumers were unaffected.

Comment on lines +181 to +187
enabled: (profile) => configuredRouterPool(profile) !== undefined,
satisfied: (client, profile, outputs) =>
poolRoutersRevoked(
client,
required(configuredRouterPool(profile), 'router conversion pool').pool,
retiredOutputs(outputs, 'earnRouter'),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 pre-existing, not blocking: When a profile edit moves a router to another PropAMM pool, the replaced router keeps its old-pool taker/recipient admission while deploy reports complete. This push retires routers on intent changes (deploy.ts:215). The revoke steps still read the pool from the edited profile. Fix: record the pool and Portal the retired router was granted on with each retired.* entry, and revoke and verify there, even when the new profile has no pool. Same pattern at 4 sites (earn/zone-router/steps.ts:181-187, earn/zone-router/steps.ts:194-198, zone-router/steps.ts:437-442, zone-router/steps.ts:452-457). [also at: deployments/core/deploy.ts:798 - An operator who moves a router to a new pool or Zone ends at complete, but the old router keeps its admission on the old pool and old Portal.]
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

Trigger: an operator changes zone.router.pool on a committed deployment, or removes the pool. That pool is hashed into the zone intent component (profile.ts:137-138), so changedIntentComponents puts zone into reconciling. After this push, retiredContracts(committed.addresses, reconciling, ...) (deploy.ts:215) retires the recorded router R1, and deploy-router deploys R2. revoke-retired-router-pool then calls poolRoutersRevoked on configuredRouterPool(profile).pool, which is the NEW pool, where R1 was never admitted. The step reports satisfied, and revokePoolRouters targets the same new pool. If the pool was removed, enabled (steps.ts:181) turns the step off entirely. R1 stays a taker/recipient on the old pool, and the profile reaches complete with no handoff. On the base branch an intent change never produced a revocation claim, so operators were not told that the leftover authority was cleared.

Verification: revoke-retired-router-pool (earn/zone-router/steps.ts:181-187) checks the pool from the edited profile. R1 was only ever admitted on the old pool P1, so poolAdmission(newPool, R1) reads taker=false and recipient=false. The step counts as satisfied and no call is made, which leaves R1 a taker and recipient on P1.

@Slokh Slokh closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants