Protocol doesn’t handle fee on transfer tokens
The protocol's sendToCosmos function credits the full amount sent by the user, even if the token charges a transfer fee, so the contract's balance increases by less than the credited amount. An attacker could exploit this to drain other users' funds by repeatedly depositing and withdrawing with a fee-on-transfer token.
Submitted by wuwe1, also found by cccz, defsec, dipp, Dravee, GermanKuber, GimelSec, jah, reassor, and WatchPug
Since the _tokenContract can be any token, it is possible that loans will be created with tokens that support fee on transfer. If a fee on transfer asset token is chosen, other user’s funds might be drained.
Proof of Concept
- Assume transfer fee to be 5% and
Gravity.solhas 200 token. - Alice sendToCosmos 100 token. Now,
Gravity.solhas 295 token. - Alice calls the send-to-eth method to withdraw 100 token.
Gravity.solends up having 195 token.
Recommended Mitigation Steps
Change to
function sendToCosmos(
address _tokenContract,
bytes32 _destination,
uint256 _amount
) public nonReentrant {
uint256 oldBalance = IERC20(_tokenContract).balanceOf(address(this));
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
uint256 receivedAmout = IERC20(_tokenContract).balanceOf(address(this)) - oldBalance;
state_lastEventNonce = state_lastEventNonce.add(1);
emit SendToCosmosEvent(
_tokenContract,
msg.sender,
_destination,
receivedAmout,
state_lastEventNonce
);
}
mlukanova (Cudos) acknowledged and commented:
Token transfers are restricted to the Cudos token which doesn’t support fee on transfer. Will be fixed with issue #58.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the contract credits the requested transfer amount rather than measuring the actual balance increase, so fee-on-transfer tokens cause an accounting mismatch.
Impact
Other users' funds could be drained if a fee-on-transfer token is used, though the project says transfers are restricted to the Cudos token which does not charge such a fee.
What the attacker needed
A fee-on-transfer token is accepted; attacker can deposit and withdraw
The fix
The contract should measure the actual balance increase after the transfer and credit that amount instead of the requested amount; the project says it will be fixed.
How it was found
- Assume a 5% transfer fee and the contract holds 200 tokens.
- Alice sends 100 tokens to the contract; the contract now holds 295 tokens.
- Alice calls the send-to-eth method to withdraw 100 tokens.
- The contract ends up holding 195 tokens.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. This protocol assumed the full amount always arrives and recorded that full amount as the user's deposit. That mistake lets someone deposit a fee-charging token, get credited more than actually arrived, and then withdraw the difference from other people's money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.