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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/// Standard 4-byte WebAssembly binary magic header (`\0asm`).
pub const WASM_BINARY_MAGIC: & = &;
/// Standard 4-byte WebAssembly MVP binary version (`1`).
pub const WASM_BINARY_VERSION: & = &;
/// Current euv dynamic WASM host ABI contract version.
pub const WASM_ABI_VERSION: u32 = 1;
/// Default maximum downloadable `.wasm` binary size (`8 MiB`).
pub const WASM_DEFAULT_MAX_BINARY_BYTES: usize = 8 * 1024 * 1024;
/// Default maximum WASM linear memory ceiling (`4 MiB`).
pub const WASM_DEFAULT_MAX_MEMORY_BYTES: usize = 4 * 1024 * 1024;
/// Default per-invocation instruction fuel budget preventing infinite loops.
pub const WASM_DEFAULT_MAX_FUEL: u64 = 100_000;
/// Default network download timeout in milliseconds.
pub const WASM_DEFAULT_TIMEOUT_MS: u64 = 15_000;
/// Default transient download retry attempts before failing or serving cache.
pub const WASM_DEFAULT_MAX_RETRIES: u32 = 2;
/// WASM linear memory page size in bytes (`64 KiB`).
pub const WASM_PAGE_BYTES: usize = 65_536;
/// Exported render entrypoint function name inside dynamic `.wasm` modules.
pub const WASM_EXPORT_RENDER: &str = "euv_render";
/// Exported interactive event handler function name inside dynamic `.wasm` modules.
pub const WASM_EXPORT_ON_EVENT: &str = "euv_on_event";
/// Exported ABI version query function name inside dynamic `.wasm` modules.
pub const WASM_EXPORT_ABI: &str = "euv_abi_version";
/// Host import function emitting a partial `DynamicNodeSpec` JSON buffer from WASM memory.
pub const WASM_IMPORT_EMIT_UI: &str = "euv_emit_ui";
/// Host import function emitting a global `DynamicUpdateBundle` JSON buffer from WASM memory.
pub const WASM_IMPORT_EMIT_BUNDLE: &str = "euv_emit_bundle";
/// Host import function recording a diagnostic log line from WASM memory.
pub const WASM_IMPORT_LOG: &str = "euv_log";
/// Host import module namespace expected by euv dynamic `.wasm` modules.
pub const WASM_IMPORT_MODULE_ENV: &str = "env";
/// Reserved global dynamic WASM root slot identifier.
pub const WASM_GLOBAL_ROOT_SLOT: &str = "__euv_global_wasm_root__";
/// Custom section name carrying optional signed metadata.
pub const WASM_CUSTOM_META_SECTION: &str = "euv.wasm.meta";
/// WebAssembly custom section ID (`0`).
pub const WASM_SEC_CUSTOM: u8 = 0;
/// WebAssembly type section ID (`1`).
pub const WASM_SEC_TYPE: u8 = 1;
/// WebAssembly import section ID (`2`).
pub const WASM_SEC_IMPORT: u8 = 2;
/// WebAssembly function section ID (`3`).
pub const WASM_SEC_FUNCTION: u8 = 3;
/// WebAssembly table section ID (`4`).
pub const WASM_SEC_TABLE: u8 = 4;
/// WebAssembly memory section ID (`5`).
pub const WASM_SEC_MEMORY: u8 = 5;
/// WebAssembly global section ID (`6`).
pub const WASM_SEC_GLOBAL: u8 = 6;
/// WebAssembly export section ID (`7`).
pub const WASM_SEC_EXPORT: u8 = 7;
/// WebAssembly element section ID (`9`).
pub const WASM_SEC_ELEMENT: u8 = 9;
/// WebAssembly code section ID (`10`).
pub const WASM_SEC_CODE: u8 = 10;
/// WebAssembly data section ID (`11`).
pub const WASM_SEC_DATA: u8 = 11;
/// WebAssembly data-count section ID (`12`).
pub const WASM_SEC_DATA_COUNT: u8 = 12;
/// WebAssembly opcode: `unreachable`.
pub const OP_UNREACHABLE: u8 = 0x00;
/// WebAssembly opcode: `nop`.
pub const OP_NOP: u8 = 0x01;
/// WebAssembly opcode: `block`.
pub const OP_BLOCK: u8 = 0x02;
/// WebAssembly opcode: `loop`.
pub const OP_LOOP: u8 = 0x03;
/// WebAssembly opcode: `if`.
pub const OP_IF: u8 = 0x04;
/// WebAssembly opcode: `else`.
pub const OP_ELSE: u8 = 0x05;
/// WebAssembly opcode: `end`.
pub const OP_END: u8 = 0x0B;
/// WebAssembly opcode: `br`.
pub const OP_BR: u8 = 0x0C;
/// WebAssembly opcode: `br_if`.
pub const OP_BR_IF: u8 = 0x0D;
/// WebAssembly opcode: `br_table`.
pub const OP_BR_TABLE: u8 = 0x0E;
/// WebAssembly opcode: `return`.
pub const OP_RETURN: u8 = 0x0F;
/// WebAssembly opcode: `call`.
pub const OP_CALL: u8 = 0x10;
/// WebAssembly opcode: `drop`.
pub const OP_DROP: u8 = 0x1A;
/// WebAssembly opcode: `select`.
pub const OP_SELECT: u8 = 0x1B;
/// WebAssembly opcode: `local.get`.
pub const OP_LOCAL_GET: u8 = 0x20;
/// WebAssembly opcode: `local.set`.
pub const OP_LOCAL_SET: u8 = 0x21;
/// WebAssembly opcode: `local.tee`.
pub const OP_LOCAL_TEE: u8 = 0x22;
/// WebAssembly opcode: `global.get`.
pub const OP_GLOBAL_GET: u8 = 0x23;
/// WebAssembly opcode: `global.set`.
pub const OP_GLOBAL_SET: u8 = 0x24;
/// WebAssembly opcode: `i32.load`.
pub const OP_I32_LOAD: u8 = 0x28;
/// WebAssembly opcode: `i32.load8_s`.
pub const OP_I32_LOAD8_S: u8 = 0x2C;
/// WebAssembly opcode: `i32.load8_u`.
pub const OP_I32_LOAD8_U: u8 = 0x2D;
/// WebAssembly opcode: `i32.load16_s`.
pub const OP_I32_LOAD16_S: u8 = 0x2E;
/// WebAssembly opcode: `i32.load16_u`.
pub const OP_I32_LOAD16_U: u8 = 0x2F;
/// WebAssembly opcode: `i32.store`.
pub const OP_I32_STORE: u8 = 0x36;
/// WebAssembly opcode: `i32.store8`.
pub const OP_I32_STORE8: u8 = 0x3A;
/// WebAssembly opcode: `i32.store16`.
pub const OP_I32_STORE16: u8 = 0x3B;
/// WebAssembly opcode: `memory.size`.
pub const OP_MEMORY_SIZE: u8 = 0x3F;
/// WebAssembly opcode: `memory.grow`.
pub const OP_MEMORY_GROW: u8 = 0x40;
/// WebAssembly opcode: `i32.const`.
pub const OP_I32_CONST: u8 = 0x41;
/// WebAssembly opcode: `i32.eqz`.
pub const OP_I32_EQZ: u8 = 0x45;
/// WebAssembly opcode: `i32.eq`.
pub const OP_I32_EQ: u8 = 0x46;
/// WebAssembly opcode: `i32.ne`.
pub const OP_I32_NE: u8 = 0x47;
/// WebAssembly opcode: `i32.lt_s`.
pub const OP_I32_LT_S: u8 = 0x48;
/// WebAssembly opcode: `i32.lt_u`.
pub const OP_I32_LT_U: u8 = 0x49;
/// WebAssembly opcode: `i32.gt_s`.
pub const OP_I32_GT_S: u8 = 0x4A;
/// WebAssembly opcode: `i32.gt_u`.
pub const OP_I32_GT_U: u8 = 0x4B;
/// WebAssembly opcode: `i32.le_s`.
pub const OP_I32_LE_S: u8 = 0x4C;
/// WebAssembly opcode: `i32.le_u`.
pub const OP_I32_LE_U: u8 = 0x4D;
/// WebAssembly opcode: `i32.ge_s`.
pub const OP_I32_GE_S: u8 = 0x4E;
/// WebAssembly opcode: `i32.ge_u`.
pub const OP_I32_GE_U: u8 = 0x4F;
/// WebAssembly opcode: `i32.clz`.
pub const OP_I32_CLZ: u8 = 0x67;
/// WebAssembly opcode: `i32.ctz`.
pub const OP_I32_CTZ: u8 = 0x68;
/// WebAssembly opcode: `i32.popcnt`.
pub const OP_I32_POPCNT: u8 = 0x69;
/// WebAssembly opcode: `i32.add`.
pub const OP_I32_ADD: u8 = 0x6A;
/// WebAssembly opcode: `i32.sub`.
pub const OP_I32_SUB: u8 = 0x6B;
/// WebAssembly opcode: `i32.mul`.
pub const OP_I32_MUL: u8 = 0x6C;
/// WebAssembly opcode: `i32.div_s`.
pub const OP_I32_DIV_S: u8 = 0x6D;
/// WebAssembly opcode: `i32.div_u`.
pub const OP_I32_DIV_U: u8 = 0x6E;
/// WebAssembly opcode: `i32.rem_s`.
pub const OP_I32_REM_S: u8 = 0x6F;
/// WebAssembly opcode: `i32.rem_u`.
pub const OP_I32_REM_U: u8 = 0x70;
/// WebAssembly opcode: `i32.and`.
pub const OP_I32_AND: u8 = 0x71;
/// WebAssembly opcode: `i32.or`.
pub const OP_I32_OR: u8 = 0x72;
/// WebAssembly opcode: `i32.xor`.
pub const OP_I32_XOR: u8 = 0x73;
/// WebAssembly opcode: `i32.shl`.
pub const OP_I32_SHL: u8 = 0x74;
/// WebAssembly opcode: `i32.shr_s`.
pub const OP_I32_SHR_S: u8 = 0x75;
/// WebAssembly opcode: `i32.shr_u`.
pub const OP_I32_SHR_U: u8 = 0x76;
/// WebAssembly opcode: `i32.rotl`.
pub const OP_I32_ROTL: u8 = 0x77;
/// WebAssembly opcode: `i32.rotr`.
pub const OP_I32_ROTR: u8 = 0x78;
/// WebAssembly multi-byte miscellaneous/bulk-memory opcode prefix (`0xFC`).
pub const OP_PREFIX_MISC: u8 = 0xFC;
/// WebAssembly bulk-memory sub-opcode: `memory.copy`.
pub const MISC_MEMORY_COPY: u32 = 0x0A;
/// WebAssembly bulk-memory sub-opcode: `memory.fill`.
pub const MISC_MEMORY_FILL: u32 = 0x0B;
/// Error message when a global section entry is truncated or malformed.
pub const WASM_ERR_GLOBAL_SECTION: &str = "malformed wasm global section";
/// Error message when a global index exceeds declared module globals.
pub const WASM_ERR_GLOBAL_INDEX: &str = "invalid wasm global index";
/// Error message when attempting to mutate an immutable global variable.
pub const WASM_ERR_IMMUTABLE_GLOBAL: &str = "cannot mutate immutable wasm global";
/// Error message when `select` encounters a stack underflow.
pub const WASM_ERR_STACK_SELECT: &str = "stack underflow on select";
/// Error message when `local.tee` encounters a stack underflow.
pub const WASM_ERR_STACK_LOCAL_TEE: &str = "stack underflow on local.tee";
/// Error message when `global.set` encounters a stack underflow.
pub const WASM_ERR_STACK_GLOBAL_SET: &str = "stack underflow on global.set";
/// Error message when `i32.div_s` overflows (`i32::MIN / -1`).
pub const WASM_ERR_DIV_OVERFLOW: &str = "integer division overflow";
/// Error message when integer division or remainder divides by zero.
pub const WASM_ERR_DIV_BY_ZERO: &str = "integer divide by zero";
/// Error message when an unsupported `0xFC` sub-opcode is encountered.
pub const WASM_ERR_UNSUPPORTED_MISC_OP: &str = "unsupported wasm 0xFC sub-opcode";
/// WebAssembly `i32` value type tag (`0x7F`).
pub const WASM_VALTYPE_I32: u8 = 0x7F;
/// WebAssembly function type tag (`0x60`).
pub const WASM_FUNCTYPE_TAG: u8 = 0x60;
/// Signing salt prefix used by `compute_wasm_signature`.
pub const WASM_SIGNATURE_PREFIX: &str = "euv-sig-v1:";
/// Supported `http://` URL scheme prefix for native WASM downloads.
pub const WASM_SCHEME_HTTP: &str = "http://";
/// Supported `file://` URL scheme prefix for local WASM bundles.
pub const WASM_SCHEME_FILE: &str = "file://";
/// Diagnostic message when `WasmDynamicManager` encounters a conflicting interior borrow.
pub const WASM_ERR_MANAGER_BORROW: &str = "manager borrow";
/// Diagnostic message when a WASM binary opcode encounters a value stack underflow.
pub const WASM_ERR_STACK_BINOP: &str = "stack underflow on binop";