-
Notifications
You must be signed in to change notification settings - Fork 2
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
mathSqrt summary #51
mathSqrt summary #51
Conversation
Rules for while are TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just a few clarification questions before approving it:
<call-stack>... .List => ListItem(frame(K, E, FUNC)) </call-stack> | ||
requires V >uMInt 3p256 [priority(40)] | ||
|
||
rule <k> mathSqrt:Id ( v(V:MInt{256}, uint256), .TypedVals ) => v (1p256, uint256) ...</k> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why the cells: <this-type>
, <contract-id>
, <contract-fn-id>
, etc. wouldn't be necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This rule replaces the entire call. So, we do not need to try and find the code of the function, we simply return a TypedVal. We know that a <contract-fn>
with <contract-fn-id> mathSqrt </contract-fn-id>
exists, but we do not need to find any information from the cells in that <contract-fn>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can think of it just like any other summary of en entire call (which it is with these conditions), e.g.
solidity-demo-semantics/src/uniswap-summaries.md
Line 2658 in c94634e
rule <k> uniswapV2LibrarySortTokens:Id ( v(V1:MInt{160}, address #as T), v(V2:MInt{160}, T), .TypedVals ) => v(ListItem(V1) ListItem(V2), T[]) ...</k> |
@@ -3280,6 +3280,13 @@ module SOLIDITY-MATHSQRT-SUMMARY | |||
<call-stack>... .List => ListItem(frame(K, E, FUNC)) </call-stack> | |||
requires V >uMInt 3p256 [priority(40)] | |||
|
|||
// While loop rewrite and condition evaluation | |||
rule <k> while (( x < z ) #as Cond) Body:Statement Ss:Statements => if (v(Vx <uMInt Vz, bool)) {Body while(Cond) Body} else {.Statements} ~> Ss ...</k> | |||
<summarize> true </summarize> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question from the case y <= 3 && y != 0
about the cell variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we are already within the body of the function mathSqrt
, i.e. to get to this rule the one doing the matching and changes to the configuration related to the call itself has already matched and done its rewriting. So, we don't need to match any of those cells.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR introduces summarized rules for the
mathSqrt
function.These rules are saving 818 steps.
I would like your opinion specifically on this rule here:
Due to the while statement rewriting to an if statement, as the function is executed, there are a lot of block statements that eventually lead to a sequence of
I added this rule to skip the unneeded updates. Due to the number of while loop body executions being input dependent, I cannot specify the exact number that this is repeated, so this is a step per loop iteration.
My question is: is this rule OK to include in a summary, or is it considered a general semantic rule?