In the PriorityPool
contract, there is an inefficient and potentially user-unfriendly behavior in the deposit function and its internal _deposit
function.
When a user attempts to deposit tokens without queuing (_shouldQueue
is false
), and the system cannot process the entire deposit immediately, the remaining tokens are transferred back to the user instead of reverting the transaction.
This can lead to unnecessary gas expenditure for the user, as they pay gas fees for transferring tokens to the contract and then back to themselves, without achieving the intended deposit. It is because the contract does not perform a preliminary check to determine if the deposit can be fully processed, and it lacks an option to revert the transaction when the deposit cannot be completed as desired.
The user calls the deposit
function with the desired _amount
, a boolean _shouldQueue
indicating whether to queue the deposit if it cannot be processed immediately, and _data
for additional parameters;
And here is the _deposit
function logic;
The _deposit
function starts by checking if the pool status is open.
It initializes toDeposit
with the _amount
.
If there are no queued deposits (totalQueued == 0
), it checks for any queued withdrawals. (L:611)
If there are queued withdrawals, it deposits tokens into the withdrawal pool and transfers staking tokens back to the user. (L:613)
The amount deposited into the withdrawal pool is up to the amount of queued withdrawals.
Depositing into the Staking Pool:
If there is still toDeposit
remaining, it attempts to deposit into the staking pool. (L:622)
It checks how much the staking pool can accept (canDeposit
).
It deposits as much as possible into the staking pool and reduces toDeposit.
Handling Remaining toDeposit
:
If there is still toDeposit remaining after attempting to deposit into the withdrawal and staking pools:
And If _shouldQueue is false
(our case), it transfers the remaining tokens back to the user (line 642).
So it´s possible that totalQueued != 0
(skips L:611) , _shouldQueue
is false
(Skip L:633) and the user lands on L:642 again receiving back their own tokens without any state changes.
Please be aware that this can easily occur organically especially at high peak times.
And since the users approve the contract for the funds being pulled from them (L:256) that would also cost another gas wastage assuming they approved only the _amount
.
Unnecessary gas costs due to redundant token transfers
Manual Review
Create a function that allows users to check if their deposit can be fully processed before initiating the transfer.
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.