15

I'm building a smart contract that is sort of an index of signed documents (pointing to ipfs for the actual docs).

What if I want to add some functionality to my app down the road and need to upgrade the contract?

I understand I need to make a new contract, but how about transferring the current state of the old contract to the new?

Would it cost a lot of XTZ to initialize a new contract with a big state? Is there another approach for achieving this?

3 Answers 3

9

Because values of type lambda can be kept in storage or passed as parameters (either as lambda or as bytes to be UNPACKed), it is possible to write contracts which can upgrade themselves... This won't always make sense, but might sometimes be useful.

For example, one of the very early mainnet contracts appears to have a kind of upgrade mechanism: https://tzscan.io/KT1R3uoZ6W1ZxEwzqtv75Ro7DhVY6UAcxuK2. The configured owner can supply a lambda to one of the entry points, which will be placed in storage and will override the contract's behavior in some cases.

0
10

Disclaimer: This is just an example for educational purposes, don't use it in production.

Here is a fairly primitive upgradable design for a Liquidity smart contract:

Amendable smart contract

Proxy Contract

  • Holds the state / storage
  • Points to a Logic Contract, and proxies its entry points
  • Can be amended / upgraded, by its rightful owner. You can run into decentralization / governance issues here - all the underlying logic contract changes are still tracked on-chain, so it's a trade-off.
  • Exposes an entry point setData, consumed by the Logic Contract to apply storage changes

Logic Contract

  • Is called exclusively by the Proxy Contract
  • Each entry point call, results into a setData entry point call on the Proxy Contract

In theory, you should be able to implement this using Liquidity's 'module-like contract system'. For the above described to work well, you must carefully implement a decent ACL (who can call which entry points).

0
2

Cryptonomic published an article on exactly this topic recently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.