-
-
Notifications
You must be signed in to change notification settings - Fork 871
Description
Simple Summary
per title
Motivation
once EIP-1153 is enabled, the cost of disabling re-entrancy into a contract before the selector table is even traversed comes down to two TSTOREs and one TLOAD, so approximately 300 gas, which is a small overhead compared to even the cost of a warm CALL, 200 gas. re-entrancy attacks are one of the biggest sources of vulnerabilities in smart contracts (todo: gather some hard stats on this), and it makes sense from a safety perspective to disable them by default. in the future, i also expect a future EIP will bring the cost of TLOAD/TSTORE down in the general case.
Specification
there are multiple possibilities here:
- introduce a
LOCKkeyword, which creates critical section/non-reentrant blocks. ex.LOCK: some_contract.foo() # re-entrancy back into this contract unavailable here - disallow re-entrancy entirely (allow re-entrancy at call site by a new syntax), ex.
some_contract.foo() # re-entrancy back into this contract unavailable here some_contract.foo(..., reeentrant_functions=(func1, func2)) # func1 and func2 can be re-entered into some_contract.foo(..., reentrant_functions=*) # all functions can be re-entered into
EDIT: it seems the preferred implementation in terms of language design will be to remove the current @nonreentrant decorator and replace with an @reentrant decorator (with inverted semantics)
Backwards Compatibility
this fundamentally changes the behavior of existing vyper contracts. to discuss.
Dependencies
will be cleaner to implement syntax-wise with the addition of #2856.
References
Copyright
Copyright and related rights waived via CC0