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