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

Binary Vault for Price Game #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

light-fury
Copy link

No description provided.


// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: This declaration shadows an existing declaration function nextTokenId(). Change variable name.


// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: This declaration shadows an existing declaration function nextTokenId(). Change variable name.

* @param user Receipt for share
* @param amount Underlying token amount
*/
function addNewLiquidityPosition(address user, uint256 amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: High
Confidence: High

BinaryVault.addNewLiquidityPosition(address,uint256) uses arbitrary from in transferFrom: underlyingToken.safeTransferFrom(user,address(this),amount)

Exploit Scenario:

    function a(address from, address to, uint256 amount) public {
        erc20.transferFrom(from, to, amount);
    }

Alice approves this contract to spend her ERC20 tokens. Bob can call a and specify Alice's address as the from parameter in transferFrom, allowing him to transfer Alice's tokens to himself.

Recommendation
Use msg.sender as from in safeTransferFrom. Remove user parameter in function and use msg.sender instead.

* @param amount Underlying token amount
* @param tokenId nft id to be added liquidity. This should be existing id.
*/
function addLiquidityPosition(address user, uint256 amount, uint256 tokenId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: High
Confidence: High

BinaryVault.addLiquidityPosition(address,uint256,uint256) uses arbitrary from in safeTransferFrom: underlyingToken.safeTransferFrom(user,address(this),amount)

Exploit Scenario:

    function a(address from, address to, uint256 amount) public {
        erc20.transferFrom(from, to, amount);
    }

Alice approves this contract to spend her ERC20 tokens. Bob can call a and specify Alice's address as the from parameter in transferFrom, allowing him to transfer Alice's tokens to himself.

Recommendation
Use msg.sender as from in safeTransferFrom. Remove user parameter in function and use msg.sender instead.

*
* Emits a {Transfer} event for each mint.
*/
function _mint(address to, uint256 quantity) internal virtual {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: High
Confidence: High

BinaryVault._mint(address,uint256) contains an incorrect shift operation:
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1)

Recommendation: Swap the order of parameters.

*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: High
Confidence: High

BinaryVault._burn(uint256,bool) contains an incorrect shift operation:
_packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1

Recommendation: Swap the order of parameters.

*
* Returns whether the call correctly returned the expected magic value.
*/
function _checkContractOnERC721Received(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: Medium
Confidence: Medium

BinaryVault._checkContractOnERC721Received(address,address,uint256,bytes) ignores return value by ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(),from,tokenId,_data)

Recommendation: Ensure that all the return values of the function calls are used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants