OpenZeppelin / openzeppelin-labs

A space for the community to interact and exchange ideas on the OpenZeppelin platform. Do not use in production!
https://openzeppelin.com/
MIT License
376 stars 116 forks source link

Attempt at a safer and better Initializable #113

Closed frangio closed 6 years ago

frangio commented 6 years ago

Here's a crazy idea... (This is labs after all. :man_scientist:)

Since modifiers are inlined, we can use the program counter to identify each separate initializer, and thus check that each of them is run exactly once. This solves the problem with multiple inheritance tackled by #111 and #112, and solves the problem with accidentally running an initializer twice in the contract hierarchy (although not statically as with normal constructors).

frangio commented 6 years ago

As we discussed offline, this approach alone doesn't work for upgrades, because the PC is likely to change, allowing an initializer to be re-run.

However, it can probably be used alongside one of the other approaches to prevent this situation.