Loss Fee does not get added due to wrong calculation
Summary
When the ROLE_KEEPER executes a transaction, we check if the execution_fee is sufficient to cover the transaction cost. If any amount remains, it is refunded to the user, and if the fee is insufficient, the excess amount is added to the loss amount. However, in the event of a loss, the loss amount is not correctly calculated and therefore not added due to an error in the calculation
Vulnerability Detail
Whenever user submit a request for any operation we charge executionFee in advance . The ROLE_KEPPER will submit the request operation and will charge the exectuion_fee. Here one pf the following 2 cases can occur.
The execution Fee was sufficient and the remaining amount sent back to users.
The executionFee was insufficient and loss added to Protocol.
In 2nd case there is an Issue due to which the Loss will never be added.
From above code We can observed that when executionFee>cache.userExecutionFee then we first assign executionFee = cache.userExecutionFee and then calculate LossFee , So LossFee will always be zero.
executionFee = 10 gwei;
cache.userExecutionFee = 9 gwei;
// we first assign
executionFee = cache.userExecutionFee; // so Here executionFee = 9 gwei
lossFee = executionFee - cache.userExecutionFee;// 9 gwei - 9 gwei =0
if (lossFee > 0) { // here lossFee=0 so it will not be added
CommonData.addLossExecutionFee(lossFee);
}
Impact
processExecutionFee will never added any loss occur.
aman
High
Loss Fee does not get added due to wrong calculation
Summary
When the
ROLE_KEEPER
executes a transaction, we check if the execution_fee is sufficient to cover the transaction cost. If any amount remains, it is refunded to the user, and if the fee is insufficient, the excess amount is added to the loss amount. However, in the event of a loss, the loss amount is not correctly calculated and therefore not added due to an error in the calculationVulnerability Detail
Whenever user submit a request for any operation we charge
executionFee
in advance . TheROLE_KEPPER
will submit the request operation and will charge theexectuion_fee
. Here one pf the following 2 cases can occur.The executionFee was insufficient and loss added to Protocol. In 2nd case there is an Issue due to which the Loss will never be added.
From above code We can observed that when
executionFee>cache.userExecutionFee
then we first assignexecutionFee = cache.userExecutionFee
and then calculateLossFee
, SoLossFee
will always be zero.Impact
processExecutionFee
will never added any loss occur.Code Snippet
https://github.com/sherlock-audit/2024-05-elfi-protocol/blob/main/elfi-perp-contracts/contracts/process/GasProcess.sol#L22-L25
Tool used
Manual Review
Recommendation
Duplicate of #108