summaryrefslogtreecommitdiff
path: root/bip-0030.mediawiki
blob: bffd6df98b2f6c0697c5cc5feff2826978457fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<pre>
  BIP: 30
  Title: Duplicate transactions
  Author: Pieter Wuille <pieter.wuille@gmail.com>
  Status: Accepted
  Type: Standards Track
  Created: 22-02-2012
</pre>

==Abstract==
This document gives a specification for dealing with duplicate transactions in the block chain, in an attempt to solve certain problems the reference implementations has with them.

==Motivation==
So far, the Bitcoin reference implementation always assumed duplicate transactions (transactions with the same identifier) didn't exist. This is not true; in particular coinbases are easy to duplicate, and by building on duplicate coinbases, duplicate normal transactions are possible as well. Recently, an attack that exploits the reference implementation's dealing with duplicate transactions was described and demonstrated. It allows reverting fully-confirmed transactions to a single confirmation, making them vulnerable to become unspendable entirely. Another attack is possible that allows forking the block chain for a subset of the network.

==Specification==
To counter this problem, the following network rule is introduced:
*Blocks are not allowed to contain a transaction whose hash matches that of an earlier transaction in the same chain, unless that earlier transaction was already fully spent before said block.

This rule is to be applied to all blocks whose timestamp is after march 15, 2012, 0:00 UTC (unix timestamp 1331769600).

==Rationale==
Whatever solution is used, the following law must be obeyed to guarantee sane behaviour: the set of usable
transactions outputs must not be modified by adding blocks to the chain and removing them again. This happens during
a reorganisation, and the current Bitcoin reference implementation does not obey this law in case the temporarily
added blocks contain a duplicate transaction.

There are several potential solutions to this problem:
#Guarantee that all coinbases are unique, making duplicate transactions very hard to create.
#Remember previous remaining outputs of a given transaction identifier, in case a new transaction with the same identifier is added.
#Only allow duplicate transactions in case the previous instance of the transaction had no spendable outputs left. Removing a block from the chain can then safely reset the removed transaction's outputs to nothing.

The first option is probably the most complete one, as it also guarantees transaction identifiers are unique. However, implementing it requires several changes that need to be accepted throughout the network. Furthermore, it does not prevent duplicate transactions based on earlier duplicate coinbases. The second option is impossible to implement in a forward-compatible way, as it potentially renders currently-invalid blocks valid. In this document we choose for the third option, because it only requires a trivial change.

Fully-spent transactions are allowed to be duplicated in order not to hinder pruning at some point in the future. Not allowing any transaction to be duplicated would require evidence to be kept for each transaction ever made.

==Backward compatibility==
The addition of this rule only makes some previously-valid blocks invalid. This implies that if the rule is implemented by a supermajority of miners, it is not possible to fork the block chain in a permanent way between nodes with and without the new rule.

==Implementation==
A patch for the reference client can be found on https://github.com/sipa/bitcoin/tree/nooverwritetx

==Acknowledgements==
Thanks to Russell O'Connor for finding and demonstrating this problem and helping test the patch, and to Ben Reeves for pointing out a few weaknesses in the implementation.

[[Category:Developer]]
[[Category:Technical]]
[[Category:BIP|D]]