Submitted by kirk-baird, also found by leastwood
https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/mainnet/CommunityPool.sol#L82-L112
https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/mainnet/MessageProxyForMainnet.sol#L235-L250
The function refundGasByUser() can be exploited by the message sender to drain nodes and SChain owners of their balances when processing incoming messages.
When a node collates a set of exits from an SChain to Ethereum, they are submitted on-chain via MessageProxyForMainnet.sol.  For each message to a registered contract the user is required to pay for the refund via CommunityPool.refundGasByUser().
The issue occurs in CommunityPool.refundGasByUser()  as the amount to be refunded is calculated as uint amount = tx.gasprice * gas;, where gas is the gas used by the message. Since tx.gasprice is set by the node and there is no upper bounds on the price. Since EIP1559 the gas price is BaseFee + Tip and although Base is predetermined Tip is any arbitrary non-zero integer.
The attack is for a node to set an excessively high tx.gasprice which will be refunded out of the balance of the user who initiated the outgoing transaction or if that user has insufficient balance then from the SChain owner.  Since the node submitting the transaction is refunded for their gas they do not lose from setting a higher gas price.
The impact of the attack is that the user requesting the exit and/or the SChain owner may have their ETH balances depleted to refund the submitter. The impact is worsened as if the user has insufficient balance a message will be sent to the SChain preventing them from making further exits until they have sufficient balance.
Note a similar issue may be seen in IWallets.refundGasBySchain() depending on how the gas calculations are performed (they are not in scope but the TestWallet also uses tx.gasprice in the same manner).
Processing incoming messages in MessageProxyForMainnet.sol
Refunding gas in CommunityPool.sol
One solution to avoid excessive over refunding of gas fees is to use a gas price oracle rather than tx.gasprice.
An alternate solution is to set a maximum gas price and have some incentives for the node submitting at a gas price below the maximum.
cstrangedk (SKALE) resolved:
