Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add a decorator called
Using a lock around a function call one can prevent a function doing send / external call with value to do a re-entrant call.
Re-entrancy is super difficult to detect as a programmer, Vyper should make it simple not to introduce or hard to get wrong.
As an extra security measure it is encouraged to force the usage of
Using a unique identifier per function (derivitive of method_id), we can set a lock per function. See https://github.com/protofire/zeppelin-solidity/blob/master/contracts/ReentrancyGuard.sol.
In pseudo vyper code this would be the equivelant of something like:
locks: map(bytes32, bool) def withdraw(): assert self.locks[method_id('withdraw()', bytes32)] == False self.locks[method_id('withdraw()', bytes32)] = True # Body of code. self.locks[method_id('withdraw()', bytes32)] = False
This will effect backwards compatibility if this becomes a forced decorator, if only an optional decorator it will not effect backwards compatibility.
Optional Implementation of
Copyright and related rights waived via CC0
I don't think we should "enforce" this as a default, rather this is a good tool for developers to use in situtations where it is called for
We should instead raise warnings of when a function should have this decorator, to reinforce the pattern that not every function will need it