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

Some bitwise and bool2Word lemmas #2241

Closed
wants to merge 11 commits into from
Closed

Some bitwise and bool2Word lemmas #2241

wants to merge 11 commits into from

Conversation

ehildenb
Copy link
Member

@ehildenb ehildenb commented Jan 9, 2024

This PR is the first of several that will come from some experiments with the Kontrol test-suite. This one adjusts the semantics and lemmas, in particular:

  • In the process of exploring generated claims from Kontrol test-suite, several simplifications were revealed that seem generally useful. The simplifications are added along with tests:
    • A rule about simplifying X xorInt Y <Int 0 -Int X, if X and Y are both positive.
    • Rules about simplifying X ==Int 0 when disequalities about X around zero are known.
    • Claims which were failing before and now are passing with these lemmas are added.

@ehildenb ehildenb self-assigned this Jan 9, 2024
@ehildenb ehildenb requested review from PetarMax and anvacaru January 9, 2024 17:43
@ehildenb ehildenb marked this pull request as ready for review January 9, 2024 17:43
Comment on lines +250 to +251
rule X ==Int 0 => true requires 0 <=Int X andBool X <=Int 0 [simplification, comm]
rule X ==Int 0 => false requires 0 <Int X [simplification, comm]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lemmas like these tend to slow down the execution. @dwightguth has flagged this in the Maude backend, I've also noticed a considerable speedup once I commented slightly more general lemmas that we had out of the work on symbolic calldata. The CI is currently timing out and lasting almost double the time it did before.

I remember introducing these more general lemmas for Optimism because of the looping on the symbolic size of a bytes parameter, getting constraints of the form 37 <=Int X and X <=Int 37, and the backend not understanding without SMT that X ==Int 37. The lemmas were:

rule   A <=Int B                =>   A  ==Int  B   requires B <=Int A [simplification, concrete(A)]
rule { A <=Int B #Equals true } => { A #Equals B } requires B <=Int A [simplification, concrete(A)]
rule { true #Equals A <=Int B } => { A #Equals B } requires B <=Int A [simplification, concrete(A)]

How did these two lemmas come up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests added are exactly the expressions that came up causing these lemmas to be added. I can try out the lemmas you suggest.

Whenever I run into something unsimplified that I want simplified, the first thing I do is snip out that expression and add it as a test to KEVM. Then I begin working on that test directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand that. I'm not suggesting that you replace your lemmas with the ones I suggest. All that I am saying is that I had similar lemmas that were slowing down the performance. I suspect that your lemmas are causing a slowdown that resulted in the CI failure. Have you got a performance comparison of this branch vs master?

@PetarMax
Copy link
Contributor

I think that we could benefit from introducing simplifications that only do a syntactic search of the pure constraints. For example:

rule X ==Int 0 => true requires 0 <=Int X andBool X <=Int 0 [simplification, comm, syntactic]

would only fire if the requires clause conjucts were verbatim in the pure constraints. I think this is the case in the examples that motivated this particular simplification and I know it was the case when I introduced the more general ones.

@ehildenb
Copy link
Member Author

It appears that all proofs take the same amount of time as master, except the bihu functional specification here, which loops:

claim <k> runLemma(#range( _MEM [ 96 := #padToWidth(32, #asByteStack(BS)) ], 96, 32))
.

I'm investigating.

@ehildenb ehildenb changed the title Bitwise and bool2Word lemmas, remove use of cell fragments Some bitwise and bool2Word lemmas Jan 11, 2024
@ehildenb ehildenb marked this pull request as draft January 12, 2024 16:43
@yale-vinson yale-vinson added the enhancement New feature or request label Jan 24, 2024
@yale-vinson
Copy link

Any update on this one? I see from two weeks ago you are investigating, but curious to see if you made any headway on it?

@ehildenb
Copy link
Member Author

ehildenb commented Feb 7, 2024

Subsumed: #2270
Subsumed: #2253

@ehildenb ehildenb closed this Feb 7, 2024
@ehildenb ehildenb deleted the bitwise-lemmas branch February 7, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants