• <option id="cacee"><noscript id="cacee"></noscript></option>
  • <table id="cacee"><noscript id="cacee"></noscript></table>
  • <td id="cacee"></td>
  • <option id="cacee"></option>
  • <table id="cacee"></table>
  • <option id="cacee"><option id="cacee"></option></option>
  • <table id="cacee"><source id="cacee"></source></table><td id="cacee"><rt id="cacee"></rt></td>
    <option id="cacee"><option id="cacee"></option></option>
     找回密碼
     立即注冊

    掃一掃,登錄網站

    首頁 百科 查看內容
    • 9524
    • 0
    • 分享到

    探討更簡單的以太坊多重簽名合約

    2018-5-11 12:31

    來源: 零識區塊鏈 作者: Christian Lundkvist

    區塊鏈中的智能合約完整代碼


    完整的代碼為:
    pragma solidity 0.4.14;
    contract SimpleMultiSig {
     
      uint publicnonce;                // (only) mutablestate
      uint publicthreshold;            // immutable state
      mapping(address => bool) isOwner; // immutable state
      address[]public ownersArr;        // immutablestate
     
      function SimpleMultiSig(uint threshold_,address[] owners_) {
        if(owners_.length > 10 || threshold_ > owners_.length || threshold_ == 0){throw;}
     
        for (uinti=0; i
         isOwner[owners_[i]] = true;
        }
        ownersArr= owners_;
        threshold= threshold_;
      }
     
      // Notethat address recovered from signatures must be strictly increasing
      functionexecute(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uintvalue, bytes data) {
        if(sigR.length != threshold) {throw;}
        if(sigR.length != sigS.length || sigR.length != sigV.length) {throw;}
     
        //Follows ERC191 signature scheme: https://github.com/ethereum/EIPs/issues/191
        bytes32txHash = sha3(byte(0x19), byte(0), this, destination, value, data, nonce);
     
        addresslastAdd = address(0); // cannot have address(0) as an owner
        for (uinti = 0; i < threshold; i++) {
           address recovered = ecrecover(txHash, sigV[i], sigR[i], sigS[i]);
            if(recovered <= lastAdd || !isOwner[recovered]) throw;
           lastAdd = recovered;
        }
     
        // If wemake it here all signatures are accounted for
        nonce =nonce + 1;
        if(!destination.call.value(value)(data)) {throw;}
      }
     
      function ()payable {}
    }
    此代碼也可以在github中找到。

    效益

    此合約的有益屬性包括:
    l  最小代碼庫:只有40行代碼
    l  最少可變狀態:唯一可變的數據是,每一次執行都會增加一個單元(unit)。
    l  最小界面:由單一功能構成的界面.
    l  能夠發送任意交易,故而支持代幣(token)

    由于缺乏復雜的狀態轉換,在沒有資金的情況下,該合約便無法轉入“凍結”狀態。而因為唯一可能的狀態轉換是簡單的增量計數器,所以該合約永遠處于正確狀態。且由于使用了32字節的整數,計數器便不可能溢出。同時,測試也變得更簡單了,因為事實上(除構造函數外)只有一個函數需要測試。
     
    但由于我們盡可能地簡化了鏈上邏輯,因而增加了鏈下工作流程的復雜性,這便導致了一些缺陷與不足,比如:
    l   需要用戶給非交易簽名,而這可能妨礙某些硬件錢包的使用
    l  為了發送交易,需要終端用戶進行鏈下協調。

    版權申明:本內容來自于互聯網,屬第三方匯集推薦平臺。本文的版權歸原作者所有,文章言論不代表鏈門戶的觀點,鏈門戶不承擔任何法律責任。如有侵權請聯系QQ:3341927519進行反饋。
    相關新聞
    發表評論

    請先 注冊/登錄 后參與評論

      回頂部
    • <option id="cacee"><noscript id="cacee"></noscript></option>
    • <table id="cacee"><noscript id="cacee"></noscript></table>
    • <td id="cacee"></td>
    • <option id="cacee"></option>
    • <table id="cacee"></table>
    • <option id="cacee"><option id="cacee"></option></option>
    • <table id="cacee"><source id="cacee"></source></table><td id="cacee"><rt id="cacee"></rt></td>
      <option id="cacee"><option id="cacee"></option></option>
      妖精视频