The BuyerAgent contract's withdrawal mechanism contains an arithmetic overflow vulnerability that allows bypassing minimum fund requirements during non-Withdraw phases. This enables malicious actors to drain funds below the required minimum balance, potentially disrupting the entire buying cycle and oracle operations.
The vulnerability exists in the withdrawal logic where unsafe arithmetic operations are performed before balance validation: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L262-L271
The check minFundAmount() + _amount can overflow with carefully crafted amounts, making the comparison pass even when it should fail. This bypasses the core protection mechanism meant to maintain minimum operating funds.
The reason is because the contract performs unsafe arithmetic when checking withdrawal conditions: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L270
This addition can overflow with large _amount values, making the comparison pass even when it shouldn't, allowing unauthorized withdrawals below the minimum required balance.
During Buy/Sell phases, the contract must maintain a minimum balance (minFundAmount) to:
Cover oracle fees
Ensure sufficient funds for next round purchases
Maintain protocol economic security
The overflow allows circumventing this protection by:
Making minFundAmount() + _amount wrap around to a small number
Passing the comparison check even with insufficient funds
Enabling withdrawal of more tokens than should be allowed
See example below:
Circumvention of minimum balance requirements
Potential disruption of oracle operations due to insufficient fees
Breaking of round-based purchasing mechanisms
The fix uses checked arithmetic and reverses the comparison logic to prevent overflow exploitation while maintaining the intended security invariants.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.