Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SingleTokenJoin#joinTokenSingle() Change inputAmount to maxInputAmount can avoid dust INTERMEDIATE_TOKEN and save gas #215

Open
code423n4 opened this issue Dec 19, 2021 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-12-amun/blob/98f6e2ff91f5fcebc0489f5871183566feaec307/contracts/basket/contracts/singleJoinExit/SingleTokenJoin.sol#L47-L71

function joinTokenSingle(JoinTokenStruct calldata _joinTokenStruct)
        external
    {
        // ######## INIT TOKEN #########
        IERC20 inputToken = IERC20(_joinTokenStruct.inputToken);

        inputToken.safeTransferFrom(
            msg.sender,
            address(this),
            _joinTokenStruct.inputAmount
        );

        _joinTokenSingle(_joinTokenStruct);

        // ######## SEND TOKEN #########
        uint256 remainingIntermediateBalance = INTERMEDIATE_TOKEN.balanceOf(
            address(this)
        );
        if (remainingIntermediateBalance > 0) {
            INTERMEDIATE_TOKEN.safeTransfer(
                msg.sender,
                remainingIntermediateBalance
            );
        }
    }

SingleTokenJoin#joinTokenSingle() can be changed to:

  1. Calculate amounts of basket underlying tokens required for outputAmount;
  2. Calculate the amount of INTERMEDIATE_TOKEN needed based on the amounts of basket underlying tokens (the output of above);
  3. Calculate the amount of inputToken needed based on the amount of INTERMEDIATE_TOKEN (the output of above);
  4. Transfer only the amount of inputToken required from msg.sender;

This way we can avoid unnecessary dust INTERMEDIATE_TOKEN.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 19, 2021
code423n4 added a commit that referenced this issue Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

1 participant