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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* This module provides functions writing initial data to and reading results from the frame used during evaluation
* of Simplicity expressions.
* These helper functions are also used for marshaling data to and from jets.
*/
/* A Bit Machine frame contains an '.edge' pointer to a slice of an array of UWORDs to hold the frame's cells.
* The '.offset' is used to represent the cursors position.
* For a read frame, the '.edge' points to one-past-the-end of the slice of the UWORDs array for the frame's cells,
* and the '.offset' value is equal to the frame's cursor position plus the amount of padding used in the frame.
* For a write frame, the '.edge' points to the beginning of the slice of the UWORDs array for the frame's cells,
* and the '.offset' value is equal to the total number of cells minus the frame's cursor position.
*/
typedef struct frameItem frameItem;
/* Initialize a new read frame.
* 'n' is the number of cells for the read frame.
* 'from' is a pointer to the beginning of the new slice for the array of UWORDS to hold the frame's cells.
*
* Precondition: UWORD from[ROUND_UWORD(n)];
*/
static inline frameItem
/* Initialize a new write frame.
* 'n' is the number of cells for the write frame.
* 'from' is a pointer to the one-past-the-end of the new slice for the array of UWORDS to hold the frame's cells.
*
* Precondition: UWORD (from - ROUND_UWORD(n))[ROUND_UWORD(n)];
*/
static inline frameItem
/* Given a read frame, return the value of the cell at the cursor.
*
* Precondition: '*frame' is a valid read frame for 1 more cell.
*/
static inline bool
/* Given a read frame, return the value of the cell at the cursor and advance the cursor by one cell.
*
* Precondition: '*frame' is a valid read frame for 1 more cell.
*/
static inline bool
/* Given a write frame, set its cursor's cell to 'bit' and advance the cursor by one cell.
* Cells in front of the cursor's final position may be overwritten.
*
* The function returns the same value as bit. This facilitates using 'writeBit' within an 'if' statement
*
* if (writeBit(frame, bit)) { ... } else { ... }
*
* so that one can both decide conditions based on a Boolean value while at the same time writing to the frame the choice made.
*
* Precondition: '*frame' is a valid write frame for 1 more cell.
*/
static inline bool
/* Given a read frame, advance the cursor by 'n' cells.
*
* Precondition: '*frame' is a valid read frame for 'n' more cells.
*/
static inline void
/* Given a write frame, advance the cursor by 'n' cells.
*
* Precondition: '*frame' is a valid write frame for 'n' more cells.
*/
static inline void
/* Given a read frame, the 'readN' function returns the value of the 'N' cells after the cursor and
* advances the frame's cursor by 'N'.
* The cell values are returned with the first cell in the MSB of the result and the last cell in the LSB of the result.
*
* Precondition: '*frame' is a valid read frame for 'N' more cells.
*/
uint_fast8_t ;
uint_fast8_t ;
uint_fast16_t ;
uint_fast32_t ;
uint_fast64_t ;
/* Given a write frame, the 'writeN' function sets the value of the 'N' cells after the cursor and
* advances the frame's cursor by 'N'.
* The first cell is set to the value of the MSB of 'x' and the last cell is set to the LSB of 'x'.
* Cells in front of the cursor's final position may be overwritten.
*
* Precondition: '*frame' is a valid write frame for 'N' more cells.
*/
void ;
void ;
void ;
void ;
static inline void
static inline void
static inline void
static inline void
/* Read bytes from a Simplicity buffer of type (TWO^8)^<2^(n+1) into 'buf'.
* Set 'len' to the number of bytes read from the buffer.
* Advance the 'src' frame to the end of the buffer type.
*
* The notation X^<2 is notation for the type (S X)
* The notation X^<(2*n) is notation for the type S (X^n) * X^<n
*
* Precondition: unsigned char buf[2^(n+1)-1];
* NULL != len;
* '*src' is a valid read frame for 8*(2^(n+1)-1)+n+1 more cells;
* 0 <= n < 16
*/
void ;
/* Write 'len' bytes to a Simplicity buffer of type (TWO^8)^<2^(n+1) from 'buf'.
* Advance the 'dst' frame to the end of the buffer type.
*
* The notation X^<2 is notation for the type (S X)
* The notation X^<(2*n) is notation for the type S (X^n) * X^<n
*
* Precondition: '*dst' is a valid write frame for 8*(2^(n+1)-1)+n+1 more cells;
* unsigned char buf[len];
* len < 2^(n+1);
* 0 <= n < 16;
*/
void ;
/* Read data from a Simplicity CTX8 type (TWO^8)^<2^64 * TWO^64 * TWO^256 and fill in a sha256_context value.
* Advance the 'src' frame to the end of the CTX8 type.
* Returns false if the context's counter is too large (i.e. the compression count is greater than or equal to 2^55).
*
* The notation X^<2 is notation for the type (S X)
* The notation X^<(2*n) is notation for the type S (X^n) * X^<n
*
* Precondition: NULL != ctx->output;
* '*src' is a valid read frame for 838 more cells;
*/
bool ;
/* Write data to a Simplicity CTX8 type (TWO^8)^<2^64 * TWO^64 * TWO^256 from a sha256_context value.
* Advance the 'dst' frame to the end of the CTX8 type.
* Returns false if the ctx had overflowed.
*
* The notation X^<2 is notation for the type (S X)
* The notation X^<(2*n) is notation for the type S (X^n) * X^<n
*
* Precondition: '*dst' is a valid write frame for 838 more cells;
* NULL != ctx->output;
* ctx->counter < 2^61;
*/
bool ;
/* Given a write frame and a read frame, copy 'n' cells from after the read frame's cursor to after the write frame's cursor,
* and then advance the write frame's cursor by 'n'.
* Cells in front of the '*dst's cursor's final position may be overwritten.
*
* Precondition: '*dst' is a valid write frame for 'n' more cells;
* '*src' is a valid read frame for 'n' more cells;
*/
void ;