Santa's List

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

`buyPresent()` lets any caller burn another user’s SantaTokens and mint the present NFT for themselves

Root: buyPresent() burns SantaToken from presentReceiver and mints the NFT to msg.sender, with no requirement that the caller pays with their own tokens or is otherwise eligible. Impact: any caller can destroy another user’s SantaToken balance and receive present NFTs for themselves.

Description

  • The intended behavior of buyPresent() is that a user with sufficient SantaToken balance should be able to spend tokens to buy a present. In a correct purchase flow, the payer should bear the token cost, and the resulting present should be distributed according to the function’s intended semantics.

  • Instead, the implementation burns tokens from presentReceiver, while minting the NFT to msg.sender. This completely breaks the payment flow: the caller does not need to own or spend any SantaToken, and can freely target another user’s token balance. As long as a victim address holds enough SantaToken, any attacker can call buyPresent(victim) to destroy the victim’s tokens and mint an NFT for themselves.

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

The issue is amplified by the fact that _mintAndIncrement() always mints to msg.sender:

function _mintAndIncrement() private {
@> _safeMint(msg.sender, s_tokenCounter++);
}

As a result, the function combines two vulnerabilities in a single broken flow:

  1. arbitrary third-party token burn,

  2. unauthorized NFT minting for the attacker.

Risk

Likelihood:

  • Any user can invoke buyPresent() directly without holding SantaTokens themselves.

  • The exploit succeeds whenever another address holds at least 1e18 SantaToken, which is obtainable by any EXTRA_NICE recipient through the normal claim flow.

Impact:

  • Attackers can forcibly destroy SantaToken balances belonging to other users.

  • Attackers can mint present NFTs for themselves without paying with their own tokens and without needing to be approved through the intended gift-eligibility flow.

Proof of Concept

Add to storage: address attacker = makeAddr("attacker");

function test_AttackerCanBurnVictimTokensAndMintPresentForSelf() public {
// Santa approves user as EXTRA_NICE so user can receive SantaToken
vm.startPrank(santa);
santasList.checkList(user, SantasList.Status.EXTRA_NICE);
santasList.checkTwice(user, SantasList.Status.EXTRA_NICE);
vm.stopPrank();
vm.warp(santasList.CHRISTMAS_2023_BLOCK_TIME() + 1);
// User claims and receives NFT + 1e18 SantaToken
vm.prank(user);
santasList.collectPresent();
assertEq(santaToken.balanceOf(user), 1e18);
assertEq(santasList.balanceOf(attacker), 0);
assertEq(santaToken.balanceOf(attacker), 0);
uint256 victimTokenBalanceBefore = santaToken.balanceOf(user);
uint256 attackerNftBalanceBefore = santasList.balanceOf(attacker);
// Attacker burns victim tokens and receives the NFT
vm.prank(attacker);
santasList.buyPresent(user);
uint256 victimTokenBalanceAfter = santaToken.balanceOf(user);
uint256 attackerNftBalanceAfter = santasList.balanceOf(attacker);
assertEq(victimTokenBalanceBefore - victimTokenBalanceAfter, 1e18);
assertEq(attackerNftBalanceAfter - attackerNftBalanceBefore, 1);
assertEq(santasList.ownerOf(1), attacker);
}

Recommended Mitigation

Burn tokens from the caller, not from an arbitrary third party, and mint the purchased present according to the intended recipient logic.

function buyPresent(address presentReceiver) external {
- i_santaToken.burn(presentReceiver);
- _mintAndIncrement();
+ i_santaToken.burn(msg.sender);
+ _safeMint(presentReceiver, s_tokenCounter++);
}

Additionally, if the intended cost is PURCHASED_PRESENT_COST, the burn path should enforce that exact amount instead of hardcoding 1e18.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 4 days ago
Submission Judgement Published
Validated
Assigned finding tags:

[H-03] SantasList::buyPresent burns token from presentReceiver instead of caller and also sends present to caller instead of presentReceiver.

## Description The `buyPresent` function sends the present to the `caller` of the function but burns token from `presentReceiver` but the correct method should be the opposite of it. Due to this implementation of the function, malicious caller can mint NFT by burning the balance of other users by passing any arbitrary address for the `presentReceiver` field and tokens will be deducted from the `presentReceiver` and NFT will be minted to the malicious caller. Also, the NatSpec mentions that one has to approve `SantasList` contract to burn their tokens but it is not required and even without approving the funds can be burnt which means that the attacker can burn the balance of everyone and mint a large number of NFT for themselves. `buyPresent` function should send the present (NFT) to the `presentReceiver` and should burn the SantaToken from the caller i.e. `msg.sender`. ## Vulnerability Details The vulnerability lies inside the SantasList contract inside the `buyPresent` function starting from line 172. The buyPresent function takes in `presentReceiver` as an argument and burns the balance from `presentReceiver` instead of the caller i.e. `msg.sender`, as a result of which an attacker can specify any address for the `presentReceiver` that has approved or not approved the SantasToken (it doesn't matter whether they have approved token or not) to be spent by the SantasList contract, and as they are the caller of the function, they will get the NFT while burning the SantasToken balance of the address specified in `presentReceiver`. This vulnerability occurs due to wrong implementation of the buyPresent function instead of minting NFT to presentReceiver it is minted to caller as well as the tokens are burnt from presentReceiver instead of burning them from `msg.sender`. Also, the NatSpec mentions that one has to approve `SantasList` contract to burn their tokens but it is not required and even without approving the funds can be burnt which means that the attacker can burn the balance of everyone and mint a large number of NFT for themselves. ```cpp /* * @notice Buy a present for someone else. This should only be callable by anyone with SantaTokens. * @dev You'll first need to approve the SantasList contract to spend your SantaTokens. */ function buyPresent(address presentReceiver) external { @> i_santaToken.burn(presentReceiver); @> _mintAndIncrement(); } ``` ## PoC Add the test in the file: `test/unit/SantasListTest.t.sol` Run the test: ```cpp forge test --mt test_AttackerCanMintNft_ByBurningTokensOfOtherUsers ``` ```cpp function test_AttackerCanMintNft_ByBurningTokensOfOtherUsers() public { // address of the attacker address attacker = makeAddr("attacker"); 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 NFT and tokens for being EXTRA_NICE vm.prank(user); santasList.collectPresent(); assertEq(santaToken.balanceOf(user), 1e18); uint256 attackerInitNftBalance = santasList.balanceOf(attacker); // attacker get themselves the present by passing presentReceiver as user and burns user's SantaToken vm.prank(attacker); santasList.buyPresent(user); // user balance is decremented assertEq(santaToken.balanceOf(user), 0); assertEq(santasList.balanceOf(attacker), attackerInitNftBalance + 1); } ``` ## Impact - Due to the wrong implementation of function, an attacker can mint NFT by burning the SantaToken of other users by passing their address for the `presentReceiver` argument. The protocol assumes that user has to approve the SantasList in order to burn token on their behalf but it will be burnt even though they didn't approve it to `SantasList` contract, because directly `_burn` function is called directly by the `burn` function and both of them don't check for approval. - Attacker can burn the balance of everyone and mint a large number of NFT for themselves. ## Recommendations - Burn the SantaToken from the caller i.e., `msg.sender` - Mint NFT to the `presentReceiver` ```diff + function _mintAndIncrementToUser(address user) private { + _safeMint(user, s_tokenCounter++); + } function buyPresent(address presentReceiver) external { - i_santaToken.burn(presentReceiver); - _mintAndIncrement(); + i_santaToken.burn(msg.sender); + _mintAndIncrementToUser(presentReceiver); } ``` By applying this recommendation, there is no need to worry about the approvals and the vulnerability - 'tokens can be burnt even though users don't approve' will have zero impact as the tokens are now burnt from the caller. Therefore, an attacker can't burn others token.

Support

FAQs

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

Give us feedback!