Submitted by samuraii77, also found by Bauchibred, ilchovski, rbserver (1, 2), mt030d, and cheatc0d3
A malicious user can steal money out of other users and the vault when a rebasing token like AMPL is used. That particular token is whitelisted as seen here.
In particular, the AMPL token has a _gonsPerFragment variable that is used to change the balances of other users. The goal of that is to keep a stable price by manipulating the supply. This creates a huge issue for this particular protocol. The cause of the issue is the fact that upon a user moving his funds to another router, the router is being approved based on the amount of tokens he deposited. However, since that is a rebasing token, that amount can change and allow him to steal funds as explained below.
Imagine the following scenario (will keep it very simplistic):
This is how the malicious router can look like (depositWithExpiry() is just a blank function):
In the end, the malicious user didnt earn anything and he also didnt lose anything but he managed to steal 500 tokens from the victim.
Also, if the balance of the contract increases instead, then that would lead to locked funds.
After reading the code more, there are even easier ways to exploit this issue. The deposit router does not even have to be changed, user can just call transferOut(), also funds can be deposited beforehand as well, user can frontrun the rebase by depositing and taking out his funds after it; essentially stealing money out of other users if the balance of AMPL decreased. However, the issue explained above and the POC for it, are still valid and possible.
For the POC, you can initiate a foundry project and paste the following code in Counter.t.sol. I simplified the AMPL token but it works the exact same way. You can compare it to the original one:
I dont think the fix is trivial, I will give some ideas but they have to be carefully examined. First, one of the root causes for the issue is the approval given to the router that is not actually equal to the amount the user is supposed to receive as this is a rebasing token. If that is taken care of and the correct approval is given, I think this vulnerability shouldnt be possible anymore.
Trust (judge) decreased severity to Medium
samuraii77 (warden) commented:
Trust (judge) commented:
samuraii77 (warden) commented:
Trust (judge) commented:
samuraii77 (warden) commented:
Trust (judge) increased severity to High and commented:
the-eridanus (Thorchain) confirmed
