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.
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:totalSupply/totalAssets-style ratio used to compute shares minted on deposit), whether or not they formally inherit an ERC-4626 interface.assets * totalSupply / totalAssetsratio 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 onbalanceOf(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_totalAssetsaccounting variable, or a minimum-deposit/donation-resistant initialization step.high, given the direct fund-loss impact and real-world precedent.Technical Scope
packages/core/src/rules/cp122-vault-inflation.tsusing the existing AST visitor pattern, consistent with the plugin API's documented rule template.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.Acceptance Criteria
highseverity finding and a specific, actionable recommendation.Estimated Scope
Approximately 700 lines of new TypeScript across the detector, fixtures, and tests.