Vault Operations: Deposit & Yield
Relevant source files
The following files were used as context for generating this wiki page:
The Tokenized Vault system within the Aztec Standards project implements an ERC-4626-like standard, adapted for the privacy-centric Aztec Network. It allows users to deposit an underlying asset (AIP-20 compliant) into a vault in exchange for yield-bearing shares. These shares represent a proportional claim on the vault's total assets, which can grow over time through yield generation or external donations.
The vault supports a diverse range of interaction flows, encompassing both public and private asset balances. Users can deposit public assets to receive private shares, or vice versa, providing flexibility between transparency and confidentiality. The system also includes specific safeguards against common DeFi vulnerabilities, such as inflation attacks, by utilizing initial deposits to dilute potential manipulation.
Sources: README.md:27-32, src/ts/test/tokenized_vault.test.ts:117-124, src/ts/test/utils.ts:182-198
Core Architecture and Initialization
The vault is implemented as a specialized configuration of the Token contract. It is initialized using the constructor_with_asset method, which links the vault to a specific underlying asset. In this configuration, the vault contract itself acts as the issuer of shares, which are also AIP-20 compliant tokens.
Deployment Process
The deployment requires specifying the underlying asset address and an optional initial deposit. The initial deposit is a critical security feature; if initialDeposit > 0, the vault mints "locked" shares to the zero address or the vault itself to provide protection against exchange rate manipulation.
Sources: README.md:29-32, src/ts/test/utils.ts:182-198
The diagram shows the initialization flow where a Vault is linked to an Asset contract and secured with an initial deposit. Sources: src/ts/test/utils.ts:182-198, benchmarks/tokenized_vault_contract.benchmark.ts:55-60
Deposit and Minting Operations
Vault operations are categorized by the visibility of the source assets and the resulting shares. Each operation involves a transfer of the underlying asset from the user to the vault, followed by the issuance (minting) of shares to the user.
Interaction Modes
Users can interact via four primary combinations of public and private states:
| Operation Mode | Asset Source | Share Destination | Description |
|---|---|---|---|
| Public to Public | Public Balance | Public Balance | Fully transparent deposit and share issuance. |
| Private to Public | Private Balance | Public Balance | Asset source is hidden; share ownership is public. |
| Public to Private | Public Balance | Private Balance | Asset source is public; share ownership is hidden. |
| Private to Private | Private Balance | Private Balance | Fully confidential transaction flow. |
Sources: src/ts/test/tokenized_vault.test.ts:117-300, benchmarks/tokenized_vault_contract.benchmark.ts:89-115
Deposit Logic Flow
When a user deposits, the vault calculates the number of shares based on the current exchange rate: shares = assets * (total_shares / total_assets).
The sequence shows the atomic nature of a deposit where the asset is transferred before shares are minted. Sources: src/ts/test/tokenized_vault.test.ts:175-185, benchmarks/tokenized_vault_contract.benchmark.ts:95-97
Yield and Asset Management
Yield is simulated or generated when the total amount of assets held by the vault increases without a corresponding increase in the total supply of shares. This can occur through:
- Minting to Vault: Directly minting assets to the vault address.
- Asset Transfers: Users or protocols transferring assets to the vault as "donations".
Impact on Exchange Rate
Because shares represent a proportional claim on total_assets, an increase in assets makes each share more valuable.
- Total Supply: The sum of all shares minted.
- Total Assets: The vault's current balance of the underlying token.
- Exchange Rate: Calculated as
total_assets / total_shares.
Sources: src/ts/test/tokenized_vault.test.ts:127-133, src/ts/test/tokenized_vault.test.ts:654-664
Security: Inflation Attack Protection
The vault includes mechanisms to prevent "inflation attacks," where an attacker manipulates the share price by donating assets to a vault with a very low total supply (e.g., 1 share).
Attack Scenario
- Attacker deposits 1 wei of asset to get 1 share.
- Attacker "donates" a large amount of assets to the vault.
- The share price becomes extremely high.
- Subsequent users' deposits result in 0 shares due to rounding, effectively donating their assets to the attacker.
Mitigation
By deploying the vault with an initial deposit (e.g., 5 wei), the vault creates a minimum base of shares. This dilution ensures that even if an attacker attempts to inflate the price, the rounding errors do not disproportionately benefit the attacker, and the victim still receives a non-zero amount of shares.
Sources: src/ts/test/tokenized_vault.test.ts:639-680, src/ts/test/utils.ts:210-225
Key Functions for Vault Operations
The following functions are used to manage the lifecycle of assets and shares.
| Function | Type | Input Parameters | Source File |
|---|---|---|---|
deposit_public_to_public | Public | from, to, amount, nonce | tokenized_vault.test.ts:117 |
issue_private_to_private_exact | Private | from, to, shares, max_assets, nonce | tokenized_vault.test.ts:257 |
withdraw_public_to_private | Mixed | from, to, assets, nonce | tokenized_vault.test.ts:167 |
redeem_private_to_public | Mixed | from, to, shares, nonce | tokenized_vault.test.ts:236 |
preview_redeem | View | shares | tokenized_vault.test.ts:228 |
Sources: src/ts/test/tokenized_vault.test.ts:117-300, benchmarks/tokenized_vault_contract.benchmark.ts:89-130
Summary
The Vault Operations module provides a robust framework for managing yield-bearing assets within the Aztec ecosystem. By supporting multiple privacy modes (public/private) for both deposits and withdrawals, and implementing native protection against inflation attacks via initial share dilution, the system offers a secure and flexible foundation for privacy-preserving decentralized finance.