Quantillon Protocol

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FlashLoanProtectionLibrary

Git Source

Author: Quantillon Labs - Nicolas Bellengé - @chewbaccoin

Library for protecting contracts against flash loan attacks

This library provides functions to detect and prevent flash loan attacks by monitoring balance changes during function execution.

Flash loan attacks can occur when:

  • An attacker borrows a large amount of tokens
  • Manipulates protocol state (e.g., governance votes, price oracles)
  • Repays the loan in the same transaction
  • Profits from the manipulated state

Protection mechanism:

  • Balance checks before and after function execution
  • Validation that balances don't decrease unexpectedly

Note: security-contact: team@quantillon.money

Functions

validateBalanceChange

Validates that a balance change is within acceptable limits

This function validates that balances don't decrease beyond acceptable limits. Currently used by all contract modifiers to prevent flash loan attacks. A maxDecrease of 0 means no decrease is allowed (strict protection).

Notes:

  • security: Prevents flash loan attacks by validating balance changes

  • validation: Validates balance changes are within acceptable limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No custom errors thrown

  • reentrancy: Not applicable - pure function

  • access: Internal function - no access restrictions

  • oracle: No oracle dependencies

function validateBalanceChange(uint256 balanceBefore, uint256 balanceAfter, uint256 maxDecrease)
    internal
    pure
    returns (bool);

Parameters

NameTypeDescription
balanceBeforeuint256Balance before operation
balanceAfteruint256Balance after operation
maxDecreaseuint256Maximum allowed decrease in balance

Returns

NameTypeDescription
<none>boolbool True if balance change is acceptable