Multisignature

我應該在 MultiSigWallet Contract 的函式中為這些參數輸入什麼?

  • February 21, 2019

在此處輸入圖像描述

這些是參數,包含在合約 multiSigWallet{} 的函式 sendMultiSig() 中。

如何輸入 expireTime 和簽名?誰將成為toAddress?一個msg.sender?簽名者?還是非簽名者?

function sendMultiSig(
   address toAddress, 
   uint value, 
   uint expireTime, 
   uint sequenceId, 
   bytes signature
) 
   onlysigner 
   payable 
{
   // Verify the other signer
   var operationHash = sha3("ETHER", toAddress, value, expireTime, sequenceId);

   var otherSigner = verifyMultiSig(toAddress, operationHash, signature, expireTime, sequenceId);
}

function verifyMultiSig(
   address toAddress, 
   bytes32 operationHash, 
   bytes signature, 
   uint expireTime, 
   uint sequenceId
) 
   private 
   returns (address) 
{

   var otherSigner = recoverAddressFromSignature(operationHash, signature);

   // Verify if we are in safe mode. In safe mode, the wallet can only send to signers
   if (safeMode && !isSigner(toAddress)) {
       // We are in safe mode and the toAddress is not a signer. Disallow!
       revert();
   }
   // Verify that the transaction has not expired
   if (expireTime < block.timestamp) {
       // Transaction expired
       revert();
   }

   // Try to insert the sequence ID. Will throw if the sequence id was invalid
   tryInsertSequenceId(sequenceId);

   if (!isSigner(otherSigner)) {
   // Other signer not on this wallet or operation does not match arguments
       revert();
   }
   if (otherSigner == msg.sender) {
       // Cannot approve own transaction
       revert();
   }
   return otherSigner;
}

function recoverAddressFromSignature(
   bytes32 operationHash, 
   bytes signature
) 
   private 
   returns (address) 
{
   if (signature.length != 65) {
       revert();
   }
   // We need to unpack the signature, which is given as an array of 65 bytes (from eth.sign)
   bytes32 r;
   bytes32 s;
   uint8 v;
   assembly {
       r := mload(add(signature, 32))
       s := mload(add(signature, 64))
       v := and(mload(add(signature, 65)), 255)
   }
   if (v < 27) {
       v += 27; // Ethereum versions are 27 or 28 as opposed to 0 or 1 which is submitted by some signing libs
   }
   return ecrecover(operationHash, v, r, s);
}

根據您提供的資訊,該合約應該是一個多重簽名錢包,需要收集多個簽名者的批准才能將一些代幣/乙太幣發送到接收者賬戶。由於前綴,它很可能是“乙太”交易。可以呼叫該sendMultiSig()函式的帳戶是簽名者。

讓我們分解所需的輸入。

  • toAddress:期望接收address類型的欄位。它應該是代幣/乙太幣交易的接收者。該地址可以是msg.sender簽名者或非簽名者。但是,當合約進入“安全模式”時,只有可接受的地址是簽名者

  • value:要交易的金額。

  • expireTime:收集所有必要簽名以驗證交易的截止日期。在此時間點之後,交易被視為“過期”。expireTime採用“unix 時間戳”的形式。要將自然時間轉換為 unix 時間戳,您可以使用此網站

  • sequenceId:從您提供的程式碼段中不清楚。我猜這是交易的唯一ID。

  • signature:來自另一個簽名者的先前簽名的消息。此簽名由另一個簽名者(不同於將要呼叫該sendMultiSig()函式的帳戶)提供,並使用web3.eth.sign(dataToSign, addressWithPrivateKey) 有關此函式的更多資訊進行計算。這裡dataToSign是某個值的雜湊(sha3更具體地說是keccak256)。這些值包含:

    • “醚”
    • toAddress
    • value
    • expireTime
    • sequenceId

引用自:https://ethereum.stackexchange.com/questions/66065