Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ For more information about cheatcodes, see the [Cheatcodes Documentation](/credi
<Note>Full examples with tests available in the [Phylax Assertion Examples Repository](https://github.com/phylaxsystems/assertion-examples/blob/main/assertions/).</Note>

## Related Assertions
- [ERC4626 Deposit and Withdrawal](/assertions-book/assertions/ass13-erc4626-deposit-withdraw)

- [ERC4626 Vault Operations](/assertions-book/assertions/ass13-erc4626-deposit-withdraw) — deposit, withdraw, mint, redeem with batch handling
46 changes: 29 additions & 17 deletions assertions-book/assertions/ass13-erc4626-deposit-withdraw.mdx
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
---
title: ERC4626 Vault Deposit and Withdrawal
description: Assert that ERC4626 deposit and withdrawal operations maintain correct accounting
title: ERC4626 Vault Operations
description: Ensure that ERC4626 operations maintain correct accounting
---

import ass13Erc4626DepositWithdraw from "/snippets/ass13-erc4626-deposit-withdraw.a.mdx";
import ass2Erc4626Operations from "/snippets/ass2-erc4626-operations.a.mdx";

## Use Case & Applications

Ensures ERC4626 deposit and withdrawal operations maintain correct accounting for both assets and shares, preventing share calculation errors and fund loss. Critical for yield aggregators (Yearn, Aave, Compound), lending protocols with ERC4626 interest-bearing tokens, liquidity pools using ERC4626 for LP tokens, and staking protocols with ERC4626 staking tokens.
Ensures ERC4626 operations maintain correct accounting for both assets and shares, preventing share calculation errors and fund loss. Critical for yield aggregators (Yearn, Aave, Compound), lending protocols with ERC4626 interest-bearing tokens, liquidity pools using ERC4626 for LP tokens, and staking protocols with ERC4626 staking tokens.

Any discrepancy between preview functions and actual operations could lead to users receiving incorrect amounts, potentially resulting in value loss.

## Explanation
## Focused Approach: Deposit & Withdraw

Collection of five assertion functions providing comprehensive verification of deposit/withdrawal operations:
Five assertion functions for deposit/withdrawal verification:

**Deposit Assertions:**
- **Asset Accounting**: Total vault assets increase by exact deposit amount
- **Share Accounting**: Depositors receive correct shares (verified against `previewDeposit()`)
- **Share Accounting**: Depositors receive correct shares

**Withdrawal Assertions:**
- **Asset Accounting**: Total vault assets decrease by exact withdrawal amount
- **Share Accounting**: Correct shares burned (verified against `previewWithdraw()`)
- **Share Accounting**: Correct shares burned

**Share Value Assertion:**
- **Share Value Monotonicity**: Share value never decreases unexpectedly
- **Share Value Monotonicity**: Share value never decreases unexpectedly (with precision tolerance for rounding)

Uses these cheatcodes:
- `ph.getCallInputs()`: Track deposit/withdraw call inputs
- `ph.forkPreState()` / `ph.forkPostState()`: Compare balances before/after operations
- `registerCallTrigger()`: Trigger on ERC4626 vault operations
Uses `ph.getCallInputs()`, `ph.forkPreTx()` / `ph.forkPostTx()`, and `registerCallTrigger()`. See the [Cheatcodes Reference](/credible/cheatcodes-reference) for details.

The assertions verify no discrepancy exists between preview function predictions and actual operation results.
<ass13Erc4626DepositWithdraw />

For more information about cheatcodes, see the [Cheatcodes Documentation](/credible/cheatcodes-reference).
## Comprehensive Approach: All Operations + Batch Handling

## Code Example
Use this approach when your protocol:
- Uses mint/redeem in addition to deposit/withdraw
- Handles multiple operations in a single transaction
- Needs validation against preview functions

<ass13Erc4626DepositWithdraw />
Four assertion functions covering all ERC4626 operations:

- **Batch Operations Consistency**: Validates deposit, mint, withdraw, and redeem in a single transaction. Uses preview functions for expected value calculation.
- **Deposit Balance Verification**: Confirms vault assets increase by exact deposit amount
- **Depositor Shares Verification**: Confirms depositor receives shares matching `previewDeposit()`
- **Base Invariant**: Ensures vault always has at least as many assets as shares

Uses both `registerCallTrigger()` and `registerStorageChangeTrigger()`.

<ass2Erc4626Operations />

<Note>Full examples with tests available in the [Phylax Assertion Examples Repository](https://github.com/phylaxsystems/assertion-examples/blob/main/assertions/).</Note>

## Related Assertions
- [ERC4626 Assets to Shares](/assertions-book/assertions/ass12-erc4626-assets-to-shares)

- [ERC4626 Assets to Shares](/assertions-book/assertions/ass12-erc4626-assets-to-shares) — simple base invariant check
- [Harvest Increases Balance](/assertions-book/assertions/ass18-harvest-increases-balance) — yield operation validation
35 changes: 0 additions & 35 deletions assertions-book/assertions/ass22-farcaster-protocol-integrity.mdx

This file was deleted.

6 changes: 1 addition & 5 deletions assertions-book/assertions/use-cases-index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This section contains assertion patterns organized by use case categories.

- [**ERC4626 Assets to Shares**](/assertions-book/assertions/ass12-erc4626-assets-to-shares): Verifies correct conversion between assets and shares in ERC4626 vaults, preventing accounting errors that could lead to fund loss.

- [**ERC4626 Deposit and Withdraw**](/assertions-book/assertions/ass13-erc4626-deposit-withdraw): Ensures deposit and withdrawal operations maintain correct accounting in ERC4626 vaults, protecting user funds during transfers.
- [**ERC4626 Vault Operations**](/assertions-book/assertions/ass13-erc4626-deposit-withdraw): Ensures all ERC4626 operations (deposit, withdraw, mint, redeem) maintain correct accounting, with support for batch transaction validation.

- [**Harvest Increases Balance**](/assertions-book/assertions/ass18-harvest-increases-balance): Verifies that yield-generating operations like harvests always increase the total balance of vaults, preventing value extraction attacks.

Expand All @@ -60,10 +60,6 @@ This section contains assertion patterns organized by use case categories.

- [**Ether Drain**](/assertions-book/assertions/ass21-ether-drain): Monitors and limits ETH outflows from contracts, protecting against unauthorized withdrawals that could deplete protocol reserves.

## Data Integrity & Message Verification

- [**Farcaster Protocol Integrity**](/assertions-book/assertions/ass22-farcaster-protocol-integrity): Ensures the integrity of cross-chain messages in the Farcaster protocol, preventing unauthorized or malformed message processing.

---

**Next:** Explore [previous hacks analysis](/assertions-book/previous-hacks/) to see how assertions could have prevented real-world exploits.
6 changes: 0 additions & 6 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@
"assertions-book/assertions/ass21-ether-drain"
]
},
{
"group": "Data Integrity & Message Verification",
"pages": [
"assertions-book/assertions/ass22-farcaster-protocol-integrity"
]
},
{
"group": "Use Case Mapping",
"pages": [
Expand Down
122 changes: 0 additions & 122 deletions snippets/ass22-farcaster-message-validity.a.mdx

This file was deleted.

39 changes: 0 additions & 39 deletions snippets/ass3-pending-balance-bedrock-staking.a.mdx

This file was deleted.