Skip to content

VIP: Implement short circuiting #1817

@iamdefinitelyahuman

Description

@iamdefinitelyahuman

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

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions