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: _unlock function should only be called with tokenId_ parameter #98

Open
code423n4 opened this issue Jan 5, 2022 · 2 comments
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

PierrickGT

Vulnerability details

Impact

We pass account_ to the _unlock function but this one is always called with msg.sender as first parameter. We can simplify the code by removing the account_ parameter and calling msg.sender inside the function instead.

Proof of Concept

Remove the account_ parameter from _unlock and _unlockBatch to only use msg.sender inside the _unlock function.

Recommended Mitigation Steps

The following changes are recommended.

For the _unlock function:

function _unlock(uint256 tokenId_) internal returns (uint256 amountUnlocked_) {
    // Check that the account is the position NFT owner.
    require(ownerOf(tokenId_) == msg.sender, "NOT_OWNER");
    ...
    emit LockPositionWithdrawn(tokenId_, msg.sender, amountUnlocked_); // On line 317
}

On line 112:

amountUnlocked_ = _unlock(tokenId_);

On line 133:

amountUnlocked_ = _unlock(tokenId_);

On line 326:

amountUnlocked_ += _unlock(tokenIds_[i]);

For the _unlockBatch function:

function _unlockBatch(uint256[] memory tokenIds_) internal returns (uint256 amountUnlocked_) {

On line 167:

amountUnlocked_ = _unlockBatch(tokenIds_);

On line 188:

amountUnlocked_ = _unlockBatch(tokenIds_);
@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 5, 2022
code423n4 added a commit that referenced this issue Jan 5, 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 6, 2022
@deluca-mike
Copy link
Collaborator

While this would save gas, our philosophy is that internal functions should be agnostic of msg and be fully parameterized. it makes it easier to create test harnesses (which call just internal functions).

@Ivshti
Copy link
Member

Ivshti commented Jan 16, 2022

agreed with the sponsor's assessment to not fix this

@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) 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