Bitcoin Transaction Malleability
eklitzke.org
eklitzke.org
This is incorrect. Each Bitcoin transaction input references a previous transaction output as the txid+output index. Transactions spending unconfirmed outputs are orphaned when the parent is malleated and confirmed.
Also, as a data hash with no checksum, txids are not convenient for humans at all.
> Transaction malleability is already more or less fixed in Bitcoin
A couple months ago, there was a significant malleability attack on the Testnet, in which nearly every transaction was malleated as it was included in a block.
https://github.com/bitcoin/bitcoin/commits/master?author=gma...
The more interesting problem was that this was non deterministic, you could encode fields with 64bit integers and they would bomb out on 32bit systems. ASN1 is also mind bogglingly complex, you can encode to arbitrary depths completely nonsensical things like negative numbers and strings, containers of multiple elements, none of the implementations manage to decode blocks the same or adhere to the same limits.
- All numbers are parsed as nonnegative integers, even though X.609-0207 section 8.3.3 specifies that integers are always encoded as two's complement.
- Integers can have length 0, even though section 8.3.1 says they can't.
- Integers with overly long padding are accepted, violation section 8.3.2.
- 127-byte long length descriptors are accepted, even though section 8.1.3.5.c says that they are not.
- Trailing garbage data inside or after the signature is ignored.
- The length descriptor of the sequence is ignored.
But some things were just too awful to implement, e.g.
- Using overly long tag descriptors for the sequence or integers inside, violating section 8.1.2.2.
- Encoding primitive integers as constructed values, violating section 8.3.1.
This last is especially fun, in OpenSSL you can create a constructed value (like a struct) of constructed values of constructed values of strings.. and it will just concatenate up all the bytes in the last level primitive elements and treat the result as a number. ... but only if it's not more than 7 (IIRC) levels deep.
And if you want to see what a malleability attack looks like at the byte level, I analyzed one three years ago: http://www.righto.com/2014/02/bitcoin-transaction-malleabili...
So the signature can be mutated as the author suggests, but the signature doesn't sign the entire section of the transaction anyway (where data is provided to the redeemScript to satisfy its conditions. This section called the scriptSig includes the sig which cannot sign itself.)
So with the scriptSig, anyone is free to add whatever new data they like to this section which gets added to the input stack, and as long as you leave the stack the same way as you found it you can insert any arbitrary junk as you like and it will change the resulting TXID as seen in the blockchain without invalidating the transaction.
This is a bad thing for "smart contracts" on Bitcoin because many contracts depend on making chains of unconfirmed, future transactions, based on hashing the entire transaction to compute its TXID (as Clarkmoody suggests.) An example of this is a cross-chain contract where you might want to send funds to a partially shared address between a stranger and yourself, and you need a way to setup a time-locked refund in case the protocol doesn't succeed (no longer necessary due to OP_CHECKLOCKTIMEVERIFY but its an example.)
To do refunds in this way you would need to be able to sign chains of unconfirmed transactions without previous transaction IDs being changed from transaction malleability. Bitcoin does include a fix for this called "segregated witness" but the fix has been controversial. I don't keep up to date with the "scaling progress" now but I doubt it has been merged yet.
I expect they are serious and we will have a fork into BCC (Bitcoin cash) and BTC (bitcoin)
Certainly on the BTC chain segwit will be locked in. Whether it claims the mantle of "bitcoin" or not is to be seen.