Skip to content

Upstream first batch of lemmas from Lido engagement #2787

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lucasmt
Copy link
Contributor

@lucasmt lucasmt commented Jul 28, 2025

Lemmas were taken from this file: https://github.com/runtimeverification/_audits_lidofinance_dual-governance_fork/blob/rv-extension-refactor-full-suite/test/kontrol/lido-lemmas.k. Not all of the lemmas have been included, as some of them require further analysis.

rule 0 <Int X => true requires 0 <=Int X andBool notBool (X ==Int 0) [simplification(60)]

rule X <=Int maxUInt256 => X <Int pow256 [simplification]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not entirely sure these three lemmas are strictly necessary. They seem to be things that the SMT solver could easily resolve, but maybe they can help trigger further simplifications.

andBool 0 <Int C
andBool A <Int ( C *Int B )
[simplification, symbolic(A, B), concrete(C), preserves-definedness]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fairly specific lemma, but I suppose it might be worth having if we run into an expression like this again.

@@ -239,4 +239,7 @@ module LEMMAS-HASKELL [symbolic]

rule (notBool (A andBool B)) andBool A => (notBool B) andBool A [simplification]

rule [notBool-or]: notBool ( A orBool B ) => ( notBool A ) andBool ( notBool B ) [simplification(60)]
rule [notBool-and]: notBool ( A andBool B ) => ( notBool A ) orBool ( notBool B ) [simplification(60)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set a later priority for these rules so they don't conflict with the preceding ones.

#asWord ( B1 +Bytes B2 ) <Int X => #asWord ( B1 ) <Int X /Int ( 2 ^Int ( 8 *Int lengthBytes ( B2 ) ) )
requires X modInt ( 2 ^Int ( 8 *Int lengthBytes ( B2 ) ) ) ==Int 0
[simplification, preserves-definedness]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if too specific. I considered if it should use the concrete(X) attribute, but if it didn't include it in the first place it's probably because the expression that originally motivated it had a symbolic X.

rule [b2w-lt]:
bool2Word ( B:Bool ) *Int X <Int Y =>
( ( notBool B ) andBool 0 <Int Y ) orBool ( B andBool X <Int Y )
[simplification, concrete(Y)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the original file this had a typo, ( notBool B ) andBool 0 <=Int Y.

Comment on lines +94 to +96
X xorInt Y <Int Z => true
requires X <Int ( 2 ^Int log2Int ( Z ) ) andBool Y <Int ( 2 ^Int log2Int ( Z ) )
[simplification, concrete(Z)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need an additional constraint for Z >Int 0 to avoid the log2Int undefinedness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'll add the constraint

@lucasmt lucasmt force-pushed the upstream-lido-lemmas branch from 2fdfcac to f432111 Compare August 1, 2025 15:08
@lucasmt lucasmt marked this pull request as ready for review August 1, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants