21

I see from the source code (script.cpp) that there is an upper limit in the script size. It there any other limit to avoid a single transaction preventing other transactions of smaller sizes to get into a block?

How is this kind of attack prevented?

I've read in CTransaction::AcceptToMemoryPool the line:

if .... ::GetSerializeSize(*this, SER_NETWORK) < 100) 
    return error("..."); 

Does this line means that the maximum transaction size is 100 bytes?

Nick ODell
  • 29,396
  • 11
  • 72
  • 130
SDL
  • 589
  • 1
  • 4
  • 8

2 Answers2

25

The maximum transaction size is the size of the block. Source.

// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
    return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");

Transactions larger than 100 kilobytes (including witness at a 75% discount rate) are non-standard. Source 1. Source 2.

static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000;
...
if (sz >= MAX_STANDARD_TX_WEIGHT)
{
    LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
    return false;
}
Nick ODell
  • 29,396
  • 11
  • 72
  • 130
7

If there is a max transaction size it is much higher than 100 bytes. Not sure what that snippet is refering to but the average transaction is closer to ~300 bytes looking at the average # of transactions and block size for last 1000 blocks.

What limits transaction size is cost. As transaction size (of all transactions awaiting next block) increases the min required fee increases non-linearly.

0.01 BTC fee per kilobyte of transaction, but: If the blocksize (size of all transactions currently waiting to be included in a block) is less than 27 kB, transactions are free. If the blocksize is more than 250 kB, transactions get increasingly more expensive as the blocksize approaches the limit of 500 kB. Sending a transaction when the blocksize is 400 kB will cost 5 times the normal amount; sending when it's 499 kB will cost 500x, etc.

https://en.bitcoin.it/wiki/Transaction_fees

So you could make a 500KB transaction but the required minimum fee would be 5BTC. The developers have indicated they intend to change transaction fee rules in the future but given block space is a valuable commodity any new rules are likely to be constructed to encourage (via larger fees) smaller transaction sizes.

DeathAndTaxes
  • 8,797
  • 2
  • 37
  • 65