1

Compiling the code

contract Bar {

    function blockingFunction() public pure returns (bool) {
        assembly {
            return(0,0x20)
        }
    }
}

contract Foo is Bar {

    function foo() public pure returns(bool) {
        bool result = blockingFunction();
        require(result == true, "msg");
        return result;
    }
}

gives me a warning

Warning: Unreachable code.
  --> contracts/implementation/Foo.sol:18:9:
   |
18 |         require(result == true, "msg");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Warning: Unreachable code.
  --> contracts/implementation/Foo.sol:19:9:
   |
19 |         return result;
   |         ^^^^^^^^^^^^^

which makes no sense to me. The blockingFunction call seems to block the following code execution, even though it should return a boolean. Can someone tell me how to fix this? This is my hardhat.config.ts

import "@nomicfoundation/hardhat-toolbox";
import { HardhatUserConfig } from "hardhat/config";

const config: HardhatUserConfig = {
  solidity: "0.8.9",
  mocha: {
    timeout: 100000000
  }
}

export default config;
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
kuco 23
  • 786
  • 5
  • 18
  • `uint256 i = 0; if (i == 0) return result;` So `if (i == 0)` will always be `true` and everything that comes after these two lines of code can never be reached – derpirscher Nov 24 '22 at 00:37
  • I know, I've written it in a stupid way, though this is not the issue, the code is unreachable at `uint256 i = 0`. You can test it. – kuco 23 Nov 24 '22 at 00:39

1 Answers1

0

from docs

return(p, s)    end execution, return data mem[p…(p+s))

execution will end in assembly{return(0,0x20)} code. so when you called this

bool result = blockingFunction();

the code after this will not be executed

Yilmaz
  • 35,338
  • 10
  • 157
  • 202