Skip to content
Business logic Audit finding Intermediate

SushiToken transfers are broken due to wrong delegates accounting on transfers

The SushiToken contract's _beforeTokenTransfer function incorrectly moves voting power from the sender's address instead of their delegate, causing transfers to revert when the sender has delegated votes. An attacker could not exploit this for gain, but users who delegated votes are unable to transfer tokens.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel.

When minting / transferring / burning tokens, the SushiToken._beforeTokenTransfer function is called and supposed to correctly shift the voting power due to the increase/decrease in tokens for the from and to accounts. However, it does not correctly do that, it tries to shift the votes from the from account, instead of the _delegates[from] account. This can lead to transfers reverting.

Proof Of Concept

Imagine the following transactions on the SushiToken contract. We’ll illustrate the corresponding _moveDelegates calls and written checkpoints for each.

  • mint(A, 1000) = transfer(0, A, 1000) => _moveDelegates(0, delegates[A]=0) => no checkpoints are written to anyone because delegatees are still zero
  • A delegates to A’ => _moveDelegates(0, A') => writeCheckpoint(A', 1000)
  • B delegates to B’ => no checkpoints are written as B has a zero balance
  • transfer(A, B, 1000) => _moveDelegates(A, delegates[B] = B') => underflows when subtracting amount=1000 from A’s non-existent checkpoint (defaults to 0 votes)

It should subtract from A’s delegatee A'’s checkpoint instead.

Impact

Users that delegated votes will be unable to transfer any of their tokens.

Recommended Mitigation Steps

In SushiToken._beforeTokenTransfer, change the _moveDelegates call to be from _delegates[from] instead:

function _beforeTokenTransfer(address from, address to, uint256 amount) internal override {
    _moveDelegates(_delegates[from], _delegates[to], amount);
    super._beforeTokenTransfer(from, to, amount);
}

This is also how the original code from Compound does it.

maxsam4 (Sushi Miso) acknowledged:

This is a known issue in Sushi token but was kept unchanged in MISO for “preservation of history :)“. That was not necessarily a wise choice lol. I think 1 severity should be fine for this as this was an intentional thing. The delegate feature is not supposed to be used in these tokens. We might create a new token type with this bug fixed.

ghoul-sol (judge) commented:

We have crazy wallets on the blockchain that will call every possible function available to them and that’s why I’m keeping this as is. Even intentional, the issue stands so the warden should get credit for it.

The original report as published on Code4rena, by cmichel. 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

Root cause

The _beforeTokenTransfer function calls _moveDelegates with the 'from' address instead of the delegate of 'from', leading to an underflow when subtracting votes from a non-existent checkpoint.

What the attacker needed

User has delegated votes; User attempts to transfer tokens

The fix

The _beforeTokenTransfer function should be changed to call _moveDelegates with _delegates[from] and _delegates[to] instead of from and to.

How it was found

  1. Mint tokens to account A; no checkpoints are written because delegates are zero.
  2. Account A delegates to A'; a checkpoint is written for A' with 1000 votes.
  3. Account B delegates to B'; no checkpoints are written because B has zero balance.
  4. Transfer 1000 tokens from A to B; _moveDelegates is called with A and B', causing an underflow when subtracting from A's non-existent checkpoint.

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.

This is a bug in a cryptocurrency token contract that handles voting power. When you transfer tokens, the contract is supposed to move your voting power to your chosen delegate, but it mistakenly tries to move voting power from your own address, which has none, causing the transfer to fail. So if you've delegated your votes, you can't send your tokens.

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 cmichel

View all

196 more disclosed reports, best first.

More from Sushi Miso 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.