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

XDEFIDistribution: lock should be reused in lockWithPermit #47

Open
code423n4 opened this issue Jan 4, 2022 · 2 comments
Open

XDEFIDistribution: lock should be reused in lockWithPermit #47

code423n4 opened this issue Jan 4, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

PierrickGT

Vulnerability details

Impact

In lockWithPermit, we use the same code to transfer XDEFI and lock the position than in lock. We can create an internal function to reuse this code and avoid duplication.

Proof of Concept

Create an internal function called _lockPosition that will transfer XDEFI and lock the position. This function will be called in lock and lockWithPermit.

Recommended Mitigation Steps

The following change is recommended.

function _lockPosition(uint256 amount_, uint256 duration_, address destination_) internal returns (uint256 tokenId_) {
    // Lock the XDEFI in the contract.
    SafeERC20.safeTransferFrom(IERC20(XDEFI), msg.sender, address(this), amount_);

    // Handle the lock position creation and get the tokenId of the locked position.
    return _lock(amount_, duration_, destination_);
}

function lock(uint256 amount_, uint256 duration_, address destination_) external noReenter returns (uint256 tokenId_) {
    return _lockPosition(amount_, duration_, destination_);
}

function lockWithPermit(uint256 amount_, uint256 duration_, address destination_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external noReenter returns (uint256 tokenId_) {
    // Approve this contract for the amount, using the provided signature.
    IEIP2612(XDEFI).permit(msg.sender, address(this), amount_, deadline_, v_, r_, s_);

    return _lockPosition(amount_, duration_, destination_);
}
@code423n4 code423n4 added 0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working labels Jan 4, 2022
code423n4 added a commit that referenced this issue Jan 4, 2022
@deluca-mike deluca-mike added G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Jan 5, 2022
@deluca-mike
Copy link
Collaborator

Yep, good catch, and it's actually also a gaas optimization.

@deluca-mike
Copy link
Collaborator

deluca-mike commented Jan 13, 2022

In release candidate contract, lock and lockWithPermit both use a new _lock, which performs the common functionality before calling a _createLockedPosition.

@deluca-mike deluca-mike added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Jan 14, 2022
@Ivshti Ivshti closed this as completed Jan 16, 2022
@CloudEllie CloudEllie added G (Gas Optimization) and removed 0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation labels Jan 19, 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) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

4 participants