Skip to content
Business logic Audit finding Intermediate

sponsorSeries() method fails when user want to swap for stake token using

The sponsorSeries() function incorrectly transfers the stake token instead of the sell token when a user tries to swap another token for the stake token, causing the transaction to fail unless a permit is used. An attacker could not exploit this; it is a functional bug that prevents legitimate sponsorship.

spyrosonic10 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-sense-judging/issues/36

Found by

spyrosonic10

Summary

sponsorSeries() fails when user want to use swapQuote to swap for stake token to sponsor a series.

Vulnerability Detail

stake is token that user need to deposit (technically is pulled) to be able to sponsor a series for a given target. User has option to send SwapQuote calldata quote and swap any ERC20 token for stake token. Below is the code that doing transferFrom() of stakeToken not sellToken()

Solidity
if (address(quote.sellToken) != ETH) _transferFrom(permit, stake, stakeSize);
 if (address(quote.sellToken) != stake) _fillQuote(quote);

Expected behaviour of this function is to pull sellToken from msg.sender when address(quote.sellToken) != stake. For example- stake token is WETH. User want to swap DAI for WETH in sponsorSeries(). In this case, user would be sending SwapQuote.sellToken = DAI and swapQuote.buyToke = WETH and expect that fillQuote() would swap it for WETH. This method will fail because sellToken not transferred from msg.sender.

Impact

sponsorSeries() fails when address(quote.sellToken) != stake

Code Snippet

https://github.com/sherlock-audit/2023-03-sense/blob/main/sense-v1/pkg/core/src/Periphery.sol#L116-L128

Tool used

Manual Review

Recommendation

Consider implementation of functionality to transferFrom sellToken from msg.sender with actual amount that is require to get exact amountOut greater or equal to stakeSize

Discussion

jparklev

Accepted:

This bug is valid but the below statement

sponsorSeries() fails when user want to use swapQuote to swap for stake token to sponsor a series.

is not quite accurate.

The problem here is that here:

Solidity
if (address(quote.sellToken) != ETH) _transferFrom(permit, stake, stakeSize);

we are sending wrong params to _transferFrom.

If we are making use of the permit feature, this would work fine because the _transferFrom ignores the params on that case.

On the contrary, if we want to make use of the traditional approval, this would revert since we will be trying to pull a the stake which has not been approved by the user.

Fix:

Solidity
if (address(quote.sellToken) != ETH) _transferFrom(permit, quote.sellToken, quote.amount);
// quote.amount does not exist so we may need to add this param to the struct

jparklev

Fixed here: https://github.com/sense-finance/sense-v1/pull/347

We used the fix mentioned above

IAm0x52

Fix looks good. _transferFrom now correctly pulls the sellToken instead of stake

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

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 code calls _transferFrom with the stake token address instead of the sell token address, so it attempts to pull the wrong token from the user.

Impact

The sponsorSeries() function fails when the sell token is not the stake token, preventing users from sponsoring a series via a swap unless they use the permit feature.

What the attacker needed

User has sell tokens and wants to sponsor; sell token differs from stake token; user has not used permit

The fix

The fix was to change the _transferFrom call to use the sell token and its amount instead of the stake token and stake size.

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 smart contract function that lets users sponsor a series by depositing a stake token. If a user wants to pay with a different token and swap it for the stake token, the function mistakenly tries to take the stake token directly from the user's wallet instead of the token they intended to swap. This causes the transaction to fail, so the user cannot sponsor the series using that method.

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 spyrosonic10

View all

1 more disclosed report, best first.

More from Sense Update #1

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.