Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Valid

The battlesWon property of Nft metadata of the winning rapper in a rap battle is never updated

Summary

The battlesWon property of Nft metadata of the winning rapper in a rap battle is never updated.

Vulnerability Details

After winning a rap battle, it is expected that the rapper NFT's battlesWon metadata property is incremented by 1. However, this detail was missed in the protocol code.

Proof of Concept

Put the following function in the test contract of your Foundry test file:

function testBattlesWonPropertyIsNeverIncremented() public {
// setup phase
address defender = makeAddr("defender");
address challenger = makeAddr("challenger");
// both the challenger and the defender get a rapper Nft minted to them, and stake it to gain some credibility tokens
vm.startPrank(defender);
oneShot.mintRapper();
oneShot.approve(address(streets), 0);
streets.stake(0);
vm.stopPrank();
vm.startPrank(challenger);
oneShot.mintRapper();
oneShot.approve(address(streets), 1);
streets.stake(1);
vm.stopPrank();
vm.warp(4 days + 1);
vm.prank(defender);
streets.unstake(0);
vm.prank(challenger);
streets.unstake(1);
// defender enters the rap battle
vm.startPrank(defender);
oneShot.approve(address(rapBattle), 0);
cred.approve(address(rapBattle), 1);
rapBattle.goOnStageOrBattle(0, 1);
vm.stopPrank();
// challenger enters the rap battle
vm.startPrank(challenger);
oneShot.approve(address(rapBattle), 1);
cred.approve(address(rapBattle), 1);
rapBattle.goOnStageOrBattle(1, 1);
vm.stopPrank();
uint256 defenderBattleswon = oneShot.getRapperStats(0).battlesWon;
uint256 challengerBattleswon = oneShot.getRapperStats(1).battlesWon;
console.log(defenderBattleswon, challengerBattleswon);
assertEq(defenderBattleswon, 0); // not updated
assertEq(challengerBattleswon, 0); // not updated
}

The test passes:

[PASS] testBattlesWonPropertyIsNeverIncremented() (gas: 638762)
Logs:
0 0

Impact

Rapper tokenIds with higher number of battles won should be more collectible and reputable. It also helps users keep track of the number of battles they have won. Invalid/stale Nft metadata is not desirable as well.

Tools Used

Foundry, VSCodium.

Recommendations

In OneShot contract, first allow the RapBattle contract to update the Nft metadata. Then, in RapBattle::_battle function, update the battlesWon property of the winner by calling OneShot::updateRapperStats function.

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`battlesWon` is never updated

Support

FAQs

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