owned this note changed 7 years ago
Linked with GitHub

如何撰寫可更新的智能合約 - 吳冠融

歡迎來到 https://hackmd.io/c/COSCUP2018 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

為何需要更新智能合約

  • BUG
  • 新功能

智能合約經部署便不可修改

  • 繞過它
  • 部署新的合約,將所有舊的資料都備份過來,並告訴使用者新的合約地址

問題

  • 使用者沒更新(小問題)
  • 舊的資料難以轉移
    • 消耗大量 GAS
    • Not Scalable

解決方法

  • 一開始就把合約內容和資料分開
    • Logic Contract
    • Data Contract
      • 只能被 Logic Contract 呼叫
      • 更新合約時,更新 Data Contract 的 owner 並通知使用者用新的 Logic Contract
    • 註冊一個新的 ENS
      • 讓 ENS 指到合約
      • 對外使用 ENS 溝通
      • 更新時僅需要將 ENS 指到新的合約

如何同時保留資料及地址

Delegate call

我照著你說的做

  • 讓某合約去 call 不同合約內的 Function

    • 對外:Proxy Contract
    • Proxy Contract 透過 Delegate call 跟 Logic Contract 溝通
    • Proxy 大約會多花 1400 GAS
  • 如何更新 ERC 20

How 如何實踐

zeppelin_os

When 何時使用可更新合約

合約不可更新也是可以加入新功能
不可更新才值得信任

Is Upgradeable Token a Good Idea ?

tags: COSCUP2018 blockchain
Select a repo