Trading Bitcoin Using Wallet Adress

Trading bitcoin using wallet adress

Bitcoin can be coldly unforgiving of mistakes, and nowhere is this better demonstrated than with change addresses.

Trading bitcoin using wallet adress

Although change addresses provide a key privacy tool, they can also lead to confusion, loss, or theft when not understood.

This article explains how to safely use one of Bitcoin’s least understood features.

It ends with a list of common pitfalls and ways to avoid them.

This article was first published in March 2014. Since then, wallet software has improved, eliminating some of the threats described below.

Crypto Wallet Vs. Address

Specifically cases (1) and (4) should only be encountered when using older, unsupported software.

The Debit Card from Hell

Imagine paying for groceries with a debit card. The checker totals the amount due and you swipe your card as usual. However, you notice the payment terminal is asking for all of the money in your account.

The checker smiles, explaining that this is part of your bank’s new rewards program. You have three options: (1) send the change back to your current account; (2) send the change to a newly-created bank account; or (3) say nothing and send the change to the payment terminal company.

Counterintuitive?

Confusing? Alarming? Many Bitcoin users are surprised to find eerie similarities between this diabolical debit card and the way transactions seem to work.

Thinking about Bitcoin in terms of past experiences with online banking and debit cards can lead to problems.

Fortunately, an older payment method offers better insights into how Bitcoin works.

Bitcoin is Electronic Cash

The similarities between Bitcoin and cash run deep.

How to Invest in Bitcoin Using Your Bitcoin Wallet?

In his whitepaper, Satoshi Nakamoto even described Bitcoin as an “electronic cash system.” Understanding the close connection between Bitcoin and physical cash is the key to understanding change addresses.

Imagine needing to track different pools of paper bills, maybe as part of a collection drive.

You might use envelopes to keep the bills physically separate from each other — a “cash envelope”.

A Bitcoin address can be thought of as the digital equivalent of a cash envelope.

Like a cash envelope, an address can hold zero or more units of electronic cash.

Instead of paper bills, Bitcoin uses the electronic equivalent: “unspent outputs”. To find the balance of any address, we sum the values of each associated unspent output. In a similar way, the amount held in a cash envelope can be found by totaling the values of all its bills.

A Bitcoin transaction transfers the ownership of one or more unspent outputs. To continue with the paper example, a transaction would teleport one or more bills from one or more envelopes into one or more envelopes.

Like many Bitcoin analogies, however, this one doesn’t capture the entire situation. A more accurate statement would be to say that bills can be rematerialized in any set of denominations provided that the sum of their values is less than or equal to the value of the dematerialized bills. A more detailed explanation may be helpful when reading this article.

How Bitcoin Transactions Work

Imagine that Alice, who controls an address containing one unspent output worth 10 bitcoin (BTC), wants to pay Bob 10 bitcoin.

Alice does so with a transaction sending her single unspent output to Bob’s empty address.

Search This Blog

In doing so, Alice’s address balance falls to zero and Bob’s address balance rises to 10 bitcoin.

After the transaction, Bob can give the unspent output he received from Alice to someone else.

However, Alice will neither be allowed to take back the unspent output she transferred, nor will she be able to spend it again.

A few days later, Alice wants to pay Bob 5 BTC from an address containing a single output valued at 10 BTC. Alice has a problem: she needs to pay Bob, but she doesn’t want to give him the entire 10 BTC. Alice wouldn’t be allowed to rip a $10 bill in half to pay Bob $5. Likewise, Bitcoin requires Alice to spend the entire value of her 10 BTC.

To resolve this dilemma, Alice uses a transaction that splits her payment, a feature fully supported by Bitcoin.

One part of the transaction sends 5 BTC to Bob’s address and the other returns 5 BTC back to her own. In a similar way, Alice could break a $10 bill at the bank into two $5 bills, giving one to Bob and keeping one for herself.

Over time, Alice’s address accumulates unspent outputs from people who have paid her. Her address now contains unspent outputs valued at 20 BTC, 10 BTC, and 5 BTC.

Once again, it’s time for Alice to pay Bob - this time 8 BTC.

Best vegan lunch options

Alice creates a transaction that splits her 10 BTC unspent output, sending 8 BTC to Bob’s address and returning 2 BTC to her own as change. Alice’s address balance falls to 27 BTC and Bob’s address balance rises to 8 BTC.

In the previous examples, Alice directed change into the same address she spent from.

Although this decision simplified accounting, it unfortunately reduced Bob’s privacy as well as her own.

Change Addresses and Privacy

By design, every Bitcoin transaction remains permanently viewable in a global public log called the “block chain.” Privacy depends on the strict separation between addresses and personal identities, a model referred to as pseudonymity.

Any observer capable of linking Bitcoin addresses to personal identities can begin to draw conclusions about money transfers between people.

Users make this job more difficult by sending change to newly-created addresses.

To see why, imagine a transaction that sends funds from Address A to Address B.

If change is returned to Address A, the block chain reveals that the person controlling Address A paid the person controlling Address B. The same reasoning holds if two or more addresses are involved. Any transaction involving Address A as a sender reveals the receiving address unambiguously.

Should the identity of the person controlling either receiving or payment addresses become known, the identities of the other parties could become known as well.

Now imagine that Address A initiates a payment to B, but this time directs change to a newly-generated change address C.

Without knowing which address receives change, all we can deduce is that a transaction split Address A’s balance between Addresses B and C. The identity of the person controlling Addresses B or C may or may not be the same as the identity of the person controlling Address A.

Given another transaction from Address C, the picture becomes even murkier. Which of the transfers represent payments and which represent the receipt of change?

An observer trying to link personal identities to addresses must gather more secondary information and expend more resources when all parties send change to newly-created addresses.

Coordinating multiple addresses is a complicated task. Wallet software frees the user from the need to do this manually.

Wallets and Change Addresses

Although change addresses play a key role in improving privacy, wallet developers can implement this feature in a number of ways. Four strategies are currently in use, each with its own implications for privacy and security.

  • Single-Address Wallets use a single address to receive both payments and change.

    Additional addresses may added when a receiving address is manually added, or a private key is imported. An example is the now-unsupported MultiBit Classic.

  • Random Address Pool Wallets use a fixed-size pool of randomly-generated addresses.

    How To Trade Bitcoin

    Change is sent to the next available empty address, causing the creation of a new empty address to take its place.

    The best-known example was Bitcoin-Qt, until its key-handling functionality was upgraded.

  • Deterministic Address Pool Wallets contain a practically infinite pool of deterministically-generated addresses. A subset of this pool contains addresses reserved for receiving change. Examples include Electrum and Armory.
  • Hybrid Wallets use multiple strategies, depending on context. MultiBit, Mycelium, and Electrum are examples.

Let’s now consider some ways that misunderstanding change addresses, combined with semi-manual address management, can lead to loss or theft of funds.

Preventing and Recovering from Change Address Disasters

Incorrect use of Bitcoin change addresses account for many cases of loss or theft of funds.

Here are some disaster scenarios and ways to avoid them.

1. Backup Failure

Alice uses an old version of Bitcoin-Qt. Understanding the importance of backups, she created an encrypted wallet backup long ago and stored it in a safe place.

After making dozens of transactions with Bitcoin-Qt, Alice’s hard drive crashed.

Alice bought a new hard drive and then re-installed Bitcoin-Qt on it. She then restored her wallet backup.

Trading bitcoin using wallet adress

To her horror, Alice discovered the restored wallet was empty.

Explanation: Alice generated enough change addresses to overflow the original pool of 100. On the 100th spending transaction, Bitcoin-Qt moved Alice’s change (which happend to be her entire balance) into an address not in the backup. Restoring the backup only restored empty addresses.

Recovery: Even if a hard drive can’t boot an operating system, individual files can still be recovered.

Using data recovery tools, Alice may be able to salvage the Bitcoin-Qt wallet from the faulty hard drive, and with it her lost funds.

Prevention:

  • Count the number of manually-created addresses and spending transactions since your last backup. If this number is greater than about 80, back up again. Weekly backups might be enough for most users.
  • Set a very high value (e.g., 10,000) for the option, either as a command line parameter, or in the file.
  • Switch to a deterministic wallet.

2.

Failure to Monitor Change Address

Bob uses Electrum to send infrequent bitcoin payments. Worried about possible theft, he wanted a way to keep an eye on his bitcoin balance from one of his many devices.

Bob decided on blockchain.info to monitor address activity.

Bob’s Electrum wallet contained several addresses, but only one of them held bitcoin (0.3 BTC).

Five Ways to Lose Money with Bitcoin Change Addresses

Assuming this was the only address he’d be using, Bob pasted it into the blockchain.info search window and bookmarked the resulting page.

A few weeks later, Bob made a 0.2 BTC payment to Overstock from his Electrum wallet. After receiving his merchandise, Bob decided to check his balance with blockchain.info.

Disturbingly, Bob discovered that part of his Overstock payment was transferred to an unknown address.

Thinking that his computer running Electrum had been compromised, Bob re-formated the hard drive.

Explanation: Although it may look to Bob as if an eavesdropper changed his transaction before it was sent to Overstock, he’s instead seeing the result of normal wallet operation.

Electrum sent the change from Bob’s transaction to one of its deterministically-generated change addresses. This cleared the balance from the sending address, the only one Bob was monitoring.

Recovery: Electrum encourages the storage of its 12-word address generation seed in a safe location.

Hackernoon Newsletter curates great stories by real tech professionals

Should Bob still have access to the seed, he can re-generate his old wallet and recover the change from the Overstock transaction.

Prevention:

  • If using a deterministic wallet, create a watching-only wallet to monitor addresses.
  • If using Bitcoin-Qt, manually update your list of watch addresses after every payment, or switch to a deterministic wallet.

3.

Spending from a Paper Wallet

Carlos is a saver.

Forex forecast gbp jpy

Awhile back he bought 20 bitcoins at $10 apiece, and then transferred them to a paper wallet he created at bitaddress.org. He didn’t do anything with Bitcoin since then.

One day Carlos noticed a deal on new laptops at Overstock and decided to pay using one of his saved bitcoins.

Where can I find my bitcoin address?

But Carlos had a problem: he needed to get his paper wallet into a software wallet to pay Overstock.

Carlos downloaded MultiBit and imported his paper wallet’s private key. After paying Overstock, he exited the program.

Carlos was worried about leaving any trace of his private key on his computer, so he securely deleted MultiBit and its data directory. He then returned his paper wallet to its safe location.

After a few weeks, Carlos checked his paper wallet’s balance.

To his shock, the balance read zero. Nineteen bitcoins were sent to an unfamiliar address on the same day as the Overstock payment.

Explanation: Carlos suspects foul play, but he’s actually seeing the result of normal wallet behavior.

The 19 missing bitcoins were sent to a change address, leaving his paper wallet empty.

Recovery: In securely deleting the MultiBit data directory, Carlos lost any chance of recovering the missing funds.

Prevention:

  • Before deleting any hot wallet with an imported paper wallet private key, send the remaining balance back to a paper wallet.
  • Use a software wallet that will return change back to the paper wallet.

    One example is Mycelium. Another is Blockchain.info through the “custom spend” option. Both approaches would return change to the paper wallet, although doing so degrades privacy.

4.

Sharing a Wallet

Dave runs Bitcoin-Qt on two computers, a laptop and a desktop in his garage. Wanting to use both computers to make payments, Dave copied a clean backup file from the laptop to the desktop.

After making many payments without a problem from both computers, Dave noticed something odd one day.

His laptop wallet showed a zero balance, but his desktop wallet showed the correct balance.

Explanation: Dave’s computer network was not compromised, nor did he uncover a bug in Bitcoin-Qt. Instead, his copy of Bitcoin-Qt running on the desktop used the last available pool address held jointly with the laptop. On his last transaction, Dave’s change was sent to an address generated on the desktop, but unknown to the wallet.

Recovery: Back up the wallets on both the laptop and the desktop.

Export all private keys from both computers, and sweep them into a new wallet. If sharing wallets is critical, don’t continue using Bitcoin-Qt.

Prevention:

  • Don’t use old versions of Bitcoin-Qt to share wallets among multiple computers.

    Trading bitcoin using wallet adress

    Use Electrum or a more recent version of Bitcoin Core, which were designed specifically with this use case in mind.

5. Theft from an Imported Paper Wallet

Frank received a paper wallet containing 2 BTC as a gift at a company event.

Eager to see how Bitcoin works, he installed MultiBit and imported the paper wallet’s private key. Not seeing a need to keep the paper wallet, Frank threw it into the recycling bin at his office.

Over time, Frank depleted his Bitcoin funds.

To re-fund his wallet, Frank bought an additional 2 BTC from Coinbase and then transferred them into his MultiBit wallet.

Shortly thereafter, Frank bought a set of sheets from Overstock for 0.1 BTC. Although this payment confirmed without issue, Frank noticed something odd.

Without his approval, a second withdrawal was made to an unknown address, emptying his wallet of the remaining 1.9 BTC.

Explanation: Although Frank was the victim of theft, the route of attack was not his computer or network.

Trading bitcoin using wallet adress

It was the paper wallet he threw into the recycling bin.

Unknown to Frank, the paper wallet was taken from the recycling bin by Eve, a dishonest coworker. Eve added the private key to a custom program that automatically detects deposits into a list of watched addresses, and then withdraws them immediately.

MultiBit, working as designed, used the imported paper wallet address to receive 1.9 BTC in change from Frank’s Overstock payment.

Eve’s program noticed the transfer and immediately withdrew the funds.

Eve pulled off her heist without access to Frank’s computer, or even knowledge of Frank’s identity.

Trading bitcoin using wallet adress

The plan worked because Eve know one of the private keys being used to receive change in Frank’s MultiBit wallet.

Recovery: Frank cannot recover the funds, nor is he likely to determine the identity of the thief.

Prevention:

  • Sweeping a paper wallet generates a transaction moving all unspent outputs into a wallet address, depleting the paper wallet.

    The paper wallet private key is never again used by the wallet software. Unless you have a compelling reason to do otherwise, sweep paper wallets instead of importing them. This is especially important for paper wallets that you did not generate yourself securely.

Partial Loss of Funds

Although the examples in the previous section resulted in complete loss of funds, the same mechanisms also allow for partial loss.

These conditions were assumed, which may or may not hold at the time a change address problem arises:

  1. The entire balance of a wallet resides at a single address.
  2. This single address contains one unspent output.

For example, a single address that receives multiple payments will contain multiple unspent outputs. Likewise, wallet balances can become distributed across multiple change addresses as the user spends funds.

Imagine Alice’s wallet contains two addresses, Address 1 and Address 2, with a total value of 15 BTC.

How To Trade Bitcoin Cryptocurrency for Beginners

To make a 6 BTC payment, the wallet chooses a 7 BTC unspent output from Address 1, receiving 1 BTC change into Address 2. As expected, her wallet balance decreases to 9 BTC.

Then disaster strikes - Alice’s hard drive fails.

After installing a new hard drive and restoring her wallet backup, Alice notices something odd. Before the hard drive crash, her wallet balance was 9 BTC. But the balance only read 8 BTC after recovering the backup. Why does 1 BTC seem to be missing?

Alice was using a random address pool wallet, in which Address 2 was not contained in her original backup. Restoring the backup gave the appearance that Address 2 had “disappeared”, and along with it the 1 BTC spent output it contained.

In a sense, Alice was lucky because she could have lost her entire wallet balance.

What Is Bitcoin?

On the other hand, without understanding change addresses, Alice would likely be very confused about what happened to the missing 1 BTC. The same mistake could happen again.

Conclusions

When used correctly, directing change to a newly-generated address promotes privacy. But with this capability comes the potential for loss and theft. To avoid potentially costly mistakes, familiarize yourself with change addresses and how your wallet software implements them.

Thanks

I’m grateful to members of the Bitcoin Subreddit who helped clarify two key technical points in the original version of this article.

Yes, send me more helpful Bitcoin stuff like this