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

Simplify exponentiation in SMT backend #106

Merged
merged 7 commits into from
May 12, 2021
Merged

Conversation

kjekac
Copy link
Collaborator

@kjekac kjekac commented May 11, 2021

Closes #99, i.e. we can now pass any exponentiation where the exponent is concrete to the SMT backend even though it has no support for exponentiation. This does not however include any algebraic analysis to attempt to simplify away symbolic values.

I'm a bit uncertain on how division is to be dealt with. Currently I'm using div and mod from Haskell's Prelude (rather than quot and rem). This is because they truncate towards negative infinity, which is what the EVM seems to be doing according to the yellow paper. But what exactly are we trying to agree with? The EVM? In that case x/0 should be 0, so we need a special case for that. Or Solidity? Or our other backends?

@kjekac kjekac requested review from d-xo and MrChico May 11, 2021 12:13
@MrChico
Copy link
Member

MrChico commented May 11, 2021

But what exactly are we trying to agree with? The EVM? In that case x/0 should be 0, so we need a special case for that. Or Solidity? Or our other backends?

IMO, specs should conform to "mathematical rigor", and not so much evm details, meaning I think we should ideally disallow specs which admit division by zero as part of future spec validity checking (discussed at #14).

-- Returns `Nothing` if the expression contains symbols.
eval :: Exp a -> Maybe a
eval e = case e of
And a b -> [a' && b' | a' <- eval a, b' <- eval b]
Copy link
Member

Choose a reason for hiding this comment

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

monad comprehension! Cool, haven't seen this before

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In lieu of idiom brackets you take what you can get :)

@kjekac
Copy link
Collaborator Author

kjekac commented May 11, 2021

But what exactly are we trying to agree with? The EVM? In that case x/0 should be 0, so we need a special case for that. Or Solidity? Or our other backends?

IMO, specs should conform to "mathematical rigor", and not so much evm details, meaning I think we should ideally disallow specs which admit division by zero as part of future spec validity checking (discussed at #14).

Ok so following that reasoning we want to truncate downwards instead of towards zero, since that's how Euclidean division works. Then the code here should be correct.

src/SMT.hs Outdated Show resolved Hide resolved
@kjekac kjekac merged commit 3992302 into master May 12, 2021
@kjekac kjekac deleted the simplify-exponentiation branch May 12, 2021 16:38
@kjekac kjekac restored the simplify-exponentiation branch May 12, 2021 16:39
@kjekac kjekac deleted the simplify-exponentiation branch May 12, 2021 16:39
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.

SMT: further simplify exponentiation expressions
3 participants