BuyerAgent.purchase
function in the BuyerAgent
contract has a low-severity vulnerability due to the presence of external calls inside a loop. Specifically, the swan.getListingPrice(asset)
function is called within a loop that iterates over an array of assets.An attacker can exploit this vulnerability by manipulating the assets
array to include assets that have a high likelihood of causing the swan.getListingPrice(asset)
function to fail or revert. This could lead to a denial-of-service (DoS) attack, where the BuyerAgent
contract is unable to complete its intended function.
An attacker manipulates the assets
array to include assets that have a high likelihood of causing the swan.getListingPrice(asset)
function to fail or revert.
The BuyerAgent
contract attempts to execute the loop, but the swan.getListingPrice(asset)
function fails or reverts, causing the loop to fail.
The attacker repeats the attack, causing the BuyerAgent
contract to become unavailable due to repeated failures.
In this example, the Attacker
contract manipulates the assets
array to include assets that have a high likelihood of causing the swan.getListingPrice(asset)
function to fail or revert. The Attacker
contract then calls the buyerAgent.purchase
function with the manipulated assets
array, which causes the swan.getListingPrice(asset)
function to fail or revert, leading to a denial-of-service (DoS) attack.
This proof of concept code demonstrates the vulnerability and shows how an attacker can exploit it to cause the BuyerAgent
contract to become unavailable.
BuyerAgent.sol
: purchase
function (lines 222-256)Swan.sol
: getListingPrice
function (lines 258-272)
Use try-catch blocks: Use try-catch blocks to handle external calls within loops, in order to ensure the robustness and reliability of the contract.
Implement input validation: Implement input validation to ensure that the assets
array is valid and not under the control of an attacker.
Implement access control: Implement access control to ensure that only authorized addresses can call the BuyerAgent
contract.
By taking these precautions, you can prevent an attacker from exploiting this vulnerability and ensure the reliability and robustness of the BuyerAgent
contract.
Code Fix:
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.