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

VIP: Implement short circuiting #1817

Closed
iamdefinitelyahuman opened this issue Jan 7, 2020 · 1 comment · Fixed by #2069
Closed

VIP: Implement short circuiting #1817

iamdefinitelyahuman opened this issue Jan 7, 2020 · 1 comment · Fixed by #2069
Assignees
Labels
VIP: Approved VIP Approved

Comments

@iamdefinitelyahuman
Copy link
Contributor

Simple Summary

Add short circuiting logic to binary operations.

Motivation

  1. This is pretty standard behavior in most programming languages - I believe the majority of users will assume that it already happens and write their code accordingly.
  2. By not doing it, we make transactions less efficient through unnecessary evaluation.
  3. We introduce a risk for exploits due to unexpected behavior:
@private
def a() -> bool:
    return True

@private
def b() -> bool:
    steal_the_money()
    return True

@public
def foo():
    if a() or b():
        # something mostly harmless

Specification

Treat and and or as short-circuit operators: evaluate them left to right, and stop evaluation as soon as an outcome is determined.

Backwards Compatibility

This will alter behavior in contracts, but should not introduce any breaking changes.

Copyright

Copyright and related rights waived via CC0

@fubuloubu fubuloubu added the VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting label Jan 8, 2020
@fubuloubu fubuloubu added VIP: Approved VIP Approved and removed VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting labels Jan 20, 2020
@fubuloubu fubuloubu added this to the v0.2 Release milestone Jun 21, 2020
@fubuloubu
Copy link
Member

In hindsight, I don't think this needs to be on the v0.2.0 milestone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VIP: Approved VIP Approved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants