Incorrect accounting on transfer-on-fee/deflationary tokens in Gravity
The Gravity bridge contract credits the Cosmos side with the full requested amount when a transfer-on-fee token is deposited, even though fewer tokens actually arrive. An attacker could exploit this to withdraw more vouchers than deposited, potentially stealing tokens from other users.
Submitted by shw
Impact
The sendToCosmos function of Gravity transfers _amount of _tokenContract from the sender using the function transferFrom. If the transferred token is a transfer-on-fee/deflationary token, the actually received amount could be less than _amount. However, since _amount is passed as a parameter of the SendToCosmosEvent event, the Cosmos side will think more tokens are locked on the Ethereum side.
Proof of Concept
Referenced code:
Recommended Mitigation Steps
Consider getting the received amount by calculating the difference of token balance (using balanceOf) before and after the transferFrom.
This is a valid issue, it does present the ability to ‘steal’ tokens from the bridge, so I think that justifies the severity.
If user (A) deposits a deflationary token and gets slightly more vouchers than where actually deposited into the bridge upon withdraw they could steal tokens from user (B) who had also deposited.
Context
Gravity is a bridge between Ethereum and Cosmos. On the Ethereum side, the Gravity contract holds tokens that users lock before the Cosmos side credits them with a corresponding voucher. The entry point for this flow is the sendToCosmos function, which pulls tokens from the sender and emits a SendToCosmosEvent that the Cosmos side consumes to decide how much to credit.
The finding concerns how sendToCosmos accounts for the amount it moves. The report references two lines of the contract, Gravity.sol#L535 and Gravity.sol#L541, in the althea-net/cosmos-gravity-bridge repository at commit [redacted].
Setup
No accounts, tools or versions are described beyond the contract and commit above. The precondition that matters is the token being bridged: it must be a transfer-on-fee or deflationary token, meaning the amount that actually arrives at the recipient is less than the amount requested in the transfer.
Finding it
The researcher looked at how sendToCosmos moves tokens and how it reports the move. The function transfers _amount of _tokenContract from the sender using transferFrom. With a transfer-on-fee or deflationary token, the amount actually received by the contract can be less than _amount.
The problem is that _amount is what gets passed as a parameter of the SendToCosmosEvent. The event therefore records the requested amount, not the amount that was really locked. The Cosmos side trusts that event and concludes that more tokens are locked on the Ethereum side than actually are.
Exploitation
Step 1: deposit a deflationary token
A user calls sendToCosmos with a transfer-on-fee or deflationary token. The contract calls transferFrom for _amount, but the token deducts its fee during the transfer, so the contract's balance increases by less than _amount.
Step 2: the event overstates the deposit
The contract emits SendToCosmosEvent with _amount as the deposited value. The Cosmos side reads the event and credits the user as though the full _amount had been locked.
Step 3: withdraw more than was deposited
Because the Cosmos side believes more tokens are locked than really are, the depositing user can withdraw slightly more vouchers than they actually put into the bridge. As the maintainer's comment puts it, if user (A) deposits a deflationary token and gets slightly more vouchers than were actually deposited into the bridge, then upon withdraw they could take tokens that user (B) had also deposited.
No request, payload or command is shown in the report; the flow above is the sequence the report describes.
Root cause
The contract uses the requested transfer amount _amount as the record of what was locked, rather than the amount the contract actually received. For standard tokens the two are equal, so the mistake is invisible. For transfer-on-fee or deflationary tokens they diverge, and the event, which is the input to the Cosmos-side accounting, carries the inflated figure. The report does not describe any check that would have caught the discrepancy.
Impact
The bridge's accounting between the two chains becomes incorrect: the Cosmos side thinks more tokens are locked on Ethereum than really are. The maintainer, jkilpatr of Althea, confirmed the issue and framed the impact as the ability to "steal" tokens from the bridge, saying that this justifies the severity. The concrete scenario given is that a user who deposits a deflationary token receives slightly more vouchers than were actually deposited, and on withdrawal can take tokens belonging to another user who had also deposited. The impact depends on the bridged token being a transfer-on-fee or deflationary token.
Fix
The recommended mitigation is to derive the received amount from the token balance rather than from the parameter: calculate the difference of the token balance using balanceOf before and after the transferFrom, and use that difference for the accounting. The report does not state whether this change was applied.
Variants to test
- Bridge or vault contracts that emit deposit events using the requested amount rather than the measured balance change, with any fee-on-transfer, rebasing or deflationary token. A positive result is an event or stored balance that exceeds the contract's actual balance increase.
- The same pattern in withdrawal or refund paths, where the amount sent is recorded as the amount received. A positive result is a recipient credited for more than arrived.
- Tokens whose transfer behaviour changed after listing (fee switched on later). A positive result is accounting that was correct at listing time and becomes inflated afterwards.
Hunting notes
This kind of bug hides in cross-chain bridges, vaults and any contract that trusts a caller-supplied amount instead of measuring its own balance before and after a token transfer. During recon, look for deposit events whose amount parameter is taken directly from the function argument, and for supported-token lists that include fee-on-transfer or deflationary assets. The maintainer confirmed the issue and described how the overstated event leads to a withdrawal that draws on another user's deposit, which he said justifies the severity.
What happened, in plain words
Gravity is a bridge. A bridge lets you move value from one blockchain to another. Gravity connects Ethereum and Cosmos: you lock tokens on the Ethereum side, and the Cosmos side gives you a voucher that represents them. The Ethereum side is a smart contract called Gravity, a program that lives on the blockchain and runs automatically.
When you deposit, the contract takes your tokens and announces the deposit by firing an event. An event is a public note that a contract writes into the blockchain's log, and other software can read it. The Cosmos side reads that note to decide how many vouchers to hand you.
The bug is about the number written in that note. Some tokens charge a fee on every transfer, so the receiver gets a little less than the sender asked to send. The contract still wrote down the amount it asked for, not the amount it actually received. The Cosmos side therefore believed more tokens were locked than really were, and the depositor could later withdraw slightly more than they put in, taking tokens that belonged to other depositors.
Background you need first
A few ideas come up repeatedly, so here they are from zero.
- Blockchain: a shared ledger that many computers keep in sync. Nobody can quietly edit past entries.
- Smart contract: a program stored on the blockchain. It runs the same way for everyone, and its code is public.
- Token: a digital asset implemented by a smart contract. The token contract keeps a table of who owns how much.
- Bridge: a service that lets an asset on one blockchain be used on another. It usually works by locking the asset on chain A and issuing a claim (a voucher) on chain B.
- Event: a message a contract writes to the blockchain log. It is cheap to write and easy for outside software to read. Think of it as a receipt pinned to a public noticeboard.
transferFrom: a function on most token contracts. It moves tokens from one address to another on behalf of someone who has given permission. It takes the amount as an argument.balanceOf: a function on a token contract that returns how many tokens a given address currently holds.- Transfer-on-fee / deflationary token: a token that deducts a small fee during every transfer. If you ask it to send 100, the receiver may get 99 and the fee disappears or goes elsewhere. The requested amount and the received amount are not the same.
With those in place, the rest of the report is easier to follow.
Context
Gravity is a bridge between Ethereum and Cosmos. On the Ethereum side, the Gravity contract holds the tokens that users lock before the Cosmos side credits them with a corresponding voucher. The entry point for this flow is the sendToCosmos function, which pulls tokens from the sender and emits a SendToCosmosEvent that the Cosmos side consumes to decide how much to credit.
The finding concerns how sendToCosmos accounts for the amount it moves. The report references two lines of the contract, Gravity.sol#L535 and Gravity.sol#L541, in the althea-net/cosmos-gravity-bridge repository at commit [redacted].
In plain terms: sendToCosmos is the front door for deposits. You call it, it takes your tokens, and it writes a receipt (the event) that the other chain reads. The two referenced lines are the place where the tokens are pulled and the place where the receipt is written. The commit identifier is simply a snapshot of the code, so anyone can look at exactly the same version the researcher examined.
Setup
No accounts, tools or versions are described beyond the contract and commit above. The precondition that matters is the token being bridged: it must be a transfer-on-fee or deflationary token, meaning the amount that actually arrives at the recipient is less than the amount requested in the transfer.
This matters because with an ordinary token the requested amount and the received amount are identical, and the bug is invisible. You need a token that shaves something off during the transfer for the two numbers to drift apart.
Finding it
The researcher looked at how sendToCosmos moves tokens and how it reports the move. The function transfers _amount of _tokenContract from the sender using transferFrom. With a transfer-on-fee or deflationary token, the amount actually received by the contract can be less than _amount.
The problem is that _amount is what gets passed as a parameter of the SendToCosmosEvent. The event therefore records the requested amount, not the amount that was really locked. The Cosmos side trusts that event and concludes that more tokens are locked on the Ethereum side than actually are.
Two names appear here. _tokenContract is which token is being deposited, and _amount is how many units the caller says they want to move. The contract hands both to transferFrom. Later it writes _amount into the event. The mistake is subtle: the contract reports its intention rather than its result. A useful comparison is a shop assistant who writes down the price on the receipt without checking what actually went into the till.
Exploitation
Step 1: deposit a deflationary token
A user calls sendToCosmos with a transfer-on-fee or deflationary token. The contract calls transferFrom for _amount, but the token deducts its fee during the transfer, so the contract's balance increases by less than _amount.
Why this step matters: the deposit is the moment where the two numbers separate. The user asked for _amount to move, the token moved less, and the contract's real holdings grew by the smaller figure.
Step 2: the event overstates the deposit
The contract emits SendToCosmosEvent with _amount as the deposited value. The Cosmos side reads the event and credits the user as though the full _amount had been locked.
Why this step matters: the event is the only thing the Cosmos side sees. It cannot inspect the Ethereum balance itself in this flow, so it believes the receipt. The voucher issued is therefore slightly too large.
Step 3: withdraw more than was deposited
Because the Cosmos side believes more tokens are locked than really are, the depositing user can withdraw slightly more vouchers than they actually put into the bridge. As the maintainer's comment puts it, if user (A) deposits a deflationary token and gets slightly more vouchers than were actually deposited into the bridge, then upon withdraw they could take tokens that user (B) had also deposited.
Why this step matters: this is where an accounting error turns into a loss for someone else. The bridge holds a shared pool of locked tokens. If one person is allowed to take out more than they put in, the extra comes out of the same pool that other depositors rely on.
No request, payload or command is shown in the report; the flow above is the sequence the report describes.
Root cause
The contract uses the requested transfer amount _amount as the record of what was locked, rather than the amount the contract actually received. For standard tokens the two are equal, so the mistake is invisible. For transfer-on-fee or deflationary tokens they diverge, and the event, which is the input to the Cosmos-side accounting, carries the inflated figure. The report does not describe any check that would have caught the discrepancy.
In everyday terms: the contract trusts what it was told instead of measuring what it has. A shop that counts the till before and after a sale notices a shortfall; a shop that only reads the price tag does not.
Impact
The bridge's accounting between the two chains becomes incorrect: the Cosmos side thinks more tokens are locked on Ethereum than really are. The maintainer, jkilpatr of Althea, confirmed the issue and framed the impact as the ability to "steal" tokens from the bridge, saying that this justifies the severity. The concrete scenario given is that a user who deposits a deflationary token receives slightly more vouchers than were actually deposited, and on withdrawal can take tokens belonging to another user who had also deposited. The impact depends on the bridged token being a transfer-on-fee or deflationary token.
The maintainer confirmed the issue and said the ability to steal tokens from the bridge justifies the severity.
Fix
The recommended mitigation is to derive the received amount from the token balance rather than from the parameter: calculate the difference of the token balance using balanceOf before and after the transferFrom, and use that difference for the accounting. The report does not state whether this change was applied.
In plain words: read the till before the sale, read it after, and record the difference. That number is always the truth, whatever the token does during the transfer.
Variants to test
These are the same mistake in other shapes, useful when reviewing similar code.
- Bridge or vault contracts that emit deposit events using the requested amount rather than the measured balance change, with any fee-on-transfer, rebasing or deflationary token. A positive result is an event or stored balance that exceeds the contract's actual balance increase.
- The same pattern in withdrawal or refund paths, where the amount sent is recorded as the amount received. A positive result is a recipient credited for more than arrived.
- Tokens whose transfer behaviour changed after listing (fee switched on later). A positive result is accounting that was correct at listing time and becomes inflated afterwards.
A vault is a contract that holds funds on behalf of users, much like a bridge does. Rebasing means a token whose holders' balances change automatically over time, which breaks the same assumption that the number you asked for is the number that moved.
Hunting notes
This kind of bug hides in cross-chain bridges, vaults and any contract that trusts a caller-supplied amount instead of measuring its own balance before and after a token transfer. During recon, look for deposit events whose amount parameter is taken directly from the function argument, and for supported-token lists that include fee-on-transfer or deflationary assets. The maintainer confirmed the issue and described how the overstated event leads to a withdrawal that draws on another user's deposit, which he said justifies the severity.
Recon means the early survey of a target: reading the code, listing the tokens it supports, and noting where numbers come from. The lesson generalises: whenever a contract records how much it received, ask whether that figure was measured or merely requested.
Glossary
- Blockchain: a shared ledger kept in sync by many computers, where past entries cannot be quietly changed.
- Smart contract: a program stored on a blockchain that runs automatically and whose code is public.
- Token: a digital asset implemented by a smart contract that tracks who owns how much.
- Bridge: a service that locks an asset on one blockchain and issues a claim to it on another.
- Vault: a contract that holds funds on behalf of users.
- Gravity: the bridge between Ethereum and Cosmos discussed in this report.
Gravitycontract: the Ethereum-side smart contract that holds locked tokens and records deposits.sendToCosmos: the function users call to deposit tokens into the bridge.transferFrom: a token function that moves a requested amount from one address to another.balanceOf: a token function that returns how many tokens an address currently holds.- Event: a message a contract writes to the blockchain log for outside software to read.
SendToCosmosEvent: the event the contract emits to tell the Cosmos side how much was deposited.- Transfer-on-fee / deflationary token: a token that deducts a fee during each transfer, so the receiver gets less than the sender requested.
- Rebasing token: a token whose holders' balances change automatically over time.
- Accounting: the record of how much is owed to whom; here, the bridge's record of locked tokens versus issued vouchers.
- Voucher: the claim on the Cosmos side that represents tokens locked on Ethereum.
- Commit: a fixed snapshot of a code repository, identified by a long hexadecimal string.
- Recon: the early survey of a target before deeper testing.
- Severity: the rating of how serious a finding is, here medium.
- Mitigation: a change that removes or reduces the problem.