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

Paper "Super-optimization of Smart Contracts" Appx. D may contain an incorrect rewrite rule #45

Open
msooseth opened this issue Feb 29, 2024 · 4 comments

Comments

@msooseth
Copy link

Appendix D of Super-optimization of Smart Contracts, rule 10 says: DIV(x, x) = 1 -- this is actually sadly not true in EVM as far as I understand. When x is zero, that value is actually 0, not 1. It can be checked here. Maybe this rule has a check that x must never be zero, so it may still be correct when applied in the code, but as it is stated in the paper I believe it may be incorrect. Unfortunately I couldn't find where this rule is applied in the code of gasol-opimizer so I couldn't verify how it's actually applied :S Sorry.

I hope the above helps,

Mate

@tutugordillo
Copy link
Member

Hi Mate! Thank you for the interest :-)
Yes, it's checked because first it tries to apply DIV(0,X) = 0 or DIV(X,0) = 0 and, after that, it checks DIV(X,X) so in case X =0 it applies always DIV(X,0) rule instead of DIV(X,X).

@msooseth
Copy link
Author

msooseth commented Feb 29, 2024

Ah, cool! And what if they are both symbolic? So let's say it's some:

DIV((SLOAD a) (SLOAD a))

Then the DIV(0, x) would not apply. Would it apply the DIV(x,x) rule in this case? Because the SLOAD a could be zero here I think? Or maybe it can never encounter this kind of symbolic expression?

@msooseth
Copy link
Author

BTW, I stole your other rules 😄 They are very cool, especially the IsZero rules we were definitely missing!

ethereum/hevm#463

@alexcere
Copy link
Member

alexcere commented Mar 4, 2024

Hi Mate,

Thanks once again for flagging the rule issue! You're right—we missed considering cases where symbolic expressions could represent zero values. In those cases, we shouldn't apply the rewrite rule. We'll fix it.

Glad to hear the rules are proving useful :)

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

No branches or pull requests

3 participants