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

fix: prevent borrowing limit violation during facade migration #258

Merged
merged 1 commit into from
Sep 1, 2024

Conversation

lekhovitsky
Copy link
Collaborator

@StErMi
Copy link

StErMi commented Aug 26, 2024

The implementation achieves to solve the issue described in https://github.com/spearbit-audits/review-gearbox/issues/58 but brings some drawbacks in the process: now every time that the CreditFacadeV3.setDebtLimits is executed the totalBorrowedInBlock state variable is initialized to type(uint128).max.

This means that every time that the CreditConfiguratorV3 calls one of the following functions:

  • setCreditFacade with migrateParams == true
  • setMaxDebtPerBlockMultiplier
  • forbidBorrowing (this can be excluded because the intent is to indeed forbid borrowing)
  • setMinDebtLimit
  • setMaxDebtLimit

and maxDebtPerBlockMultiplier is not configured to be equal to type(uint8).max (skip the borrowing per block check), any borrowing operations included in the block will revert.

@lekhovitsky and Gearbox team, could you please confirm that this is the behavior you want to achieve with this PR?

@lekhovitsky
Copy link
Collaborator Author

lekhovitsky commented Aug 26, 2024

@StErMi yeah that's fine, since we're restricting the system anyways it doesn't hurt much to revert during some risky actions (which borrowing is) performed right after configuration, especially given that (i) the only loss is gas fees paid (ii) the likelihood of this actually happening is quite low and (iii) alternative solutions to the problem were really cumbersome.

On Ethereum Mainnet (the only place where gas fees for reverts can be considerable), there are some additional practical considerations on why this won't likely be an issue:

  • typically, borrowing operations are coupled with swaps of various kinds which entail MEV, so block builders would be incentivized to place them before our configuration transactions within a single block;
  • RPC endpoints that guarantee non-inclusion of reverting txs are quite common nowadays.

Base automatically changed from spearbit-55-61-63-102-103-110 to spearbit-fixes September 1, 2024 10:22
@lekhovitsky lekhovitsky merged commit 17b2e98 into spearbit-fixes Sep 1, 2024
3 checks passed
@lekhovitsky lekhovitsky deleted the spearbit-58 branch September 1, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants