Skip to content

fix(contracts): resolve remaining Zenith findings [skip-line-limit] - #1788

Merged
hmzakhalid merged 7 commits into
mainfrom
fix/zenith-direct-findings
Aug 12, 2026
Merged

fix(contracts): resolve remaining Zenith findings [skip-line-limit]#1788
hmzakhalid merged 7 commits into
mainfrom
fix/zenith-direct-findings

Conversation

@hmzakhalid

@hmzakhalid hmzakhalid commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • reject RISC Zero verifier addresses without deployed code
  • reallocate unclaimed base rewards when an expulsion opens after failure settlement
  • revoke the LiquidityLauncher transfer exemption after sale distribution
  • require exact transfers for fee, refund, ticket, and license-token custody
  • document the slash rounding policy
  • require the operator exit delay to exceed the sortition submission window
  • sweep license-token surplus in the same transaction as an asset rotation
  • keep the Rust event catalog aligned with the BondingRegistry ABI

Fixes:

Testing

  • pnpm evm:test
  • cargo test -p e3-evm
  • pnpm --filter @interfold/contracts size:check
  • pnpm format:check
  • repository pre-push checks

Summary by CodeRabbit

  • Bug Fixes

    • Enforced exact token transfers for fees, deposits, payouts, refunds, claims, and settlements; mismatches now revert.
    • Rejected rebasing and fee-on-transfer assets where exact accounting is required.
    • Atomically swept surplus license-token reserves during asset rotation.
    • Enforced exit delays beyond sortition windows and outstanding request deadlines.
    • Improved slash rounding and retained unresolved rewards appropriately.
    • Required deployed verifier contracts for ciphertext verification.
  • Updates

    • Disabled liquidity-launcher transfer access after token distribution.
    • Added clearer transfer-mismatch and invalid-timing errors.
    • Added visibility into the minimum required exit delay.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
crisp Ready Ready Preview Aug 12, 2026 9:40am
interfold-dashboard Ready Ready Preview Aug 12, 2026 9:40am
interfold-docs Ready Ready Preview Aug 12, 2026 9:40am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cf19bfb-b947-4fce-ab11-57d5ef23af04

📥 Commits

Reviewing files that changed from the base of the PR and between 20ce159 and eefd62f.

📒 Files selected for processing (2)
  • packages/interfold-contracts/test/E3Lifecycle/E3Integration.spec.ts
  • packages/interfold-contracts/test/Registry/BondingRegistry.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/interfold-contracts/test/Registry/BondingRegistry.spec.ts
  • packages/interfold-contracts/test/E3Lifecycle/E3Integration.spec.ts

📝 Walkthrough

Walkthrough

The PR enforces exact token transfers, atomic license-token surplus sweeping, strict exit-delay validation, deterministic slash rounding, deployed verifier checks, and post-distribution LiquidityLauncher whitelist removal. Tests cover token, registry, settlement, sale, and verifier flows.

Changes

Protocol invariants

Layer / File(s) Summary
Exact transfer accounting
packages/interfold-contracts/contracts/Interfold.sol, packages/interfold-contracts/contracts/lib/*, packages/interfold-contracts/contracts/E3RefundManager.sol, packages/interfold-contracts/contracts/interfaces/*
Fee, refund, reward, treasury, settlement, bonding, and exit transfers now require exact balance changes. Mismatches revert with AssetTransferMismatch.
Bonding rotation and exit timing
packages/interfold-contracts/contracts/registry/*, packages/interfold-contracts/contracts/lib/BondingAssetLib.sol, packages/interfold-contracts/test/Registry/*, packages/interfold-contracts/test/Governance/*
License surplus is swept before asset replacement. Exit delays must exceed sortition windows and frozen request deadlines.
Ticket collateral and sale state
packages/interfold-contracts/contracts/token/InterfoldTicketToken.sol, packages/interfold-contracts/contracts/token/sale/*, packages/interfold-contracts/test/Token/*, packages/interfold-contracts/deploy/sale/*, packages/interfold-contracts/scripts/sale/*
Ticket deposits mint the requested amount only after exact receipt. Withdrawals and payouts reject mismatches. LiquidityLauncher is removed from the FOLD transfer whitelist after distribution.
Settlement rewards and verifier validation
packages/interfold-contracts/contracts/E3RefundManager.sol, packages/interfold-contracts/contracts/verifiers/*, packages/interfold-contracts/test/E3Lifecycle/*, packages/interfold-contracts/test/Risc0BfvCiphertextVerifier.spec.ts
Slash rounding assigns remainders deterministically. Expulsion proposals retain unclaimed base rewards. Verifier constructors require deployed verifier contracts.
Protocol flow documentation and event catalog
agent/INVARIANTS.md, agent/flow-trace/*, crates/evm/src/event_decoding/catalog.rs
Invariants and flow traces document the updated transfer, timing, reward, rotation, whitelist, and verifier rules. The removed shortfall event is deleted from the event catalog.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Requester
  participant Interfold
  participant InterfoldPricing
  participant FeeToken
  Requester->>Interfold: request with quoted fee
  Interfold->>InterfoldPricing: transferFromExact fee
  InterfoldPricing->>FeeToken: transferFrom requested amount
  FeeToken-->>InterfoldPricing: delivered balance delta
  InterfoldPricing-->>Interfold: accept exact amount or revert
Loading

Possibly related PRs

Suggested reviewers: cedoor, ryardley

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: resolving the remaining Zenith findings in the contracts scope.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/zenith-direct-findings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/interfold-contracts/test/E3Lifecycle/E3Integration.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/interfold-contracts/test/Registry/BondingRegistry.spec.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/interfold-contracts/contracts/lib/BondingAssetLib.sol (1)

283-301: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Check the registry balance delta before accepting an outgoing transfer.

_transferExact checks only the recipient balance delta. A sender-fee or debit-rebasing token can credit recipient by amount while debiting BondingRegistry by more than amount.

This bypasses AssetTransferMismatch. sweepLicenseSurplus can then consume bonded liabilities. Exit claims and slashed-fund withdrawals can leave the registry undercollateralized.

Record and validate the sender balance delta too. Use a separate error, or generalize AssetTransferMismatch, so the error reports the failed delta correctly. Add a sender-fee token regression test.

Proposed direction
+uint256 senderBefore = token.balanceOf(address(this));
 uint256 beforeBalance = token.balanceOf(recipient);
 token.safeTransfer(recipient, amount);
 uint256 afterBalance = token.balanceOf(recipient);
+uint256 senderAfter = token.balanceOf(address(this));

+uint256 spent = senderBefore > senderAfter ? senderBefore - senderAfter : 0;
+if (spent != amount) {
+    revert IBondingRegistry.AssetTransferMismatch(tokenAddress, amount, spent);
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/interfold-contracts/contracts/lib/BondingAssetLib.sol` around lines
283 - 301, Update _transferExact to record the registry/token sender balance
before and after safeTransfer, validate that the sender’s decrease equals amount
in addition to validating the recipient’s increase, and report any failed delta
with the correct value using a separate or generalized transfer-mismatch error.
Add a regression test using a sender-fee token covering outgoing transfers and
preventing surplus sweeping or withdrawals from leaving the registry
undercollateralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agent/flow-trace/02_TOKENS_AND_ACTIVATION.md`:
- Around line 419-420: Update the documented license transfer step to pass
licenseAmount to licenseToken.safeTransfer instead of amount, keeping the
totalLicenseLiability decrement and asset accounting consistent.

---

Outside diff comments:
In `@packages/interfold-contracts/contracts/lib/BondingAssetLib.sol`:
- Around line 283-301: Update _transferExact to record the registry/token sender
balance before and after safeTransfer, validate that the sender’s decrease
equals amount in addition to validating the recipient’s increase, and report any
failed delta with the correct value using a separate or generalized
transfer-mismatch error. Add a regression test using a sender-fee token covering
outgoing transfers and preventing surplus sweeping or withdrawals from leaving
the registry undercollateralized.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e63f704b-1c66-4d61-8f1f-b421945f7606

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd86c2 and 5f08a30.

📒 Files selected for processing (27)
  • agent/INVARIANTS.md
  • agent/flow-trace/00_INDEX.md
  • agent/flow-trace/02_TOKENS_AND_ACTIVATION.md
  • agent/flow-trace/03_E3_REQUEST_AND_COMMITTEE.md
  • agent/flow-trace/05_FAILURE_REFUND_SLASHING.md
  • agent/flow-trace/06_DEACTIVATION_AND_COMPLETION.md
  • packages/interfold-contracts/contracts/E3RefundManager.sol
  • packages/interfold-contracts/contracts/Interfold.sol
  • packages/interfold-contracts/contracts/interfaces/IBondingRegistry.sol
  • packages/interfold-contracts/contracts/interfaces/ICiphernodeRegistry.sol
  • packages/interfold-contracts/contracts/interfaces/IE3RefundManager.sol
  • packages/interfold-contracts/contracts/interfaces/IInterfold.sol
  • packages/interfold-contracts/contracts/lib/BondingAssetLib.sol
  • packages/interfold-contracts/contracts/lib/InterfoldPricing.sol
  • packages/interfold-contracts/contracts/registry/BondingRegistry.sol
  • packages/interfold-contracts/contracts/registry/CiphernodeRegistryOwnable.sol
  • packages/interfold-contracts/contracts/test/MockBondingRegistry.sol
  • packages/interfold-contracts/contracts/token/InterfoldTicketToken.sol
  • packages/interfold-contracts/contracts/token/sale/InterfoldTokenSaleDeployer.sol
  • packages/interfold-contracts/deploy/sale/MAINNET_CCA_CHECKLIST.md
  • packages/interfold-contracts/scripts/sale/validate.ts
  • packages/interfold-contracts/test/E3Lifecycle/E3Integration.spec.ts
  • packages/interfold-contracts/test/Governance/AccessAndBounds.spec.ts
  • packages/interfold-contracts/test/Pricing/PullPaymentsAndAllowlist.spec.ts
  • packages/interfold-contracts/test/Registry/BondingRegistry.spec.ts
  • packages/interfold-contracts/test/Token/InterfoldTicketToken.spec.ts
  • packages/interfold-contracts/test/Token/InterfoldTokenSaleDeployer.spec.ts

Comment thread agent/flow-trace/02_TOKENS_AND_ACTIVATION.md Outdated
ctrlc03
ctrlc03 previously approved these changes Aug 11, 2026
@hmzakhalid
hmzakhalid marked this pull request as draft August 11, 2026 14:38
@hmzakhalid
hmzakhalid force-pushed the fix/zenith-direct-findings branch from de8faef to 20ce159 Compare August 11, 2026 19:27
@hmzakhalid
hmzakhalid marked this pull request as ready for review August 12, 2026 09:02
@hmzakhalid hmzakhalid changed the title fix(contracts): resolve remaining Zenith findings fix(contracts): resolve remaining Zenith findings [skip-line-limit] Aug 12, 2026
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