The StakingPool contract distributes fees to recipients in a loop using the transferAndCallFrom function. This process works efficiently when recipients are standard addresses, but introduces significant vulnerabilities when a recipient is a smart contract. Specifically:
If a smart contract recipient does not implement the onTokenTransfer function, the transaction will fail.
Even if the onTokenTransfer function is implemented, it can contain malicious or faulty logic, causing the transaction to revert.
If the recipient is an upgradeable contract, future modifications can introduce errors or malicious behavior, leading to failure in fee distribution.
The transferAndCallFrom function, used to send fees in the loop, calls contractFallback if the recipient is a smart contract:
If the recipient is a contract, contractFallback is called, which invokes the onTokenTransfer function in the recipient contract:
_updateStrategyRewards:The fee distribution is performed in a loop. If any recipient's contract fails, the entire process reverts, causing no recipient to receive their fee.
onTokenTransferIf a smart contract does not implement the onTokenTransfer function, the contractFallback call will fail, reverting the entire transaction. This leads to the failure of fee distribution to all recipients.
onTokenTransferEven if the onTokenTransfer function is implemented, there is no guarantee that it is safe. Malicious or faulty code within this function could intentionally revert the transaction or introduce gas limits, causing the entire fee distribution process to fail.
Upgradeable contracts introduce additional risk. Even if the onTokenTransfer function is properly implemented at the time of integration, the contract owner can later upgrade the contract and either remove the onTokenTransfer function or introduce malicious logic. This can cause the entire fee distribution to fail when interacting with the updated contract.
If any smart contract recipient causes a failure (either by missing the onTokenTransfer function or having a faulty implementation), the entire fee distribution process for all recipients will revert. This means that even valid recipients will not receive their fees.
Manually
Implementing a mechanism like try-catch can help manage unexpected failures. this will ensure that even if one contract causes an error, the rest of the recipients will still receive their fees.
It should be called with try and catch to avoid DOS by receiver.
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.