Description:
https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L138
https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/SwanManager.sol#L80-L84
The Swan protocol's market timing system relies on accurate initialization of marketParameterIdx in the BuyerAgent contract. However, there's a critical race condition in the initialization process that can lead to incorrect phase and round calculations throughout the agent's lifetime.
Key components involved:
Swan.createBuyer() - Creates new buyer agents
BuyerAgent.constructor() - Initializes market parameter index
SwanManager.setMarketParameters() - Updates market parameters
BuyerAgent.getRoundPhase() - Calculates current phase based on market parameters
The vulnerability stems from the following sequence:
Impact:
Phase Calculation Errors:
Agents could operate in wrong phases (Buy/Sell/Withdraw)
Incorrect timing windows for asset purchases
Misaligned market cycles between agents
Financial Implications:
Incorrect spending period calculations
Potential manipulation of market timing
Incorrect spending period calculations
Proof of Concept:
Recommended Mitigation:
Add timestamp validation in SwanManager:
2.Improve BuyerAgent initialization:
3.Consider moving parameter index assignment to factory:
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.