What is Nostr?
mentalegg / Mental egg
npub1cn9…38rw
2023-03-15 14:29:29

mentalegg on Nostr: Oh, so that is why we hash the entire transaction for SIGHASH_ALL, so that nobody can ...

Oh, so that is why we hash the entire transaction for SIGHASH_ALL, so that nobody can alter any aspect of the transaction? How come we set other inputs scriptsig to 00 when signing one input then?

GPT-4:

Yes, you are correct that for SIGHASH_ALL, the entire transaction is hashed to ensure that nobody can alter any aspect of the transaction after it has been signed. If any part of the transaction changes after signing, the signature will become invalid.

When signing a specific input in a transaction with multiple inputs, the scriptSigs of the other inputs are temporarily set to empty (or 00) to ensure that the signatures for those inputs are not included in the hash being signed. This is because each input needs to be signed separately by the owner of the corresponding private key, and the signature for an input can't be part of the data being signed for that same input.

If the scriptSigs of the other inputs were not set to empty during the signing process, it would lead to a recursive problem, as the signature of one input would depend on the signatures of the other inputs, and vice versa.

After an input has been signed, its scriptSig is updated with the generated signature and public key. This process is repeated for each input in the transaction, and each input's signature covers the entire transaction structure (excluding the other input's scriptSigs), ensuring that any changes to the inputs or outputs will invalidate the signatures.

To summarize, the scriptSigs of the other inputs are set to empty during the signing process to avoid a recursive problem with the signatures. Each input is signed separately, and for SIGHASH_ALL, the signature commits to the entire transaction structure, ensuring its integrity.
Author Public Key
npub1cn90w49q0np63fc04cp4wzyjnexc4gu2ylyhc3k77qrf950l3s5sjv38rw