The withdraw()
function in the Staking contract don't have a check that ensures the contract has sufficient tokens to distribute before transferring tokens to a user. This could potentially lead to a failed transaction if the contract's token balance is insufficient to fulfill a user's withdrawal request.
The vulnerability arises from the lack of a balance check in the withdraw()
function of the Staking.sol
contract. When a user calls the withdraw()
function to remove their stake, the contract deducts the withdrawal amount from the user's balance and attempts to transfer the corresponding amount of tokens to the user. However, the contract does not check if it has enough tokens to fulfill the withdrawal request before initiating the transfer.
In the case of an insufficient contract balance, the execution of the withdraw()
function could result in a failed transaction. This could disrupt the normal functioning of the staking protocol and could potentially lock user funds. This presents a considerable usability and functional risk to the contract.
Manual Code Analysis
To mitigate this potential vulnerability, it is recommended to include a check that ensures the contract has a sufficient token balance before initiating a transfer. This could look something like this:
This addition ensures that the contract has enough tokens to fulfill the withdrawal request. If the contract balance is insufficient, the transaction will fail with an "Insufficient contract balance" error, which alerts users to the issue in a clear manner.
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.