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

Different error codes are produced by solc under different optimization parameters #15553

Open
lum7na opened this issue Oct 30, 2024 · 1 comment
Labels

Comments

@lum7na
Copy link

lum7na commented Oct 30, 2024

Hi! When compiling the program below with --via-ir --optimize and using --optimize-runs 200 and --optimize-runs 99999999 respectively, different error codes are returned when the f() function is called. Specifically, --optimize-runs 200 yields 0x4e487b710000000000000000000000000000000000000000000000000000000000000032, while --optimize-runs 99999999 results in 0x0. I conducted tests on Remix using the 0.8.27 compiler version, and the issue can be reproduced on the latest compiler version as well.

I'm interested in knowing: are error codes always accurate, and what is the correct error code?

contract C {
  function f() public returns(uint, uint) {
    try this.f() {
    } catch Error(string memory x) {
      x;
    } catch (bytes memory x) {
      if (x.length > 0) {
        require(abi.decode(x, (bool)), hex"");
      }
      for (uint256 i = 0;i < 7; i++) {
        x[i] = x[i];
      }
      require(abi.decode(x, (bool)), hex"");
    }
  }
}
@lum7na
Copy link
Author

lum7na commented Nov 12, 2024

Here's another example: at a lower optimization level (200), executing the transaction f() results in an error code of 0x32. However, at a higher optimization level (99999999), the transaction successfully returns.

contract C {
  function g(uint256 x, uint256 y) private returns(uint256) {
    return x;
  }

  function f() public returns(uint[] memory, uint) {
    try this.f() returns (uint[] memory x, uint y) {
      return (x, g(y, x[1]));
    } catch {
    }
  }
}

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

1 participant