Skip to content
Business logic Audit finding Intermediate

The current implementation of the VotingEscrow contract doesn’t support fee on transfer tokens

The VotingEscrow contract records the user-supplied amount as locked, but if the token charges a transfer fee, the contract receives less. This can leave the contract with insufficient balance to honour withdrawals, so some users cannot retrieve their funds.

CertoraInc Follow

Originally disclosed on Code4rena

Submitted by CertoraInc, also found by cccz, csanuragjain, jonatascm, and scaraven

https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L418

Some ERC20 tokens implemented so a fee is taken when transferring them, for example STA and PAXG. The current implementation of the VotingEscrow contract will mess up the accounting of the locked amounts if token will be a token like that, what will lead to a state where users won’t be able to receive their funds.

This will happen because the value that is added to the locked amount is not the actual value received by the contract, but the value supplied by the user (the value which the fee is taken from).

Proof of Concept

The STA token burns 1% of the value provided to the transfer function, which means the recipient gets only 99% of the transferred asset. Let’s assume that token is the address of the STA token.

  1. Bob wants to lock 100 STA tokens and calls createLock(100 * 10**18, unlockTime).
  2. The addition to the locked amount variable is done with 100 * 10**18, while the actual amount that was received by the contract is 99 * 10**18.
  3. When the lock expires Bob will try to withdraw his tokens, and the transfer function will be called with the accounted locked amount (which is 100 * 10**18). This might succeed due to other users locking too, so the transferred tokens will be taken from “their tokens”, but in the end there will be users left without an option to withdraw their funds, because the balance of the contract will be less than the locked amount that the contract is trying to transfer.

Tools Used

Manual auditing - VS Code and me :)

Recommended Mitigation Steps

Calculate the amount to add to the locked amount by the difference between the balances before and after the transfer instead of using the supplied value.

lacoop6tu (FIAT DAO) disputed and commented:

In our case, the token will be BalancerV2 Pool Token , which has no fee on transfer, in case someone else would like to fork this contract and use it, that fix will be required.

Justin Goro (judge) commented:

Given that the warden couldn’t know the use of Balancer only tokens, the severity will still be upheld.

elnilz (FIAT DAO) commented:

@Justin Goro so should we explicitly exclude all weird implementations of e.g. ERC20 in the future in the contest docs? I mean there are other wild examples of ERC20 implementations that someone could point out would cause problems with this contract. I am not trying to discount the work of any warden here but I think the correct response here as well as for #231 would be to improve docs stating which ERC20 implementations are safe to use in combination with VotingEscrow.

Justin Goro (judge) commented:

@elnilz This topic is very important to get right and the more it’s debated, the more it’s clear that there is no one size fits all answer. When I sponsored a contest, I only figured out after the fact the sorts of things that would have reduced unhelpful warden submissions, through no fault of C4.

My suggestion is that we curate an open source optional questionnaire for sponsors. The more detail the sponsor gives a priori, the more we can mark unhelpful issues as invalid. As an example, the tools I use to deploy my dapps do not allow me to accidentally omit addresses in constructor arguments. So wardens who warn me that I don’t check for the zero address in my constructors are not helping me. The questionnaire would cover many common case submissions such as that.

In your case, I had to dance a bit of a fine line: on the one hand, the wardens are not wrong in the event that you’re unaware of token design nuance and so they shouldn’t be penalized. On the other hand, this is a DAO and the wardens should at least suspect that the choice of token is a central decision. In the end, since both parties have good points to make and there’s no clear decider, I chose to side with the wardens since it doesn’t incur any additional cost to you as the sponsor and since it would seem unfair to penalize the wardens for an honest report with no flaws at the correct severity level.

IllIllI (warden) reviewed mitigation:

The sponsor disputed the issue because the Balancer V2 Pool tokens it’s planned to be used with do not implement a fee-on-transfer mechanic. The tokens do not appear to be upgradeable so there is no risk of fees being added to existing tokens via upgrade. Without more information about how which pool tokens are chosen/allowed/used, and what prevents future pool tokens that implement such a mechanic from being used with the same contract, I have to agree with the warden and judge that this is a Medium risk issue. The suggested mitigation is to measure the balance of the token that the contract holds before the transferFrom() call is made, and afterwards, and use the difference as the value, rather than the amount the user states. You could also add a require() enforcing the invariant that the change in balance must equal the stated amount, which would prevent fee-on-transfer tokens from being used.

In the final PR, the sponsor has acknowledged the issue and added a code comment saying that fee-on-transfer tokens are not supported.


The original report as published on Code4rena, by CertoraInc. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Impact

If a fee-on-transfer token is used, the contract's accounting becomes inconsistent and some users may be unable to withdraw their funds; the sponsor notes the planned token (Balancer V2 Pool Token) has no such fee, so the issue does not affect the intended deployment.

What the attacker needed

The contract uses a fee-on-transfer token

The fix

The contract should measure the token balance before and after the transfer and use the difference as the locked amount, or enforce that the balance change equals the stated amount; the sponsor acknowledged the issue and added a comment that fee-on-transfer tokens are not supported.

How it was found

  1. Bob calls createLock with 100 STA tokens.
  2. The contract adds 100 to the locked amount, but only 99 tokens arrive due to the 1% fee.
  3. When the lock expires, Bob tries to withdraw the recorded 100 tokens.
  4. The transfer may succeed using other users' tokens, but eventually the contract balance is less than total locked amounts, leaving some users unable to withdraw.

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 transferred, so the receiver gets less than the sender sends. This contract assumes the full amount arrives and records that larger number as locked. Later, when users withdraw, the contract may not have enough tokens to pay everyone because it over-counted what it actually held.

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.

More by CertoraInc

View all

16 more disclosed reports, best first.

More from FIAT DAO veFDT contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.