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
A type script for Bitcoin SPV clients which synchronize [Bitcoin] state into [CKB].
4
+
A type script designed for Bitcoin SPV clients ensures the valid synchronization of the [Bitcoin]blockchain state into the Nervos [CKB] network.
5
5
6
6
## Brief Introduction
7
7
8
-
A [Bitcoin] SPV in [CKB] contains a set of cells, this type script is used
9
-
to manage them.
10
-
11
-
The set is identified by the script [`args`]. The number of live cells with this
12
-
specific `args` script is fixed once created, and all cells in the set are
13
-
destroyed together.
8
+
A Bitcoin SPV on CKB consists of cells that are managed by the CKB Bitcoin SPV Type Script and identified by the script args. The number of live cells with the script args remains fixed once created, and these cells will be destroyed collectively as a group.
14
9
15
10
### Cells
16
11
17
-
There are 2 kinds of cells in a Bitcoin SPV instance:
12
+
A Bitcoin SPV instance contains two types of cells: **SPV info cell** and **SPV client cell**.
18
13
19
-
- Client Cell
14
+
-**SPV Client Cell**
20
15
21
-
This cell is used to store the Bitcoin state.
16
+
A cell is identified as an SPV client cell if its type script matches the SPV type script.
22
17
23
-
Each Bitcoin SPV instance should contain at least 3 client cells.
18
+
SPV client cells store the Bitcoin state. Each Bitcoin SPV instance includes a minimum of three SPV client cells.
24
19
25
20
```yaml
26
21
Client Cell:
@@ -35,12 +30,10 @@ There are 2 kinds of cells in a Bitcoin SPV instance:
35
30
- target adjust info
36
31
```
37
32
38
-
- Info Cell
39
-
40
-
This cell is used to store the basic information of current Bitcoin SPV
41
-
instance. Such as the ID of the tip client cell.
33
+
- **SPV Info Cell**
42
34
43
-
Each Bitcoin SPV instance should contain only 1 info cell.
35
+
The SPV info cell stores the basic information of the current Bitcoin SPV instance, such as `tip_client_id`. Each Bitcoin SPV
36
+
instance contains only one SPV info cell.
44
37
45
38
```yaml
46
39
Info Cell:
@@ -54,26 +47,16 @@ There are 2 kinds of cells in a Bitcoin SPV instance:
54
47
55
48
### Operations
56
49
57
-
There are 4 kinds of operations:
58
-
59
-
- Create
50
+
There are 4 kinds of operations in the Bitcoin SPV type script:
60
51
61
-
Create all cells for a Bitcoin SPV instance in one transaction.
52
+
- **Create**
62
53
63
-
The outputs of this transaction should contain 1 info cell and at least 1 client cell.
54
+
This operation initiates all necessary cells for a Bitcoin SPV instance in a single transaction.
64
55
65
-
In the follow part of this document, we denoted the number of client cells
66
-
as `n`.
56
+
The `outputs` include one SPV info cell and at least three SPV client cell. Cells should be consecutive, with the SPV info cell first,
57
+
followed by N SPV client cells ordered by their ID from smallest to largest.
67
58
68
-
In current implementation, it requires that cells must be continuous and
69
-
in specified order:
70
-
71
-
- The client info cell should be at the first.
72
-
73
-
- Immediately followed by `n` client cells, and these cells should be
74
-
ordered by their ID from smallest to largest.
75
-
76
-
The structure of this kind of transaction is as follows:
59
+
Let's denote the number of SPV client cells as `n`. The structure of this transaction is as follows:
77
60
78
61
```yaml
79
62
Cell Deps:
@@ -95,10 +78,9 @@ There are 4 kinds of operations:
95
78
- ... ...
96
79
```
97
80
98
-
- Destroy
81
+
- **Destroy**
99
82
100
-
All cells that use the same instance of this type lock should be destroyed
101
-
together in one transaction.
83
+
Cells within a single Bitcoin SPV instance should be destroyed in one transaction..
102
84
103
85
The structure of this kind of transaction is as follows:
104
86
@@ -123,22 +105,17 @@ There are 4 kinds of operations:
123
105
- ... ...
124
106
```
125
107
126
-
- Update
108
+
- **Update**
127
109
128
110
After creation, the `n` client cells should have same data.
129
111
130
-
The client cell who has the same ID as the `tip_client_id` in the info cell,
131
-
we consider that it has the latest data.
132
-
133
-
The client cell who has the next ID of the `tip_client_id` in the info cell,
134
-
we consider that it has the oldest data. These client cells form a ring, where
135
-
the next ID after `n-1` is `0`.
136
-
137
-
Once we update the Bitcoin SPV instance, we put the new data into the client
138
-
cell which has the oldest data, and update the `tip_client_id` in the client
139
-
info cell to its ID.
112
+
The SPV client cell which ID matches the `tip_client_id` of the SPV info cell contains the most recent data, the SPV client cell next
113
+
in the sequence after the `tip_client_id` of the info cell holds the oldest data. This sequence arrangement of cells forms a ring
114
+
where after the last cell (`ID = n-1`), it wraps around back to the first cell (`ID = 0`).
140
115
141
-
Do the above step in repetition.
116
+
When the Bitcoin SPV instance is updated, the new data will be put into the client cell that currently has the oldest data. Also,
117
+
the `tip_client_id` in the SPV info cell will be replaced by the `ID` of the SPV client cell that just received the new data. This SPV
118
+
info cell now becomes the new "latest data" holder.
142
119
143
120
The structure of this kind of transaction is as follows:
144
121
@@ -160,18 +137,15 @@ There are 4 kinds of operations:
160
137
- ... ...
161
138
```
162
139
163
-
- Reorg
140
+
- **Reorg**
164
141
165
-
When receives blocks from a new longer chain, and there has at least one
166
-
client cell whose tip block is the common ancestor block of both the old
167
-
chain and the new chain, then a chain reorganization will be required.
142
+
When receiving blocks from a new, longer chain, if there is at least one client cell whose tip block is the
143
+
common ancestor block of both the old chain and the new chain, a reorg is triggered. The reorg will be based
144
+
on this common ancestor, and all client cells with a tip higher than it will be updated accordingly.
168
145
169
-
**If no common ancestor block was found, then the Bitcoin SPV instance
170
-
will be broken, and it requires re-deployment.**
146
+
**If no common ancestor block is identified, the Bitcoin SPV instance will fail and require re-deployment.**
171
147
172
-
let's denote the client ID of the best common ancestor to be `t`.
173
-
174
-
The structure of this kind of transaction is as follows:
148
+
Let's denote the client ID of the best common ancestor as `t`. The structure of this transaction is as follows:
175
149
176
150
```yaml
177
151
Cell Deps:
@@ -203,65 +177,54 @@ index of the output SPV info cell, and the proof should be set in
203
177
204
178
### Usages
205
179
206
-
When you want to verify a transaction with Bitcoin SPV Client cell:
180
+
To verify a transaction using the Bitcoin SPV Client cell, follow these steps:
207
181
208
-
- Choose any client cell which contains the block that transaction in.
182
+
- Select an SPV client cell that contains the block where the transaction is;
209
183
210
184
- Create a transaction proof, with the following data:
211
185
212
-
- The MMR proof of the header which contains this transaction.
186
+
- The MMR proof of the block header which contains this transaction;
213
187
214
-
- The TxOut proof of that transaction.
188
+
- The TxOut proof of the transaction;
215
189
216
-
- The index of that transaction.
190
+
- The index of the transaction;
217
191
218
-
- The height of that header.
192
+
- The height of the block header.
219
193
220
-
- Use [the API `SpvClient::verify_transaction(..)`](https://github.com/ckb-cell/ckb-bitcoin-spv/blob/2464c8f/verifier/src/types/extension/packed.rs#L275-L292) to verify the transaction.
221
-
222
-
A simple example could be found in [this test](https://github.com/ckb-cell/ckb-bitcoin-spv/blob/2464c8f/prover/src/tests/service.rs#L132-L181).
194
+
- Use the [`SpvClient::verify_transaction(..)`](https://github.com/ckb-cell/ckb-bitcoin-spv/blob/2464c8f/verifier/src/types/extension/packed.rs#L275-L292) for the verification. For detailed guidance, please refer to the [API example].
223
195
224
196
### Limits
225
197
226
-
- The lower limit of SPV client cells count is 3.
227
-
228
-
- The upper limit of SPV client cells count is not set, but base on the data type, `u8`,
229
-
any number larger than `250` is not recommended.
230
-
231
-
### Known Issues
232
-
233
-
- `VM Internal Error: MemWriteOnExecutablePage`
234
-
235
-
Don't set hash type[^1] to be `Data`.
198
+
- The minimum count of SPV client cells is 3;
199
+
200
+
- The maximum count of SPV client cells is advisable not to exceed `250` given the **`u8`** data type.
236
201
237
-
`Data1`is introduced from [CKB RFC 0032], and `Data2` is introduced from [CKB RFC 0051].
202
+
### Known Issues and Solutions
238
203
239
-
- Failed to reorg when there is only 1 stale SPV client.
0 commit comments