Skip to content

Commit 64a47e0

Browse files
committed
suggestions
1 parent a3976a1 commit 64a47e0

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

content/stellar-contracts/tokens/vault/vault.mdx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
title: Fungible Vault Token
2+
title: Fungible Token Vault
33
---
44

5-
[Source Code](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/extensions/vault)
5+
[Source Code](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/vault)
66

7-
The Fungible Vault Token implements the ERC-4626 tokenized vault standard,
7+
The Fungible Token Vault extends the [Fungible Token](/stellar-contracts/tokens/fungible/fungible) and implements the ERC-4626 tokenized vault standard,
88
enabling fungible tokens to represent shares in an underlying asset pool. The tokenized vault standard
99
is the formalized interface for yield-bearing vaults that hold underlying assets. Vault shares enable
10-
hyperfungible collaterals in DeFi.
10+
hyperfungible collaterals in DeFi and remain fully compatible with standard fungible token operations.
1111

1212
This module allows users to deposit underlying assets in exchange for vault shares, and later redeem
1313
those shares for the underlying assets. The vault maintains a dynamic conversion rate between shares and
1414
assets based on the total supply of shares and total assets held by the vault contract.
1515

1616
## Overview
1717

18-
The [Vault](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/extensions/vault) module provides a complete implementation of tokenized vaults following the ERC-4626 standard. Vaults are useful for:
18+
The [Vault](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/vault) module provides a complete implementation of tokenized vaults following the ERC-4626 standard. Vaults are useful for:
1919

2020
- **Yield-bearing tokens**: Represent shares in a yield-generating strategy
2121
- **Liquidity pools**: Pool assets together with automatic share calculation
@@ -33,7 +33,7 @@ The vault automatically handles:
3333
### Shares vs Assets
3434

3535
- **Assets**: The underlying token that the vault manages (e.g., USDC, XLM)
36-
- **Shares**: The vault tokens that represent proportional ownership of the assets
36+
- **Shares**: The Token Vaults that represent proportional ownership of the assets
3737

3838
When assets are deposited into a vault, shares are minted to the depositor.
3939
The number of shares minted depends on the current exchange rate, which is determined by:
@@ -52,7 +52,8 @@ assets = (shares × totalAssets) / totalSupply
5252

5353
The vault uses a "virtual decimals offset" to add extra precision to share calculations.
5454
This helps prevent rounding errors and improves the accuracy of share-to-asset conversions,
55-
especially when the vault has few assets or shares.
55+
especially when the vault has few assets or shares. It's also a key defense mechanism against
56+
[inflation attacks](#inflation-precision-attacks).
5657

5758
The offset adds virtual shares and assets to the conversion formula:
5859

@@ -65,12 +66,16 @@ Values higher than 10 provide minimal practical benefits and may cause overflow
6566

6667
## Rounding Behavior
6768

68-
The vault implements specific rounding behavior to protect the vault from being drained:
69+
The vault implements specific rounding behavior to protect against being drained through repeated rounding exploits.
70+
Without proper rounding, an attacker could exploit precision loss to extract more assets than they deposited by
71+
performing many small operations where rounding errors accumulate in their favor.
72+
73+
To prevent this:
6974

7075
- **Deposit/Redeem**: Rounds **down** (depositor receives slightly fewer shares/assets)
7176
- **Mint/Withdraw**: Rounds **up** (depositor provides slightly more assets/shares)
7277

73-
This ensures the vault always retains a slight advantage in conversions, preventing precision attacks.
78+
This ensures the vault always retains a slight advantage in conversions, making such attacks unprofitable.
7479

7580
| Operation | Input | Output | Rounding Direction |
7681
| ---------- | ------ | ------ | ---------------------------- |
@@ -105,12 +110,14 @@ If a higher offset is required, a custom version of `set_decimals_offset()` must
105110
The virtual decimals offset helps protect against inflation attacks where an attacker:
106111
1. Deposits 1 stroop to get the first share (becoming the sole shareholder)
107112
2. **Donates** (not deposits) an enormous amount of assets directly to the vault contract via a direct transfer, without receiving any shares in return. This inflates the vault's total assets while keeping total shares at 1, making that single share worth an enormous amount
108-
3. When a legitimate user tries to deposit a normal amount (e.g., 1000 stroops), the share calculation rounds down to 0 shares because their deposit is negligible compared to the inflated vault balance. The user loses their deposit while receiving nothing
113+
3. When a legitimate user tries to deposit (e.g., 1000 stroops), the share calculation rounds down to 0 shares because their deposit is negligible compared to the inflated vault balance. The user loses their deposit while receiving nothing
109114

110115
For example: If the attacker donates 1,000,000 stroops after their initial 1 stroop deposit, the vault has 1,000,001 total assets and 1 total share. A user depositing 1000 stroops would receive `(1000 × 1) / 1,000,001 = 0.000999` shares, which rounds down to 0.
111116

112117
The offset adds virtual shares and assets to the conversion formula, making such attacks economically infeasible by ensuring the denominator is never so small that legitimate deposits round to zero.
113118

119+
For more details about the mechanics of this attack, see the [OpenZeppelin ERC-4626 security documentation](https://docs.openzeppelin.com/contracts/5.x/erc4626#security-concern-inflation-attack).
120+
114121
### Custom Authorization
115122

116123
Custom authorization logic can be implemented as needed:

src/navigation/stellar.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"type": "page",
6363
"name": "RWA",
6464
"url": "/stellar-contracts/tokens/rwa/rwa"
65+
},
66+
{
67+
"type": "page",
68+
"name": "Vault",
69+
"url": "/stellar-contracts/tokens/vault/vault"
6570
}
6671
]
6772
},

0 commit comments

Comments
 (0)