The claimThrone
function contains logic to distribute the incoming msg.value
between the contract's pot
and the platformFeesBalance
. This logic includes a "defensive" if
statement intended to prevent the platform fee from exceeding the available amount.
However, due to the surrounding logic, this if
statement is unreachable. The check if (currentPlatformFee > (sentAmount - previousKingPayout))
can never evaluate to true because previousKingPayout
is hardcoded to 0
(because it is never calculated as previously presented in another finding) and currentPlatformFee
(calculated as a percentage of sentAmount
) can never be greater than sentAmount
. This dead code makes the function confusing and indicates a potential misunderstanding of the intended fee distribution mechanism.
Likelihood: High
This logical flaw is present in every single call to claimThrone
.
Impact: Low
This issue does not lead to a direct loss or theft of funds. The fee distribution works, but not for the reasons the code suggests.
The presence of dead, unreachable code makes the contract harder to read, maintain, and audit, and it could mask the true intent of the fee logic.
This issue can be demonstrated by analyzing the variables and the condition itself:
The Condition: For the if
block to execute, the condition currentPlatformFee > (sentAmount - previousKingPayout)
must be true.
Simplifying the Condition: Since previousKingPayout
is hardcoded to 0
, the condition simplifies to currentPlatformFee > sentAmount
.
The Mathematical Impossibility: We can now substitute the calculation for currentPlatformFee
into the simplified condition:
(sentAmount * platformFeePercentage) / 100 > sentAmount
This inequality can never be true. The platformFeePercentage
is logically capped at 100.
If platformFeePercentage
is 100, the expression becomes sentAmount > sentAmount
, which is false.
If platformFeePercentage
is less than 100, the expression is (a fraction of sentAmount) > sentAmount
, which is also always false.
Since currentPlatformFee
can at most be equal to sentAmount
but never greater, the condition is impossible to satisfy, proving the if
block is unreachable dead code.
The easiest way to fix this issue is to implement the previous king payout functionality, as shown in a previous finding.
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.