owned this note changed 7 years ago
Linked with GitHub

用Solidity開發高效能智能合約 - 陳翊銓

歡迎來到 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 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

https://docs.google.com/presentation/d/137pYAOHGLr9gbD0Cx5ENPaDEZIXBizzdODLhC-vBAOM/edit#slide=id.p33

什麼是效能好的智能合約?

  • 速度快(x)
  • 記憶體少(x)
  • Gas 消耗少(O)

Gas 收費組成

  • 基本費
  • 傳輸資料
  • 執行的運算

優化重點

建立合約

  • 分析
    • 空合約 42901(total 64173)
    • ERC Token 697051
    • 刪除一個合約退 24999
      • 但執行刪除會消耗 6877 實際上最多,實際上節省 17000 左右
      • 節省不得超過Gass一半
        • 50000 -> 25000
        • 30000 -> 15000
  • 優化策略
    • 避免建立合約
      • Bad
      • GOOD
      • or

資料儲存

  • 分析
    • 新增 20000
      • 將 0 值改 0
    • 修改: 500
    • 刪除: 省 15000
      • 將非0值改為0值
      • 但會算一次修改,實際上最多-10000
      • 節省不得超過總Gas一半
    • 256 bit 為一資料區塊
      • 同一區塊(256bit 變數)同時寫入僅計算一次
  • 優化策略
    • 將可以湊滿 256 的變數排在一起
    • 將共同使用的變數排在一起

交易資料

  • 分析
    • 基本費21000

    • Input data

      • 每Byte收費68 Gas
      • 若Byte為00收費4 Gas
    • 例如

      • 0x0dbe671f: 68 * 4 = 272
      • 0x0000001f: 68 * 1 + 4 * 3 = 80

轉帳

tags: COSCUP2018 blockchain
Select a repo