Closed Havoc19 closed 7 hours ago
#### Mechanism 1. Before borrowing, we capture the initial length of borrowed tokens: ```solidity uint256 borrowedLengthBefore = ( assetHandler.getBorrowedTokens(_vault, _controller) ).length;
After borrowing, we capture the new length:
uint256 borrowedLengthAfter = ( assetHandler.getBorrowedTokens(_vault, _controller) ).length;
We increment tokensBorrowed only if a new token type was borrowed:
tokensBorrowed
if (borrowedLengthAfter > borrowedLengthBefore) { tokensBorrowed++; }
MAX_BORROW_TOKEN_LIMIT
#### Mechanism 1. Flag Initialization: ```solidity bool _isFlashLoanActive;
false
Before Flash Loan Initiation:
// Set flash loan flag to true to allow callback execution _isFlashLoanActive = true;
Callback Verification:
function algebraFlashCallback(...) external override { // Prevent unauthorized callbacks if(!_isFlashLoanActive) revert ErrorLibrary.FlashLoanIsInactive(); // Proceed with callback logic // ... }
1. Borrowed Token Length Tracking
After borrowing, we capture the new length:
We increment
tokensBorrowed
only if a new token type was borrowed:Why This Approach?
MAX_BORROW_TOKEN_LIMIT
Example Scenario
tokensBorrowed
remains 2tokensBorrowed
increments to 3Safeguards
2. Flash Loan Safety Mechanism
false
Before Flash Loan Initiation:
Callback Verification:
Security Considerations
Potential Attack Vectors Mitigated