Skip to content

Detect ERC-4626 / Vault Share-Price Inflation and First-Depositor Attacks (CP-122) #67

Description

@Nanle-code

Problem Statement

Share-price inflation attacks (also known as "first depositor" or "donation" attacks) against ERC-4626-style vaults and other share-based pooled-asset contracts have been responsible for real losses across DeFi: an attacker deposits a minimal amount to mint the first share, then directly transfers ("donates") assets to the vault contract to inflate the share price before a second depositor's deposit, causing the second depositor's shares to round down to zero or a negligible amount. Neither ChainProof's existing SWC-aligned rules nor its ERC-20/721/1155 compliance checker look for this class of business-logic vulnerability, which is specific to share-accounting math rather than a generic standard-compliance gap.

Proposed Solution

Implement CP-122, a detector targeting vault/share-accounting patterns:

  • Identify contracts implementing a deposit/mint/withdraw/redeem share-accounting pattern (via function signature and state-variable heuristics — e.g., a totalSupply/totalAssets-style ratio used to compute shares minted on deposit), whether or not they formally inherit an ERC-4626 interface.
  • Flag vaults where: (a) share price is computed as a naive assets * totalSupply / totalAssets ratio without a minimum-liquidity/dead-shares guard on first deposit, (b) the vault's asset balance can be directly inflated by a plain token transfer (i.e., accounting relies on balanceOf(address(this)) rather than an internally tracked, transfer-independent asset ledger), and (c) there is no protection such as virtual shares/assets offset, an internal _totalAssets accounting variable, or a minimum-deposit/donation-resistant initialization step.
  • Provide a concrete, contract-specific remediation recommendation (e.g., "mint and burn a fixed dead-share amount to the zero address on first deposit," or "track internal accounting instead of relying on live token balance") rather than a generic warning.
  • Severity: high, given the direct fund-loss impact and real-world precedent.

Technical Scope

  • New packages/core/src/rules/cp122-vault-inflation.ts using the existing AST visitor pattern, consistent with the plugin API's documented rule template.
  • Heuristics for identifying share-accounting contracts should be conservative enough to avoid flagging unrelated ratio math elsewhere in a contract; document the detection heuristic clearly so false positives can be triaged and tuned.
  • New fixture contracts under examples/contracts/: a vulnerable vault reproducing the classic first-depositor inflation pattern, and a patched version using dead-shares/virtual-offset mitigation that should scan clean.
  • Unit tests covering the vulnerable fixture, the patched fixture, and at least one contract with unrelated ratio-based math that must not trigger a false positive.

Acceptance Criteria

  • Flags the vulnerable fixture vault with a high severity finding and a specific, actionable recommendation.
  • Does not flag the patched (dead-shares) fixture vault.
  • Does not flag an unrelated contract that performs similar-looking ratio arithmetic outside a deposit/withdraw share-accounting context.
  • The new rule is documented in the README's Vulnerability Rules table.

Estimated Scope

Approximately 700 lines of new TypeScript across the detector, fixtures, and tests.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions