Skip to content

TIP-907: Track overflow in melvm #63

@jaybutera

Description

@jaybutera
TIP 907
Category 9xx (consensus-breaking)
Author Jay Butera

Summary

Proposing the addition of a sticky overflow flag to melvm, and Oflo/Cloflo opcodes which push the flag's value to the stack and clears the flag to false respectively. This will allow programs to check if an arithmetic operation overflowed.

Motivation

Right now overflow on arithmetic is not explicitly reported in melvm. While it can be determined in some cases by the remaining value of an arithmetic expression, an overflow flow flag can help in the case that a sequence of arithmetic is done concluding with a final check.

Proposed changes

Add an overflow boolean to melvm's execution state. When an arithmetic operation (+,-,*,^) overflows it sets the overflow flag to true. When an op does not overflow it sets the flag to false. So in (x+y)+z the first addition might overflow but if the second does not then the overflow flag will be false after this expression. Therefore a user should check overflow directly after an operation where needed.

The Oflo opcode simply pushes the value in the overflow flag to the stack.

** edit: considering changes discussed below

Metadata

Metadata

Assignees

No one assigned

    Labels

    TIPThemelio Improvement Proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions