radix_engine/vm/wasm/
wasm_validator_config.rs

1extern crate radix_wasm_instrument as wasm_instrument;
2
3use crate::internal_prelude::*;
4use wasm_instrument::gas_metering::MemoryGrowCost;
5use wasm_instrument::gas_metering::Rules;
6use wasmparser::Operator::{self, *};
7
8use super::InstructionWeights;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct WasmValidatorConfigV1 {
12    weights: InstructionWeights,
13    max_stack_size: u32,
14}
15
16impl WasmValidatorConfigV1 {
17    pub fn new() -> Self {
18        Self {
19            weights: InstructionWeights::default(),
20            max_stack_size: 1024,
21        }
22    }
23
24    pub fn version(&self) -> u8 {
25        1
26    }
27
28    pub fn max_stack_size(&self) -> u32 {
29        self.max_stack_size
30    }
31}
32
33impl Default for WasmValidatorConfigV1 {
34    fn default() -> Self {
35        Self::new()
36    }
37}
38
39impl Rules for WasmValidatorConfigV1 {
40    fn instruction_cost(&self, instruction: &Operator) -> Option<u32> {
41        match instruction {
42            // MVP
43            Unreachable => Some(0),
44            Nop => Some(self.weights.i64const),
45            Block { .. } => Some(self.weights.i64const),
46            Loop { .. } => Some(self.weights.i64const),
47            If { .. } => Some(self.weights.r#if),
48            Else { .. } => Some(0),
49            End => Some(0),
50            Br { .. } => Some(self.weights.br),
51            BrIf { .. } => Some(self.weights.br_if),
52            BrTable { .. } => Some(self.weights.br_table),
53            Return => Some(0),
54            Call { .. } => Some(self.weights.call),
55            CallIndirect { .. } => Some(self.weights.call_indirect),
56            Drop => Some(self.weights.i64const),
57            Select => Some(self.weights.select),
58            LocalGet { .. } => Some(self.weights.local_get),
59            LocalSet { .. } => Some(self.weights.local_set),
60            LocalTee { .. } => Some(self.weights.local_tee),
61            GlobalGet { .. } => Some(self.weights.global_get),
62            GlobalSet { .. } => Some(self.weights.global_set),
63            I32Load { .. } => Some(self.weights.i64load),
64            I64Load { .. } => Some(self.weights.i64load),
65            F32Load { .. } => None,
66            F64Load { .. } => None,
67            I32Load8S { .. } => Some(self.weights.i64load),
68            I32Load8U { .. } => Some(self.weights.i64load),
69            I32Load16S { .. } => Some(self.weights.i64load),
70            I32Load16U { .. } => Some(self.weights.i64load),
71            I64Load8S { .. } => Some(self.weights.i64load),
72            I64Load8U { .. } => Some(self.weights.i64load),
73            I64Load16S { .. } => Some(self.weights.i64load),
74            I64Load16U { .. } => Some(self.weights.i64load),
75            I64Load32S { .. } => Some(self.weights.i64load),
76            I64Load32U { .. } => Some(self.weights.i64load),
77            I32Store { .. } => Some(self.weights.i64store),
78            I64Store { .. } => Some(self.weights.i64store),
79            F32Store { .. } => None,
80            F64Store { .. } => None,
81            I32Store8 { .. } => Some(self.weights.i64store),
82            I32Store16 { .. } => Some(self.weights.i64store),
83            I64Store8 { .. } => Some(self.weights.i64store),
84            I64Store16 { .. } => Some(self.weights.i64store),
85            I64Store32 { .. } => Some(self.weights.i64store),
86            MemorySize { .. } => Some(self.weights.memory_size),
87            MemoryGrow { .. } => Some(self.weights.memory_grow),
88            I32Const { .. } => Some(self.weights.i64const),
89            I64Const { .. } => Some(self.weights.i64const),
90            F32Const { .. } => None,
91            F64Const { .. } => None,
92            I32Eqz => Some(self.weights.i64eqz),
93            I32Eq => Some(self.weights.i64eq),
94            I32Ne => Some(self.weights.i64ne),
95            I32LtS => Some(self.weights.i64lts),
96            I32LtU => Some(self.weights.i64ltu),
97            I32GtS => Some(self.weights.i64gts),
98            I32GtU => Some(self.weights.i64gtu),
99            I32LeS => Some(self.weights.i64les),
100            I32LeU => Some(self.weights.i64leu),
101            I32GeS => Some(self.weights.i64ges),
102            I32GeU => Some(self.weights.i64geu),
103            I64Eqz => Some(self.weights.i64eqz),
104            I64Eq => Some(self.weights.i64eq),
105            I64Ne => Some(self.weights.i64ne),
106            I64LtS => Some(self.weights.i64lts),
107            I64LtU => Some(self.weights.i64ltu),
108            I64GtS => Some(self.weights.i64gts),
109            I64GtU => Some(self.weights.i64gtu),
110            I64LeS => Some(self.weights.i64les),
111            I64LeU => Some(self.weights.i64leu),
112            I64GeS => Some(self.weights.i64ges),
113            I64GeU => Some(self.weights.i64geu),
114            F32Eq => None,
115            F32Ne => None,
116            F32Lt => None,
117            F32Gt => None,
118            F32Le => None,
119            F32Ge => None,
120            F64Eq => None,
121            F64Ne => None,
122            F64Lt => None,
123            F64Gt => None,
124            F64Le => None,
125            F64Ge => None,
126            I32Clz => Some(self.weights.i64clz),
127            I32Ctz => Some(self.weights.i64ctz),
128            I32Popcnt => Some(self.weights.i64popcnt),
129            I32Add => Some(self.weights.i64add),
130            I32Sub => Some(self.weights.i64sub),
131            I32Mul => Some(self.weights.i64mul),
132            I32DivS => Some(self.weights.i64divs),
133            I32DivU => Some(self.weights.i64divu),
134            I32RemS => Some(self.weights.i64rems),
135            I32RemU => Some(self.weights.i64remu),
136            I32And => Some(self.weights.i64and),
137            I32Or => Some(self.weights.i64xor),
138            I32Xor => Some(self.weights.i64xor),
139            I32Shl => Some(self.weights.i64shl),
140            I32ShrS => Some(self.weights.i64shrs),
141            I32ShrU => Some(self.weights.i64shru),
142            I32Rotl => Some(self.weights.i64rotl),
143            I32Rotr => Some(self.weights.i64rotr),
144            I64Clz => Some(self.weights.i64clz),
145            I64Ctz => Some(self.weights.i64ctz),
146            I64Popcnt => Some(self.weights.i64popcnt),
147            I64Add => Some(self.weights.i64add),
148            I64Sub => Some(self.weights.i64sub),
149            I64Mul => Some(self.weights.i64mul),
150            I64DivS => Some(self.weights.i64divs),
151            I64DivU => Some(self.weights.i64divu),
152            I64RemS => Some(self.weights.i64rems),
153            I64RemU => Some(self.weights.i64remu),
154            I64And => Some(self.weights.i64and),
155            I64Or => Some(self.weights.i64or),
156            I64Xor => Some(self.weights.i64xor),
157            I64Shl => Some(self.weights.i64shl),
158            I64ShrS => Some(self.weights.i64shrs),
159            I64ShrU => Some(self.weights.i64shru),
160            I64Rotl => Some(self.weights.i64rotl),
161            I64Rotr => Some(self.weights.i64rotr),
162            F32Abs => None,
163            F32Neg => None,
164            F32Ceil => None,
165            F32Floor => None,
166            F32Trunc => None,
167            F32Nearest => None,
168            F32Sqrt => None,
169            F32Add => None,
170            F32Sub => None,
171            F32Mul => None,
172            F32Div => None,
173            F32Min => None,
174            F32Max => None,
175            F32Copysign => None,
176            F64Abs => None,
177            F64Neg => None,
178            F64Ceil => None,
179            F64Floor => None,
180            F64Trunc => None,
181            F64Nearest => None,
182            F64Sqrt => None,
183            F64Add => None,
184            F64Sub => None,
185            F64Mul => None,
186            F64Div => None,
187            F64Min => None,
188            F64Max => None,
189            F64Copysign => None,
190            I32WrapI64 => Some(self.weights.i32wrapi64),
191            I32TruncF32S => None,
192            I32TruncF32U => None,
193            I32TruncF64S => None,
194            I32TruncF64U => None,
195            I64ExtendI32S => Some(self.weights.i64extendsi32),
196            I64ExtendI32U => Some(self.weights.i64extendui32),
197            I64TruncF32S => None,
198            I64TruncF32U => None,
199            I64TruncF64S => None,
200            I64TruncF64U => None,
201            F32ConvertI32S => None,
202            F32ConvertI32U => None,
203            F32ConvertI64S => None,
204            F32ConvertI64U => None,
205            F32DemoteF64 => None,
206            F64ConvertI32S => None,
207            F64ConvertI32U => None,
208            F64ConvertI64S => None,
209            F64ConvertI64U => None,
210            F64PromoteF32 => None,
211            I32ReinterpretF32 => None,
212            I64ReinterpretF64 => None,
213            F32ReinterpretI32 => None,
214            F64ReinterpretI64 => None,
215
216            // sign-extension-ops proposal
217            I32Extend8S => Some(self.weights.i64extendsi32),
218            I32Extend16S => Some(self.weights.i64extendsi32),
219            I64Extend8S => Some(self.weights.i64extendsi32),
220            I64Extend16S => Some(self.weights.i64extendsi32),
221            I64Extend32S => Some(self.weights.i64extendsi32),
222
223            // Bulk memory proposal
224            | MemoryInit { .. }
225            | DataDrop { .. }
226            | MemoryCopy { .. }
227            | MemoryFill { .. }
228            | TableInit { .. }
229            | ElemDrop { .. }
230            | TableCopy { .. }
231
232            // Exception handling proposal
233            | Try { .. }
234            | Catch { .. }
235            | Throw { .. }
236            | Rethrow { .. }
237            | Delegate { .. }
238            | CatchAll { .. }
239
240            // Typed function references proposal
241            | CallRef { .. }
242            | ReturnCallRef { .. }
243            | RefAsNonNull { .. }
244            | BrOnNull { .. }
245            | BrOnNonNull { .. }
246
247            // GC proposal
248            | I31New { .. }
249            | I31GetS { .. }
250            | I31GetU { .. }
251
252            // Memory control proposal
253            | MemoryDiscard { .. }
254
255            // Reference types proposal
256            | TypedSelect { .. }
257            | RefNull { .. }
258            | RefIsNull { .. }
259            | RefFunc { .. }
260            | TableFill { .. }
261            | TableGet { .. }
262            | TableSet { .. }
263            | TableGrow { .. }
264            | TableSize { .. }
265
266            // Relaxed SIMD proposal
267            | I8x16RelaxedSwizzle { .. }
268            | I32x4RelaxedTruncF32x4S { .. }
269            | I32x4RelaxedTruncF32x4U { .. }
270            | I32x4RelaxedTruncF64x2SZero { .. }
271            | I32x4RelaxedTruncF64x2UZero { .. }
272            | F32x4RelaxedMadd { .. }
273            | F32x4RelaxedNmadd { .. }
274            | F64x2RelaxedMadd { .. }
275            | F64x2RelaxedNmadd { .. }
276            | I8x16RelaxedLaneselect { .. }
277            | I16x8RelaxedLaneselect { .. }
278            | I32x4RelaxedLaneselect { .. }
279            | I64x2RelaxedLaneselect { .. }
280            | F32x4RelaxedMin { .. }
281            | F32x4RelaxedMax { .. }
282            | F64x2RelaxedMin { .. }
283            | F64x2RelaxedMax { .. }
284            | I16x8RelaxedQ15mulrS { .. }
285            | I16x8RelaxedDotI8x16I7x16S { .. }
286            | I32x4RelaxedDotI8x16I7x16AddS { .. }
287
288            // nontrapping-float-to-int-conversions proposal
289            | I32TruncSatF32S { .. }
290            | I32TruncSatF32U { .. }
291            | I32TruncSatF64S { .. }
292            | I32TruncSatF64U { .. }
293            | I64TruncSatF32S { .. }
294            | I64TruncSatF32U { .. }
295            | I64TruncSatF64S { .. }
296            | I64TruncSatF64U { .. }
297
298            // SIMD proposal
299            | V128Load { .. }
300            | V128Load8x8S { .. }
301            | V128Load8x8U { .. }
302            | V128Load16x4S { .. }
303            | V128Load16x4U { .. }
304            | V128Load32x2S { .. }
305            | V128Load32x2U { .. }
306            | V128Load8Splat { .. }
307            | V128Load16Splat { .. }
308            | V128Load32Splat { .. }
309            | V128Load64Splat { .. }
310            | V128Load32Zero { .. }
311            | V128Load64Zero { .. }
312            | V128Store { .. }
313            | V128Load8Lane { .. }
314            | V128Load16Lane { .. }
315            | V128Load32Lane { .. }
316            | V128Load64Lane { .. }
317            | V128Store8Lane { .. }
318            | V128Store16Lane { .. }
319            | V128Store32Lane { .. }
320            | V128Store64Lane { .. }
321            | V128Const { .. }
322            | I8x16Shuffle { .. }
323            | I8x16ExtractLaneS { .. }
324            | I8x16ExtractLaneU { .. }
325            | I8x16ReplaceLane { .. }
326            | I16x8ExtractLaneS { .. }
327            | I16x8ExtractLaneU { .. }
328            | I16x8ReplaceLane { .. }
329            | I32x4ExtractLane { .. }
330            | I32x4ReplaceLane { .. }
331            | I64x2ExtractLane { .. }
332            | I64x2ReplaceLane { .. }
333            | F32x4ExtractLane { .. }
334            | F32x4ReplaceLane { .. }
335            | F64x2ExtractLane { .. }
336            | F64x2ReplaceLane { .. }
337            | I8x16Swizzle { .. }
338            | I8x16Splat { .. }
339            | I16x8Splat { .. }
340            | I32x4Splat { .. }
341            | I64x2Splat { .. }
342            | F32x4Splat { .. }
343            | F64x2Splat { .. }
344            | I8x16Eq { .. }
345            | I8x16Ne { .. }
346            | I8x16LtS { .. }
347            | I8x16LtU { .. }
348            | I8x16GtS { .. }
349            | I8x16GtU { .. }
350            | I8x16LeS { .. }
351            | I8x16LeU { .. }
352            | I8x16GeS { .. }
353            | I8x16GeU { .. }
354            | I16x8Eq { .. }
355            | I16x8Ne { .. }
356            | I16x8LtS { .. }
357            | I16x8LtU { .. }
358            | I16x8GtS { .. }
359            | I16x8GtU { .. }
360            | I16x8LeS { .. }
361            | I16x8LeU { .. }
362            | I16x8GeS { .. }
363            | I16x8GeU { .. }
364            | I32x4Eq { .. }
365            | I32x4Ne { .. }
366            | I32x4LtS { .. }
367            | I32x4LtU { .. }
368            | I32x4GtS { .. }
369            | I32x4GtU { .. }
370            | I32x4LeS { .. }
371            | I32x4LeU { .. }
372            | I32x4GeS { .. }
373            | I32x4GeU { .. }
374            | I64x2Eq { .. }
375            | I64x2Ne { .. }
376            | I64x2LtS { .. }
377            | I64x2GtS { .. }
378            | I64x2LeS { .. }
379            | I64x2GeS { .. }
380            | F32x4Eq { .. }
381            | F32x4Ne { .. }
382            | F32x4Lt { .. }
383            | F32x4Gt { .. }
384            | F32x4Le { .. }
385            | F32x4Ge { .. }
386            | F64x2Eq { .. }
387            | F64x2Ne { .. }
388            | F64x2Lt { .. }
389            | F64x2Gt { .. }
390            | F64x2Le { .. }
391            | F64x2Ge { .. }
392            | V128Not { .. }
393            | V128And { .. }
394            | V128AndNot { .. }
395            | V128Or { .. }
396            | V128Xor { .. }
397            | V128Bitselect { .. }
398            | V128AnyTrue { .. }
399            | I8x16Abs { .. }
400            | I8x16Neg { .. }
401            | I8x16Popcnt { .. }
402            | I8x16AllTrue { .. }
403            | I8x16Bitmask { .. }
404            | I8x16NarrowI16x8S { .. }
405            | I8x16NarrowI16x8U { .. }
406            | I8x16Shl { .. }
407            | I8x16ShrS { .. }
408            | I8x16ShrU { .. }
409            | I8x16Add { .. }
410            | I8x16AddSatS { .. }
411            | I8x16AddSatU { .. }
412            | I8x16Sub { .. }
413            | I8x16SubSatS { .. }
414            | I8x16SubSatU { .. }
415            | I8x16MinS { .. }
416            | I8x16MinU { .. }
417            | I8x16MaxS { .. }
418            | I8x16MaxU { .. }
419            | I8x16AvgrU { .. }
420            | I16x8ExtAddPairwiseI8x16S { .. }
421            | I16x8ExtAddPairwiseI8x16U { .. }
422            | I16x8Abs { .. }
423            | I16x8Neg { .. }
424            | I16x8Q15MulrSatS { .. }
425            | I16x8AllTrue { .. }
426            | I16x8Bitmask { .. }
427            | I16x8NarrowI32x4S { .. }
428            | I16x8NarrowI32x4U { .. }
429            | I16x8ExtendLowI8x16S { .. }
430            | I16x8ExtendHighI8x16S { .. }
431            | I16x8ExtendLowI8x16U { .. }
432            | I16x8ExtendHighI8x16U { .. }
433            | I16x8Shl { .. }
434            | I16x8ShrS { .. }
435            | I16x8ShrU { .. }
436            | I16x8Add { .. }
437            | I16x8AddSatS { .. }
438            | I16x8AddSatU { .. }
439            | I16x8Sub { .. }
440            | I16x8SubSatS { .. }
441            | I16x8SubSatU { .. }
442            | I16x8Mul { .. }
443            | I16x8MinS { .. }
444            | I16x8MinU { .. }
445            | I16x8MaxS { .. }
446            | I16x8MaxU { .. }
447            | I16x8AvgrU { .. }
448            | I16x8ExtMulLowI8x16S { .. }
449            | I16x8ExtMulHighI8x16S { .. }
450            | I16x8ExtMulLowI8x16U { .. }
451            | I16x8ExtMulHighI8x16U { .. }
452            | I32x4ExtAddPairwiseI16x8S { .. }
453            | I32x4ExtAddPairwiseI16x8U { .. }
454            | I32x4Abs { .. }
455            | I32x4Neg { .. }
456            | I32x4AllTrue { .. }
457            | I32x4Bitmask { .. }
458            | I32x4ExtendLowI16x8S { .. }
459            | I32x4ExtendHighI16x8S { .. }
460            | I32x4ExtendLowI16x8U { .. }
461            | I32x4ExtendHighI16x8U { .. }
462            | I32x4Shl { .. }
463            | I32x4ShrS { .. }
464            | I32x4ShrU { .. }
465            | I32x4Add { .. }
466            | I32x4Sub { .. }
467            | I32x4Mul { .. }
468            | I32x4MinS { .. }
469            | I32x4MinU { .. }
470            | I32x4MaxS { .. }
471            | I32x4MaxU { .. }
472            | I32x4DotI16x8S { .. }
473            | I32x4ExtMulLowI16x8S { .. }
474            | I32x4ExtMulHighI16x8S { .. }
475            | I32x4ExtMulLowI16x8U { .. }
476            | I32x4ExtMulHighI16x8U { .. }
477            | I64x2Abs { .. }
478            | I64x2Neg { .. }
479            | I64x2AllTrue { .. }
480            | I64x2Bitmask { .. }
481            | I64x2ExtendLowI32x4S { .. }
482            | I64x2ExtendHighI32x4S { .. }
483            | I64x2ExtendLowI32x4U { .. }
484            | I64x2ExtendHighI32x4U { .. }
485            | I64x2Shl { .. }
486            | I64x2ShrS { .. }
487            | I64x2ShrU { .. }
488            | I64x2Add { .. }
489            | I64x2Sub { .. }
490            | I64x2Mul { .. }
491            | I64x2ExtMulLowI32x4S { .. }
492            | I64x2ExtMulHighI32x4S { .. }
493            | I64x2ExtMulLowI32x4U { .. }
494            | I64x2ExtMulHighI32x4U { .. }
495            | F32x4Ceil { .. }
496            | F32x4Floor { .. }
497            | F32x4Trunc { .. }
498            | F32x4Nearest { .. }
499            | F32x4Abs { .. }
500            | F32x4Neg { .. }
501            | F32x4Sqrt { .. }
502            | F32x4Add { .. }
503            | F32x4Sub { .. }
504            | F32x4Mul { .. }
505            | F32x4Div { .. }
506            | F32x4Min { .. }
507            | F32x4Max { .. }
508            | F32x4PMin { .. }
509            | F32x4PMax { .. }
510            | F64x2Ceil { .. }
511            | F64x2Floor { .. }
512            | F64x2Trunc { .. }
513            | F64x2Nearest { .. }
514            | F64x2Abs { .. }
515            | F64x2Neg { .. }
516            | F64x2Sqrt { .. }
517            | F64x2Add { .. }
518            | F64x2Sub { .. }
519            | F64x2Mul { .. }
520            | F64x2Div { .. }
521            | F64x2Min { .. }
522            | F64x2Max { .. }
523            | F64x2PMin { .. }
524            | F64x2PMax { .. }
525            | I32x4TruncSatF32x4S { .. }
526            | I32x4TruncSatF32x4U { .. }
527            | F32x4ConvertI32x4S { .. }
528            | F32x4ConvertI32x4U { .. }
529            | I32x4TruncSatF64x2SZero { .. }
530            | I32x4TruncSatF64x2UZero { .. }
531            | F64x2ConvertLowI32x4S { .. }
532            | F64x2ConvertLowI32x4U { .. }
533            | F32x4DemoteF64x2Zero { .. }
534            | F64x2PromoteLowF32x4 { .. }
535
536            // tail-call proposal
537            | ReturnCall { .. }
538            | ReturnCallIndirect { .. }
539
540            // Threads proposal
541            | MemoryAtomicNotify { .. }
542            | MemoryAtomicWait32 { .. }
543            | MemoryAtomicWait64 { .. }
544            | AtomicFence { .. }
545            | I32AtomicLoad { .. }
546            | I64AtomicLoad { .. }
547            | I32AtomicLoad8U { .. }
548            | I32AtomicLoad16U { .. }
549            | I64AtomicLoad8U { .. }
550            | I64AtomicLoad16U { .. }
551            | I64AtomicLoad32U { .. }
552            | I32AtomicStore { .. }
553            | I64AtomicStore { .. }
554            | I32AtomicStore8 { .. }
555            | I32AtomicStore16 { .. }
556            | I64AtomicStore8 { .. }
557            | I64AtomicStore16 { .. }
558            | I64AtomicStore32 { .. }
559            | I32AtomicRmwAdd { .. }
560            | I64AtomicRmwAdd { .. }
561            | I32AtomicRmw8AddU { .. }
562            | I32AtomicRmw16AddU { .. }
563            | I64AtomicRmw8AddU { .. }
564            | I64AtomicRmw16AddU { .. }
565            | I64AtomicRmw32AddU { .. }
566            | I32AtomicRmwSub { .. }
567            | I64AtomicRmwSub { .. }
568            | I32AtomicRmw8SubU { .. }
569            | I32AtomicRmw16SubU { .. }
570            | I64AtomicRmw8SubU { .. }
571            | I64AtomicRmw16SubU { .. }
572            | I64AtomicRmw32SubU { .. }
573            | I32AtomicRmwAnd { .. }
574            | I64AtomicRmwAnd { .. }
575            | I32AtomicRmw8AndU { .. }
576            | I32AtomicRmw16AndU { .. }
577            | I64AtomicRmw8AndU { .. }
578            | I64AtomicRmw16AndU { .. }
579            | I64AtomicRmw32AndU { .. }
580            | I32AtomicRmwOr { .. }
581            | I64AtomicRmwOr { .. }
582            | I32AtomicRmw8OrU { .. }
583            | I32AtomicRmw16OrU { .. }
584            | I64AtomicRmw8OrU { .. }
585            | I64AtomicRmw16OrU { .. }
586            | I64AtomicRmw32OrU { .. }
587            | I32AtomicRmwXor { .. }
588            | I64AtomicRmwXor { .. }
589            | I32AtomicRmw8XorU { .. }
590            | I32AtomicRmw16XorU { .. }
591            | I64AtomicRmw8XorU { .. }
592            | I64AtomicRmw16XorU { .. }
593            | I64AtomicRmw32XorU { .. }
594            | I32AtomicRmwXchg { .. }
595            | I64AtomicRmwXchg { .. }
596            | I32AtomicRmw8XchgU { .. }
597            | I32AtomicRmw16XchgU { .. }
598            | I64AtomicRmw8XchgU { .. }
599            | I64AtomicRmw16XchgU { .. }
600            | I64AtomicRmw32XchgU { .. }
601            | I32AtomicRmwCmpxchg { .. }
602            | I64AtomicRmwCmpxchg { .. }
603            | I32AtomicRmw8CmpxchgU { .. }
604            | I32AtomicRmw16CmpxchgU { .. }
605            | I64AtomicRmw8CmpxchgU { .. }
606            | I64AtomicRmw16CmpxchgU { .. }
607            | I64AtomicRmw32CmpxchgU { .. } =>
608                todo!("instruction {:?} not covered", instruction),
609        }
610    }
611
612    fn memory_grow_cost(&self) -> MemoryGrowCost {
613        // Per Substrate documentation, the `memory.grow` instruction cost is from benchmarks using MAX page size.
614        // Similarly, Radix Engine enforces `DEFAULT_MAX_WASM_MEM_PER_CALL_FRAME`.
615        // Thus, no additional costing is applied.
616        MemoryGrowCost::Free
617    }
618
619    fn call_per_local_cost(&self) -> u32 {
620        self.weights.call_per_local
621    }
622}
623
624#[cfg(test)]
625mod tests {
626    use super::*;
627
628    #[test]
629    fn print_params() {
630        assert_eq!(format!("{:?}", WasmValidatorConfigV1::new()), "WasmValidatorConfigV1 { weights: InstructionWeights { version: 4, fallback: 0, i64const: 1372, i64load: 3597, i64store: 3905, select: 3434, if: 8054, br: 3529, br_if: 4706, br_table: 8198, br_table_per_entry: 29, call: 14340, call_indirect: 19936, call_per_local: 1651, local_get: 2816, local_set: 2822, local_tee: 2087, global_get: 7002, global_set: 7806, memory_size: 2555, memory_grow: 14764221, i64clz: 1509, i64ctz: 2035, i64popcnt: 1499, i64eqz: 1889, i64extendsi32: 1478, i64extendui32: 1939, i32wrapi64: 1505, i64eq: 2149, i64ne: 1628, i64lts: 1654, i64ltu: 2088, i64gts: 2205, i64gtu: 1661, i64les: 1648, i64leu: 2135, i64ges: 2226, i64geu: 1661, i64add: 1623, i64sub: 2212, i64mul: 1640, i64divs: 2678, i64divu: 1751, i64rems: 2659, i64remu: 1681, i64and: 2045, i64or: 1641, i64xor: 2196, i64shl: 1662, i64shrs: 2124, i64shru: 1646, i64rotl: 1658, i64rotr: 2062 }, max_stack_size: 1024 }")
631    }
632}