Race condition in BuyerAgent's oracle purchase mechanism allows transactions to execute in incorrect market phases, breaking core protocol invariants and potentially leading to out-of-sequence trading operations.
The phase validation and oracle request execution in BuyerAgent.sol are non-atomic operations. The time gap between phase check and request execution allows the protocol phase to change, invalidating the initial phase validation: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L189-L195
This vulnerability creates a critical timing issue in the protocol's phase management system. The non-atomic nature of the phase check and oracle request allows for a race condition where:
The function checks if we're in Buy phase
Time passes, potentially changing phases
Oracle request executes in wrong phase
This breaks the core protocol invariant that purchase requests must only occur during Buy phase. The impact is severe:
Disrupts the strict ordering of Sell -> Buy -> Withdraw phases
Could allow purchases during Sell/Withdraw phases
Undermines the entire market timing mechanism
May lead to unexpected asset pricing and trading conditions
POC
Breaks fundamental phase ordering (Sell -> Buy -> Withdraw)
Allows purchase requests during incorrect phases
Implement phase validation at execution time by encoding phase information with the request data. This ensures phase consistency throughout the request lifecycle.
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.