Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DebtRatio problem #376

Closed
zgfzgf opened this issue May 26, 2021 · 13 comments · Fixed by #381
Closed

DebtRatio problem #376

zgfzgf opened this issue May 26, 2021 · 13 comments · Fixed by #381
Labels
bug Something isn't working p1 Critical/Needed

Comments

@zgfzgf
Copy link
Contributor

zgfzgf commented May 26, 2021

strategy_debtLimit: uint256 = (
self.strategies[strategy].debtRatio
* self.totalDebt
/ self.debtRatio
)

strategy_debtLimit: uint256 = self.strategies[strategy].debtRatio * vault_totalAssets / MAX_BPS

above. compute strategy_debtLimit is different
vault_debtLimit: uint256 = self.debtRatio * vault_totalAssets / MAX_BPS

should add var debtLimit
vault_debtLimit: uint256 = self.debtLimit * vault_totalAssets / MAX_BPS
self.debtLimit <= MAX_BPS

No more judgment self.debtRatio<=MAX_BPS

compute strategy_debtLimit
self.strategies[strategy].debtRatio * self.totalDebt / self.debtRatio
add strategy
self.debtRatio += self.strategies[strategy].debtRatio

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

now use var self.debtRatio controller vault_debtLimit. It's hard to control and understand.

@zgfzgf zgfzgf changed the title debtRatio problem DebtRatio problem May 26, 2021
@ghost
Copy link

ghost commented May 26, 2021

What you are suggesting is the code we use to have prior to the changes.
a5c51b2#diff-b583ba5c4d7b67e56b9084eff9fe883e12a2cdd94a2ea25029322c6f3568d807L1140

The original design was based on totalAssets() but this can be user manipulated.

A potential fraudulent strategy that doesn't want to return back his assets after gains could fraud by depositing assets into the vault, call harvest it debtRatio compared to total assets would not change and then the strategist can withdraw the funds.

We tried to prevent that with our latest changes but that introduced another issue:
#375

@ghost
Copy link

ghost commented May 26, 2021

What you are suggesting is the code we use to have prior to the changes.
a5c51b2#diff-b583ba5c4d7b67e56b9084eff9fe883e12a2cdd94a2ea25029322c6f3568d807L1140

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

I think. add var debtLimit controller available amout. vault 1 code:
// Custom logic in here for how much the vault allows to be borrowed
// Sets minimum required on-hand to keep small withdrawals cheap
function available() public view returns (uint) {
return token.balanceOf(address(this)).mul(min).div(max);
}
a5c51b2#diff-b583ba5c4d7b67e56b9084eff9fe883e12a2cdd94a2ea25029322c6f3568d807L1140
there is no such function here.
add var debtLimit.
We don't need that judgment
self.debtRatio<=MAX_BPS

I think it's better and easier to understand. @steffenix @fubuloubu

@ghost
Copy link

ghost commented May 26, 2021

sorry, I do not understand your suggestion.
Can you propose some changes?

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

Well, I'll change the code tomorrow, and we'll discuss it. You can better understand my idea from the code.

@ghost
Copy link

ghost commented May 26, 2021

Ok I will discuss with @fubuloubu
Thanks!

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

a5c51b2#diff-b583ba5c4d7b67e56b9084eff9fe883e12a2cdd94a2ea25029322c6f3568d807L1140
def addStrategy(
strategy: address,
debtLimit: uint256,
rateLimit: uint256,
performanceFee: uint256,
) before debtLimit is good. it controller strategy amount. why delete it now?

@ghost
Copy link

ghost commented May 26, 2021

Because a strategy owner can reduce or bypass debt reduction.

The computation of the ratio change depends on total assets, which are computed using the balance of the vault. However, a strategy owner can temporarily increase this value with a flash loan, with the following sequences of calls in a single transaction:

  1. Take a flash loan
  2. Make deposit
  3. Call report
  4. Make a withdrawal
  5. Repay the flash loan

Since the value of the _totalAssets() will be increased (up to the deposit limit), the amount of ratio_change can be reduced, even to zero, avoiding the debt change.

The updates I made were incorrect and we have to find a way around that.

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

thank you.
I suggest add strategy debtLimit. not add self.debtLimit. add var self.available controller use asset.
for example:
self.available=9500. max may use asset = 9500*vault_totalAssets/MAX_BPS
strategy 1 debtLimit = 100 strategy 1 may use asset <= 100.
strategy 2 debtLimit = 200 strategy 2 may use asset <= 200.

@ghost
Copy link

ghost commented May 26, 2021

To my understanding, your suggestion is also prone to the manipulation described above.

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 26, 2021

Because a strategy owner can reduce or bypass debt reduction.

The computation of the ratio change depends on total assets, which are computed using the balance of the vault. However, a strategy owner can temporarily increase this value with a flash loan, with the following sequences of calls in a single transaction:

  1. Take a flash loan
  2. Make deposit
  3. Call report
  4. Make a withdrawal
  5. Repay the flash loan

Since the value of the _totalAssets() will be increased (up to the deposit limit), the amount of ratio_change can be reduced, even to zero, avoiding the debt change.

The updates I made were incorrect and we have to find a way around that.

To solve this problem, we estimate that we should lock deposit amount.
like _calculateLockedProfit function

@zgfzgf
Copy link
Contributor Author

zgfzgf commented May 27, 2021

for example:
strategy 1 strategy 2 parameters are the same. debtLimit = 100.
strategy 1 debt = 100 and strategy 2 debt = 100
when withdraw 80.
strategy 1 debt = 20 and strategy 2 debt = 100
normal: report
strategy 1 debt = 60 and strategy 2 debt = 60
if strategy 2 do above flash loan
strategy 1 debt = 20 and strategy 2 debt = 100 There is nothing wrong with that. debt<debtLimit. strategy 2 may max use 100.
if control strategy 2 debt. update strategy debtLimit =60.

@fubuloubu fubuloubu added bug Something isn't working p1 Critical/Needed labels May 27, 2021
@ghost ghost closed this as completed in #381 May 27, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1 Critical/Needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants