TwentyOne::playersHand
& TwnetyOne::dealersHand
calculates the total value of player and dealer hands respectively. However in these two functions for
loop has been used, which results in HIGH GAS cost, since it has to iterate through all the players. And as the number of players increases, iteration will increase which will result in HIGHER GAS.TwentyOne::playersHand
using for
loop:
TwentyOne::dealersHand
using for
loop:
Test demonstrating vulnerability:
Running these test functions will show the HIGH GAS output.
As the number of cards in the player's hand increases, iteration in for
loop increases and consumes more gas, resulting in the following impact:
High Gas fees, creating a barrier to entry, for new users.
Transactions could approach or exceed the block gas limit, creating a DoS situation, where users cannot complete their game or claim their winnings.
Manual Testing, Foundry
Use of a mapping-based approach or precomputed totals instead of iterating through arrays in TwentyOne::playersHand
& TwentyOne::dealersHand
Impose a limit on the number of cards a player can hold to prevent excessive iterations or HIGH GAS usage scenarios.
First, optimize TwentyOne::playersHand
function:
Then, add new logic for Precomputing Totals by updating addCardForPlayer, maintaining a running total in precomputedTotals:
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.