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

Gas optimization in XDEFIDistribution.sol - inlining some functions #121

Open
code423n4 opened this issue Jan 6, 2022 · 1 comment
Open
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

OriDabush

Vulnerability details

XDEFIDistribution.sol lines 245-251

Make functions like "_getPoints" and "_getPointsFromTokenId" inline (saves the function call gas, the functions can be left and the inline "call" can reference to them with a comment or something)

    function _getPoints(uint256 amount_, uint256 duration_) internal view returns (uint256 points_) {
        return amount_ * (duration_ + _zeroDurationPointBase);
    }

    function _getPointsFromTokenId(uint256 tokenId_) internal pure returns (uint256 points_) {
        return tokenId_ >> uint256(128);
    }


    // old usage:
    return _getPointsFromTokenId(tokenId_);

    // new usage:
    return tokenId_ >> uint256(128);
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 6, 2022
code423n4 added a commit that referenced this issue Jan 6, 2022
@deluca-mike deluca-mike added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Jan 8, 2022
@deluca-mike
Copy link
Collaborator

_getPoints and _getScoreFromTokenId are each used twice, so it's better for that math to be in one place, even if it is trivial. It increases deploy costs but decrease runtime costs such that the breakeven is about 100 calls, which is a good trade-off. Issue is valid, but we won't implement.

@Ivshti Ivshti closed this as completed Jan 16, 2022
@CloudEllie CloudEllie reopened this Jan 22, 2022
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 acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

4 participants