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

Bounds checks for exponentiation #2072

Merged
merged 11 commits into from
Jun 30, 2020

Conversation

iamdefinitelyahuman
Copy link
Contributor

@iamdefinitelyahuman iamdefinitelyahuman commented Jun 30, 2020

What I did

Add overflow checks for exponentiation

Closes #1684
Closes #1685

How I did it

Given a ** b:

  • when a or b is a literal, calculate the highest possible variable value at compile-time, and perform a check against that value at runtime. The logic for finding the upper limits is thanks to @fubuloubu's proof of concept 🙏 I'm just a copy-paster
  • when both a and b are variables, raise an exception suggesting the use of pow_mod256
  • add a new builtin function pow_mod256 that allows access to the EXP instruction without any overflow checks

How to verify it

Run tests. I added quite a few new cases.

Cute Animal Picture

image

tests/fuzzing/test_exponents.py Show resolved Hide resolved
tests/parser/types/numbers/test_uint256.py Outdated Show resolved Hide resolved
vyper/context/types/value/numeric.py Show resolved Hide resolved
vyper/parser/expr.py Outdated Show resolved Hide resolved
vyper/parser/expr.py Show resolved Hide resolved
vyper/parser/expr.py Outdated Show resolved Hide resolved
vyper/parser/expr.py Outdated Show resolved Hide resolved
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 30, 2020

This pull request introduces 1 alert when merging e0c596a into bd8e0d3 - view on LGTM.com

new alerts:

  • 1 for Unused import

iamdefinitelyahuman and others added 2 commits July 1, 2020 00:39
Co-authored-by: Bryant Eisenbach <3859395+fubuloubu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants