I'm currently reviewing the code of RANDAO and there is a function that does not return on all codepaths. Is this legal? Is the return value well defined in the case that the if statement does not hold?

  function returnRandom(Campaign storage c) bountyPhase(c.bnum) internal returns (uint256) {
      if (c.revealsNum == c.commitNum) {
          c.settled = true;
          return c.random;

Looks like it's a known bug/feature in Solidity: https://github.com/ethereum/solidity/issues/4751

There's plenty of discussions about it in the link and in its related issues but I fail to find a definitive consensus yet about what should be done about it.

| improve this answer | |

Interesting question, I did never try to write/saw something similar.

To verify if it could work, I wrote a minimal contract to verify whether it could work or not with the REMIX IDE (with Javascript VM).

  pragma ^0.4.24;
  contract A {
        function returnRandom(uint256 a) pure public returns (uint256) {
           if(a == 2) {
              return 5;

Surprisingly, this code does not produce warnings. When I run the code with an input different from 2, it returns 0.

I am sorry but I cannot explain the motivation for this design choice, which sounds odd ( I would expect at least a warning)

| improve this answer | |
  • 1
    I also confirmed that it compiles - but what is really important is whether the return value is well-defined or undefined by the specification. – user1282931 Aug 22 '18 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.