Skip to content
Business logic Audit finding Intermediate

ERC5095 has not approved MarketPlace to spend tokens in ERC5095

ERC5095 does not approve the MarketPlace contract to spend its tokens before calling sellUnderlying or sellPrincipalToken, which use transferFrom. As a result, functions like deposit, mint, withdraw, and redeem fail, preventing users from selling tokens through ERC5095.

cccz Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-illuminate-judging/issues/23

Found by

cccz

Summary

ERC5095 requires approving MarketPlace to spend the tokens in ERC5095 before calling MarketPlace.sellUnderlying/sellPrincipalToken

Vulnerability Detail

MarketPlace.sellUnderlying/sellPrincipalToken will call transferFrom to send tokens from msg.sender to pool, which requires msg.sender to approve MarketPlace. However, before calling MarketPlace.sellUnderlying/sellPrincipalToken in ERC5095, there is no approval for MarketPlace to spend the tokens in ERC5095, which causes functions such as ERC5095.deposit/mint/withdraw/redeem functions fail, i.e. users cannot sell tokens through ERC5095.

Solidity
    function sellUnderlying(
        address u,
        uint256 m,
        uint128 a,
        uint128 s
    ) external returns (uint128) {
        // Get the pool for the market
        IPool pool = IPool(pools[u][m]);

        // Get the number of PTs received for selling `a` underlying tokens
        uint128 expected = pool.sellBasePreview(a);

        // Verify slippage does not exceed the one set by the user
        if (expected < s) {
            revert Exception(16, expected, 0, address(0), address(0));
        }

        // Transfer the underlying tokens to the pool
        Safe.transferFrom(IERC20(pool.base()), msg.sender, address(pool), a);
...
    function sellPrincipalToken(
        address u,
        uint256 m,
        uint128 a,
        uint128 s
    ) external returns (uint128) {
        // Get the pool for the market
        IPool pool = IPool(pools[u][m]);

        // Preview amount of underlying received by selling `a` PTs
        uint256 expected = pool.sellFYTokenPreview(a);

        // Verify that the amount needed does not exceed the slippage parameter
        if (expected < s) {
            revert Exception(16, expected, s, address(0), address(0));
        }

        // Transfer the principal tokens to the pool
        Safe.transferFrom(
            IERC20(address(pool.fyToken())),
            msg.sender,
            address(pool),
            a
        );

In the test file, vm.startPrank(address(token)) is used and approves the MarketPlace, which cannot be done in the mainnet

Solidity
        vm.startPrank(address(token));
        IERC20(Contracts.USDC).approve(address(marketplace), type(uint256).max);
        IERC20(Contracts.YIELD_TOKEN).approve(
            address(marketplace),
            type(uint256).max
        );

Impact

It makes functions such as ERC5095.deposit/mint/withdraw/redeem functions fail, i.e. users cannot sell tokens through ERC5095.

Code Snippet

https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/MarketPlace.sol#L396-L414 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/MarketPlace.sol#L319-L342 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L188-L197 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L230-L244 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L267-L276 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L372-L385 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L267-L307 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/src/tokens/ERC5095.sol#L372-L409 https://github.com/sherlock-audit/2023-01-illuminate/blob/main/test/fork/ERC5095.t.sol#L72-L77

Tool used

Manual Review

Recommendation

Approve MarketPlace to spend tokens in ERC5095 in ERC5095.setPool.

Diff
    function setPool(address p)
        external
        authorized(marketplace)
        returns (bool)
    {
        pool = p.fyToken();
+      Safe.approve(IERC20(underlying), marketplace, type(uint256).max);
+      Safe.approve(IERC20(p.), marketplace, type(uint256).max);

        return true;
    }

        pool = address(0);
    }

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

Likely the ERC5095 contract does not set an allowance for the MarketPlace contract to spend its tokens before calling functions that use transferFrom.

Impact

Functions such as deposit, mint, withdraw, and redeem fail, so users cannot sell tokens through ERC5095.

What the attacker needed

None

The fix

The ERC5095 contract should approve the MarketPlace to spend its tokens, for example in the setPool function.

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.

In Ethereum, a contract can only move your tokens if you have given it permission, called an allowance. Here, the ERC5095 contract tries to sell tokens on a marketplace but never gave the marketplace that permission, so the sale always fails. This means users cannot use the deposit, mint, withdraw, or redeem functions that rely on selling.

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 cccz

View all

104 more disclosed reports, best first.

More from Illuminate Round 2

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.