DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Rewards are always 0 in likeUser function

Summary

No reward computed / no fee computed.

Vulnerability Details

userBalance is not updated in the likeUser function

Impact

No reward and no fee computed then the whole reward system is broken.

Tools Used

Test: i'v added an event MatchRewardCalculated(uint256 totalRewards, uint256 matchingFees, uint256 rewards); in the contract and added here:

function matchRewards(address from, address to) internal {
uint256 matchUserOne = userBalances[from];
uint256 matchUserTwo = userBalances[to];
userBalances[from] = 0;
userBalances[to] = 0;
uint256 totalRewards = matchUserOne + matchUserTwo;
uint256 matchingFees = (totalRewards * FIXEDFEE) / 100;
uint256 rewards = totalRewards - matchingFees;
totalFees += matchingFees;
emit MatchRewardCalculated(totalRewards, matchingFees, rewards);
MultiSigWallet multiSigWallet = new MultiSigWallet(from, to);
(bool success,) = payable(address(multiSigWallet)).call{value: rewards}("");
require(success, "Transfer failed");
}

The below test does not passed.

function testForRewards() public {
vm.prank(user);
soulboundNFT.mintProfile("Alice", 25, "ipfs://profileImage");
vm.prank(user2);
soulboundNFT.mintProfile("Bob", 30, "ipfs://profileImage");
LikeRegistry likeRegistry = new LikeRegistry(address(soulboundNFT));
vm.deal(user,2 ether);
vm.prank(user);
likeRegistry.likeUser{value: 1 ether}(user2);
vm.deal(user2,2 ether);
vm.prank(user2);
likeRegistry.likeUser{value: 1 ether}(user);
uint256 balanceUser1 = likeRegistry.userBalances(user);
uint256 balanceUser2 = likeRegistry.userBalances(user2);
assertEq(balanceUser1, 0, "userBalances for user1 should be zero after match");
assertEq(balanceUser2, 0, "userBalances for user2 should be zero after match");
uint256 totalFees = likeRegistry.getTotalFees();
assertEq(totalFees, 0.2 ether, "totalFees should be 0.2 ether after match");
}

The error : │ ├─ emit MatchRewardCalculated(totalRewards: 0, matchingFees: 0, rewards: 0)

Recommendations

Need to update userBalances[msg.sender]+= msg.sender accordingly in likeUser function otherwiase the rewards calculation will always use zero values.

Updates

Appeal created

n0kto Lead Judge 5 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_likeUser_no_userBalances_updated

Likelihood: High, always. Impact: High, loss of funds

Support

FAQs

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