Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

The price to buy a present in `SantasList::buyPresent` function is different from the price stated in documentation

Summary

As per protocol's documentation, SantasList::buyPresent is intended to trade2e18 of SantaToken for an NFT present.
But in the protocol's code, the function costs only 1e18 of SantaToken to buy an NFT. This would result in a loss of revenue for the protocol as well as confusion among the users.

Vulnerability Details

In the documentation of the protocol under the Collecting Presents section, the SantasList::buyPresent function is intended to cost 2e18 of SantaToken for an NFT :

buyPresent: A function that trades 2e18 of SantaToken for an NFT. This function can be called by anyone.

And while that intended cost is declared at line 88 in SantasList.sol, it's never actually used in the concerned function :

uint256 public constant PURCHASED_PRESENT_COST = 2e18;

The vulnerable SantasList::buyPresent function which doesn't make use of the PURCHASED_PRESENT_COST constant :

function buyPresent(address presentReceiver) external {
i_santaToken.burn(presentReceiver);
_mintAndIncrement();
}

Furthermore, the SantaToken::burn function isn't even programmed to accept any parameter for the NFT cost; instead a cost of 1e18 of SantaToken is hardcoded in it to execute the function :

function burn(address from) external {
if (msg.sender != i_santasList) {
revert SantaToken__NotSantasList();
}
_burn(from, 1e18);
}

All of this results in SantasList::buyPresent only costing 1e18 of SantaToken instead of 2e18 to buy an NFT present.

Impact

This vulnerability has following financial and functional consequences :

  • Due to the bug, users are able to acquire NFTs at half the intended cost, resulting in a direct financial loss for the protocol.

  • The bug creates a misalignment between the intended protocol design and the actual implementation. This inconsistency can lead to confusion among users.

  • The discrepancy between the stated cost and the actual cost can erode user trust in the protocol.

Tools Used

Manual review.

Recommendations

Make appropriate changes in both SantaToken::burn and SantasList::buyPresent functions to accept PURCHASED_PRESENT_COST constant as the NFT cost.
Note: I'm not providing exact code modifications here because of another vulnerability impacting these functions which would require further modifications to the code.

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Price is not enforced in buyPresent

This line indicates that the intended cost of presents for naughty people should be 2e18: https://github.com/Cyfrin/2023-11-Santas-List/blob/6627a6387adab89ae2ba2e82b38296723261c08a/src/SantasList.sol#L87 PURCHASE_PRESENT_COST should be implemented to enforce the cost of presents.

Support

FAQs

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