Vault Contract Benchmarks
Relevant source files
The following files were used as context for generating this wiki page:
Vault Contract Benchmarks provide a standardized performance measurement framework for the Tokenized Vault Contract within the Aztec Standards ecosystem. This module evaluates the gas costs and execution efficiency of various entry points compliant with the AIP-4626 standard, which allows users to deposit underlying assets in exchange for yield-bearing shares.
The benchmarks specifically target operations involving both private and public balances, ensuring that the privacy-preserving features of the Aztec Network are accurately accounted for during execution. This includes complex interactions like private-to-public deposits and exact share issuance mechanisms.
Sources: README.md:38-42, benchmarks/tokenized_vault_contract.benchmark.ts:25-33
Benchmark Architecture
The benchmarking system is built using the @defi-wonderland/aztec-benchmark package and extends a base class to handle environment setup, execution, and teardown.
Benchmark Context
The benchmark execution environment is encapsulated in the TokenBenchmarkContext, which manages the state required for testing various contract methods.
| Property | Type | Description |
|---|---|---|
wallet | Wallet | The Aztec wallet instance used for signing transactions. |
deployer | AztecAddress | The address of the account that deployed the contracts. |
vaultContract | TokenContract | The vault instance (share token) being tested. |
assetContract | TokenContract | The underlying asset contract instance. |
authWitnesses | AuthWitness[] | A collection of pre-signed private authorization witnesses. |
Sources: benchmarks/tokenized_vault_contract.benchmark.ts:18-28, package.json:42
Execution Flow
The benchmark follows a strict lifecycle: setup() -> getMethods() -> teardown(). During setup, the underlying asset is minted to users, and the vault is initialized by depositing a small amount to the zero address to establish an initial total supply.
Benchmarked Interactions
The benchmark suite covers four primary categories of vault interactions: Deposits, Issuance, Withdrawals, and Redemptions. Each category tests different combinations of public and private state transitions.
Deposit and Issue Methods
These methods focus on the intake of assets from a user and the subsequent minting of shares. "Exact" methods are specifically tested to measure the cost of logic that calculates precise share/asset ratios.
| Method | Source State | Destination State | Description |
|---|---|---|---|
deposit_public_to_public | Public Asset | Public Share | Standard public deposit. |
deposit_private_to_private | Private Asset | Private Share | Fully confidential deposit using AuthWitnesses. |
deposit_public_to_private_exact | Public Asset | Private Share | Deposits public assets for a fixed amount of private shares. |
issue_private_to_public_exact | Private Asset | Public Share | Issues public shares by pulling private assets. |
Sources: benchmarks/tokenized_vault_contract.benchmark.ts:106-150, src/ts/test/tokenized_vault.test.ts:114-118
Withdrawal and Redemption Methods
These methods evaluate the process of burning shares to release the underlying assets.
Security and Protection Mechanisms
The benchmarks include specific scenarios to evaluate protection against common DeFi vulnerabilities, such as inflation attacks (also known as the "first depositor" attack).
Inflation Attack Protection
The benchmarks test the efficiency of the vault when deployed with an initial deposit (locked shares). This mechanism dilutes manipulation attempts by preventing the share price from being easily manipulated through donations.
- Vulnerability Test: Deploying with an initial deposit of 0, where an attacker can donate assets to the vault to inflate share value and grief subsequent depositors.
- Protection Test: Deploying with an initial deposit (e.g., 5 wei) to anchor the share ratio.
Sources: src/ts/test/tokenized_vault.test.ts:639-650, src/ts/test/utils.ts:200-220
Implementation Details
Authorization Witnesses (AuthWits)
Because many vault operations involve the vault contract pulling assets from a user's account, AuthWitness objects are required for private interactions. The benchmarks generate these in the setup phase to simulate real-world usage where a user must authorize the vault to spend their private notes.
// Example of preparing a private authwitness for benchmarking
const nonce = 100 + i;
const action = assetMethods.transfer_private_to_public(deployer, vaultContract.address, amt(1), nonce);
const authWitness = await setPrivateAuthWit(vaultContract.address, action, deployer, wallet);
authWitnesses.push(authWitness);
Sources: benchmarks/tokenized_vault_contract.benchmark.ts:74-82, src/ts/test/utils.ts:236-248
Asset-Share Conversions
To maintain precision and avoid overflows during benchmarks, the vault interactions typically use a scale of 6 decimals (1_000_000n). This is used during both testing simulations and the benchmark setup to ensure consistent calculations between convert_to_shares and convert_to_assets.
Sources: src/ts/test/tokenized_vault.test.ts:88, benchmarks/tokenized_vault_contract.benchmark.ts:31-33
Conclusion
The Vault Contract Benchmarks provide essential data for developers building on the Aztec Standards. By measuring the cost of both private and public AIP-4626 operations, the project ensures that yield-bearing vault implementations are both efficient and secure against common manipulation tactics while maintaining user privacy.