Santa's List

AI First Flight #3
Beginner FriendlyFoundry
EXP
View results
Submission Details
Severity: medium
Valid

SantaToken Burn Amount Misaligned with SantasList Purchase Cost

Root + Impact

The issue comes from the burn logic in buyPresent() not matching the intended purchase cost, because the function either calls burn incorrectly or fails to deduct the exact PRESENT_COST from the caller’s balance, leaving users with more SantaTokens than they should after minting. This misalignment lets users underpay for presents, inflates token supply, weakens the economic design of the system, and undermines fairness since some participants can obtain NFTs without spending the proper amount of tokens.

Description

The SantaToken contract hardcodes minting and burning to 1e18 tokens per call. In SantasList, the constant PURCHASED_PRESENT_COST is defined as 2e18, representing the intended cost of buying a present. However, the buyPresent() function calls i_santaToken.burn(presentReceiver) without specifying an amount, which defaults to burning only 1e18 tokens. This creates a mismatch between the documented purchase cost and the actual enforced cost.

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

Risk

Likelihood:

  • NFTs can be purchased for zero cost

Impact:

  • Breaks the economic invariant of the system, allowing underpayment for NFTs and undermining token utility.

Proof of Concept

  1. Deploy SantasList and SantaToken.

  2. Mint SantaTokens .

  3. Call buyPresent(USER1) with only 1e18 tokens in USER1’s balance.

  4. Transaction succeeds, burning 1e18 tokens and minting an NFT.

function setUp() public {
vm.startPrank(santa);
santasList = new SantasList();
santaToken = SantaToken(santasList.getSantaToken());
vm.stopPrank();
// Advance time to after CHRISTMAS_2023_BLOCK_TIME
vm.warp(1703480382); // one second after the constant
vm.startPrank(santa);
santasList.checkList(user, SantasList.Status.EXTRA_NICE);
santasList.checkTwice(user, SantasList.Status.EXTRA_NICE);
vm.stopPrank();
vm.startPrank(user);
// Collect present → mints NFT + 1e18 SantaToken
santasList.collectPresent();
vm.stopPrank();
}
function testBuyPresentAtHalfCost() public {
vm.startPrank(user);
// USER only has 1e18 SantaToken
uint256 balanceBefore = santaToken.balanceOf(user);
assertEq(balanceBefore, 1e18);
// Attempt to buy present
santasList.buyPresent(user);
// Only 1e18 burned, not 2e18
uint256 balanceAfter = santaToken.balanceOf(user);
assertEq(balanceAfter, 0, "Only 1e18 burned");
// NFT minted successfully
assertEq(santasList.balanceOf(user), 2, "User now owns 2 NFTs");
vm.stopPrank();
}

Recommended Mitigation

  • Update SantaToken.burn() to accept an amount parameter

  • Modify buyPresent() in SantasList to burn the correct cost

function burn(address from,
+ uint256 amount)
external {
if (msg.sender != i_santasList)
revert SantaToken__NotSantasList();
_burn(from, amount);
}
function buyPresent(address presentReceiver) external {
- i_santaToken.burn(presentReceiver);
+ i_santaToken.burnFrom(msg.sender, PURCHASED_PRESENT_COST);
- _mintAndIncrement();
+ _safeMint(presentReceiver, s_tokenCounter++);
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 5 hours ago
Submission Judgement Published
Validated
Assigned finding tags:

[M-01] Cost to buy NFT via SantasList::buyPresent is 2e18 SantaToken but it burns only 1e18 amount of SantaToken

## Description - The cost to buy NFT as mentioned in the docs is 2e18 via the `SantasList::buyPresent` function but in the actual implementation of buyPresent function it calls the SantaToken::burn function which doesn't take any parameter for amount and burns a fixed 1e18 amount of SantaToken, thus burning only half of the actual amount that needs to be burnt, and hence user can buy present for their friends at cheaper rates. - Along with this the user is able to buy present for themselves but the docs mentions that present can be bought only for other users. ## Vulnerability Details The vulnerability lies in the code in the function `SantasList::buyPresent` at line 173 and in `SantaToken::burn` at line 28. The function `burn` burns a fixed amount of 1e18 SantaToken whenever `buyPresent` is called but the true value of SantaToken that was expected to be burnt to mint an NFT as present is 2e18. ```cpp function buyPresent(address presentReceiver) external { @> i_santaToken.burn(presentReceiver); _mintAndIncrement(); } ``` ```cpp function burn(address from) external { if (msg.sender != i_santasList) { revert SantaToken__NotSantasList(); } @> _burn(from, 1e18); } ``` ## PoC Add the test in the file: `test/unit/SantasListTest.t.sol`. Run the test: ```cpp forge test --mt test_UsersCanBuyPresentForLessThanActualAmount ``` ```cpp function test_UsersCanBuyPresentForLessThanActualAmount() public { vm.startPrank(santa); // Santa checks user once as EXTRA_NICE santasList.checkList(user, SantasList.Status.EXTRA_NICE); // Santa checks user second time santasList.checkTwice(user, SantasList.Status.EXTRA_NICE); vm.stopPrank(); // christmas time 🌳🎁 HO-HO-HO vm.warp(santasList.CHRISTMAS_2023_BLOCK_TIME()); // user collects their present vm.prank(user); santasList.collectPresent(); // balance after collecting present uint256 userInitBalance = santaToken.balanceOf(user); // now the user holds 1e18 SantaToken assertEq(userInitBalance, 1e18); vm.prank(user); santaToken.approve(address(santasList), 1e18); vm.prank(user); // user buy present // docs mention that user should only buy present for others, but they can buy present for themselves santasList.buyPresent(user); // only 1e18 SantaToken is burnt instead of the true price (2e18) assertEq(santaToken.balanceOf(user), userInitBalance - 1e18); } ``` ## Impact - Protocol mentions that user should be able to buy NFT for 2e18 amount of SantaToken but users can buy NFT for their friends by burning only 1e18 tokens instead of 2e18, thus NFT can be bought at much cheaper rate which is half of the true amount that was expected to buy NFT. - User can buy a present for themselves but docs strictly mentions that present can be bought for someone else. ## Recommendations Include an argument inside the `SantaToken::burn` to specify the amount of token to burn and also update the `SantasList::buyPresent` function with updated parameter for `burn` function to pass correct amount of tokens to burn. - Update the `SantaToken::burn` function ```diff -function burn(address from) external { +function burn(address from, uint256 amount) external { if (msg.sender != i_santasList) { revert SantaToken__NotSantasList(); } - _burn(from, 1e18); + _burn(from, amount); } ``` - Update the `SantasList::buyPresent` function ```diff + error SantasList__ReceiverIsCaller(); function buyPresent(address presentReceiver) external { + if (msg.sender == presentReceiver) { + revert SantasList__ReceiverIsCaller(); + } - i_santaToken.burn(presentReceiver); + i_santaToken.burn(presentReceiver, PURCHASED_PRESENT_COST); _mintAndIncrement(); } ```

Support

FAQs

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

Give us feedback!