Skip to content

P4: Tip Forwarding Module — Design & Implementation Plan#85

Draft
ccp-manash wants to merge 3 commits intofeat/proposal-p4from
feat/p4-tip-forwarding-module
Draft

P4: Tip Forwarding Module — Design & Implementation Plan#85
ccp-manash wants to merge 3 commits intofeat/proposal-p4from
feat/p4-tip-forwarding-module

Conversation

@ccp-manash
Copy link
Copy Markdown

@ccp-manash ccp-manash commented Apr 9, 2026

Summary

Design doc and implementation plan for P4 (Tip Forwarding in setFeeAndPledge), implemented as an optional separate module rather than modifying the core KeepWhatsRaised flow.

  • Approach: Hook pattern — extract tip handling from _pledge() into _handleTip() internal virtual, child contract overrides to forward tips atomically
  • Factory changes: Zero — implementationMap already supports multiple implementations via implementationId
  • Existing behavior: Completely unchanged — default _handleTip() preserves current accumulate-and-claim pattern
  • Security: Thorough analysis across security, gas, proxy, Permit2, accounting, factory, testing, integration, and audit perspectives. 3 HIGH findings all mitigated (CEI ordering, DoS via blocklisting, phantom claimTip state)

What's in this PR

Design document only (docs/proposals/P4-tip-forwarding-module-design.md). No code changes yet — this is for SC team review and alignment before implementation.

Key design decisions for review

  1. Is immediate forwarding a hard requirement? "Option 0" (just pass real tip to existing setFeeAndPledge, zero contract changes) is fully viable if deferred claimTip() is acceptable
  2. Try/catch fallback — if platformAdmin is blocklisted by a token, tip falls back to storage instead of DoS-ing the pledge. Acceptable?
  3. claimTip() behavior — no-op in forwarding variant (handles fallback-stored tips). Should it revert instead?
  4. Pre-existing issues foundclaimRefund()/disburseFees() lack nonReentrant, tip-only pledges create phantom NFTs. Separate PR?

Design doc sections

  • Problem statement & approach comparison
  • Hook pattern design (KeepWhatsRaised changes + child contract)
  • Security findings (0 Critical, 3 High, 3 Medium, 3 Low — all mitigated)
  • Accounting invariant verification
  • Gas analysis (break-even at ~29 pledges, main value is operational simplification)
  • Permit2 compatibility (zero impact)
  • Factory/deployment (zero changes)
  • Integration impact (events, indexers, frontend)
  • Test plan (~30 test cases, invariant/fuzz tests, differential testing)
  • Implementation steps
  • Open questions for SC team

Proposal reference

https://hackmd.io/@vaki/SypnuDM_Wg#4-P2-Tip-Forwarding-in-setFeeAndPledge

Test plan

  • SC team reviews design doc and provides feedback
  • Align on open questions (immediate forwarding requirement, claimTip behavior, pre-existing issues)
  • Implement based on agreed design
  • Full test suite (unit, integration, invariant, fuzz, differential)
  • Verify all existing KWR tests pass unchanged

🤖 Generated with Claude Code

ccp-manash and others added 2 commits April 9, 2026 20:17
Comprehensive design and implementation plan for making tip forwarding
an optional module via hook pattern in KeepWhatsRaised, based on analysis
from 10 independent perspectives (security, gas, proxy, Permit2,
accounting, factory, testing, off-chain alternatives, integration, audit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ccp-manash ccp-manash changed the base branch from main to feat/proposal-p4 April 9, 2026 18:20
@ccp-manash
Copy link
Copy Markdown
Author

I don't understand anything here, just trying to help out Suvadra with vibe planning 😂

KeepWhatsRaised changes (minimal, backward-compatible):
- 5 storage mappings private→internal for child contract access
- _pledge() private→internal virtual for override

New KeepWhatsRaisedWithTipForwarding contract:
- Admin path (setFeeAndPledge): deducts tip from pledgeAmount,
  only transfers effective pledge. Tip stays with admin.
- Permit2 path: transfers full amount via Permit2, forwards tip
  to platformAdmin after all state updates (CEI compliant).
- TipForwarded event, TipExceedsPledgeAmount error

Includes: deployment script, shared test setup, unit + security tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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