-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsafrole.asn
142 lines (116 loc) · 3.42 KB
/
safrole.asn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- Syntax for Safrole protocol test vectors
SafroleModule DEFINITIONS ::= BEGIN
-- Define constants
IMPORTS validators-count, epoch-length FROM SafroleConstants;
-- Define basic types
U8 ::= INTEGER (0..255)
U32 ::= INTEGER (0..4294967295)
-- Define fixed-length arrays
ByteArray32 ::= SEQUENCE (SIZE(32)) OF U8
OpaqueHash ::= ByteArray32
Ed25519Key ::= ByteArray32
BlsKey ::= SEQUENCE (SIZE(144)) OF U8
BandersnatchKey ::= ByteArray32
EpochKeys ::= SEQUENCE (SIZE(epoch-length)) OF BandersnatchKey
TicketsBodies ::= SEQUENCE (SIZE(epoch-length)) OF TicketBody
-- Define enumerations
TicketsOrKeys ::= CHOICE {
tickets TicketsBodies,
keys EpochKeys
}
-- State transition function execution error.
-- Error codes **are not specified** in the the Graypaper.
-- Feel free to ignore the actual value.
CustomErrorCode ::= ENUMERATED {
-- Timeslot value must be strictly monotonic.
bad-slot (0),
-- Received a ticket while in epoch's tail.
unexpected-ticket (1),
-- Tickets must be sorted.
bad-ticket-order (2),
-- Invalid ticket ring proof.
bad-ticket-proof (3),
-- Invalid ticket attempt value.
bad-ticket-attempt (4),
-- Reserved
reserved (5),
-- Found a ticket duplicate.
duplicate-ticket (6)
}
-- Define structures
TicketBody ::= SEQUENCE {
id OpaqueHash,
attempt U8
}
ValidatorData ::= SEQUENCE {
bandersnatch BandersnatchKey,
ed25519 Ed25519Key,
bls BlsKey,
metadata SEQUENCE (SIZE(128)) OF U8
}
ValidatorsData ::= SEQUENCE (SIZE(validators-count)) OF ValidatorData
TicketEnvelope ::= SEQUENCE {
attempt U8,
signature SEQUENCE (SIZE(784)) OF U8
}
EpochMark ::= SEQUENCE {
entropy OpaqueHash,
validators SEQUENCE (SIZE(validators-count)) OF BandersnatchKey
}
TicketsMark ::= SEQUENCE (SIZE(epoch-length)) OF TicketBody
-- Output markers.
OutputMarks ::= SEQUENCE {
-- New epoch signal.
epoch-mark [0] EpochMark OPTIONAL,
-- Tickets signal.
tickets-mark [1] TicketsMark OPTIONAL
}
-- State relevant to Safrole protocol
State ::= SEQUENCE {
-- Most recent block's timeslot.
tau U32,
-- Entropy accumulator and epochal randomness.
eta SEQUENCE (SIZE(4)) OF OpaqueHash,
-- Validator keys and metadata which were active in the prior epoch.
lambda ValidatorsData,
-- Validator keys and metadata currently active.
kappa ValidatorsData,
-- Validator keys for the following epoch.
gamma-k ValidatorsData,
-- Validator keys and metadata to be drawn from next.
iota ValidatorsData,
-- Sealing-key contest ticket accumulator.
gamma-a SEQUENCE (SIZE(0..epoch-length)) OF TicketBody,
-- Sealing-key series of the current epoch.
gamma-s TicketsOrKeys,
-- Bandersnatch ring commitment.
gamma-z SEQUENCE (SIZE(144)) OF U8
}
-- Input for Safrole protocol.
Input ::= SEQUENCE {
-- Current slot.
slot U32,
-- Per block entropy (originated from block entropy source VRF).
entropy OpaqueHash,
-- Safrole extrinsic.
extrinsic SEQUENCE (SIZE(0..16)) OF TicketEnvelope
}
-- Output from Safrole protocol
Output ::= CHOICE {
-- Markers
ok OutputMarks,
-- Error code (not specified in the Graypaper)
err CustomErrorCode
}
-- Safrole state transition function execution dump
Testcase ::= SEQUENCE {
-- Input.
input Input,
-- Pre-execution state.
pre-state State,
-- Output.
output Output,
-- Post-execution state.
post-state State
}
END