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

InternalCompilerError: Internal compiler error #14765

Open
Xardesso opened this issue Dec 31, 2023 · 2 comments
Open

InternalCompilerError: Internal compiler error #14765

Xardesso opened this issue Dec 31, 2023 · 2 comments
Labels

Comments

@Xardesso
Copy link

Xardesso commented Dec 31, 2023

Hi i creating arbitrage bot using Solidity in Hardhat and i created smart contract which take aave flashloan make 2 swaps and repay flashloan itself and i got error when i tried to compile smart contract

Solidity version ^0.6.12
Hardhat version ^2.19.4
Operating System Windows 11

Code:

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.12;
import "@aave/protocol-v2/contracts/interfaces/ILendingPool.sol";
import "@aave/protocol-v2/contracts/interfaces/ILendingPoolAddressesProvider.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Context.sol";

contract ArbitrageBot1 is Context, ReentrancyGuard {
    using SafeMath for uint256;

    ILendingPoolAddressesProvider provider;
    ILendingPool lendingPool;
    IUniswapV2Router02 uniswapRouter;
    IUniswapV2Router02 sushiSwapRouter;
    address private owner;

    constructor(
        address _provider,
        address _uniswapRouter,
        address _sushiSwapRouter
    ) public {
        provider = ILendingPoolAddressesProvider(_provider);
        lendingPool = ILendingPool(provider.getLendingPool());
        uniswapRouter = IUniswapV2Router02(_uniswapRouter);
        sushiSwapRouter = IUniswapV2Router02(_sushiSwapRouter);
        owner = msg.sender;
    }

    modifier OnlyOwner() {
        require(msg.sender == owner);
        _;
    }

    function borrowAndSwap(
        uint256 _amount,
        uint256 amountOutExpected,
        uint256 amountOutExpected2,
        address coin1,
        address coin2
    ) external nonReentrant {
        lendingPool.borrow(coin1, _amount, 1, 0, address(this));

        address[] memory path2 = new address[](2);
        path2[0] = coin1;
        path2[1] = coin2;

        sushiSwapRouter.swapExactTokensForTokens(
            _amount,
            amountOutExpected,
            path2,
            address(this),
            block.timestamp
        );

        address[] memory path = new address[](2);
        path[0] = coin2;
        path[1] = coin1;

        uniswapRouter.swapExactTokensForTokens(
            IERC20(coin2).balanceOf(address(this)),
            amountOutExpected2,
            path,
            address(this),
            block.timestamp
        );

        // Get the borrow rate
        DataTypes.ReserveData memory reserveData = lendingPool.getReserveData(
            coin1
        );
        uint256 borrowRate = reserveData.currentVariableBorrowRate;

        // Calculate the amount of interest
        uint256 interest = _amount.mul(borrowRate).div(1e27);

        // Calculate the total amount to repay
        uint256 amountToRepay = _amount.add(interest);

        // Approve the lending pool to transfer the repayment amount
        IERC20(coin1).approve(address(lendingPool), amountToRepay);

        // Repay the borrowed amount
        lendingPool.repay(coin1, amountToRepay, 1, address(this));
    }

    function withdrawWETH(address outCoin) external OnlyOwner {
        require(
            IERC20(outCoin).balanceOf(address(this)) > 0,
            "No funds to withdraw"
        );
        IERC20(outCoin).transfer(
            owner,
            IERC20(outCoin).balanceOf(address(this))
        );
    }}

And error:

 $ npx hardhat compile 
InternalCompilerError: Internal compiler error (C:\projects\solidity\libsolidity\codegen\CompilerUtils.cpp:1441)
Error HH600: Compilation failed

For more info go to https://hardhat.org/HH600 or run Hardhat with --show-stack-traces
@nikola-matic
Copy link
Collaborator

We always consider an internal compiler error (ICE) to be a bug (usually a low priority one), so thanks for the report.
@Xardesso can you please post the exact version of the compiler you were using? ^0.6.12 just means higher than 0.6.12, so I assume you weren't using 0.6.x, since those are fairly old.

@cameel
Copy link
Member

cameel commented Jan 10, 2024

Well ^0.6.12 also means <0.7.0 and 0.6.12 was the last in the 0.6.x series, so it must have been 0.6.12.

It looks like this assert:

unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCalldata, bool _padToWords)
{
solAssert(_type.isValueType(), "");

Looks like it might have already been reported in #12114 but that issue was closed by the user because they found a workaround. The ICE might still be there though - we should try to reproduce on 0.8.23 (but with abicoder v1 since it's no longer the default).

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

No branches or pull requests

3 participants