Santa's List

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

Documented present cost is 2e18 but buyPresent only burns 1e18 — buyers pay half price

Description

The code comments and constant declare the present price as 2e18 SantaToken ("The cost of santa tokens for naughty people to buy presents"), but SantaToken.burn hardcodes _burn(from, 1e18) — half the documented price. Every buyPresent call undercharges by 1e18: a 50% revenue leak relative to the documented pricing, on every single purchase.

Root cause

// src/SantasList.sol
// The cost of santa tokens for naughty people to buy presents
uint256 public constant PURCHASED_PRESENT_COST = 2e18;
// src/SantaToken.sol
function burn(address from) external {
if (msg.sender != i_santasList) { revert SantaToken__NotSantasList(); }
_burn(from, 1e18); // hardcoded 1e18 vs documented/constant 2e18
}

The constant PURCHASED_PRESENT_COST is never referenced anywhere — documented pricing and execution logic are disconnected.

Impact

  • Each buyPresent: buyer effectively pays 1e18 instead of the documented 2e18. Per the design intent, the protocol recovers 1e18 fewer tokens per sale.

  • If the token has a deflationary/recycling design intent (burn = destroy), the burn rate is halved vs documented, and the tokenomics diverge from the spec.

  • Not rounding: a full 2x pricing error, triggered on every purchase (Likelihood High).

Risk

Likelihood: High — this is the default execution path; every buyPresent call undercharges, no special conditions needed.

Proof of Concept

// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import {SantasList} from "../../src/SantasList.sol";
import {SantaToken} from "../../src/SantaToken.sol";
import {Test, console} from "forge-std/Test.sol";
contract SantasListCostMismatchPoC is Test {
SantasList santasList; SantaToken santaToken;
address santa = makeAddr("santa");
address user = makeAddr("user");
address buyer;
function setUp() public {
buyer = makeAddr("buyer");
vm.startPrank(santa);
santasList = new SantasList();
santaToken = SantaToken(santasList.getSantaToken());
santasList.checkList(buyer, SantasList.Status.EXTRA_NICE);
santasList.checkTwice(buyer, SantasList.Status.EXTRA_NICE);
santasList.checkList(user, SantasList.Status.EXTRA_NICE);
santasList.checkTwice(user, SantasList.Status.EXTRA_NICE);
vm.stopPrank();
vm.warp(santasList.CHRISTMAS_2023_BLOCK_TIME() + 1);
}
function testPoC_CostMismatch() public {
vm.prank(buyer); santasList.collectPresent();
vm.prank(user); santasList.collectPresent();
vm.prank(user); santaToken.transfer(buyer, 1e18);
assertEq(santaToken.balanceOf(buyer), 2e18, "buyer holds documented price");
assertEq(santasList.PURCHASED_PRESENT_COST(), 2e18, "documented cost is 2e18");
vm.prank(buyer); santasList.buyPresent(buyer); // should burn 2e18 per docs
assertEq(santaToken.balanceOf(buyer), 1e18, "only 1e18 burned, not 2e18");
assertEq(santasList.balanceOf(buyer), 2, "1 collected + 1 bought");
}
}

forge test --match-test testPoC_CostMismatch → PASS (balanceOf(buyer) == 1e18 proves only half was charged).

Recommended Mitigation

Make execution reference the documented price instead of a hardcoded literal:

function burn(address from) external {
if (msg.sender != i_santasList) { revert SantaToken__NotSantasList(); }
- _burn(from, 1e18);
+ _burn(from, 2e18); // == SantasList.PURCHASED_PRESENT_COST
}

Rationale: PURCHASED_PRESENT_COST is the price agreed by docs and code; the hardcoded 1e18 is a wrong literal. Pricing is part of the protocol's economic model and execution must match the spec. Better still: have burn take an amount parameter and pass PURCHASED_PRESENT_COST from buyPresent, eliminating the "two places each hardcode a number" disconnect permanently. Note this pairs with the buyPresent-burns-victim fix (that one fixes whose tokens burn; this one fixes how many) — both are needed to fully repair buyPresent.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 1 hour 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!