Token Contract Benchmarks
Relevant source files
The following files were used as context for generating this wiki page:
The Token Contract Benchmarks provide a standardized framework for measuring the performance and resource consumption of Aztec-based smart contracts. Utilizing the @defi-wonderland/aztec-benchmark package, these benchmarks cover a wide range of operations including private and public transfers, minting, burning, and specialized interactions such as those found in tokenized vaults and escrow systems.
The scope of these benchmarks includes the standard Token Contract, NFT Contract, and specialized extensions like the Tokenized Vault. These tests are critical for understanding the gas costs, proof generation times, and latency associated with confidentiality-preserving transactions on the Aztec Network.
Sources: benchmarks/token_contract.benchmark.ts:1-15, Nargo.toml:11-17
Benchmark Architecture
The benchmarking system is built upon a base Benchmark class. Each benchmark implementation must define a setup() method to prepare the environment, a getMethods() method to return the specific contract calls to be measured, and a teardown() method for cleanup.
The diagram above illustrates the inheritance structure and lifecycle of a typical benchmark run within the project.
Sources: benchmarks/token_contract.benchmark.ts:28-115, benchmarks/nft_contract.benchmark.ts:15-68
Core Token Benchmarks
The TokenContractBenchmark evaluates the primary functionalities of the AIP-20 Aztec Token Standard. This includes operations across private and public domains, as well as transitions between them.
Benchmarked Methods
The benchmark tracks several categories of interactions:
| Category | Method Name | Description |
|---|---|---|
| Minting | mint_to_private, mint_to_public | Creating new supply in either domain. |
| Transfer | transfer_private_to_public, transfer_public_to_private, transfer_private_to_private, transfer_public_to_public | Moving balances between users and domains. |
| Burning | burn_private, burn_public | Removing supply from the domains. |
| Partial Notes | initialize_transfer_commitment, transfer_public_to_commitment | Benchmarking the privacy-preserving partial note flow. |
Sources: benchmarks/token_contract.benchmark.ts:63-112
Partial Note Initialization Flow
Benchmarking partial notes requires a specific sequence to handle decryption of private logs for commitment extraction.
This flow represents the setup required to benchmark the transfer_private_to_commitment method accurately.
Sources: benchmarks/token_contract.benchmark.ts:42-57, src/ts/test/utils.ts:328-356
Tokenized Vault Benchmarks
The TokenContract is also benchmarked in its capacity as a yield-bearing vault (AIP-4626). These benchmarks are significantly more complex as they involve two interacting contracts: the Asset contract (underlying) and the Vault contract (shares).
Setup and Authorization Witnesses
To benchmark vault operations like deposit_private_to_private, the system must pre-generate AuthWitness objects. This is because the Vault contract acts as an intermediary that must be authorized to spend the user's underlying assets.
- Public AuthWits: Set using
setPublicAuthWitfor methods likedeposit_public_to_public. - Private AuthWits: Set using
setPrivateAuthWitand passed via the.with({ authWitnesses: [...] })pattern.
Sources: benchmarks/tokenized_vault_contract.benchmark.ts:43-86, src/ts/test/utils.ts:291-322
Vault Operations Table
The vault benchmark evaluates 19 distinct interaction types:
| Operation Type | Implementation Variants |
|---|---|
| Deposit | Public->Public, Public->Private, Private->Private, Private->Public, Exact variants |
| Issue | Public->Public, Public->Private, Private->Public Exact, Private->Private Exact |
| Withdraw | Public->Public, Public->Private, Private->Private, Private->Public Exact, Private->Private Exact |
| Redeem | Public->Public, Private->Public, Private->Private Exact, Public->Private Exact |
Sources: benchmarks/tokenized_vault_contract.benchmark.ts:100-184
NFT and Escrow Benchmarks
Benchmarks for non-fungible tokens and escrow logic focus on the transfer of unique identifiers and the coordination between logic contracts and storage contracts.
Escrow Benchmark Logic
The escrow benchmark measures the cost of a "Logic" contract (the authorized spender) interacting with an "Escrow" contract (the vault holding assets).
NFT Methods Measured
The NFTContractBenchmark specifically targets ownership transfers across domains:
mint_to_private/mint_to_publictransfer_private_to_publictransfer_public_to_privatetransfer_private_to_privatetransfer_public_to_publicburn_private/burn_public
Sources: benchmarks/nft_contract.benchmark.ts:32-65
Benchmark Configuration
Benchmarks are configured via the root Nargo.toml and utilize the setupTestSuite utility which handles the initialization of the Aztec node, PXE, and prover.
// Example Setup from benchmarks/token_contract.benchmark.ts
async setup(): Promise<TokenBenchmarkContext> {
const { cleanup, wallet, accounts } = await setupTestSuite(true);
const [deployer] = accounts;
const deployedBaseContract = await deployTokenWithMinter(wallet, deployer);
const tokenContract = TokenContract.at(deployedBaseContract.address, wallet);
// ... additional initialization
return { cleanup, wallet, deployer, accounts, tokenContract, commitments };
}
Sources: benchmarks/token_contract.benchmark.ts:33-60, src/ts/test/utils.ts:75-103
Conclusion
The Token Contract Benchmarks provide an essential tool for performance regression testing and gas optimization within the Aztec Standards project. By simulating high-complexity scenarios like tokenized vaults and private escrow transfers, they ensure that the standard implementations remain efficient and scalable for production privacy-preserving applications.