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

Higher optimize-runs parameter results in yul::StackTooDeepError #15233

Open
lum7na opened this issue Jul 1, 2024 · 0 comments
Open

Higher optimize-runs parameter results in yul::StackTooDeepError #15233

lum7na opened this issue Jul 1, 2024 · 0 comments
Labels

Comments

@lum7na
Copy link

lum7na commented Jul 1, 2024

Description

Compiling the following code with solc 0.8.25 results in yul::StackTooDeepError.

Compiling command: solc-0.8.25 out.sol --optimize --via-ir --optimize-runs 10000 --bin

contract C {
  uint test1;
  uint test2;
  uint test3;
  uint test4;
  uint test5;
  uint test6;
  uint test7;
  function test(string memory s, uint n, uint a) public payable returns(uint) {
    if (test2 > 3) {
      uint256 v1 = (test5 * test1) / (test2 - ((test3 * a) / (test6 - (test5 / 2)) / 2));
      uint256 v2 = test2 / 2 + 1;
      uint256 v3 = (~(2 ** (8 * (32 - v1)) - 1) * test4);
      v3 /= (test2 - (v1 - test7) / test4 - (test6 / 2));
      while ((uint256(1) << test1) < n) {
        v2 = ((((test3 * (2 ** (8 * (32 - test4)) - 1)) / (test3 - (test2 / 2))) / (test1 * test2)) / (a - (test1 / 2)) + v2) / 2;
      }
    } else if (test3 != 0) {
      if (n > 3) {
        if (test2 > test6) {
          test4 = test3 - (test7 - (2 ** (8 * (32 - test1)) - 1)) / test2;
          uint256 v4 = a - ((test4 * test1) / 1e18);
        }
      }
    }
    uint[] memory x = new uint[](test6);
    return x[a];
  }
}

Result:

Uncaught exception:
/solidity/libyul/backends/evm/EVMObjectCompiler.cpp(106): Throw in function void solidity::yul::EVMObjectCompiler::run(solidity::yul::Object&, bool)
Dynamic exception type: boost::wrapexcept<solidity::yul::StackTooDeepError>
std::exception::what: Variable value is 1 too deep in the stack [ value _5 _4 _1 _21 _6 r_1 _13 _14 _15 r _19 product _23 _22 var_v diff_5 ]
memoryguard was present.
[solidity::util::tag_comment*] = Variable value is 1 too deep in the stack [ value _5 _4 _1 _21 _6 r_1 _13 _14 _15 r _19 product _23 _22 var_v diff_5 ]
memoryguard was present.

No exceptions are thrown when setting a smaller optimize-runs parameter, such as 200.

Environment

  • Compiler version: 0.8.25
@lum7na lum7na added the bug 🐛 label Jul 1, 2024
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