Skip to content

Commit 3176623

Browse files
authored
Update Bip300
1 parent 8447ec6 commit 3176623

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

bip-0300.mediawiki

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,7 @@ First, how are new sidechains created?
179179

180180
They are first proposed (with M1), and later acked (with M2). This process resembles Bip9 soft fork activation.
181181

182-
==== M1 and M2 (Adding a new sidechain) ====
183-
184-
Examples:
185-
186-
<img src="bip-0300/m1-gui.jpg?raw=true" align="middle"></img>
187-
188-
<img src="bip-0300/m1-cli.png?raw=true" align="middle"></img>
182+
==== M1 -- Propose Sidechain ====
189183

190184
M1 is a coinbase OP Return output containing the following:
191185

@@ -202,47 +196,67 @@ M1 is a coinbase OP Return output containing the following:
202196
32-byte hashID1
203197
20-byte hashID2
204198
199+
===== Examples =====
200+
201+
<img src="bip-0300/m1-gui.jpg?raw=true" align="middle"></img>
202+
203+
<img src="bip-0300/m1-cli.png?raw=true" align="middle"></img>
204+
205+
==== M2 -- ACK Sidechain Proposal ====
206+
205207
M2 is a coinbase OP Return output containing the following:
206208

207209
1-byte - OP_RETURN (0x6a)
208210
4-byte - Message header (0xD6E1C5BF)
209211
32-byte - sha256D hash of sidechain's serialization
210212
213+
===== Notes =====
214+
211215
The new M1/M2 validation rules are:
212216

213-
# Any miner can propose a new sidechain 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 in 90% of the following 2016 blocks.
214-
# It is possible to "overwrite" a sidechain. This requires more ACKs -- 50% of the following 26300 blocks must contain an M2. The possibility of overwrite, does not change the security assumptions (because we already assume that users perform extra-protocolic validation at a rate of 1 bit per 26300 blocks).
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).
219+
220+
215221

222+
==== Notes on Withdrawing Coins ====
216223

217-
==== M3 and M4 (Withdrawing Coins) ====
224+
Bip300 withdrawals ("M6") are very significant.
218225

219-
Withdrawals in Bip300 (ie, "M6"), are very significant. So, we will first discuss how these are approved/rejected -- a process involving M3, M4, and D2.
226+
For an M6 to be valid, it must be first "prepped" by one M3 and then 13,150+ M4s. M3 and M4 are about "Bundles".
220227

221228
===== What are Bundles? =====
222229

223-
All Bip300 withdrawals take the form of “Bundles” -- named because they "bundle up" many individual withdrawal-requests into one single rare layer1 transaction.
230+
Sidechain withdrawals take the form of “Bundles” -- named because they "bundle up" many individual withdrawal-requests into a single rare layer1 transaction.
231+
232+
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+
234+
This 32-byte hash is what miners will be slowly ACKing over 3-6 months, not the M6 itself (nor any sidechain data, of course).
235+
236+
A bundle either pays all its withdrawals out (via M6), or else it fails (and pays nothing out).
224237

225-
This bundle either pays all of the withdrawals out, or else it fails (and pays nothing out). Bip300 / layer 1 does not assemble Bundles (the sidechain developer does this, in a manner of their choosing).
238+
===== Bundle Hash = Blinded TxID of M6 =====
226239

227-
Bundles are identified by a 32-byte hash, which aspires to be the TxID of M6. Unfortunately, the Bundle-hash and M6-TxID cannot match exactly, since the first input to M6 is a CTIP which is constantly changing. So, we must accomplish a task, which is conceptually similar to AnyPrevOut (BIP 118). We define a "blinded TxID" as a way of hashing a txn, in which some bytes are first overwritten with zeros. In our case, the precise "overwritten bytes" are: the first input and the first output.
240+
The Bundle hash is static as it is being ACKed. Unfortunately, the M6 TxID will be constantly changing -- as users deposit to the sidechain, the input to M6 will change.
228241

229-
===== M3 (Propose a Bundle) =====
242+
To solve this problem, we do something conceptually similar to AnyPrevOut (BIP 118). We define a "blinded TxID" as a way of hashing a txn, in which some bytes are first overwritten with zeros. These are: the first input and the first output. Via the former, a sidechain can accept deposits, even if we are acking a TxID that spends from it later. Via the latter, we can force all of the non-withdrawn coins to be returned to the sidechain (even if we don't yet know how many coins this will be).
243+
244+
==== M3 -- Propose Bundle ====
230245

231246
M3 is a coinbase OP Return output containing the following:
232247

233248
1-byte - OP_RETURN (0x6a)
234249
4-byte - Commitment header (0xD45AA943)
235250
32-byte - The Bundle hash, to populate a new D2 entry
236251
237-
238252
The new validation rules pertaining to M3 are:
239253

240254
# 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.
241255
# Each block can only contain one M3 per sidechain.
242256
243257
Once a Bundle is in D2, how can we give it enough ACKs to make it valid?
244258

245-
===== M4 (ACK Withdrawals) =====
259+
==== M4 -- ACK Bundle(s) ====
246260

247261
M4 is a coinbase OP Return output containing the following:
248262

@@ -251,7 +265,9 @@ M4 is a coinbase OP Return output containing the following:
251265
1-byte - Version
252266
n-byte - The vector describing the "upvoted" bundle-choice, for each sidechain.
253267
254-
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. If a sidechain has no pending bundles, then it is skipped over when M4 is created and parsed.
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.
269+
270+
If a sidechain has no pending bundles, then it is skipped over when M4 is created and parsed.
255271

256272
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.
257273

@@ -263,39 +279,35 @@ Within a sidechain-group, upvoting one Bundle ("+1") requires you to downvote al
263279

264280
Finally, we describe Deposits and Withdrawals.
265281

266-
==== M5 and M6 (User's Deposits and Withdrawals) ====
267282

268-
Both M5 and M6 are regular Bitcoin txns. They are identified, as Deposits/Withdrawals, when they select one of the special CTIP UTXOs as one of their inputs (see D1).
283+
==== M5 -- Deposit BTC to Sidechain ====
269284

270-
All of a sidechain’s coins, are stored in one UTXO. (Deposits/Withdrawals never cause UTXO bloat.) So, each Deposit/Withdrawal must select a CTIP, and generate a new CTIP (this is tracked in D1, above).
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).
271286

272-
If the from-CTIP-to-CTIP quantity of coins 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].
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).
273288

274-
275-
===== M5 (Make a Deposit) -- a transfer of BTC from-main-to-side =====
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].
276290

277291
As far as mainchain consensus is concerned, all deposits to a sidechain are always valid.
278292

279-
===== M6 (Execute a Withdrawal) -- a transfer of BTC from-side-to-main =====
293+
===== M6 -- Withdraw BTC from a Sidechain =====
280294

281295
We come, finally, to the critical matter: where users can take their money *out* of the sidechain.
282296

283-
In each block, a Bundle in D2 is considered "approved" if its "ACK-counter" value meets the threshold (13,150).
284-
285-
If a Bundle is approved, then its associated M6 can be included in a block.
297+
First, M6 must obey the same CTIP rules of M5 (see immediately above).
286298

287-
An M6 must meet all these criteria, else it be invalid:
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.
288300

289-
# "Be ACKed" -- The "blinded TxID" of the M6 must match an approved Bundle. In other words, an M6 can only be included in a block, after the 3+ month (13150 block) ceremony.
290-
# "Return Change to Account" -- TxOut0 must be paid back to the sidechain's Bip300 script. In other words, since we select the UTXO with *all* of the money, we must make sure we pay all of the non-withdrawn money back into the sidechain.
291-
# "Return *all* Change to Account" -- Sum of all inputs must equal the sum of all outputs. No traditional tx fee is possible. (The txn fee is paid via an OP TRUE output in the Bundle -- this allows the withdraw-ers to set the fee via the Bundle, and ACK it over 3 months like everything else.)
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.
292304
293305

294306
==Backward compatibility==
295307

296-
As a soft fork, older software will continue to operate without modification. Non-upgraded nodes will see a number of phenomena that they don't understand -- coinbase txns with non-txn data, value accumulating in anyone-can-spend UTXOs for months at a time, and then random amounts leaving the UTXO in single, infrequent bursts. However, these phenomena don't affect them, or the validity of the money that they receive.
308+
As a soft fork, older software will continue to operate without modification. Non-upgraded nodes will see a number of phenomena that they don't understand -- coinbase txns with non-txn data, value accumulating in anyone-can-spend UTXOs for months at a time, and then random amounts leaving these UTXOs in single, infrequent bursts. However, these phenomena don't affect them, or the validity of the money that they receive.
297309

298-
( As a nice bonus, note that the sidechains themselves inherit a resistance to hard forks. The only way to guarantee that a sidechain's Bundles will continue to match identically, is to upgrade sidechains via soft forks of themselves. )
310+
( As a nice bonus, note that the sidechains themselves inherit a resistance to hard forks. The only way to guarantee that all different sidechain-nodes will always report the same Bundle, is to upgrade sidechains via soft forks of themselves. )
299311

300312

301313
==Deployment==

0 commit comments

Comments
 (0)