Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Valid

Division Precision Issue in (_handleTie) Function

Summary

A precision loss vulnerability exists in the _handleTie function due to improper handling of integer division in Solidity. Specifically, when refunding ETH to players after a draw, the contract performs a division that may result in a remainder. This leads to permanent loss (or lock-up) of funds within the contract and disrupts financial accuracy

Vulnerability Details

Solidity performs integer division with truncation toward zero. If (totalPot - fee) is an odd number, 1 wei will remain unallocated, leading to:

Example:

  • totalPot = 101 weifee = 10 wei (10%)

  • 101 - 10 = 91 wei91 / 2 = 45 wei (per player)

  • Result: Players get 90 wei total (1 wei locked forever)

uint256 refundPerPlayer = (totalPot - fee) / 2;

Impact

  • permanent loss of funds

Tools Used

manual, foundry

Recommendations

Update the refund logic to handle division remainders:

This ensures all wei are accounted for, and no ETH is unintentionally trapped.

uint256 netAmount = totalPot - fee;
uint256 remainder = netAmount % 2;
uint256 refundPerPlayer = (netAmount - remainder) / 2;
accumulatedFees += remainder; // Optionally emit event for traceability
Updates

Appeal created

m3dython Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Rounding Error

The tie-handling logic loses one wei due to integer division

m3dython Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Rounding Error

The tie-handling logic loses one wei due to integer division

Support

FAQs

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