Transaction-Verification

OP_CHECKSIG 是如何工作的

  • August 29, 2019

嗨,我正在學習比特幣並學習腳本的工作原理以及如何使用 P2PKH。我想知道 OP_CHECKSIG 是如何工作的。我想了解私鑰簽名以創建數字簽名本身的數據是什麼?

是否有一個簡單的解釋來說明如何建構數字簽名以在 OP_CHECKSIG 中進行驗證?我了解 Opcode 使用 ECDSA 算法來驗證簽名,但我想了解如何生成簽名以進行驗證?

如果這是一個基本問題,請原諒我。謝謝

簽署的是交易的簡化版本(替換 scriptSig,因為這是我們正在創建的)。這裡有很多,所以希望我涵蓋了所有內容:

* `version` (4 Bytes) - Transaction format version
* `flag` (2 Byte Array) - Optional flag, if present, must be 0001, which indicates there is witness data in this transaction
* `input counter` (Variable Length) - Number of inputs in the transaction represented by a Variable Length Integer.
* `inputs` (based on Input Counter) - List of all transaction inputs which will be spent and which reference unspent transaction outputs from previous transactions.
* `output counter` (Variable Length) - Number of outputs in the transaction represented by a Variable Length Integer.
* `outputs` (based on Output Counter) - List of all transaction outputs where the coins will be sent and which will become unspent transaction outputs to be spent in future transactions.
* `scriptsig` (variable) - First, a one-byte varint which denotes the length of the scriptSig, then it is temporarily filled with the scriptPubKey of the output we want to redeem.
* sequence number (4 Bytes) - Used as a relative lock time if transaction version is >= 2. See BIP68.
* one-byte varint containing the number of outputs in our new transaction
* 8-byte field (64 bit integer) containing the amount we want to redeem from the specified output (in satoshis)
* one-byte varint denoting the length of the output script
* output script
* `locktime` (4 Bytes) - If non-zero and sequence numbers are < `ffffffff`: it represents either the block height or timestamp when transaction is final.
* four-byte "hash code type" (1 in our case): 01000000 see [Sighash types][1]

然後,雙 SHA256 散列整個結構,散列就是簽名的內容。例如,請參閱<https://bitcoin.stackexchange.com/a/5241/60443>

引用自:https://bitcoin.stackexchange.com/questions/90087