by davepeck · 5y ago · 0 comments
While it’s certainly true that firmware on many devices can’t be or simply isn’t updated, it’s also the case that bugs ship. Because of this, engineers design and ship their more complex devices with the facility to upgrade firmware. Even my ages old stereo receiver is upgradable (although painfully so).
But this is about smart contracts: code that in many cases moves money. I’d put that in the category of code that really could benefit from carefully controlled upgradability.
I’m not the only one. For instance, the primary USDC contract on Ethereum is a proxy contract — it’s upgradable by design. I think that makes a lot of sense, and apparently so do the engineers managing those many billions of dollars: they’ve weighed the balance of “trust” in the abstract with “make sure it doesn’t break” in the real and made their decision.
Beyond that, a guiding principle of some newer blockchains (like Tezos) is that code will need to evolve over time. Like many things Web3, it’s too soon to tell how things will shake out in the long run, and a variety of approaches seems desirable.
First, if you're saying that you need a way to upgrade your money-managing code periodically because you will likely ship versions of it with show-stopping bugs (such as those that enable the destruction or theft of the users' funds), then why should I trust that you will ship flawless code for upgrades?
Second, if the combined security budget of the people who can carry out the upgrade is less than that of the majority of the block producers on the chain, then why build an upgrade procedure at all? Why risk it? Instead, just deploy a new version of the smart contract, and ask users to use that one instead. If it gets confirmed, then an honest majority of block producers will ensure that it stays confirmed. This takes no code at all. You simply sign the new code with the same key that deployed the old code to demonstrate that it originates from the same author(s). Let users decide on their own whether or not to use your upgraded code -- after all, it might introduce new bugs, and the "bugs" you are fixing might be features to other people. It's not your place to tell users what version of the code should be used, and what should not be used.
You shouldn’t, because no code of sufficient complexity is flawless.
> just deploy a new version of the smart contract
On the Ethereum blockchain (for instance) storage and smart contracts are tightly coupled. If you move to a new smart contract you may well lose your state. This is fine in many cases and preferable in some. But not in others!
So why build an upgrade procedure at all, when you don't have to?
> On the Ethereum blockchain (for instance) storage and smart contracts are tightly coupled.
Sounds like an unforced error on these smart contracts' authors parts, and should not be used as an excuse to compromise the principle of code immutability.
If the possibility existed that they need to replace the business logic at a later date, then they should factor the storage logic so as to avoid this coupling. It can be done -- for example, a smart contract dapp can leverage a shared contract that only implements a public key/value store, where the keys are prefixed by the calling contract's address. Then, when the business logic contract changes, it can access any old versions' state with the old versions' contract address, apply any migrations on-the-fly, and store new state that will not overwrite old state due to this key prefixing.
In the Stacks blockchain (which I work on), we go one step further by making it so you can run an arbitrary read-only code snippet on the state of the blockchain at any point in the past (as given by a block hash). Then, you don't even need to do any migrations -- you can just query the historic state of your old contract and only store new data once it's necessary.
Flaws, once known, can be remediated. I don’t think macOS has bulletproof security but I’m sure glad Apple keeps updating it.
> In the Stacks blockchain (which I work on), we go one step further by making it so you can run an arbitrary read-only code snippet on the state of the blockchain at any point in the past (as given by a block hash).
That’s a super interesting design point; I’m excited to see where that leads.
Out of curiosity, how does this typically get exposed in dApps (or wallet UIs) built on Stacks?
I can't see how the operation you describe here is defined or possible for any blockchain that hosts more than one smart contract. Just for a start, how do you decide whether to include a smart contract upgrade that the majority of verifiers doesn't care about either way (surely the most common case)? It's like saying that legislation doesn't matter because we have elections. The elections (consensus) produce the legislation (allowed transactions). You can squish those two layers together, but starts to break the premises of the underlying system (e.g. DAO fork).
I would love to know what software system you were thinking of when you wrote this. Or were you? Sincere question.
1. polygon is a cheap(as in transaction fees) knock off of Ethereum, competition good. bad from the perspective of capture value in the protocol.
2. as far as I can tell as long as one oracle doesn't become dominate that provides competition
3. Defi is enabling users value across other networks. uniswap, etc.
4. On a side note, not sure why there's not an api that encrypts an nft on ipfs and only returns the watermarked version unless you send it a fee. or your the owner.
What you describe could be rather easily implemented, but why would anyone build or use that?
By whom?
"Upgrading" a contract should require the approval of all parties to the contract.
(EDIT: if I’m reading my etherscan correctly, it’s account 0xfcb19e6a322b27c06842a71e8c725399f049ae3a with upgrade rights. Sorry, I’m in transit so tapping on my phone.)
(Obvious Darth Vader reference).
See 25. Amendments.
You might find these two blog posts useful:
1. OpenZeppelin’s post on the Ethereum proxy pattern: https://blog.openzeppelin.com/proxy-patterns/
2. USDC’s adventure in upgrading their contract: https://blog.coinbase.com/usdc-v2-upgrading-a-multi-billion-...