Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

function _burn() / buyPresent() causes arithmetic underflow_

Summary

buyPresent() function is used to trade tokens with NFTs.

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

i_santaToken.burn(presentReceiver) function is used to burn the SantaToken and _mintAndIncrement()is used to mint an NFT.

Vulnerability Details

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

There is no logic in the burn function to prevent the user to check if the balance is less than the required amount of 1e18 SantaToken.

Impact

So even the balance is less than 1e18 the function goes through and causes arithmetic underflow.

function testNCTBuyPresentCausesArithmeticUnderFlow() public {
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);
vm.startPrank(user);
vm.expectRevert();
santasList.buyPresent(user);
vm.stopPrank();
}

Tools Used

  • foundry

  • manual code review

Recommendations

A balance check is required before calling the buyPresent() function to avoid arithmetic underflow

Updates

Lead Judging Commences

inallhonesty Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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