bigchaindb / bigchaindb

Meet BigchainDB. The blockchain database.
https://www.bigchaindb.com/
Apache License 2.0
4.03k stars 772 forks source link

Handle transaction reordering attacks #345

Open ttmc opened 8 years ago

ttmc commented 8 years ago

When transactions arrive at a node, can the node undetectably change their order (sequence) before writing them to the backlog? Similarly, can a node change the order that it writes transactions (from the same public key) to blocks? It wouldn't have to do this on a large scale; it could just switch the order of two transactions.

Sometimes it doesn't matter if the order of two transactions gets changed, but sometimes it does. For example, if Bob first transfers his dog to Jack, and shortly thereafter tries to transfer it to Mike, the second transfer should fail because Bob no longer owns the dog. Now imagine if the "transfer to Mike" transaction gets re-ordered to come before the "transfer to Jack" transaction...

Possible solutions

Non-solutions

Related issue: issue #327

ssadler commented 7 years ago

Unfortunately I think this is Jack's problem isn't it? Our HTTP server replies with "202 ACCEPTED" for this reason, that the transaction has been accepted for processing but it is not yet complete. Jack must then demand that Bob wait until the transaction part of a valid block, ie, it's a payment clearing time.

In the possible solutions above, neither sequence number nor hash of previous transaction are a solution to the possible double spending issue.

ttmc commented 7 years ago

This issue isn't about catching double-spending. We already do that. The second transaction would be the one deemed invalid, because it's trying to spend an output that's already spent. The problem is that a malicious node could change which transaction is the second one.

ttmc commented 6 years ago

Right now, we can't guarantee that some transactions sent from a client in the order A, B, C will get processed in the same order (A, B, C). One way to ensure that would be to add a "client sequence number" (integer) to the body of the transaction model, with the idea that a transaction can't be processed until all sequence numbers before it have been processed. (Or maybe the transaction is considered invalid and dropped if there are some earlier sequence numbers not yet in the committed valid transactions [i.e. not yet in the blockchain]).

This could go along with the idea of modifying the transaction model to require every transaction be signed independently of whatever is in the fulfillments in the inputs. The public key of the signer would identify which series of sequence numbers this transaction belongs to.