Skip to content

Add clarifying comments for common security audit false positives#588

Open
joshuahannan wants to merge 1 commit intomasterfrom
docs/security-clarifying-comments
Open

Add clarifying comments for common security audit false positives#588
joshuahannan wants to merge 1 commit intomasterfrom
docs/security-clarifying-comments

Conversation

@joshuahannan
Copy link
Member

Summary

During a security audit, several code patterns were identified that are consistently misidentified as vulnerabilities by automated tools and AI-assisted bug bounty reporters. This PR adds inline comments at each location explaining the intent and why the pattern is safe, to reduce noise from invalid bug reports.

Patterns documented:

  • FlowToken.cdc — Service account address exclusions in TokensWithdrawn/TokensDeposited are a documented performance optimization for epoch transitions, not a security bypass
  • FlowClusterQC.cdcvoteThreshold() returns an inclusive lower bound, so >= in isComplete() is correct; the threshold itself enforces strictly >2/3 quorum
  • FlowTransactionScheduler.cdcslotUsedEffort addition is bounded by upstream validation and cannot overflow; getStatus() inference logic only applies to aged-out transactions (Scheduled txs are always in the active map and returned earlier); setConfig() is admin-only via UpdateConfig entitlement
  • FlowIDTableStaking.cdcdelegatorIDCounter is scoped per node so (nodeID, delegatorID) is the unique key; the empty vault in addNodeRecord is intentional — tokensCommitted is validated against the minimum and deposited immediately after
  • LockedTokens.cdcunlockLimit precondition prevents underflow in withdrawUnlockedTokens
  • get_total_balance.cdc — Marked as outdated/broken: getAuthAccount is not available in Cadence 1.0 scripts and this template cannot be used on mainnet

Test plan

  • make ci passes (all Cadence + Go tests, check-tidy)

🤖 Generated with Claude Code

Documents the intent and safety of patterns that are frequently
misidentified as vulnerabilities by automated analysis tools:

- FlowToken.cdc: Service account address exclusions are a documented
  performance optimization, not a security bypass
- FlowClusterQC.cdc: voteThreshold() is an inclusive lower bound so
  >= in isComplete() is correct; clarify the 2/3 quorum math
- FlowTransactionScheduler.cdc: slotUsedEffort addition cannot overflow
  due to upstream validation; getStatus() inference only applies to
  aged-out transactions (Scheduled txs are always in the transactions
  map); setConfig() is admin-only via UpdateConfig entitlement
- FlowIDTableStaking.cdc: delegatorIDs are scoped per node —
  (nodeID, delegatorID) is the unique key; empty vault in addNodeRecord
  is intentional, tokens are validated and committed immediately after
- LockedTokens.cdc: unlockLimit precondition prevents underflow
- get_total_balance.cdc: mark script as broken/outdated (getAuthAccount
  is not available in Cadence 1.0 scripts)

Co-Authored-By: Claude Sonnet 4.6 <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