7

I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?

For example, does the transaction need to have a specific structure in order to be spent, like the script from TxIn needs to compile to the encoded message, and the TxOut script needs to properly run OP_Checksig on that particular message? If not, one could simply drop the message from TxIn, push their own malicious message and run OP_Checksig on that.

What steps does the protocol require a client to go through to check if the transaction is valid?

  • It's not clear what you're asking. By "valid" do you just mean that the client won't consider a block invalid if it contains that transaction? Or by "valid" do you mean the default client will include that transaction in blocks it generates? Or by "valid" you mean the default client will relay it to other nodes? Or something else? There are different checks on transactions to decide if they are "valid" for a number of different purposes. For example, consider a transaction that spends coins not yet available but that could become available. In some senses, that's valid. In some, not yet. – David Schwartz Jan 5 '12 at 2:21
  • @DavidSchwartz I suppose all of the above would be useful, but mainly I was thinking about including the transactions in the block. – ThePiachu Jan 5 '12 at 10:51
3

On the bitcoin wiki, there is rather complete list of validation checks that are done by the Satoshi client: Protocol_rules.

There is a section specifically about transaction checking as well.

0

I recommend using the bitcore library built by BitPay which has a transaction.verify() function that works well.

You can also attempt to decode a transaction hex using this blockcypher tool and if it decodes properly and all of the components of a valid transaction are there, then your transaction should be good to go

-1

I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?

You check the chain, if it goes all the way back to a generation, it is valid. You must wait for a confirmation to get it set in stone.

What steps does the protocol require a client to go through to check if the transaction is valid?

https://github.com/bitcoin/bitcoin/tree/master/src

  • Well, quite more than "a [single] confirmation" to "set [it] in stone". – o0'. Apr 5 '12 at 11:08
  • Though you're technically correct in saying that you need to check the chain all the way back to generation, this is not useful. Clients only store the part of the chain they've verified to be valid, and the only thing they need to check is whether it correctly connects to the transactions therein. Also, transactions are never entirely set in stone, but each confirmation significantly reduces the chance for reverting further. – Pieter Wuille May 5 '12 at 12:06
  • There has not been and there will likely not be a single Chain Fork attack. It is not worth it, it is unlikely, it has not happened. fThe only ever attack to the Bitcoin Client or Chain was an Integer Overflow back at the beginnings of time. – Fabián Heredia Montiel May 5 '12 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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