Submitted by GimelSec
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L65
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L100
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L130
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L172
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L191
https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L228
VaultTracker neglect previously accrued interest while attempting to calculate new interest. This causes nToken holders to receive less yield than they should.
All functions within VaultTracker that calculate interest are affected, including addNotional, removeNotional, redeemInterest, transferNotionalFrom and transferNotionalFee.
Consider the case where some user N tries to initiate a vault at 3 specific moments where cToken exchange rate is 5/10/20 respectively.
The corresponding market stays active and has not reached maturity. Additionally, N selects his premium volume to make principalFilled match the cToken exchange rate during each call to initiateVaultFillingZcTokenInitiate.
We recognize those exchange rates are most likely unrealistic, but we chose those for ease of demonstrating the bug. We also assume fees to be 0 for simplicity.
For the first call to Swivel.deposit
Assuming no additional fees while minting cToken, N will receive cToken\ for his 5 underlying tokens.
For the matching call to VaultTracker.addNotional
Since this is the first time adding nToken to the vault, there is no need to consider any accumulated interests, and we can assign a directly to vlt.notional.
The result will be
For the second call to `Swivel.deposit, we have
The matching call to VaultTracker.addNotional has
The yield is derived from ((exchangeRate * 1e26) / vlt.exchangeRate) - 1e26 = ((10 * 1e26) / 5) - 1e26 = 1e26
Applying this to vlt.notional, we get interest = 1e26 * 5 / 1e26 = 5
This results in
Now comes the last call to Swivel.deposit, where
VaultTracker.addNotional has
yield = ((20 * 1e26) / 10) - 1e26 = 1e26
interest = 1e26 * 15 / 1e26 = 15
So we finally end up with
Now take a step back and think about the actual value of 3 cToken when exchangeRate = 20, it should be pretty obvious that the value tracked by VaultTracker = 35 + 20 = 55 is lesser than the actual value of cToken held by Swivel = 20*3 = 60.
This is due to VaultTracker neglecting that previously accrued interest should also be considered while calculating new interest.
For all interest calculations, use vlt.notional + vlt.redeemable instead of just vlt.notional as yield base.
JTraversa (Swivel) disputed and commented:
JTraversa (Swivel) disagreed with severity and commented:
robrobbins (Swivel) commented:
robrobbins (Swivel) resolved:
0xean (judge) decreased severity to Medium and commented:
