vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.89k stars 800 forks source link

VIP: Use REVERT opcode for assert statement #478

Closed jacqueswww closed 6 years ago

jacqueswww commented 6 years ago

This is the suggested template for new VIPs.

Preamble

VIP: 478
Title:  REVERT for assert
Author: Jacques Wagener
Type: Standard Track
Status: Draft
Created: 2017-11-17

Simple Summary

The assert statement should be converted to use REVERT opcode.

Abstract

Suggests changing the assert statement to using REVERT opcode underlying, allowing gas to be remaining gas be returned.

Motivation

Most scenarios one would prefer remaing gas to be sent back, and not completely absorbed. Currently the assert statement in Viper produces a an invalid jump, draining all gas.

Specification

Syntax wise assert statys exactly the same:

def test(x: num) -> bool:                                                                                                                                           
    assert x > 0                                                                                                                                                    
    return True 

Backwards Compatibility

Previous Dapps or contracts that assumed gas will completely spent after a failed assert, will now receive gas back. It doesn't effect compatibility much, as viper isn't used in production yet.

References

https://github.com/ethereum/eips/issues/140

Copyright

Copyright and related rights waived via CC0

jacqueswww commented 6 years ago

Whether a secondary keyword for 0xfd (INVALID) asserts are necessary, should be discussed - however I much prefer only having assert, having multiple require/assert/require keywords tends to just be confusing. And I don't really see the need for a throw/assert keyword that drains all gas ?

fubuloubu commented 6 years ago

Yeah, I agree. I don't think there is a need to use the opcode that drains all gas. Perhaps this INVALID opcode might not be as useful as originally intended? Unless it is there as a means to punish abuse of the system, like in overflows, recursion issues, loop issues, etc.