Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: high
Invalid

Use of Revert in BuyerAgent::purchase( ) function cancels previous purchases as well

Vulnerability Details

  • In the purchase() function, each asset is purchased in sequence, and the function checks if the total spending (spendings[round]) exceeds the predefined amountPerRound limit before each purchase. When this limit is exceeded due to the purchase of a specific asset, the entire transaction reverts.

  • This behavior effectively cancels all previously successful purchases made during the same transaction, leaving buyer with nothing.

  • Instead of revert, could use an error or a break.

  • code in question:

for (uint256 i = 0; i < assets.length; i++) {
address asset = assets[i];
// must not exceed the roundly buy-limit
uint256 price = swan.getListingPrice(asset);
spendings[round] += price;
---> if (spendings[round] > amountPerRound) {
---> revert BuyLimitExceeded(spendings[round], amountPerRound);
}

Impact

  • The reversion behavior results in users being unable to complete any asset purchases if a limit is reached mid-transaction, even if multiple assets were within budget prior to the limit-exceeding asset. This behavior:

  • Increases gas costs for users through failed transactions.

  • Leads to inefficiencies, as users may be unable to finalize any purchases due to a single limit violation.

Tools Used

  • Manual Review

Recommendations

  • Avoid Reverting Entire Transaction on Limit Exceedance: Instead of reverting when the spending limit is exceeded, implement a mechanism to gracefully terminate the transaction with an error message, allowing previously successful purchases to remain intact. This will enable users to retain the benefits of their purchases, even if the transaction cannot be completed in full.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.