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

Are there any bugs in the Bridge.sol? #21

Open
xuebingqing opened this issue Oct 25, 2023 · 0 comments
Open

Are there any bugs in the Bridge.sol? #21

xuebingqing opened this issue Oct 25, 2023 · 0 comments

Comments

@xuebingqing
Copy link

Description

When we recently used the fuzz testing tool, we scanned the contract Bridge.sol. We found some issues and wanted to confirm with you.

    function depositAndBridgeOut(
        address originalTokenAddress,
        address pTokenAddress,
        uint64 toChainId,
        bytes calldata toAddress,
        uint256 amount,
        bytes calldata callData
    ) external override nonReentrant whenNotPaused returns(bool) {
        require(amount != 0, "amount cannot be zero!");

        // no bridge fee for deposit

        // transfer_to_this + deposit + burn = transfer_to_ptoken
        require(IPToken(pTokenAddress).tokenUnderlying() == originalTokenAddress, "invalid originalToken / pToken");
        require(IPToken(pTokenAddress).checkIfDepositWithdrawEnabled(), "ptoken deposit/withdraw not enabled");

        uint256 balanceBefore = IERC20(originalTokenAddress).balanceOf(pTokenAddress);
        IERC20(originalTokenAddress).safeTransferFrom(_msgSender(), pTokenAddress, amount);
        amount = IERC20(originalTokenAddress).balanceOf(pTokenAddress).sub(balanceBefore);

        // precision conversion
        uint8 ptokenDecimals = ERC20(pTokenAddress).decimals();
        uint8 underlyingTokenDecimals = ERC20(originalTokenAddress).decimals();
        amount = amount.mul(10**ptokenDecimals).div(10**underlyingTokenDecimals);
        require(amount != 0, "bridge amount cannot be zero!");

        return _bridgeOut(pTokenAddress, toChainId, toAddress, amount, callData);
    }

As you can see, originalTokenAddress is used as input and is controllable by the user. If there is malicious input later and implement the IERC20 interface standard, it calls safeTransferFrom without checking the originalTokenAddress parameter. Are there any problems?

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

No branches or pull requests

1 participant