Dria

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

Unnecessary allowance check in request function due to pre-approved maximum in BuyerAgent contract

Summary

In the BuyerAgent contract, the request function unnecessarily checks the token allowance even though it is already pre-approved with the maximum value during contract deployment. This check causes redundancy, as the approve function has already set the allowance to its maximum.

Vulnerability Details

The request function checks the allowance of the BuyerAgent contract using the feeToken.allowance() function, expecting it to be greater than or equal to the required totalFee. However, in the constructor, the allowance has already been approved with the maximum uint256 value (type(uint256).max), making this check redundant and unnecessary. This could confuse future audits and maintainers, as it introduces an unnecessary condition.

https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L142-L143
https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/llm/LLMOracleCoordinator.sol#L159-L162

Impact

This redundancy does not introduce a direct security vulnerability but adds unnecessary checks, which can increase transaction complexity, gas usage, and confusion in the contract logic.

Tools Used

Recommendations

  • Remove the unnecessary allowance check in the request function as the contract already ensures maximum approval during deployment.

- uint256 allowance = feeToken.allowance(msg.sender, address(this));
- if (allowance < totalfee) {
- revert InsufficientFees(allowance, totalfee);
- }
  • Optionally, include a comment in the constructor clarifying that the approve function has set the maximum allowance to avoid future confusion.

This cleanup will make the contract logic more efficient and easier to maintain.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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