Santa's List

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

`PURCHASED_PRESENT_COST` Declared as 2e18 but `burn()` Only Consumes 1e18

F4 — PURCHASED_PRESENT_COST Declared as 2e18 but burn() Only Consumes 1e18

Scope

  • src/SantasList.sol (L88, L170–180)

  • src/SantaToken.sol (L28–33)

Description

PURCHASED_PRESENT_COST is declared as 2e18 SantaTokens, implying the cost to buy a present. However, SantaToken.burn() is a fixed-amount function that always burns exactly 1e18 tokens regardless of PURCHASED_PRESENT_COST. The constant is never read in the burn call — it is documented but not enforced.

// SantasList.sol
uint256 public constant PURCHASED_PRESENT_COST = 2e18; // declared cost
function buyPresent(address presentReceiver) external {
@> i_santaToken.burn(presentReceiver); // burns 1e18 — ignores PURCHASED_PRESENT_COST
_mintAndIncrement();
}
// SantaToken.sol
function burn(address from) external {
if (msg.sender != i_santasList) revert SantaToken__NotSantasList();
@> _burn(from, 1e18); // hardcoded 1e18 — not PURCHASED_PRESENT_COST
}

Meanwhile, collectPresent() only mints 1e18 SantaTokens to EXTRA_NICE users, meaning a legitimate user can never afford the declared 2e18 cost without exploiting the double-mint (F3).

Risk

Likelihood: Medium

  • The mismatch only matters for users attempting buyPresent() normally.

Impact: Medium

  • The PURCHASED_PRESENT_COST constant is misleading documentation — actual cost is half the declared value.

  • Users accumulating tokens for buyPresent() would find the purchase possible with 1e18 (not 2e18).

Severity: Medium

Proof of Concept

Alice mints 1e18 SantaToken via collectPresent(). The declared cost is 2e18, but buyPresent() only burns 1e18.

function test_Bonus_TokenCostMismatch() public {
uint256 cost = santasList.PURCHASED_PRESENT_COST();
assertEq(cost, 2e18); // declared cost: 2e18
// Alice earns SantaToken
// ... (setup)
uint256 aliceTokens = santaToken.balanceOf(alice);
assertEq(aliceTokens, 1e18); // minted: 1e18
// burn() only takes 1e18 despite PURCHASED_PRESENT_COST = 2e18
}
// [PASS] test_Bonus_TokenCostMismatch() (gas: ~174k)

Recommended Mitigation

Align the burn amount with the declared constant (or vice versa). If 2e18 is the intended cost, pass the constant to _burn:

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

Or alternatively, lower the cost declaration to match the burn amount:

-uint256 public constant PURCHASED_PRESENT_COST = 2e18;
+uint256 public constant PURCHASED_PRESENT_COST = 1e18;

Updates

Lead Judging Commences

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