bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 19쪽 중 9쪽
ing transactions with the highest fees.
As transaction volume increases, fees would become prohibitively large for transactions of small
amounts (such as Alice buying an apple from Bob). Only people willing to outbid everyone else
would get their transactions into the blockchain. 20
Monero avoids those extremes (unlimited vs fixed) with a dynamic block weight.
Size vs Weight
Since src/crypto-
note basic/
cryptonote
format
utils.cpp
get trans-
action
weight()
Bulletproofs were added (v8), transaction and block sizes are no longer considered strictly.
The term used now is transaction weight. Transaction weight for a miner transaction (see Section
7.3.6), or a normal transaction with two outputs, is equal to the size in bytes. When a normal
transaction has more than two outputs the weight is somewhat higher than the size.
Recalling Section 5.5, a Bulletproof occupies (2 ·⌈ log2(64·p)⌉ + 9)· 32 bytes, so as more outputs
are added the additional storage for range proofs is sub-linear. However, Bulletproof verification
is linear, so artificially increasing transaction weights ‘prices in’ that extra verification time (it’s
called a ‘clawback’).
Suppose src/crypto-
note basic/
cryptonote
format
utils.cpp
get trans-
action
weight
clawback()
we have a transaction with p outputs, and imagine that if p isn’t a power of 2 we create
enough dummy outputs to fill the gap. We find the difference between the actual Bulletproof size,
and the size of all the Bulletproofs if those p + ‘dummy outputs’ had been in 2-out transactions
(it’s 0 if p = 2). We only claw back 80% of the difference. 21
transaction clawback = 0.8∗ [(23∗ (p + num dummy outs)/2)· 32− (2·⌈ log2(64·p)⌉ + 9)· 32]
Therefore the transaction weight is
transaction weight = transaction size + transaction clawback
A block’s weight src/crypto-
note core/
block-
chain.cpp
create
block
template()
is equal to the sum of its component transactions’ weights plus the miner trans-
action’s weight.
Long term block weight
If dynamic blocks are allowed to grow at a rapid pace the blockchain can quickly become unman-
ageable [83]. To mitigate this, maximum block weights are tethered by long term block weights .
20 Bitcoin has a history of overloaded transaction volume. This website ( https://bitcoinfees.info/) charts the
ridiculous fee levels encountered (up to the equivalent of 35$ per transaction at one point).
21 Note that log 2(64· 2) = 7, and 2∗ 7 + 9 = 23.
CHAPTER 7. THE MONERO BLOCKCHAIN 64
Each block has, in addition to its normal weight, a ‘long term weight’ calculated based on the pre-
vious block’s effective median long term weight. 22 A block’s effective median long term weight is
related to the median of the most recent 100000 blocks’ long term weights (including its own). src/crypto-
note core/
block-
chain.cpp
update
next cumu-
lative
weight
limit()
23,24
longterm block weight =min{block weight, 1.4∗ previous effective longterm median}
effective longterm median =max{300kB, median 100000blocks longterm weights}
If normal block weights stay large for a long time, then it will take at least 50,000 blocks (about
69 days) for the effective long term median to rise by 40% (that’s how long it takes a given long
term weight to become the median).
Cumulative median weight
Transaction volume can change dramatically in a short period of time, especially around holidays
[128]. To accommodate this, Monero allows short term flexibility in block weights. To smooth
CRYPTONOTE
REWARD
BLOCKS
WINDOW
out
transient variability, a block’s cumulative median uses the median of the last 100 blocks’ normal
block weights (including its own).
cumulative weights median =max{300kB,min{max{300kB, median 100blocks weights},
50∗ effective longterm median}}
The next block to be added to the blockchain is constrained in this way: 25
max next block weight src/crypto-
note basic/
cryptonote
basic
impl.cpp
get block
reward()
= 2∗ cumulative weights median
While the maximum block weight can rise up to 100 times the effective median long term weight
after a few hundred blocks, it cannot rise more than 40% beyond that over the next 50,000 blocks.
Therefore long-term block weight growth is tethered by the long term weights, and in the short
term weights may surge above their steady-state values.
7.3.3 Block reward penalty
To mine blocks bigger than the cumulative median, miners have to pay a price, or penalty, in the
form of reduced block reward. This means there are functionally two zones within the maximum
22 Similar to block difficulties, block weights and long term block weights are calculated and stored by blockchain
verifiers rather than being included in blockchain data.
23 Blocks made before long term weights were implemented have long term weights equal to their normal weights,
so there is no concern for us about details surrounding the genesis block or early blocks. A brand new chain could
easily make sensible choices.
24 In the beginning src/crypto-
note basic/
cryptonote
basic
impl.cpp
get min
block
weight()
of Monero the ‘300kB’ term was 20kB, then increased to 60kB in March 2016, (v2 of the
protocol) [14], and has been 300kB since April 2017 (v5 of the protocol) [1]. This non-zero ‘floor’ within the dynamic
block weight medians helps transient transaction volume changes when the absolute volume is low, especially in the
early stages of Monero adoption.
25 The cumulative median replaced ‘M100’ (a similar median term) in protocol v8. Penalties and fees described
in the first edition of this report [33] used M100.
CHAPTER 7. THE MONERO BLOCKCHAIN 65
block weight: the penalty-free zone, and the penalty zone. The median can slowly rise, allowing
progressively larger blocks with no penalty.
If the intended block weight is greater than the cumulative median, then, given base block reward
B, the block reward penalty is
P = B∗ ((block weight/cumulative weights median)− 1)2
The actual block reward src/crypto-
note basic/
cryptonote
basic
impl.cpp
get block
reward()
is therefore26
Bactual = B− P
Bactual = B∗ (1− ((block weight/cumulative weights median)− 1)2)
Using the ˆ2 operation means penalties are sub-proportional to block weight. A block weight
10% larger than the previous cumulative weights median has just a 1% penalty, 50% larger is 25%
penalty, 90% larger is 81% penalty, and so on. [19]
We can expect miners to create blocks larger than the cumulative median when the fee from adding
another transaction is bigger than the penalty incurred.
7.3.4 Dynamic minimum fee
To prevent malicious actors from flooding the blockchain with transactions that could be used to
pollute ring signatures, and generally bloat it unnecessarily, Monero has a minimum fee src/crypto-
note core/
block-
chain.cpp
check fee()
per byte
of transaction data. 27 Originally this was 0.01 XMR/KiB (added early during protocol v1) [80],
then it became 0.002 XMR/KiB in September 2016 (v3). 28
In January 2017 (v4), a dynamic fee per KiB algorithm [46, 45, 44, 73] was added, 29 and then
along with transaction weight reductions due to Bulletproofs (v8) it changed from per KiB to per
byte. The most important feature of the algorithm is that it prevents minimum possible total fees
26 Before confidential transactions (RingCT) were implemented (v4), all amounts were communicated in clear
text and in some early protocol versions split into chunks (e.g. 1244 → 1000 + 200 + 40 + 4). To reduce miner tx
size, the core implementation chopped off the lowest significant digits of block rewards (anything less than 0.0001
Moneroj; see BASE REWARD CLAMP THRESHOLD) in v2-v3. The extra little bit was not lost, just made available for
future block rewards. More generally, since v2 src/crypto-
note core/
block-
chain.cpp
validate
miner trans-
action()
the block reward calculation here is just an upper limit on the real
block reward that can be dispersed in a miner tx’s outputs. Also of note, very early transactions’ outputs with
cleartext amounts not split into chunks can’t be used in ring signatures in the current implementation, so to spend
them they are migrated into chunked, ‘mixable’, outputs, which can then be spent in normal RingCT transactions
by creating rings out of other chunks with the same amount. Exact modern protocol rules around these ancient
pre-RingCT outputs are not clear.
27 This minimum is enforced by the node consensus protocol, not the blockchain protocol. Most nodes won’t
relay a transaction to other nodes if it has a fee below the minimum src/crypto-
note core/
tx pool.cpp
add tx()
(at least in part so only transactions likely
to be mined by someone are passed along [45]), but they will accept a new block containing that transaction. In
particular, this means there is no need to maintain backward compatibility with fee algorithms.
28 The unit KiB (kibibyte, 1 KiB = 1024 bytes) is different from kB (kilobyte, 1 kB = 1000 bytes).
29 The base fee was changed from 0.002 XMR/KiB to 0.0004 XMR/KiB in April 2017 (v5 of the protocol) [1].
The first edition of this report described the original dynamic fee algorithm [33].
CHAPTER 7. THE MONERO BLOCKCHAIN 66
from exceeding the block reward (even with small block rewards and large block weights), which
is thought to cause instability [98, 47, 59]. 30
The fee algorithm
We base our fee algorithm around a reference transaction [73] of weight 3000 bytes (similar to a
basic RCTTypeBulletproof2 2-input, 2-output transaction, which is usually about 2600 bytes) 31,
and the fees it would take to offset the penalty when the median is at its minimum (the smallest
penalty-free zone, 300kB) [45]. In other words, the penalty induced by a 303kB block weight.
Firstly, the fee F to balance the marginal penalty MP from adding a transaction with weight TW
to a block with weight BW, is
F = MP = B∗ (([BW + TW]/cumulative median− 1)2−
B∗ ((BW/cumulative median− 1)2
Defining the block weight factor WF b = (BW/cumulative median− 1), and transaction weight
factor WFt = (TW/cumulative median), lets us simplify
F = B∗ (2∗ WFb∗ WFt + WF2t )
Using a block weighing 300kB (with a cumulative median at the default 300kB) and our reference
transaction with 3000 bytes,
Fref = B∗ (2∗ 0∗ WFt + WF2t )
Fref = B∗ WF2t
Fref = B∗ ( TWrefcumulative medianref )2
This fee is spread out over 1% of the penalty zone (3000 out of 300000). We can spread the same
fee over 1% of any penalty zone with a generalized reference transaction.
TWref
cumulative medianref
= TWgeneral-ref
cumulative mediangeneral
1 = ( TWgeneral-ref
cumulative mediangeneral
)∗ (cumulative medianref
TWref
)
Fgeneral-ref = Fref
= Fref∗ ( TWgeneral-refcumulative mediangeneral )∗ (cumulative medianrefTWref )
Fgeneral-ref = B∗ ( TWgeneral-refcumulative mediangeneral )∗ ( TWrefcumulative medianref )
30 Credit for the concepts in this section largely belongs to Francisco Caba˜ nas (a.k.a. ‘ArticMine’), the architect
of Monero’s dynamic block and fee system. See [46, 45, 44].
31 A basic 1-input, 2-output Bitcoin transaction is 250 bytes [26], or 430 bytes for 2-in/2-out.
CHAPTER 7. THE MONERO BLOCKCHAIN 67
Now we can scale the fee based on a real transaction weight at a given median, so e.g. if the
transaction is 2% of the penalty zone the fee gets doubled.
Fgeneral = Fgeneral-ref∗ TWgeneralTWgeneral-ref
Fgeneral = B∗ ( TWgeneralcumulative mediangeneral )∗ ( TWrefcumulative medianref )
This rearranges to the default fee per byte, which we have been working toward.
fBdefault = Fgeneral/TWgeneral
fBdefault = B∗ ( 1cumulative mediangeneral )∗ ( 3000300000)
When transaction volume is below the median there is no real reason for fees to be at the reference
level [73]. We set the minimum to be 1/5 th the default.
fBmin = B∗ ( 1cumulative weights median)∗ ( 3000300000)∗ (15)
fBmin = B∗ ( 1cumulative weights median)∗ 0.002
The fee median
It turns out using the cumulative median for fees enables a spam attack. By raising the short
term median to its highest value (50 x long term median), an attacker can use minimum fees to
maintain high block weights (relative to organic transaction volume) with very low cost.
To avoid this we limit fees for transactions to go in the next block with the smallest median
available, which favors higher fees in all cases. 32
smallest median src/crypto-
note core
block-
chain.cpp
check fee()
=max{300kB,min{median 100blocks weights, effective longterm median}}
Favoring higher fees during rising transaction volume also facilitates adjusting the short term
median and ensuring transactions aren’t left pending, as miners are more likely to mine into the
penalty zone.
32 An attacker can spend just enough in fees for the short term median to hit 50*long-term-median. With current
(as of this writing) block rewards at 2 XMR, an optimized attacker can increase the short term median by 17%
every 50 blocks, and reach the upper bound after about 1300 blocks (about 43 hours), spending 0.39*2 XMR per
block, for a total setup cost of about 1000 XMR (or around 65k USD at current valuations), and then go back to the
minimum fee. When the fee median equals the penalty-free zone, then the minimum total fee to fill the penalty-free
zone is 0.004 XMR (about 0.26 USD at current valuations). If the fee median equals the long term median, it would
in the spam scenario be 1/50th the penalty-free zone. Therefore it would just be 50x the short-median case, for
0.2 XMR per block (13 USD per block). This comes out to 2.88 XMR per day vs 144 XMR per day (for 69 days,
until the long term median rises by 40%) to maintain every block with 50*long-term-median block weight. The 1000
XMR setup cost would be worthwhile in the former case, but not the latter. This will reduce to 300 XMR setup,
and 43 XMR maintenance, at the emission tail.
CHAPTER 7. THE MONERO BLOCKCHAIN 68
The actual minimum fee is therefore 33,34
fBmin−actual src/crypto-
note core
block-
chain.cpp
get dyna-
mic base
fee()
= B∗ ( 1smallest median)∗ 0.002
Transaction fees
As Caba˜ nas said in his insightful presentation on this topic [45], “[f]ees tell the miner how deep
into the penalty [transaction authors are] willing to pay for, in order to get a transaction mined.”
Miners will fill up their blocks by adding transactions in descending order of fee amount [45]
(assuming all transactions have the same weight), so to move into the penalty zone there must be
numerous transactions with large fees. This means it is likely the block weight cap can only be
reached if total fees are at least about 3-4 times the base block reward (at which point the actual
block reward is zero). 35
To calculate fees for a transaction, Monero’s core implementation wallet uses ‘priority’ src/wallet/
wallet2.cpp
get fee
multi-
plier()
multipliers.
A ‘slow’ transaction uses the minimum fee directly, ‘normal’ is the default fee (5x), if all trans-
actions use ‘fast’ (25x) they can reach 2.5% of the penalty zone, and a block with ‘super urgent’
(1000x) transactions can fill 100% of the penalty zone.
One important consequence of dynamic block weights is average total block fees will tend to be
of a magnitude lower than, or at least the same as, the block reward (total fees can be expected
to equal the base block reward at about 37% of the penalty zone [68.5% of the maximum block
weight], when the penalty is 13%). Transactions competing for block space with higher fees leads
to a bigger supply of block space, and lower fees. 36 This feedback mechanism is a strong counter
to the renowned ‘selfish miner’ [59] threat.
7.3.5 Emission tail
Let’s suppose a cryptocurrency with fixed maximum supply and dynamic block weight. After a
while its block rewards fall to zero. With no more penalty on increasing block weight, miners add
any transaction with a non-zero fee to their blocks.
33 To check if a given fee is correct, we allow a 2% buffer onfBmin−actual in case of integer overflow (we must compute
fees before tx weights are completely determined). This means the effective minimum fee is 0.98* fBmin−actual. src/crypto-
note core
block-
chain.cpp
check fee()
34 Research to improve minimum fees even further is ongoing. [131]
35 The marginal penalty from the last bytes to fill up a block can be considered a ‘transaction’ comparable to
other transactions. In order for a clump of transactions to buy that transaction space from a miner, all its individual
transaction fees should be higher than the penalty, since if any one of them is lower then the miner will keep the
marginal reward instead. This last marginal reward, assuming a block filled with small transactions, requires at least
4x the base block reward in total fees to be purchased. If transaction weights are maximized (50% of the minimum
penalty-free zone, i.e. 150kB) then if the median is minimized (300kB) the last marginal transaction requires at
least 3x in total fees.
36 As block rewards decline over time, and the median rises due to increased adoption (theoretically), fees should
steadily become smaller and smaller. In ‘real purchasing power’ terms, this may be less impactful on transaction
costs if the value of Moneroj rises due to adoption and economic deflation.
CHAPTER 7. THE MONERO BLOCKCHAIN 69
Block weights stabilize around the average rate of transactions submitted to the network, and
transaction authors have no compelling reason to use transaction fees above the minimum, which
would be zero according to Section 7.3.4.
This introduces an unstable, insecure situation. Miners have little to no incentive to mine new
blocks, leading to a fall in network hash rate as returns on investment decline. Block times remain
the same as difficulties adjust, but the cost of performing a double-spend attack may become
feasible.37 If minimum fees are forced to be non-zero then the ‘selfish miner’ [59] threat becomes
realistic [47].
Monero src/crypto-
note basic/
cryptonote
basic
impl.cpp
get block
reward()
prevents this by not allowing the block reward to fall below 0.6 XMR (0.3 XMR per
minute). When the following condition is met,
0.6> ((L−M)>> 19)/1012
M> L− 0.6∗ 219∗ 1012
M/1012> L/1012− 0.6∗ 219
M/1012> 18, 132, 171.273709551615
the Monero chain will enter a so-called ‘emission tail’, with constant 0.6 XMR (0.3 XMR/minute)
block rewards forever after. 38 This corresponds with about 0.9% yearly inflation to begin with,
steadily declining thereafter.
7.3.6 Miner transaction: RCTTypeNull
A block’s miner has the right to claim ownership of the fees provided in its transactions, and to
mint new money in the form of a block reward. The mechanism is a miner transaction src/crypto-
note core/
cryptonote
tx utils.cpp
construct
miner tx()
(a.k.a.
coinbase transaction), which is similar to a normal transaction. 39
The output amount(s) of a miner transaction must be no more than the sum of transaction fees
and block reward, and are communicated in clear text. 40 In place of an input, the block’s height
is recorded (i.e. “I claim the block reward and fees for the n th block”).
Ownership of the miner output(s) is assigned to a standard one-time address41, with a correspond-
ing transaction public key stored in the extra field. The funds are locked, unspendable, until the
37 The case of fixed supply and fixed block weight, as in Bitcoin, is also thought to be unstable. [47]
38 The Monero emission tail’s estimated arrival is May 2022 [17]. The money supply limit L will be reached in
May 2024, but since coin emission will no longer depend on the supply it will have no effect. Based on Monero’s
range proof, it will be impossible to send more money than L in one output, even if someone manages to accumulate
more than that (and assuming they have wallet software that can handle that much).
39 Apparently, at one point miner transactions could be constructed using deprecated transaction format versions,
and could include some normal transaction (RingCT) components. The issues were fixed in protocol v12 after this
hackerone report was published: [8].
40 In the current version miners may claim less than the calculated block reward. The leftovers are pushed back
into the emission schedule for f프로젝트로 돌아가기