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

Solc 0.8.18: Added optimization rule and(shl(X, Y), shl(X, Z)) => shl(X, and(Y, Z)) #14060

Closed
barakman opened this issue Mar 20, 2023 · 1 comment
Projects

Comments

@barakman
Copy link

This is either a documentation issue or a real bug.

I have not verified this is a bug, only read it in the release notes of solc 0.8.18.

So it is possibly just a documentation issue (either incorrect documentation or my incorrect understanding of it).

Yet, I wanted to point that to your immediate attention:

A quick check reveals that for X = 1, Y = 0, Z = 1:

  • The LHS and(shl(X, Y), shl(X, Z)) evaluates to 0
  • The RHS shl(X, and(Y, Z)) evaluates to 1
@github-actions github-actions bot added this to Triage in Solidity Mar 20, 2023
@ekpyron
Copy link
Member

ekpyron commented Mar 20, 2023

with X = 1, Y = 0, Z = 1, it holds that

and(shl(X, Y), shl(X, Z)) =
and(shl(1, 0), shl(1, 1)) =
and(0, 2) = 0

shl(X, and(Y, Z)) =
shl(1, and(0, 1)) =
shl(1, 0) = 0

Note that the argument order for shifts is (not our fault, it's like that on the EVM level) shl(shiftAmount, value).

We do have SMT-based formal proofs about the correctness of these rules, so they're not likely to be incorrect. But to me this doesn't look like a bug in the documentation/changelog either, but rather a misunderstanding about the arguments of the opcodes.

Hence I'm closing this issue, but feel free to reopen, if you think this is an issue after all!

@ekpyron ekpyron closed this as completed Mar 20, 2023
Solidity automation moved this from Triage to Done Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Solidity
  
Done
Development

No branches or pull requests

2 participants