The Rock Paper Scissors contract calculates protocol fees using integer division that rounds down, potentially allowing players to bypass fee payment entirely for small bet amounts. This can lead to reduced revenue collection for the protocol and could be intentionally exploited through strategic betting amounts.
The vulnerability exists in the fee calculation mechanism within the _finishGame
and _handleTie
functions:
Due to Solidity's integer division behavior, when (totalPot * PROTOCOL_FEE_PERCENT)
is less than 100, the result will round down to zero. With PROTOCOL_FEE_PERCENT
set to 10, this means that any total pot less than 10 wei will result in zero fees being collected.
For example:
With a bet of 4 wei, the total pot is 8 wei
Fee calculation: (8 * 10) / 100 = 0
(rounded down from 0.8)
No fees are collected despite the game being played
This vulnerability has several negative impacts:
Loss of Protocol Revenue: Small-bet games will generate no fees at all, reducing overall protocol revenue.
Exploitation Potential: Players could intentionally choose small bet amounts to avoid paying fees while still using the protocol functionality.
Economic Inefficiency: The fee structure becomes regressive, charging proportionally less for smaller games than larger ones.
While the minimum bet is set at 0.01 ether (which is large enough that fees will be collected), the contract lacks proper validation that could prevent players from bypassing this minimum in certain scenarios.
Manual code review and analysis of the integer division behavior in Solidity.
To address this vulnerability, I recommend the following solutions:
Use Fixed-Point Arithmetic: Implement a more precise calculation method:
By implementing these changes, the protocol will ensure consistent fee collection regardless of bet size, maintaining a fair economic model for all participants.
The tie-handling logic loses one wei due to integer division
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.