|
1 | 1 | # Safrole Test Vectors |
2 | 2 |
|
3 | | -For details refer to ASN.1 [schema](./safrole.asn). |
| 3 | +We offer two types of test vectors: |
4 | 4 |
|
5 | | -## NOTES |
| 5 | +- Tiny: These are designed for quick adjustments and prototyping, with reduced validators (6) |
| 6 | + and a shorter epoch duration (12). They are provided in both JSON format for easy inspection |
| 7 | + and modification, and in SCALE format, which is the production binary codec. |
6 | 8 |
|
7 | | -- Error codes returned as output are not part of the specification. Feel free to ignore actual values. |
8 | | -- On error, post-state must match pre-state. |
9 | | -- Ring verifier is constructed using [ark-ec-vrfs](https://github.com/davxy/ark-ec-vrfs) procedures. |
| 9 | +- Full: These vectors use production validators count (1023) and epoch duration (600). |
| 10 | + Similar to the tiny vectors, they are available in JSON and SCALE format. |
10 | 11 |
|
11 | | -## TODO |
| 12 | +Both JSON and SCALE formats conform to the specified ASN.1 schema provided [here](./safrole.asn). |
12 | 13 |
|
13 | | -- Better specify the procedure used to construct test ring verifier. |
| 14 | +## zk-SNARK SRS |
14 | 15 |
|
15 | | -## Vectors |
| 16 | +Ring proofs were constructed using a SNARK built using the the [Zcash SRS paramaters](zcash-srs-2-11-uncompressed.bin). |
| 17 | +([powers of tau ceremony details](https://zfnd.org/conclusion-of-the-powers-of-tau-ceremony)). |
16 | 18 |
|
17 | | -- [enact-epoch-change-no-tickets-1.json](enact-epoch-change-with-no-tickets-1.json) |
18 | | - - Progress from slot 0 to 1. |
19 | | - - No tickets extrinsic. |
20 | | -- [enact-epoch-change-no-tickets-2.json](enact-epoch-change-with-no-tickets-2.json) |
21 | | - - Progress from slot 1 to slot 1. |
| 19 | +For construction and usage refer to Bandersnatch vrfs spec [example](https://github.com/davxy/bandersnatch-vrfs-spec/tree/main/example). |
| 20 | + |
| 21 | +NOTE: for "tiny" initialize the `RingContext` with `ring_size = 6`; while for full `ring size = 1023`. |
| 22 | + |
| 23 | +## Safrole **is not** Sassafras |
| 24 | + |
| 25 | +You can use the Sassafras [RFC](https://github.com/polkadot-fellows/RFCs/blob/main/text/0026-sassafras-consensus.md) |
| 26 | +as a guideline provided it does not conflict with the protocol described by the *Graypaper* |
| 27 | +If case of any discrepancy, the *Graypaper* **must** be considered the authoritative source |
| 28 | +for the JAM protocol. |
| 29 | + |
| 30 | +Here are some key differences: |
| 31 | +- Safrole does not use a threshold to determine if a ticket score should be considered. |
| 32 | + A ticket is persisted in the state if the ticket accumulator is not full or if the |
| 33 | + score is lower than the highest score currently in the accumulator (which is removed |
| 34 | + after the new ticket is inserted). |
| 35 | +- Safrole requires the entire ticket accumulator to be filled before it can be used. |
| 36 | + If not enough tickets are received, a fallback mechanism is enacted. In contrast, |
| 37 | + Sassafras can operate with an epoch that is only partially filled with tickets. |
| 38 | +- In Safrole, the ticket envelope contains no additional application-specific data, |
| 39 | + it includes only the "attempt" and the "ring proof". |
| 40 | + |
| 41 | +Most of these differences aim to provide a clear and concise protocol specification. |
| 42 | + |
| 43 | +## Error Output |
| 44 | + |
| 45 | +On STF (State Transition Function) execution error, post-state must match pre-state. |
| 46 | + |
| 47 | +Possible error codes returned as output are not part of the specification, |
| 48 | +feel free to ignore actual numeric values. |
| 49 | + |
| 50 | +A map for errors codes semantics used by for the test vectors is given in the ASN.1 schema. |
| 51 | + |
| 52 | +## Tiny Vectors |
| 53 | + |
| 54 | +- [enact-epoch-change-with-no-tickets-1.json](./tiny/enact-epoch-change-with-no-tickets-1.json) |
| 55 | + - Progress by one slot. |
| 56 | + - Randomness accumulator is updated. |
| 57 | +- [enact-epoch-change-with-no-tickets-2.json](./tiny/enact-epoch-change-with-no-tickets-2.json) |
| 58 | + - Progress from slot X to slot X. |
22 | 59 | - Fail: Timeslot must be strictly monotonic. |
23 | | -- [enact-epoch-change-no-tickets-3.json](enact-epoch-change-with-no-tickets-3.json) |
24 | | - - Progress from slot 1 to a slot in epoch's tail. |
25 | | - - Tickets mark is not generated (no enough ticket). |
26 | | -- [enact-epoch-change-no-tickets-4.json](enact-epoch-change-with-no-tickets-4.json) |
| 60 | +- [enact-epoch-change-with-no-tickets-3.json](./tiny/enact-epoch-change-with-no-tickets-3.json) |
| 61 | + - Progress from a slot at the begin of the epoch to a slot in the epoch's tail. |
| 62 | + - Tickets mark is not generated (no enough tickets). |
| 63 | +- [enact-epoch-change-with-no-tickets-4.json](./tiny/enact-epoch-change-with-no-tickets-4.json) |
27 | 64 | - Progress from epoch's tail to next epoch. |
28 | | - - Authorities / entropies rotated. |
29 | | - - Epoch mark generated. |
30 | | - |
31 | | -- [skip-epochs-1](skip-epochs-1.json) |
32 | | - - Progress by skipping epochs. |
33 | | - - Accumulated tickets are discarded> |
34 | | - - Tickets mark is not generated (skipped epochs). |
| 65 | + - Authorities and entropies are rotated. |
| 66 | + - Epoch mark is generated. |
| 67 | +- [skip-epochs-1](./tiny/skip-epochs-1.json) |
| 68 | + - Progress skipping epochs with a full tickets accumulator. |
| 69 | + - Tickets mark is not generated. |
| 70 | + - Accumulated tickets are discarded. |
35 | 71 | - Fallback method is enacted. |
36 | | - |
37 | | -- [skip-epoch-tail-1](skip-epoch-tail-1.json) |
38 | | - - Progress to next epoch by skipping epochs tail. |
| 72 | +- [skip-epoch-tail-1](./tiny/skip-epoch-tail-1.json) |
| 73 | + - Progress to next epoch by skipping epochs tail with a full tickets accumulator. |
39 | 74 | - Tickets mark has no chance to be generated. |
40 | | - - Even tough we have enough tickets, these are discarded when next epoch is enacted. |
| 75 | + - Accumulated tickets are discarded. |
41 | 76 | - Fallback method is enacted. |
42 | | - |
43 | | -- [publish-tickets-no-mark-1](publish-tickets-no-mark-1.json) |
44 | | - - Fail: Submit an extrinsic with more tickets than allwed. |
45 | | -- [publish-tickets-no-mark-2](publish-tickets-no-mark-2.json) |
46 | | - - Submit tickets extrinsics from authority 0 and 1. |
47 | | -- [publish-tickets-no-mark-3](publish-tickets-no-mark-3.json) |
48 | | - - Fail: Re-submit tickets from authority 0. |
49 | | -- [publish-tickets-no-mark-4](publish-tickets-no-mark-4.json) |
| 77 | +- [publish-tickets-no-mark-1](./tiny/publish-tickets-no-mark-1.json) |
| 78 | + - Fail: Submit an extrinsic with a bad ticket attempt number. |
| 79 | +- [publish-tickets-no-mark-2](./tiny/publish-tickets-no-mark-2.json) |
| 80 | + - Submit good tickets extrinsics from some authorities. |
| 81 | +- [publish-tickets-no-mark-3](./tiny/publish-tickets-no-mark-3.json) |
| 82 | + - Fail: Re-submit one ticket already in the state. |
| 83 | +- [publish-tickets-no-mark-4](./tiny/publish-tickets-no-mark-4.json) |
50 | 84 | - Fail: Submit tickets in bad order. |
51 | | -- [publish-tickets-no-mark-5](publish-tickets-no-mark-5.json) |
| 85 | +- [publish-tickets-no-mark-5](./tiny/publish-tickets-no-mark-5.json) |
52 | 86 | - Fail: Submit tickets with bad ring proof. |
53 | | -- [publish-tickets-no-mark-6](publish-tickets-no-mark-6.json) |
54 | | - - Submit a ticket from authority 2. |
55 | | -- [publish-tickets-no-mark-7](publish-tickets-no-mark-7.json) |
56 | | - - Fail: Submit a ticket while in epoch's tail. |
57 | | -- [publish-tickets-no-mark-8](publish-tickets-no-mark-8.json) |
| 87 | +- [publish-tickets-no-mark-6](./tiny/publish-tickets-no-mark-6.json) |
| 88 | + - Submit some tickets. |
| 89 | +- [publish-tickets-no-mark-7](./tiny/publish-tickets-no-mark-7.json) |
| 90 | + - Fail: Submit tickets while in epoch's tail. |
| 91 | +- [publish-tickets-no-mark-8](./tiny/publish-tickets-no-mark-8.json) |
58 | 92 | - Progress into epoch tail. |
59 | | - - No enough tickets, thus no tickets mark. |
60 | | - - TODO: technically we can already drop the tickets from accumulator (check graypaper). |
61 | | -- [publish-tickets-no-mark-9](publish-tickets-no-mark-9.json) |
| 93 | + - No enough tickets, thus no tickets mark is generated. |
| 94 | +- [publish-tickets-no-mark-9](./tiny/publish-tickets-no-mark-9.json) |
62 | 95 | - Progress into next epoch with no enough tickets. |
63 | | - - Tickets are dropped. |
| 96 | + - Accumulated tickets are discarded. |
| 97 | + - Epoch mark is generated. |
64 | 98 | - Fallback method is enacted. |
65 | | - |
66 | | -- [pubblish-tickets-with-mark-1](publish-tickets-with-mark-1.json) |
67 | | - - Publish some tickets with a half filled accumulator. |
68 | | - - Accumulator is not filled yet. |
69 | | - - No ticket is dropped from accumulator. |
70 | | -- [pubblish-tickets-with-mark-2](publish-tickets-with-mark-2.json) |
| 99 | +- [publish-tickets-with-mark-1](./tiny/publish-tickets-with-mark-1.json) |
| 100 | + - Publish some tickets with an almost full tickets accumulator. |
| 101 | + - Tickets accumulator is not full yet. |
| 102 | + - No ticket are dropped from accumulator. |
| 103 | +- [publish-tickets-with-mark-2](./tiny/publish-tickets-with-mark-2.json) |
71 | 104 | - Publish some more tickets. |
72 | | - - Accumulator is filled. |
73 | | - - One old ticket is removed from the accumulator. |
74 | | -- [pubblish-tickets-with-mark-3](publish-tickets-with-mark-3.json) |
| 105 | + - Tickets accumulator is filled. |
| 106 | + - Two old ticket are removed from the accumulator. |
| 107 | +- [publish-tickets-with-mark-3](./tiny/publish-tickets-with-mark-3.json) |
75 | 108 | - Publish some more tickets. |
76 | | - - Accumulator is filled. |
| 109 | + - Accumulator is full before execution. |
77 | 110 | - Some old ticket are removed to make space for new ones. |
78 | | -- [pubblish-tickets-with-mark-4](publish-tickets-with-mark-4.json) |
| 111 | +- [publish-tickets-with-mark-4](./tiny/publish-tickets-with-mark-4.json) |
79 | 112 | - Progress into epoch tail. |
80 | | - - Tickets mark is produced. |
81 | | -- [pubblish-tickets-with-mark-5](publish-tickets-with-mark-5.json) |
| 113 | + - Tickets mark is generated. |
| 114 | +- [publish-tickets-with-mark-5](./tiny/publish-tickets-with-mark-5.json) |
82 | 115 | - Progress into next epoch. |
| 116 | + - Epoch mark is generated. |
83 | 117 | - Tickets are enacted. |
| 118 | + |
| 119 | +## Full Vectors |
| 120 | + |
| 121 | +Currently, the same test cases as tiny vectors but at a larger scale. |
0 commit comments