Skip to content

Commit fb23847

Browse files
committed
Add a new case when root script can terminate leaf scripts
1 parent b79dea6 commit fb23847

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

rfcs/0000-arbitrary-multisig/0000-arbitrary-multisig.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Before executing spawn syscall, the root script must create 2 pipes via [pipe](h
238238

239239
In spawn syscall, the root script must pass `root_to_leaf_pipe[0]` and `leaf_to_root_pipe[1]` in this exact order to the invoked leaf script. The leaf script uses [Inherited File Descriptors](https://github.com/nervosnetwork/rfcs/blob/bd5d3ff73969bdd2571f804260a538781b45e996/rfcs/0050-vm-syscalls-3/0050-vm-syscalls-3.md#inherited-file-descriptors) syscall to gather 2 file descriptors for the leaf script to use.
240240

241-
When the spawn syscall succeeds, the root script would continuously send signature data packet via `root_to_leaf_pipe[1]` to the leaf script. The leaf script loops to read such packets from `root_to_leaf_pipe[0]`. Right now, 2 formats exist for verification:
241+
When the spawn syscall succeeds, the root script would continuously send certain packets described below via `root_to_leaf_pipe[1]` to the leaf script. The leaf script loops to read such packets from `root_to_leaf_pipe[0]`. Right now, 2 formats exist for verification:
242242

243243
### Signature Packet Format 1
244244

@@ -274,7 +274,7 @@ If all verification work succeeds, the leaf script sends the following response
274274
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
275275
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
276276

277-
The leaf script then waits to read more packets for verification from `root_to_leaf_pipe[0]`. There is no situation when a leaf script terminates with a success exit code. We rely on CKB's behavior that when the root VM terminates, all the child VMs also terminate.
277+
The leaf script then waits to read more packets for verification from `root_to_leaf_pipe[0]`.
278278

279279
### Signature Packet Format 2
280280

@@ -313,10 +313,22 @@ If all verification work succeeds, the leaf script sends the following response
313313
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
314314
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
315315

316-
The leaf script then waits to read more packets for verification from `root_to_leaf_pipe[0]`. There is no situation when a leaf script terminates with a success exit code. We rely on CKB's behavior that when the root VM terminates, all the child VMs also terminate.
316+
The leaf script then waits to read more packets for verification from `root_to_leaf_pipe[0]`.
317317

318318
This signature packet format is in fact designed for `ALGO_ID` of `63`, when an arbitrary script is loaded for signature verification. Signature packet format 2 can be used to exchange signatures to valid between root script and the arbitrary leaf script.
319319

320+
### Terminating Packet Format
321+
322+
A terminating packet might be sent by the root script to terminate a leaf script. The format is as follows:
323+
324+
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
325+
* 3 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
326+
* 0 encoded in [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) format.
327+
328+
Upon receiving this packet, the leaf script terminates with zero as return code immediately, it does not send any response packet.
329+
330+
Normally, a root script does not need to terminate a leaf script. When the VM instance with VM ID 0 terminates, all child VMs terminate automatically. This packet is only suitable when too many child VM isntances have been created by the current running script group. In this case, the root script might choose to terminate some leaf scripts first, then spawn new ones.
331+
320332
## Exec
321333

322334
A root script might use exec syscall to invoke a leaf script, when the following conditions are met:

0 commit comments

Comments
 (0)