The Swan
contract's initialize
function does not set the timestamp
field of the SwanMarketParameters
struct to the current block.timestamp
. This omission can lead to underflow errors in the BuyerAgent
contract's getRoundPhase
function when calculating elapsed time, causing the function to revert. This disrupts the normal operation of the protocol, since that function is used project-wide.
In the SwanManager
contract, the SwanMarketParameters
struct is designed to have its timestamp
field set to the current block.timestamp
internally, regardless of the user-provided value. This is correctly implemented in the setMarketParameters
function:
However, in the Swan
contract—which inherits from SwanManager
—the initialize
function does not overwrite the timestamp
field when pushing the initial market parameters or perform checks that the timestamp
field falls within acceptable ranges and that all timestamps are in ascending order:
As a result, if the provided _marketParameters.timestamp
is earlier than the createdAt
timestamp of the BuyerAgent
contract (which is set to block.timestamp
upon deployment), it can cause underflow in time calculations within the BuyerAgent
's getRoundPhase
function.
In the BuyerAgent
contract, the getRoundPhase
function calculates the current round and phase based on the elapsed time since the market parameters were set:
If marketParams[idx + 1].timestamp
is less than createdAt
, the subtraction marketParams[idx + 1].timestamp - createdAt
results in a negative value, causing the function to revert.
This vulnerability can prevent the BuyerAgent
contract from correctly determining the current round and phase, leading to a failure in executing critical functions like purchasing assets, updating the buyer's state, or withdrawing funds. Users may experience denial of service, inability to participate in asset rounds, or financial losses due to the contract's inability to process transactions as expected.
Manual Review
Modify the Swan
contract's initialize
function to set the timestamp
field to the current block timestamp. This ensures that the timestamps used in time calculations are always accurate and prevents underflow errors in the BuyerAgent
contract.
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.