Beginner FriendlyFoundryGameFi
100 EXP
View results
Submission Details
Severity: high
Valid

Absence of check allows to modify token count in `MartenitsaToken`

Summary

Absence of check allows to modify token count in MartenitsaToken

Vulnerability Details

The function MartenitsaToken::updateCountMartenitsaTokensOwner updates the amount of tokens an user has:

function updateCountMartenitsaTokensOwner(
address owner,
string memory operation
) external {
//Q el encodepacked perjudica?
if (
keccak256(abi.encodePacked(operation)) ==
keccak256(abi.encodePacked("add"))
) {
countMartenitsaTokensOwner[owner] += 1;
} else if (
keccak256(abi.encodePacked(operation)) ==
keccak256(abi.encodePacked("sub"))
) {
countMartenitsaTokensOwner[owner] -= 1;
} else {
revert("Wrong operation");
}
}

However, because the function is external and has no checks for ownership, anyone could modify the count of tokens of other person or itself.

Impact

Allows to grief and modify the token count for the attacker´s benefit

Tools Used

Foundry, Manual review

PoC:

function testUpdateCountAttack() public createMartenitsa {
vm.prank(jack);
martenitsaToken.updateCountMartenitsaTokensOwner(chasy, "add");
assert(martenitsaToken.getCountMartenitsaTokensOwner(chasy) == 2);
}

Recommendations

Add a line that checks if the address that sends the call is allowed to modify the token count

Updates

Lead Judging Commences

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

Missing access control

Support

FAQs

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