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

Optimizer's optimization effectiveness varies for different opcodes. #15020

Open
Subway2023 opened this issue Apr 12, 2024 · 0 comments
Open
Labels

Comments

@Subway2023
Copy link

Description

When handling overflow in mload, keccak256, the Optimizer can enable the code to run normally. However, when dealing with mstore, and extcodecopy opcodes, the Optimizer fails to prevent code execution rollback.

Environment

  • Compiler version: 0.8.25
  • Target EVM version (as per compiler settings): No restrictions
  • Framework/IDE (e.g. Truffle or Remix): Remix
  • EVM execution environment / backend / blockchain client: None
  • Operating system: None

Steps to Reproduce

Compile with different compilation conditions.

mload

contract C {
  function f() public {
    assembly {
      pop(mload(4294967297))
      sstore(0, 1)
    }
  }
}
  1. origin: out of gas
  2. --optimize: storage: {0:1}
  3. --via-ir: storage: {0:1}
  4. --optimize and --via-ir: storage: {0:1}

keccak256

contract C {
  function f() external{
    assembly {
      pop(keccak256(999999999999999999999999,43486543872))
      sstore(0, 1)
    }
  }
}
  1. origin: gas uint64 overflow
  2. --optimize: storage: storage: {0:1}
  3. --via-ir: storage: storage: {0:1}
  4. --optimize and --via-ir: storage: {0:1}

mstore

contract C {
  function f() public {
    assembly {
      pop(mload(4294967297))
      sstore(0, 1)
    }
  }
}
  1. origin: gas uint64 overflow
  2. --optimize: storage: gas uint64 overflow
  3. --via-ir: storage: gas uint64 overflow
  4. --optimize and --via-ir: storage: {0:1}

extcodecopy

mstore

contract C {
  function f() external{
    assembly {
      extcodecopy(1, not(1), not(not(1)), not(1))
      sstore(0,1)
    }
  }
}
  1. origin: gas uint64 overflow
  2. --optimize: storage: gas uint64 overflow
  3. --via-ir: storage: gas uint64 overflow
  4. --optimize and --via-ir: storage: {0:1}

From the above, we can see that the Optimizer's optimization effectiveness varies for different opcodes.

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