Bitcoin Forum
November 04, 2024, 04:57:16 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [BUG] Possible Double Spend  (Read 1160 times)
zellfaze (OP)
Full Member
***
Offline Offline

Activity: 141
Merit: 101


Security Enthusiast


View Profile WWW
August 16, 2011, 10:31:02 PM
 #1

I think I found a situation where the Bitcoin Client will double spend.

BACKGROUND:
I sent all my Bitcoins to myself so that I would stop having to pay the 0.005 BTC transaction fee (my money was in very small amounts throughout several addresses).  By consolidating all my money into one address I would not have to pay the fee because my transaction wouldn't be over the size limit.

REPRODUCE:
Send all your coins to several addresses until your forced to pay the 0.005 transaction fee for any transaction.
Send all your coins to a new address in the same client. (Paying the fee)
Before the transaction has 6 confirms (it only has 2 for me) send money to a new address.
It should ask you to pay a transaction fee.

MY UNDERSTANDING:
I believe that this is because it is trying to send money from the old addresses because the new address has less than 6 confirmations.  I think it still see the money in your wallet balance and therefore it is willing to overlook the fact that you have already sent that money.

Of course I could be entirely wrong, but I would like it if someone could look into it a bit more.  At least to give me an explanation of why it happens if I am wrong.

A+, CCENT, CCNA
Security Enthusiast
PHP Coder

Not that I expect anyone to, but should you like my post, please donate:
Donate: 1BRbfqii6Sm9tEUE8A16H7QeDmYFjyBZ7V
SgtSpike
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
August 16, 2011, 10:33:36 PM
 #2

I think I found a situation where the Bitcoin Client will double spend.

BACKGROUND:
I sent all my Bitcoins to myself so that I would stop having to pay the 0.005 BTC transaction fee (my money was in very small amounts throughout several addresses).  By consolidating all my money into one address I would not have to pay the fee because my transaction wouldn't be over the size limit.

REPRODUCE:
Send all your coins to several addresses until your forced to pay the 0.005 transaction fee for any transaction.
Send all your coins to a new address in the same client. (Paying the fee)
Before the transaction has 6 confirms (it only has 2 for me) send money to a new address.
It should ask you to pay a transaction fee.

MY UNDERSTANDING:
I believe that this is because it is trying to send money from the old addresses because the new address has less than 6 confirmations.  I think it still see the money in your wallet balance and therefore it is willing to overlook the fact that you have already sent that money.

Of course I could be entirely wrong, but I would like it if someone could look into it a bit more.  At least to give me an explanation of why it happens if I am wrong.
I don't see a double spend here.  What you've done is....

Send coins from A to B
Send coins from B to C (tx fee of 0.005)
Send coins from C to D (tx fee of 0.005)

The reason it requests a transaction fee is because of the "newness" of the coins.
zellfaze (OP)
Full Member
***
Offline Offline

Activity: 141
Merit: 101


Security Enthusiast


View Profile WWW
August 16, 2011, 10:36:08 PM
 #3

The newness?  I didn't realize the client put a transaction fee on new coins.

I thought it wouldn't even let you send coins until they had 6 confirms (12 for fresh minted coins).

A+, CCENT, CCNA
Security Enthusiast
PHP Coder

Not that I expect anyone to, but should you like my post, please donate:
Donate: 1BRbfqii6Sm9tEUE8A16H7QeDmYFjyBZ7V
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1280


May Bitcoin be touched by his Noodly Appendage


View Profile
August 16, 2011, 10:42:29 PM
 #4

You can spend your coins with 0 confirmation

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
SgtSpike
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
August 16, 2011, 10:50:13 PM
 #5

The newness?  I didn't realize the client put a transaction fee on new coins.

I thought it wouldn't even let you send coins until they had 6 confirms (12 for fresh minted coins).
Well, it's a complex formula.  It won't always put a transaction fee on new coins, but it often will.  If you send a large amount, that helps to avoid a fee.
zellfaze (OP)
Full Member
***
Offline Offline

Activity: 141
Merit: 101


Security Enthusiast


View Profile WWW
August 16, 2011, 11:00:45 PM
 #6

What file is the formula in.  I would like to see it for myself (just so I can understand when I will and when I won't have to pay a fee).

Thank you guys for your help.

A+, CCENT, CCNA
Security Enthusiast
PHP Coder

Not that I expect anyone to, but should you like my post, please donate:
Donate: 1BRbfqii6Sm9tEUE8A16H7QeDmYFjyBZ7V
SgtSpike
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
August 16, 2011, 11:06:28 PM
 #7

I tried to find the same thing, but it's a very convoluted piece of code.  I don't even remember where it was in the github, but even when I did see it, I didn't really fully understand what was happening or how I could determine when I would pay a fee and when I would not.

Anyway, maybe someone else will chime in with the dozens of lines of code that determine the fee so you can take a look for yourself.
vector76
Member
**
Offline Offline

Activity: 70
Merit: 18


View Profile
August 17, 2011, 05:59:41 PM
Last edit: August 17, 2011, 07:02:45 PM by vector76
 #8

It looks like

Code:
// Priority is sum(valuein * age) / txsize
and
Code:
    static bool AllowFree(double dPriority)
    {
        // Large (in bytes) low-priority (new, small-coin) transactions
        // need a fee.
        return dPriority > COIN * 144 / 250;
    }
and
Code:
                // Free transaction area
                if (nNewBlockSize < 27000)
                    nMinFee = 0;
but
Code:
        // To limit dust spam, require MIN_TX_FEE/MIN_RELAY_TX_FEE if any output is less than 0.01
        if (nMinFee < nBaseFee)
            BOOST_FOREACH(const CTxOut& txout, vout)
                if (txout.nValue < CENT)
                    nMinFee = nBaseFee;

So, if I'm reading this correctly, if the priority is high enough and the block it's going into is small enough, then the transaction can be free, as long as none of the outputs are too small, in which case the base fee is charged instead.

Edit:  COIN is the number of satoshis in one bitcoin, which is 100,000,000.  The valuein for the purpose of priority is measured in satoshis.
zellfaze (OP)
Full Member
***
Offline Offline

Activity: 141
Merit: 101


Security Enthusiast


View Profile WWW
August 17, 2011, 06:13:25 PM
 #9

I think I understand this.

So here is how we determine if we get a fee:
  • First we computer the first part of the priority by taking the value of the each transaction input and multiplying that by its age.
  • We then sum the values we just computed for each input and multiply by the transaction size to get our priority
  • A fee is then required if the variable (COIN [what is the value of this?] multiplied by 144 divided by 250) is more than 0.05
  • The fee is then dismissed if the block still has a lot of free room
  • But potentially re-added (or added to begin with) if we are sending less than 0.01 BTC.

My C++ isn't very sharp (I am a PHP coder) and I am getting this all out of context, so if someone could correct me where I am wrong, I would appreciate it.

A+, CCENT, CCNA
Security Enthusiast
PHP Coder

Not that I expect anyone to, but should you like my post, please donate:
Donate: 1BRbfqii6Sm9tEUE8A16H7QeDmYFjyBZ7V
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!