Skip to main content

When to Use This Pattern

Ensures harvest operations in yield farming protocols maintain integrity by preventing balance decreases and price per share manipulation. Critical for yield farming protocols (Beefy, Yearn, Harvest), liquidity mining programs, staking protocols with reward distribution, and auto-compounding vaults. Incorrect harvest implementations could lead to loss of user funds, price per share manipulation enabling flash loan attacks, or protocol insolvency through improper reward distribution.

What This Pattern Checks

Implements multi-layered approach to verify harvest operations:
  • _preTx() / _postTx() with Reshiram snapshot reads: Capture vault balance and price per share before/after harvest
  • ph.loadStateAt(): Read balance and price-per-share slots before and after the harvest call
  • registerFnCallTrigger(): Trigger on harvest function calls
  • Ensures balance hasn’t decreased (can stay same if harvested recently)
  • Confirms price per share hasn’t decreased
  • Prevents manipulation through multiple harvest calls
The assertion verifies each balance change is valid relative to previous state, ensuring no balance decreases occur at any point and maintaining protocol solvency. For more information about cheatcodes, see the Cheatcodes Documentation.

Assertion Pattern

Full examples and mock protocol code are available in credible-std.