<!-- canonical: https://0xsimao.com/findings/aegis-donation-although-unlikely-deposit -->

# Donation attack possible, although unlikely, could make an initial deposit

Low/Info · Sherlock · Bitcoin-backed stablecoin · 22nd April, 2025

Finding L-2 of the Aegis Staked YUSD security review.

- Protocol: https://www.aegisweb3.com/
- Report: /reports/aegis
- Source: https://github.com/sherlock-protocol/sherlock-reports/blob/main/audits/2025.04.26%20-%20Final%20-%20Aegis%20Collaborative%20Audit%20Report.pdf

---

## Summary

ERC4626 donations attack are mitigated by default in the current Openzeppelin implementation by setting the decimals offset to 0, which is enough to dillute attacker donations as per the assets/shares conversion, [here](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L225-L227). However, this means the attack may not always be profitable for the attacker, but there is still a chance it is, and the users take losses.

## Vulnerability Detail

Essentially the attack is as follows:
1. Attacker mints 1 shares.
2. Attacker donates `YUSD` to `sYUSD`.
3. User deposits and mints 0 or a rounded down amount of shares (specifying that shares minted > 0 is not enough because if it rounds down to 1, 2 or similar the user also takes losses).

This is mitigated by the current ERC4626 implementation as it results in:
1. Attacker mints 1 shares.
2. Attacker donates 10e18 assets + 1.
3. If the attacker redeems their share, they get `1 * (1e18 + 1 + 1) / (1 + 1) = 0.5e18`.

However, a user may still get caught in this:
Step 4, user deposits 4e18 assets, getting `4e18 * (1 + 1) / (10e18 + 1) = 0` shares.

## Impact

Attacker steals user funds

## Code Snippet

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L225-L227

## Tool Used

Manual Review

## Recommendation

Make an initial, small deposit and keep it deposited to fully prevent these attacks.

---

Related findings:

- [Withdrawing after a slash event before the vault has ended will decrease `fixedSidestETHOnStartCapacity` by less than it should, so following users will withdraw more their initial deposit](https://0xsimao.com/findings/saffron-lido-vaults-slash-eth-withdraw-deposit): Saffron Lido Vaults
- [Incorrect initial deposit calculation may cause cancelProgram to revert](https://0xsimao.com/findings/superfluid-locker-system-ii-initial-deposit-program-revert): Superfluid Locker Pumponomics
