I am familiar with the many ways an unlocking script is created. But in this scenario, lets use P2PKH. When we generate the unlocking script (excuse the simplicity):

<dup> <hash160> <wallet address> <equalverify> <checksig> |<signature> <Public Key>

Does a node such as a mining node push this data into the stack and verify it using the opcodes or is it the wallet software?

2 Answers 2


To be clear, what you list is both the locking and unlocking script:

  • The locking script: DUP HASH160 <recipient address> EQUALVERIFY CHECKSIG
  • The unlocking script: <signature> <pubkey>

The locking script (scriptPubKey) is part of the transaction where the sender S pays the recipient R. The unlocking script is part of any transaction where R uses their received money to send it further to a destination D.

So to be clear, in the example I'm describing there are two transactions: one from S to R, and later one from R to D.

  • In the first step, R gives their address to S. S constructs a transaction with some of their own inputs, along with an output to R, in the form of the locking script above.
  • In the second step, D gives their address to R. R constructs a transaction with as input the funds sent by S and the unlocking script above to authorize spending it, and an output which has a locking script based on D's address.

That R->D transaction (the one with <signature> <pubkey> in) undergoes the following steps:

  • It is created by R's wallet which likely does some basic safety check on it
  • It is sent out by R's wallet, and then relayed further to other nodes. If those are full nodes, they will validate the script, by executing the scriptSig, yielding [sig pubkey], and feeding that as input to the previous transaction's scriptPubKey (which will, if the signature and public key are valid, evaluate to true). If this evaluation returns failure, the transaction is ignored. Not all nodes are full nodes, and some may skip the full checking.
  • At some point the transaction reaches its destination D, which is a node like any other, and may or may not do full validation on it, depending on the software used.
  • At some point the transaction reaches one or more miners, who will hopefully include it in their next attempt to construct a block. Miners ought to perform full validation on the transaction, because if they don't, and include the transaction in a block despite being invalid, then that entire block will be invalid, and ignored by the network's full nodes.

Does a node such as a mining node push this data into the stack and verify it using the opcodes or is it the wallet software?

The wallet will construct a transaction that provides the unlocking script and transfers to the new locking condition. Then this transaction will be propagated to the rest of the network typically by the full node associated with that wallet. When other nodes receive this transaction they verify that the unlocking script meets the conditions needed to transfer those Bitcoin (and it is a valid transaction). If it does they accept into their mempool. Miners should also verify that the transaction is valid before considering whether to include that transaction in a block that they are attempting to mine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.