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

AaveYield.getTokensForShares(), AaveYield.getSharesForTokens() Implementation can be simpler and save some gas #128

Open
code423n4 opened this issue Dec 15, 2021 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

Based on the current implementation, shares are in aToken, which is 1:1 to the underlying token.

Therefore, getTokensForShares() and getSharesForTokens() can be much simplier.

https://github.com/code-423n4/2021-12-sublime/blob/9df1b7c4247f8631647c7627a8da9bdc16db8b11/contracts/yield/AaveYield.sol#L256-L265

    function getTokensForShares(uint256 shares, address asset) public view override returns (uint256 amount) {
        if (shares == 0) return 0;
        address aToken = liquidityToken(asset);

        (, , , , , , , uint256 liquidityIndex, , ) = IProtocolDataProvider(protocolDataProvider).getReserveData(asset);

        amount = IScaledBalanceToken(aToken).scaledBalanceOf(address(this)).mul(liquidityIndex).mul(shares).div(
            IERC20(aToken).balanceOf(address(this))
        );
    }

can be changed to:

    function getTokensForShares(uint256 shares, address asset) public view override returns (uint256) {
        return shares;
    }

https://github.com/code-423n4/2021-12-sublime/blob/9df1b7c4247f8631647c7627a8da9bdc16db8b11/contracts/yield/AaveYield.sol#L273-L275

    function getSharesForTokens(uint256 amount, address asset) external view override returns (uint256 shares) {
        shares = (amount.mul(1e18)).div(getTokensForShares(1e18, asset));
    }

can be changed to:

    function getSharesForTokens(uint256 amount, address asset) external view override returns (uint256) {
        return amount;
    }
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 15, 2021
code423n4 added a commit that referenced this issue Dec 15, 2021
@ritik99 ritik99 added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Dec 24, 2021
@ritik99
Copy link
Collaborator

ritik99 commented Dec 24, 2021

Instead of making the proposed changes, we plan to use Aave's wrappers for aTokens so that it conforms with the behaviour of other LP tokens

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) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

2 participants