Skip to content

Security review improvements across utility contracts#187

Open
joshuahannan wants to merge 2 commits intomasterfrom
fix/security-review-improvements
Open

Security review improvements across utility contracts#187
joshuahannan wants to merge 2 commits intomasterfrom
fix/security-review-improvements

Conversation

@joshuahannan
Copy link
Member

@joshuahannan joshuahannan commented Mar 12, 2026

Summary

  • TokenForwarding: fix incorrect error message in init; fix force-unwrap in deposit; eliminate TOCTOU in getSupportedVaultTypes (single borrow instead of check + borrow); simplify isSupportedVaultType
  • PrivateReceiverForwarder: Make recipient field let (no changeRecipient exists so it was always effectively immutable); fix CEI violation — PrivateDeposit event was emitted after the external deposit call, now emitted before; replace force-unwrap with descriptive panic
  • FungibleTokenSwitchboard: Replace assert() with pre block in addNewVaultWrapper; eliminate nil+force-unwrap antipattern in checkReceiverByType and safeBorrowByType; fix TOCTOU in getSupportedVaultTypes/getVaultTypesWithAddress (single borrow replaces check+borrow); fix broken dictionary iteration (for key, value in dict gives integer index in Cadence — rewritten using for key in dict.keys); simplify isSupportedVaultType
  • ExampleToken: Remove redundant getSupportedVaultTypes/isSupportedVaultType overrides — FungibleToken.Vault already provides identical default implementations
  • FungibleToken: Fix typo "panicing""panicking"
  • Burner: Update stale comment referencing Cadence 1.0 as a future release

Test plan

  • All Cadence tests pass: flow test --cover --covercode="contracts" tests/*.cdc
  • All Go tests pass: cd lib/go && make test
  • make ci passes clean (includes go generate + git diff --exit-code check)

🤖 Generated with Claude Code

joshuahannan and others added 2 commits March 12, 2026 12:15
- TokenForwarding: typed Capability<&{FungibleToken.Receiver}>, fix init error message,
  CEI comment, eliminate TOCTOU in getSupportedVaultTypes, simplify isSupportedVaultType
- PrivateReceiverForwarder: recipient var→let (immutable), fix CEI violation (emit before
  external deposit call), replace force-unwrap with descriptive panic
- FungibleTokenSwitchboard: fix addNewVaultWrapper to use pre-condition instead of assert,
  eliminate nil-check+force-unwrap in checkReceiverByType/safeBorrowByType, fix TOCTOU in
  getSupportedVaultTypes/getVaultTypesWithAddress (single borrow replaces check+borrow),
  fix dictionary iteration (keys pattern instead of broken for-key,value syntax),
  simplify isSupportedVaultType
- ExampleToken: remove redundant getSupportedVaultTypes/isSupportedVaultType overrides
  (FungibleToken.Vault interface provides identical default implementations)
- FungibleToken: fix typo "panicing" -> "panicking"
- Burner: update stale comment about Cadence 1.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Changing a stored field type is not allowed in Cadence contract upgrades.
Revert recipient from Capability<&{FungibleToken.Receiver}> back to the
untyped Capability, and restore explicit type parameters on all borrow()
and check() calls that depend on it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
return ExampleToken.resolveContractView(resourceType: nil, viewType: view)
}

/// getSupportedVaultTypes optionally returns a list of vault types that this receiver accepts
Copy link
Member Author

Choose a reason for hiding this comment

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

removed because they have identical default implementations in FungibleToken.

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