current position:Home>Why does if (1 = = 1) {XXX} affect the execution of XXX code?

Why does if (1 = = 1) {XXX} affect the execution of XXX code?

2022-02-03 23:18:56 Q & A of Denglian community

I've been testing one recently flashloan The contract of , If you delete paragraph 9 Yes if(1==1){xxx} , Then the whole flash loan process is normal without any problems , But add if(1==1){xxx} after , Will report a mistake :"There is no profit! Reverting!", The mistake is 44 Yes require Of . I don't know why the same code , After adding a control statement, it cannot be executed normally ?

Test environment :Truffle v5.1.47 (core: 5.1.47)Solidity v0.5.16 (solc-js)Node v12.18.4Web3.js v1.2.1sol pragma: pragma solidity ^0.5.0;

 function executeOperation(        address _reserve,        uint _amount,        uint _fee,        bytes calldata _params    ) external {        require(_amount <= getBalanceInternal(address(this), _reserve), "Invalid balance, was the flashLoan successful?");        if(1 == 1) {        uint256 deadline = now + 3000;        address RESERVE_ADDRESS = _reserve;        // get Exchange Address for the reserve asset        address addressForLoanAssetExchangeA = uniswapFactoryA.getExchange(RESERVE_ADDRESS);        address addressForLoanAssetExchangeB = uniswapFactoryB.getExchange(RESERVE_ADDRESS);        // Instantiate Exchange A        exchangeAforLoanAsset = IUniswapExchange(addressForLoanAssetExchangeA);        exchangeBforLoanAsset = IUniswapExchange(addressForLoanAssetExchangeB);        IERC20 loan = IERC20(RESERVE_ADDRESS);        IERC20 bat = IERC20(BAT_ADDRESS);        // Swap the reserve asset (e.g. DAI) for BAT        require(loan.approve(address(exchangeBforLoanAsset), _amount), "Could not approve reserve asset sell");  // B dai to bat        uint256 batPurchased = exchangeBforLoanAsset.tokenToTokenSwapInput(            _amount,            1,            1,            deadline,            BAT_ADDRESS        );        require(bat.approve(address(exchangeAforBAT), batPurchased), "Could not approve BAT asset sell");  // A bat to dai        // Swap BAT back to the reserve asset (e.g. DAIs)        uint256 reserveAssetPurchased = exchangeAforBAT.tokenToTokenSwapInput(            batPurchased,            1,            1,            deadline,            RESERVE_ADDRESS        );        uint amount = _amount;        uint totalDebt = amount.add(_fee);        require(reserveAssetPurchased > totalDebt, "There is no profit! Reverting!");        transferFundsBackToPoolInternal(RESERVE_ADDRESS, amount.add(_fee));     }        }

Normally executed tx: https://kovan.etherscan.io/tx/0xb1f7d758028f71a824b65bacfacd5cac3a2e9034bcdf6f05fb60c95a89c2b919 Wrong tx:https://kovan.etherscan.io/tx/0xa3a07fa388b2e97718f0ea60aeb1dfd14b59cc9bc16b53fc738d3b3e36471c07






Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032318534888.html

Random recommended