The purchase function in Swan.sol implements a non-atomic two-step transfer pattern where assets flow through the protocol before reaching the buyer. Combined with premature status updates and delayed payment processing, this creates scenarios where assets can be locked, payments can fail after transfers, and the protocol temporarily takes custody of assets against the P2P trading principle.
The core issue lies in the sequence of operations in the purchase function: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/Swan.sol#L276-L299
The transfers should be atomic, but the current implementation uses a two-step transfer process where the asset first moves to Swan contract then to the buyer.
Why It's Happening:
The contract implements a double transfer pattern to avoid requiring multiple approvals
However, this creates a state where the asset is temporarily held by the Swan contract
The specification rule fails because there's a moment where the transfer is "active" but not complete
For the following reasons,
Premature Status Update:
The listing is marked as sold before ensuring the transfers succeed
If transfers fail, the listing remains in "Sold" state but ownership hasn't changed
This could permanently lock assets in an invalid state
Non-atomic Transfer Pattern:
Creates a temporary state where the protocol holds the asset
Violates the direct P2P trading principle
Introduces unnecessary custody risk
Creates potential for front-running between transfers
Payment Sequencing:
Payment processing after asset transfer creates risk
If payment fails, asset ownership has already changed
No mechanism to revert the asset transfer if payment fails
Assets can be permanently locked in "Sold" state if transfers fail
Protocol temporarily holds assets, violating P2P trading principles
Failed payments after successful transfers create unrecoverable states
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.