0

Let's us consider a scenario where I am using my ethereum wallet for creating a transaction request (where my account balance is 100 eth and I am doing a transaction of 50 eth to someone from one device in a particular geographic location say India).

Now, let us continue with the same scenario where my brother is also using the same ethereum wallet for creating a different transaction request (say transferring 90 eth to someone where my account balance is still 100 eth) within the same time duration where I was proposing the first transaction but here in this case the geographic location and the device used for the second transaction request are different say california.

Can anybody here help me in understanding how and on what parameters what all transaction proposals are accepted and how ethereum avoids double spending problem.

1
  • With nonce per transaction per account. Commented Feb 10, 2020 at 7:05

2 Answers 2

2

If the transactions are created close to each other they are possibly valid transactions. If one transactions has already been processed (mined) and the wallet knows about this then the wallet refuses to even send the second transaction.

If both of the transactions are accepted by the wallet they are added to an abstract transaction pool which is basically the list of transactions which are not yet processed by any miner. Transactions from the pool are taken by miners for processing. Once a miner picks up transactions from the pool for processing he places them in a half-random order inside a block he tries to mine. Then he starts executing them in that order and if any of the cause a conflict (like your two transactions would) it simply refuses the second transaction.

So miners are eventually responsible for refusing transactions which are conflicting. But even if some of them tries to cheat other miners will refuse the mined block if it has conflicting transactions. So double-spending can't happen this easily.

Geographical and timezone differences don't make any difference here really.

1

The wallet's idea of its balance is irrelevant. It's the network's accounting that matters. That is what is authoritative. A wallet merely reports it.

There are really two scenarios here:

  • Double-spending and confirmation, generally, and
  • Your brother is using the same signing key.

Generally

You don't need your brother to try a double-spend. Just sign two transactions and send the second right away, before anything has had a chance to confirm. If that would work, then there would be a huge problem, right?

The mining, block formation and consensus process is mainly concerned with ordering the inputs (the results are computed by every node). So, the nodes would consider:

  • Sent 50 (okay)
  • Sent 90 (failed, not enough money)

Two clients, Same signing key

This is not a good idea unless you know what you are doing. Ethereum uses a nonce to prevent replay attacks and to ensure ensure correct transaction ordering from the same account. It is a counter and accounts are assured that the transactions they send will be mined in the correct order. In the example above, "Sent 90" cannot be mined first because of the account nonce.

The nonce is a client-side responsibility. That is to say, the client should know what it is because there is no reliable way to discover, from the network, how many unconfirmed transactions are flying around.

Your Brother could send a transaction with the same nonce as the first one. In fact, probably will unless those moves are coordinated.

That creates a race condition. One of those transactions will mine first. It may be the one that was sent first, the one with the higher gas price (priority) or the other one might get lucky. It is not deterministic.

Whichever one comes second will be rejected because the nonce is too low.

There is no way both transactions will succeed.

Hope it helps.

3
  • I disagree with you in "wallet's idea of its balance is irrelevant". For users that's the first check which is typically enough: wallet notices that balance is not enough and refuses to send the transaction. If the user gets past that initial check then the actual blockchain's checks are relevant. Commented Feb 10, 2020 at 8:39
  • "wallet's idea of its balance isn't authoritative?" Commented Feb 10, 2020 at 14:34
  • it's not the final word, sure, but for typical users it's a good first barrier. Commented Feb 10, 2020 at 14:44

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.