Users are able to battle with 0 risk by not setting an allowance, or by not having enough funds to pay out a loss.
When attempting a battle, neither RapBattle:goOnStageOrBattle()
or RapBattle:_battle()
verify that the user has: a) has set an allowance, and b) has the erc20 tokens needed to cover the battles bet. This allows users to battle for 0 risk by just not setting an allowance (or by simply not having the funds). This only applies when battling as a challenger, as when becoming a defender funds are always transferred into the contract, whereas when challenging, the funds are directly transferred from the challenger to the defender if the challenger loses.
If a user challenges a defender without setting an allowance or without having the funds, there are two potential scenarios:
If the challenger wins, the funds are transferred from the contract to the challenger and the defender is dethroned.
If the defender wins, the transaction fails due to the contract trying to transfer funds directly from the challenger to the defender.
This can be verified by adding the following two tests to the test suite:
This allows users to battle completely risk free when a defender is on the stage, as if the challenger where to lose the battle, the transaction would simply revert.
Manual review
Foundry test suite
I recommend adding the following two validation checks to the top of the RapBattle:goOnStageOrBattle()
method, these checks ensure the user has set up a allowance with greater then or equal to their bet, and it verifies the user has the funds to pay out that bet if they lose:
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.