You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -75,54 +75,44 @@ D1 is a list of active sidechains. D1 is updated via M1 and M2.
75
75
| Version number.
76
76
|-
77
77
| 3
78
-
| String KeyID
79
-
| string
80
-
| Used to derive all sidechain deposit addresses.
81
-
|-
82
-
| 4<br />
83
-
| Sidechain Private Key
84
-
| string
85
-
| The private key of the sidechain deposit script.
86
-
|- style="vertical-align:middle;"
87
-
| 5<br />
88
-
| ScriptPubKey
89
-
| CScript
90
-
| Where the sidechain coins go. This always stays the same, even though the CTIP (UTXO) containing the coins is always changing.
91
-
|- style="vertical-align:middle;"
92
-
| 6
93
78
| Sidechain Name
94
79
| string
95
80
| A human-readable name of the sidechain.
96
81
|- style="vertical-align:middle;"
97
-
| 7
82
+
| 4
98
83
| Sidechain Description
99
84
| string
100
85
| A human-readable name description of the sidechain.
101
86
|- style="vertical-align:middle;"
102
-
| 8
87
+
| 5
103
88
| Hash1 - tarball hash
104
89
| uint256
105
90
| Intended as the sha256 hash of the tar.gz of the canonical sidechain software. (This is not enforced anywhere by Bip300, and is for human purposes only.)
106
91
|- style="vertical-align:middle;"
107
-
| 9
92
+
| 6
108
93
| Hash2 - git commit hash
109
94
| uint160
110
95
| Intended as the git commit hash of the canonical sidechain node software. (This is not enforced anywhere by Bip300, and is for human purposes only.)
111
96
|-
112
-
| 10
97
+
| 7
113
98
| Active
114
99
| bool
115
100
| Does this sidechain slot contain an active sidechain?<br />
116
101
|- style="vertical-align:middle;"
117
-
| 11
118
-
| "CTIP" -- Part 1 "TxID"
102
+
| 8
103
+
| Activation Status
104
+
| int , int
105
+
| The age of the proposal (in blocks); and the number of "fails" (a block that does NOT ack the sidechain). This is discarded after the sidechain activates.
106
+
|- style="vertical-align:middle;"
107
+
| 9
108
+
| "CTIP" -- "TxID"
119
109
| uint256
120
-
| The CTIP, or "Critical (TxID, Index) Pair" is a variable for keeping track of where the sidechain's money is (ie, which member of the UTXO set).
110
+
| A UTXO that holds the sidechain's money. (Part 1 of 2).
121
111
|- style="vertical-align:middle;"
122
-
| 12
123
-
| "CTIP" -- Part 2 "Index"
112
+
| 10
113
+
| "CTIP" -- "vout"
124
114
| int32_t
125
-
| Of the CTIP, the second element of the pair: the Index. See #11 above.
115
+
| A UTXO that holds the sidechain's money. (Part 2 of 2).
126
116
|}
127
117
128
118
@@ -138,7 +128,7 @@ D2 is driven by M3, M4, M5, and M6. Those messages enforce the following princip
138
128
# From one block to the next, the value in "ACKs" may either increase or decrease, by a maximum of 1 (see M4).
139
129
# If a Bundle's "ACKs" reach 13150 or greater, it "succeeds" and its corresponding M6 message can be included in a block.
140
130
# If the M6 of a Bundle is paid out, it is also removed.
141
-
# If a Bundle cannot possibly succeed ( 13500 - "ACKs" > "Blocks Remaining" ), it is removed immediately.
131
+
# If a Bundle cannot possibly succeed ( 13150 - "ACKs" > "Blocks Remaining" ), it is removed immediately.
142
132
143
133
144
134
{| class="wikitable"
@@ -158,19 +148,21 @@ D2 is driven by M3, M4, M5, and M6. Those messages enforce the following princip
158
148
| A withdrawal attempt. Specifically, it is a "blinded transaction id" (ie, the double-Sha256 of a txn that has had two fields zeroed out, see M6) of a txn which could withdraw funds from a sidechain.
159
149
|-
160
150
| 3
161
-
| ACKs (Work Score)
151
+
| Work Score (ACKs)
162
152
| uint16_t
163
-
| The current ACK-counter, which is the total number of ACKs (the PoW that has been used to validate the Bundle).
153
+
| How many miner upvotes a withdrawal has. Starts at 0. Fastest possible rate of increase is 1 per block.
164
154
|-
165
155
| 4
166
-
| Blocks Remaining (Age)
156
+
| Blocks Remaining
167
157
| uint16_t
168
-
| The number of blocks which this Bundle has remaining to accumulate ACKs
158
+
| How long this bundle has left to live (measured in blocks). Starts at 26,300 and counts down.
169
159
|}
170
160
161
+
D1, with all 256 slots active, reaches a maximum size of: 256 * ( 1 (map index) + 36 (outpoint) + 8 (amount) ) = 11,520 bytes.
171
162
163
+
D2, under normal conditions, would reach a size of: (38 bytes per withdrawal * 256 sidechains) = 9,728 bytes.
172
164
173
-
165
+
It is possible to spam D2. A miner can add the max M3s (256) every block, forever. This costs 9,728 on-chain bytes per block, an opportunity cost of about 43 txns. It results in no benefit to the miner whatsoever. D2 will eventually hit a ceiling at 124.5568 MB. (By comparison, the Bitcoin UTXO set is about 7,000 MB.) When the attacker stops, D2 will eventually shrink back down to 9,728 bytes.
174
166
175
167
176
168
=== The Six New Bip300 Messages ===
@@ -188,34 +180,53 @@ M1 is a coinbase OP Return output containing the following:
M2 is a coinbase OP Return output containing the following:
208
203
209
204
1-byte - OP_RETURN (0x6a)
210
205
4-byte - Message header (0xD6E1C5BF)
211
-
32-byte - sha256D hash of sidechain's serialization
206
+
32-byte - the sha256D hash of sidechain's serialization
207
+
208
+
209
+
M2 is ignored if it doesn't parse, or if it is for a sidechain that doesn't exist.
210
+
211
+
M2 is invalid if:
212
+
213
+
* An M2 is already in this block.
214
+
* It tries to ACK two different M1s for the same slot.
212
215
213
-
===== Notes =====
216
+
Otherwise:
214
217
215
-
The new M1/M2 validation rules are:
218
+
* The sidechain is "ACK"ed and does NOT get a "fail" for this block. (As it otherwise would.)
216
219
217
-
# Any miner can propose a new sidechain (M1) at any time. This procedure resembles BIP 9 soft fork activation: the network must see a properly-formatted M1, followed by "acknowledgment" of the sidechain (M2) in 90% of the following 2016 blocks.
218
-
# Bip300 comes with only 256 sidechain-slots. If all are used, it is possible to "overwrite" a sidechain. This requires vastly more M2 ACKs -- 50% of the following 26300 blocks must contain an M2. The possibility of overwrite, does not change the Bip300 security assumptions (because we already assume that the sidechain is vulnerable to miners, at a rate of 1 catastrophe per 13150 blocks).
220
+
A sidechain fails to activate if:
221
+
222
+
* If the slot is unused: during the next 2016 blocks, it accumulates 201 fails. (Ie, 90% threshold).
223
+
* If the slot is in use: during the next 26,300 blocks, it accumulates 13,150 fails. (Ie, 50% threshold).
224
+
225
+
( Thus we can overwrite a used sidechain slot. Bip300 sidechains are already vulnerable to one catastrophe per 13150 blocks (the invalid withdrawal) so this slot-overwrite option does not change the security assumptions. )
226
+
227
+
Otherwise, the sidechain activates (Active is set to TRUE).
228
+
229
+
In the block in which the sidechain activates, the coinbase MUST include at least one 0-valued OP_TRUE. This output becomes the initial CTIP for the sidechain.
219
230
220
231
221
232
@@ -227,7 +238,7 @@ For an M6 to be valid, it must be first "prepped" by one M3 and then 13,150+ M4s
227
238
228
239
===== What are Bundles? =====
229
240
230
-
Sidechain withdrawals take the form of “Bundles” -- named because they "bundle up" many individual withdrawal-requests into a single rare layer1 transaction.
241
+
Sidechain withdrawals take the form of "Bundles" -- named because they "bundle up" many individual withdrawal-requests into a single rare layer1 transaction.
231
242
232
243
Sidechain full nodes aggregate the withdrawal-requests into a big set. The sidechain calculates what M6 would have to look like, to pay all of these withdrawal-requests out. Finally, the sidechain calculates what the hash of this M6 would be. This 32-byte hash identifies the Bundle.
233
244
@@ -248,11 +259,18 @@ M3 is a coinbase OP Return output containing the following:
248
259
1-byte - OP_RETURN (0x6a)
249
260
4-byte - Commitment header (0xD45AA943)
250
261
32-byte - The Bundle hash, to populate a new D2 entry
262
+
1-byte - nSidechain (the slot number)
263
+
264
+
M3 is ignored if it does not parse, or if it is for a sidechain that doesn't exist.
251
265
252
-
The new validation rules pertaining to M3 are:
266
+
M3 is invalid if:
253
267
254
-
# If the network detects a properly-formatted M3, it must add an entry to D2 in the very next block. The starting "Blocks Remaining" value is 26,299. The starting ACKs count is 1.
255
-
# Each block can only contain one M3 per sidechain.
268
+
* This block already has an M3 for that nSidechain.
269
+
* A bundle with this hash is already in D2.
270
+
* A bundle with this hash already paid out.
271
+
* A bundle with this hash was rejected in the past.
272
+
273
+
Otherwise: M3 adds an entry to D2, with initial ACK score = 1 and initial Blocks Remaining = 26,299. (Merely being added to D2, does count as your first upvote.)
256
274
257
275
Once a Bundle is in D2, how can we give it enough ACKs to make it valid?
258
276
@@ -263,44 +281,139 @@ M4 is a coinbase OP Return output containing the following:
263
281
1-byte - OP_RETURN (0x6a)
264
282
4-byte - Commitment header (0xD77D1776)
265
283
1-byte - Version
266
-
n-byte - The vector describing the "upvoted" bundle-choice, for each sidechain.
284
+
n-byte - The "upvote vector" -- describes which bundle-choice is "upvoted", for each sidechain.
285
+
286
+
The upvote vector will code "abstain" as 0xFF (or 0xFFFF); it will code "alarm" as 0xFE (or 0xFFFE). Otherwise it simply indicates which withdrawal-bundle in the list, is the one to be "upvoted".
287
+
288
+
For example: if there are two sidechains, and we wish to upvote the 7th bundle on sidechain #1 plus the 4th bundle on sidechain #2, then the upvote vector would be { 07, 04 }. And M4 would be [0x6A,D77D1776,00,0006,0003].
267
289
268
-
Version 0x01 uses one byte per sidechain, and applies in most cases. Version 0x02 uses two bytes per sidechain and applies in unusual situations where at least one sidechain has more than 256 distinct withdrawal-bundles in progress at one time. Other interesting versions are possible: 0x03 might say "do exactly what was done in the previous block" (which could consume a fixed 6 bytes total, regardless of how many sidechains). 0x04 might say "upvote everyone who is clearly in the lead" (which also would require a mere 6 bytes), and so forth.
290
+
The version number allows us to shrink the upvote vector in many cases. Version 0x00 requires a full two bytes per sidechain, but it always works. Version 0x01 uses half that (one byte per sidechain), and it works while all sidechains have fewer than 255 disputed withdrawals (ie, 99.99%+ of the time). Version 0x02 uses zero bytes (ie, 6 bytes for the whole M4) and sets this block's M4 equal to the previous block's M4. Version 0x03 upvotes only those withdrawals that are leading their rivals by at least 50 votes.
269
291
270
292
If a sidechain has no pending bundles, then it is skipped over when M4 is created and parsed.
271
293
272
-
The upvote vector will code "abstain" as 0xFF (or 0xFFFF); it will code "alarm" as 0xFE (or 0xFFFE). Otherwise it simply indicates which withdrawal-bundle in the list, is the one to be "upvoted". For example, if there are two sidechains, and we wish to upvote the 7th bundle on sidechain #1 plus the 4th bundle on sidechain #2, then the vector would be 0x0704.
294
+
For example, an upvote vector of { 2 , N/A, 1 } would be represented as [0x6A,D77D1776,01,00,00]. It means: "upvote the first bundle in sidechain #1; and the first bundle in sidechain #3" (iff sidechains #2 has no bundles proposed).
273
295
274
-
The M4 message will be invalid (and invalidate the block), if it tries to upvote a Bundle that doesn't exist (for example, trying to upvote the 7th bundle on sidechain #2, when sidechain #2 has only three bundles). If there are no Bundles at all (no one is trying to withdraw from any sidechain), then *any* M4 message present in the coinbase will be invalid. If M4 is NOT present in a block, then it is treated as "abstain".
296
+
An upvote vector of { N/A, N/A, 4 } would be [0x6A,D77D1776,01,03].
275
297
276
-
The ACKed withdrawal will gain one point for its ACK field. Therefore, the ACK-counter of any Bundle can only change by (-1,0,+1).
277
298
278
-
Within a sidechain-group, upvoting one Bundle ("+1") requires you to downvote all other Bundles in that group. However, the minimum ACK-counter is zero. While only one Bundle can be upvoted at once; the whole group can all be unchanged at once ("abstain"), and they can all be downvoted at once ("alarm").
299
+
The M4 message will be invalid (and invalidate the block), if:
279
300
280
-
Finally, we describe Deposits and Withdrawals.
301
+
* It tries to upvote a Bundle that doesn't exist. (For example, trying to upvote the 7th bundle on sidechain #2, when sidechain #2 has only three bundles.)
302
+
* There are no Bundles at all, from any sidechain.
303
+
304
+
If M4 is NOT present in a block, then it is treated as "abstain".
305
+
306
+
If M4 is present and valid: each withdrawal-bundle that is ACKed, will gain one upvote.
307
+
308
+
Important: Within a sidechain-group, upvoting one Bundle ("+1") automatically downvotes ("-1") all other Bundles in that group. However, the minimum ACK-counter is zero. While only one Bundle can be upvoted at once; the whole group can all be unchanged at once ("abstain"), and they can all be downvoted at once ("alarm").
309
+
310
+
For example:
311
+
312
+
{| class="wikitable"
313
+
|-
314
+
! SC#
315
+
! Bundle Hash
316
+
! ACKs
317
+
! Blocks Remaining
318
+
|-
319
+
| 1
320
+
| h1
321
+
| 45
322
+
| 22,109
323
+
|-
324
+
| 1
325
+
| h2
326
+
| 12
327
+
| 22,008
328
+
|-
329
+
| 2
330
+
| h3
331
+
| 13
332
+
| 22,999
333
+
|-
334
+
| 2
335
+
| h4
336
+
| 8
337
+
| 23,550<br />
338
+
|-
339
+
| 2
340
+
| h5
341
+
| 2
342
+
| 22,560
343
+
|}
344
+
345
+
346
+
...in block 900,000 could become...
347
+
348
+
349
+
{| class="wikitable"
350
+
|-
351
+
! SC#
352
+
! Bundle Hash
353
+
! ACKs
354
+
! Blocks Remaining
355
+
|-
356
+
| 1
357
+
| h1
358
+
| 46
359
+
| 22,108
360
+
|-
361
+
| 1
362
+
| h2
363
+
| 11
364
+
| 22,007
365
+
|-
366
+
| 2
367
+
| h3
368
+
| 12
369
+
| 22,998
370
+
|-
371
+
| 2
372
+
| h4
373
+
| 9
374
+
| 23,549<br />
375
+
|-
376
+
| 2
377
+
| h5
378
+
| 1
379
+
| 22,559
380
+
|}
381
+
382
+
...if M4 were [0x6A,D77D1776,00,0000,0001].
281
383
282
384
385
+
Finally, we describe Deposits and Withdrawals.
386
+
283
387
==== M5 -- Deposit BTC to Sidechain ====
284
388
285
-
Both M5 and M6 are regular Bitcoin txns. They are distinguished from regular txns (non-M5 non-M6 txns), when they select one of the special Bip300 CTIP UTXOs as one of their inputs (see D1).
389
+
Each sidechain stores all its BTC in one UTXO, called the "CTIP".
286
390
287
-
All of a sidechain’s coins, are stored in one UTXO, called the "CTIP". Every time a deposit or withdrawal is made, the CTIP changes. Each deposit/withdrawal will select the sidechains CTIP, and generate a new CTIP. (Deposits/Withdrawals never cause UTXO bloat.) The current CTIP is cached in D1 (above).
391
+
By definition, an M5 is a transaction which spends the CTIP and '''increases''' the quantity of coins. An M6 is a transaction which spends the CTIP and '''decreases''' the quantity of coins in the CTIP. See [https://github.com/LayerTwo-Labs/mainchain/blob/391ab390adaa19f92871d769f8e120ca62c1cf14/src/validation.cpp#L688-L801 here].
288
392
289
-
If the '''quantity of coins''', in the from-CTIP-to-CTIP transaction, goes '''up''', (ie, if the user is adding coins), then the txn is treated as a Deposit (M5). Else it is treated as a Withdrawal (M6). See [https://github.com/drivechain-project/mainchain/blob/e37b008fafe0701b8313993c8b02ba41dc0f8a29/src/validation.cpp#L667-L780 here].
393
+
Every time a deposit/withdrawal is made, the old CTIP is spent and a new one is created. (Deposits/Withdrawals never cause UTXO bloat.) At all times, the CTIP of each sidechain is cached in D1 (above).
394
+
395
+
Every M5 is valid, as long as:
396
+
397
+
* It has at least one OP_TRUE output -- this becomes the new CTIP.
398
+
* The new CTIP has '''more''' coins in it, than before.
290
399
291
-
As far as mainchain consensus is concerned, all deposits to a sidechain are always valid.
292
400
293
401
==== M6 -- Withdraw BTC from a Sidechain ====
294
402
295
403
We come, finally, to the critical matter: where users can take their money *out* of the sidechain.
296
404
297
-
First, M6 must obey the same CTIP rules of M5 (see immediately above).
405
+
M6 is invalid if:
406
+
407
+
* The blinded hash of M6 does NOT match one of the approved Bundle-hashes. (In other words: M6 must first be approved by 13,150 upvotes.)
408
+
* The first output of M6 is NOT an OP_TRUE. (This OP_TRUE becomes the new CTIP. In other words: all non-withdrawn coins are paid back to the sidechain.)
409
+
* The second output is NOT an OP_RETURN script of exactly 10 bytes, of which 8 bytes are a serialized Bitcoin amount.
410
+
* The txn fee of M6 is NOT exactly equal to the amount of the previous bullet point.
411
+
412
+
Else, M6 is valid.
413
+
414
+
(The point of the latter two bullet points, is to allow the bundle hash to cover the L1 transaction fee.)
298
415
299
-
Second, an M6 is only valid for inclusion in a block, if its blinded TxID matches an "approved" Bundle hash (ie, one with an ACK score of 13150+). In other words, an M6 can only be included in a block, after the 3+ month (13150 block) ceremony.
300
416
301
-
Third, M6 must meet two accounting criteria, lest it be invalid:
302
-
# "Give change back to Escrow" -- The first output, TxOut0, must be paid back to the sidechain's Bip300 script. In other words, all non-withdrawn coins must be paid back into the sidechain.
303
-
# "No traditional txn fee" -- For this txn, the sum of all inputs must equal the sum of all outputs. No traditional tx fee is possible. (Of course, there is still a txn fee for miners: it is paid via an OP TRUE output in the Bundle.) We want the withdraw-ers to set the fee "inside" the Bundle, and ACK it over 3 months like everything else.
304
417
305
418
306
419
==Backward compatibility==
@@ -331,7 +444,7 @@ See http://www.drivechain.info/literature/index.html
331
444
332
445
==Credits==
333
446
334
-
Thanks to everyone who contributed to the discussion, especially: ZmnSCPxj, Adam Back, Peter Todd, Dan Anderson, Sergio Demian Lerner, Chris Stewart, Matt Corallo, Sjors Provoost, Tier Nolan, Erik Aronesty, Jason Dreyzehner, Joe Miyamoto, Ben Goldhaber.
447
+
Thanks to everyone who contributed to the discussion, especially: Luke Dashjr, ZmnSCPxj, Adam Back, Peter Todd, Dan Anderson, Sergio Demian Lerner, Chris Stewart, Matt Corallo, Sjors Provoost, Tier Nolan, Erik Aronesty, Jason Dreyzehner, Joe Miyamoto, Ben Goldhaber.
0 commit comments