fuel_tx/transaction/consensus_parameters/
gas.rs

1//! Tools for gas instrumentalization
2
3use core::ops::Deref;
4
5#[cfg(feature = "alloc")]
6use alloc::sync::Arc;
7
8use fuel_asm::PanicReason;
9use fuel_types::Word;
10
11/// Default gas costs are generated from the
12/// `fuel-core` repo using the `collect` bin
13/// in the `fuel-core-benches` crate.
14/// The git sha is included in the file to
15/// show what version of `fuel-core` was used
16/// to generate the costs.
17#[allow(dead_code)]
18mod default_gas_costs;
19
20/// Gas costings for every op.
21/// The inner values are wrapped in an [`Arc`]
22/// so this is cheap to clone.
23#[derive(Debug, Clone, PartialEq, Eq, Hash)]
24#[cfg(feature = "alloc")]
25pub struct GasCosts(Arc<GasCostsValues>);
26
27#[cfg(feature = "alloc")]
28impl<'de> serde::Deserialize<'de> for GasCosts {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
30    where
31        D: serde::Deserializer<'de>,
32    {
33        Ok(GasCosts(Arc::new(serde::Deserialize::deserialize(
34            deserializer,
35        )?)))
36    }
37}
38
39#[cfg(feature = "alloc")]
40impl serde::Serialize for GasCosts {
41    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
42    where
43        S: serde::Serializer,
44    {
45        serde::Serialize::serialize(self.0.as_ref(), serializer)
46    }
47}
48
49#[cfg(feature = "alloc")]
50impl GasCosts {
51    /// Create new cost values wrapped in an [`Arc`].
52    pub fn new(costs: GasCostsValues) -> Self {
53        Self(Arc::new(costs))
54    }
55}
56
57#[cfg(feature = "alloc")]
58impl Default for GasCosts {
59    fn default() -> Self {
60        Self(Arc::new(GasCostsValues::default()))
61    }
62}
63
64impl Default for GasCostsValues {
65    fn default() -> Self {
66        // The default values for gas costs
67        // are generated from fuel-core-benches.
68        default_gas_costs::default_gas_costs()
69    }
70}
71
72/// The versioned gas costs for every op.
73#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
74pub enum GasCostsValues {
75    /// Version 1 of the gas costs.
76    V1(GasCostsValuesV1),
77    /// Version 2 of the gas costs.
78    V2(GasCostsValuesV2),
79    /// Version 3 of the gas costs.
80    V3(GasCostsValuesV3),
81    /// Version 4 of the gas costs.
82    V4(GasCostsValuesV4),
83    /// Version 5 of the gas costs.
84    V5(GasCostsValuesV5),
85}
86
87/// Gas cost for this instruction is not defined for this version.
88pub struct GasCostNotDefined;
89
90impl From<GasCostNotDefined> for PanicReason {
91    fn from(_: GasCostNotDefined) -> PanicReason {
92        PanicReason::GasCostNotDefined
93    }
94}
95
96#[allow(missing_docs)]
97impl GasCostsValues {
98    pub fn add(&self) -> Word {
99        match self {
100            GasCostsValues::V1(v1) => v1.add,
101            GasCostsValues::V2(v2) => v2.add,
102            GasCostsValues::V3(v3) => v3.add,
103            GasCostsValues::V4(v4) => v4.add,
104            GasCostsValues::V5(v5) => v5.add,
105        }
106    }
107
108    pub fn addi(&self) -> Word {
109        match self {
110            GasCostsValues::V1(v1) => v1.addi,
111            GasCostsValues::V2(v2) => v2.addi,
112            GasCostsValues::V3(v3) => v3.addi,
113            GasCostsValues::V4(v4) => v4.addi,
114            GasCostsValues::V5(v5) => v5.addi,
115        }
116    }
117
118    pub fn and(&self) -> Word {
119        match self {
120            GasCostsValues::V1(v1) => v1.and,
121            GasCostsValues::V2(v2) => v2.and,
122            GasCostsValues::V3(v3) => v3.and,
123            GasCostsValues::V4(v4) => v4.and,
124            GasCostsValues::V5(v5) => v5.and,
125        }
126    }
127
128    pub fn andi(&self) -> Word {
129        match self {
130            GasCostsValues::V1(v1) => v1.andi,
131            GasCostsValues::V2(v2) => v2.andi,
132            GasCostsValues::V3(v3) => v3.andi,
133            GasCostsValues::V4(v4) => v4.andi,
134            GasCostsValues::V5(v5) => v5.andi,
135        }
136    }
137
138    pub fn bal(&self) -> Word {
139        match self {
140            GasCostsValues::V1(v1) => v1.bal,
141            GasCostsValues::V2(v2) => v2.bal,
142            GasCostsValues::V3(v3) => v3.bal,
143            GasCostsValues::V4(v4) => v4.bal,
144            GasCostsValues::V5(v5) => v5.bal,
145        }
146    }
147
148    pub fn bhei(&self) -> Word {
149        match self {
150            GasCostsValues::V1(v1) => v1.bhei,
151            GasCostsValues::V2(v2) => v2.bhei,
152            GasCostsValues::V3(v3) => v3.bhei,
153            GasCostsValues::V4(v4) => v4.bhei,
154            GasCostsValues::V5(v5) => v5.bhei,
155        }
156    }
157
158    pub fn bhsh(&self) -> Word {
159        match self {
160            GasCostsValues::V1(v1) => v1.bhsh,
161            GasCostsValues::V2(v2) => v2.bhsh,
162            GasCostsValues::V3(v3) => v3.bhsh,
163            GasCostsValues::V4(v4) => v4.bhsh,
164            GasCostsValues::V5(v5) => v5.bhsh,
165        }
166    }
167
168    pub fn burn(&self) -> Word {
169        match self {
170            GasCostsValues::V1(v1) => v1.burn,
171            GasCostsValues::V2(v2) => v2.burn,
172            GasCostsValues::V3(v3) => v3.burn,
173            GasCostsValues::V4(v4) => v4.burn,
174            GasCostsValues::V5(v5) => v5.burn,
175        }
176    }
177
178    pub fn cb(&self) -> Word {
179        match self {
180            GasCostsValues::V1(v1) => v1.cb,
181            GasCostsValues::V2(v2) => v2.cb,
182            GasCostsValues::V3(v3) => v3.cb,
183            GasCostsValues::V4(v4) => v4.cb,
184            GasCostsValues::V5(v5) => v5.cb,
185        }
186    }
187
188    pub fn cfsi(&self) -> Word {
189        match self {
190            GasCostsValues::V1(v1) => v1.cfsi,
191            GasCostsValues::V2(v2) => v2.cfsi,
192            GasCostsValues::V3(v3) => v3.cfsi,
193            GasCostsValues::V4(v4) => v4.cfsi,
194            GasCostsValues::V5(v5) => v5.cfsi,
195        }
196    }
197
198    pub fn div(&self) -> Word {
199        match self {
200            GasCostsValues::V1(v1) => v1.div,
201            GasCostsValues::V2(v2) => v2.div,
202            GasCostsValues::V3(v3) => v3.div,
203            GasCostsValues::V4(v4) => v4.div,
204            GasCostsValues::V5(v5) => v5.div,
205        }
206    }
207
208    pub fn divi(&self) -> Word {
209        match self {
210            GasCostsValues::V1(v1) => v1.divi,
211            GasCostsValues::V2(v2) => v2.divi,
212            GasCostsValues::V3(v3) => v3.divi,
213            GasCostsValues::V4(v4) => v4.divi,
214            GasCostsValues::V5(v5) => v5.divi,
215        }
216    }
217
218    pub fn eck1(&self) -> Word {
219        match self {
220            GasCostsValues::V1(v1) => v1.eck1,
221            GasCostsValues::V2(v2) => v2.eck1,
222            GasCostsValues::V3(v3) => v3.eck1,
223            GasCostsValues::V4(v4) => v4.eck1,
224            GasCostsValues::V5(v5) => v5.eck1,
225        }
226    }
227
228    pub fn ecr1(&self) -> Word {
229        match self {
230            GasCostsValues::V1(v1) => v1.ecr1,
231            GasCostsValues::V2(v2) => v2.ecr1,
232            GasCostsValues::V3(v3) => v3.ecr1,
233            GasCostsValues::V4(v4) => v4.ecr1,
234            GasCostsValues::V5(v5) => v5.ecr1,
235        }
236    }
237
238    pub fn eq_(&self) -> Word {
239        match self {
240            GasCostsValues::V1(v1) => v1.eq,
241            GasCostsValues::V2(v2) => v2.eq,
242            GasCostsValues::V3(v3) => v3.eq,
243            GasCostsValues::V4(v4) => v4.eq,
244            GasCostsValues::V5(v5) => v5.eq,
245        }
246    }
247
248    pub fn exp(&self) -> Word {
249        match self {
250            GasCostsValues::V1(v1) => v1.exp,
251            GasCostsValues::V2(v2) => v2.exp,
252            GasCostsValues::V3(v3) => v3.exp,
253            GasCostsValues::V4(v4) => v4.exp,
254            GasCostsValues::V5(v5) => v5.exp,
255        }
256    }
257
258    pub fn expi(&self) -> Word {
259        match self {
260            GasCostsValues::V1(v1) => v1.expi,
261            GasCostsValues::V2(v2) => v2.expi,
262            GasCostsValues::V3(v3) => v3.expi,
263            GasCostsValues::V4(v4) => v4.expi,
264            GasCostsValues::V5(v5) => v5.expi,
265        }
266    }
267
268    pub fn flag(&self) -> Word {
269        match self {
270            GasCostsValues::V1(v1) => v1.flag,
271            GasCostsValues::V2(v2) => v2.flag,
272            GasCostsValues::V3(v3) => v3.flag,
273            GasCostsValues::V4(v4) => v4.flag,
274            GasCostsValues::V5(v5) => v5.flag,
275        }
276    }
277
278    pub fn gm(&self) -> Word {
279        match self {
280            GasCostsValues::V1(v1) => v1.gm,
281            GasCostsValues::V2(v2) => v2.gm,
282            GasCostsValues::V3(v3) => v3.gm,
283            GasCostsValues::V4(v4) => v4.gm,
284            GasCostsValues::V5(v5) => v5.gm,
285        }
286    }
287
288    pub fn gt(&self) -> Word {
289        match self {
290            GasCostsValues::V1(v1) => v1.gt,
291            GasCostsValues::V2(v2) => v2.gt,
292            GasCostsValues::V3(v3) => v3.gt,
293            GasCostsValues::V4(v4) => v4.gt,
294            GasCostsValues::V5(v5) => v5.gt,
295        }
296    }
297
298    pub fn gtf(&self) -> Word {
299        match self {
300            GasCostsValues::V1(v1) => v1.gtf,
301            GasCostsValues::V2(v2) => v2.gtf,
302            GasCostsValues::V3(v3) => v3.gtf,
303            GasCostsValues::V4(v4) => v4.gtf,
304            GasCostsValues::V5(v5) => v5.gtf,
305        }
306    }
307
308    pub fn ji(&self) -> Word {
309        match self {
310            GasCostsValues::V1(v1) => v1.ji,
311            GasCostsValues::V2(v2) => v2.ji,
312            GasCostsValues::V3(v3) => v3.ji,
313            GasCostsValues::V4(v4) => v4.ji,
314            GasCostsValues::V5(v5) => v5.ji,
315        }
316    }
317
318    pub fn jmp(&self) -> Word {
319        match self {
320            GasCostsValues::V1(v1) => v1.jmp,
321            GasCostsValues::V2(v2) => v2.jmp,
322            GasCostsValues::V3(v3) => v3.jmp,
323            GasCostsValues::V4(v4) => v4.jmp,
324            GasCostsValues::V5(v5) => v5.jmp,
325        }
326    }
327
328    pub fn jne(&self) -> Word {
329        match self {
330            GasCostsValues::V1(v1) => v1.jne,
331            GasCostsValues::V2(v2) => v2.jne,
332            GasCostsValues::V3(v3) => v3.jne,
333            GasCostsValues::V4(v4) => v4.jne,
334            GasCostsValues::V5(v5) => v5.jne,
335        }
336    }
337
338    pub fn jnei(&self) -> Word {
339        match self {
340            GasCostsValues::V1(v1) => v1.jnei,
341            GasCostsValues::V2(v2) => v2.jnei,
342            GasCostsValues::V3(v3) => v3.jnei,
343            GasCostsValues::V4(v4) => v4.jnei,
344            GasCostsValues::V5(v5) => v5.jnei,
345        }
346    }
347
348    pub fn jnzi(&self) -> Word {
349        match self {
350            GasCostsValues::V1(v1) => v1.jnzi,
351            GasCostsValues::V2(v2) => v2.jnzi,
352            GasCostsValues::V3(v3) => v3.jnzi,
353            GasCostsValues::V4(v4) => v4.jnzi,
354            GasCostsValues::V5(v5) => v5.jnzi,
355        }
356    }
357
358    pub fn jmpf(&self) -> Word {
359        match self {
360            GasCostsValues::V1(v1) => v1.jmpf,
361            GasCostsValues::V2(v2) => v2.jmpf,
362            GasCostsValues::V3(v3) => v3.jmpf,
363            GasCostsValues::V4(v4) => v4.jmpf,
364            GasCostsValues::V5(v5) => v5.jmpf,
365        }
366    }
367
368    pub fn jmpb(&self) -> Word {
369        match self {
370            GasCostsValues::V1(v1) => v1.jmpb,
371            GasCostsValues::V2(v2) => v2.jmpb,
372            GasCostsValues::V3(v3) => v3.jmpb,
373            GasCostsValues::V4(v4) => v4.jmpb,
374            GasCostsValues::V5(v5) => v5.jmpb,
375        }
376    }
377
378    pub fn jnzf(&self) -> Word {
379        match self {
380            GasCostsValues::V1(v1) => v1.jnzf,
381            GasCostsValues::V2(v2) => v2.jnzf,
382            GasCostsValues::V3(v3) => v3.jnzf,
383            GasCostsValues::V4(v4) => v4.jnzf,
384            GasCostsValues::V5(v5) => v5.jnzf,
385        }
386    }
387
388    pub fn jnzb(&self) -> Word {
389        match self {
390            GasCostsValues::V1(v1) => v1.jnzb,
391            GasCostsValues::V2(v2) => v2.jnzb,
392            GasCostsValues::V3(v3) => v3.jnzb,
393            GasCostsValues::V4(v4) => v4.jnzb,
394            GasCostsValues::V5(v5) => v5.jnzb,
395        }
396    }
397
398    pub fn jnef(&self) -> Word {
399        match self {
400            GasCostsValues::V1(v1) => v1.jnef,
401            GasCostsValues::V2(v2) => v2.jnef,
402            GasCostsValues::V3(v3) => v3.jnef,
403            GasCostsValues::V4(v4) => v4.jnef,
404            GasCostsValues::V5(v5) => v5.jnef,
405        }
406    }
407
408    pub fn jneb(&self) -> Word {
409        match self {
410            GasCostsValues::V1(v1) => v1.jneb,
411            GasCostsValues::V2(v2) => v2.jneb,
412            GasCostsValues::V3(v3) => v3.jneb,
413            GasCostsValues::V4(v4) => v4.jneb,
414            GasCostsValues::V5(v5) => v5.jneb,
415        }
416    }
417
418    pub fn lb(&self) -> Word {
419        match self {
420            GasCostsValues::V1(v1) => v1.lb,
421            GasCostsValues::V2(v2) => v2.lb,
422            GasCostsValues::V3(v3) => v3.lb,
423            GasCostsValues::V4(v4) => v4.lb,
424            GasCostsValues::V5(v5) => v5.lb,
425        }
426    }
427
428    pub fn log(&self) -> Word {
429        match self {
430            GasCostsValues::V1(v1) => v1.log,
431            GasCostsValues::V2(v2) => v2.log,
432            GasCostsValues::V3(v3) => v3.log,
433            GasCostsValues::V4(v4) => v4.log,
434            GasCostsValues::V5(v5) => v5.log,
435        }
436    }
437
438    pub fn lt(&self) -> Word {
439        match self {
440            GasCostsValues::V1(v1) => v1.lt,
441            GasCostsValues::V2(v2) => v2.lt,
442            GasCostsValues::V3(v3) => v3.lt,
443            GasCostsValues::V4(v4) => v4.lt,
444            GasCostsValues::V5(v5) => v5.lt,
445        }
446    }
447
448    pub fn lw(&self) -> Word {
449        match self {
450            GasCostsValues::V1(v1) => v1.lw,
451            GasCostsValues::V2(v2) => v2.lw,
452            GasCostsValues::V3(v3) => v3.lw,
453            GasCostsValues::V4(v4) => v4.lw,
454            GasCostsValues::V5(v5) => v5.lw,
455        }
456    }
457
458    pub fn mint(&self) -> Word {
459        match self {
460            GasCostsValues::V1(v1) => v1.mint,
461            GasCostsValues::V2(v2) => v2.mint,
462            GasCostsValues::V3(v3) => v3.mint,
463            GasCostsValues::V4(v4) => v4.mint,
464            GasCostsValues::V5(v5) => v5.mint,
465        }
466    }
467
468    pub fn mlog(&self) -> Word {
469        match self {
470            GasCostsValues::V1(v1) => v1.mlog,
471            GasCostsValues::V2(v2) => v2.mlog,
472            GasCostsValues::V3(v3) => v3.mlog,
473            GasCostsValues::V4(v4) => v4.mlog,
474            GasCostsValues::V5(v5) => v5.mlog,
475        }
476    }
477
478    pub fn mod_op(&self) -> Word {
479        match self {
480            GasCostsValues::V1(v1) => v1.mod_op,
481            GasCostsValues::V2(v2) => v2.mod_op,
482            GasCostsValues::V3(v3) => v3.mod_op,
483            GasCostsValues::V4(v4) => v4.mod_op,
484            GasCostsValues::V5(v5) => v5.mod_op,
485        }
486    }
487
488    pub fn modi(&self) -> Word {
489        match self {
490            GasCostsValues::V1(v1) => v1.modi,
491            GasCostsValues::V2(v2) => v2.modi,
492            GasCostsValues::V3(v3) => v3.modi,
493            GasCostsValues::V4(v4) => v4.modi,
494            GasCostsValues::V5(v5) => v5.modi,
495        }
496    }
497
498    pub fn move_op(&self) -> Word {
499        match self {
500            GasCostsValues::V1(v1) => v1.move_op,
501            GasCostsValues::V2(v2) => v2.move_op,
502            GasCostsValues::V3(v3) => v3.move_op,
503            GasCostsValues::V4(v4) => v4.move_op,
504            GasCostsValues::V5(v5) => v5.move_op,
505        }
506    }
507
508    pub fn movi(&self) -> Word {
509        match self {
510            GasCostsValues::V1(v1) => v1.movi,
511            GasCostsValues::V2(v2) => v2.movi,
512            GasCostsValues::V3(v3) => v3.movi,
513            GasCostsValues::V4(v4) => v4.movi,
514            GasCostsValues::V5(v5) => v5.movi,
515        }
516    }
517
518    pub fn mroo(&self) -> Word {
519        match self {
520            GasCostsValues::V1(v1) => v1.mroo,
521            GasCostsValues::V2(v2) => v2.mroo,
522            GasCostsValues::V3(v3) => v3.mroo,
523            GasCostsValues::V4(v4) => v4.mroo,
524            GasCostsValues::V5(v5) => v5.mroo,
525        }
526    }
527
528    pub fn mul(&self) -> Word {
529        match self {
530            GasCostsValues::V1(v1) => v1.mul,
531            GasCostsValues::V2(v2) => v2.mul,
532            GasCostsValues::V3(v3) => v3.mul,
533            GasCostsValues::V4(v4) => v4.mul,
534            GasCostsValues::V5(v5) => v5.mul,
535        }
536    }
537
538    pub fn muli(&self) -> Word {
539        match self {
540            GasCostsValues::V1(v1) => v1.muli,
541            GasCostsValues::V2(v2) => v2.muli,
542            GasCostsValues::V3(v3) => v3.muli,
543            GasCostsValues::V4(v4) => v4.muli,
544            GasCostsValues::V5(v5) => v5.muli,
545        }
546    }
547
548    pub fn mldv(&self) -> Word {
549        match self {
550            GasCostsValues::V1(v1) => v1.mldv,
551            GasCostsValues::V2(v2) => v2.mldv,
552            GasCostsValues::V3(v3) => v3.mldv,
553            GasCostsValues::V4(v4) => v4.mldv,
554            GasCostsValues::V5(v5) => v5.mldv,
555        }
556    }
557
558    pub fn noop(&self) -> Word {
559        match self {
560            GasCostsValues::V1(v1) => v1.noop,
561            GasCostsValues::V2(v2) => v2.noop,
562            GasCostsValues::V3(v3) => v3.noop,
563            GasCostsValues::V4(v4) => v4.noop,
564            GasCostsValues::V5(v5) => v5.noop,
565        }
566    }
567
568    pub fn not(&self) -> Word {
569        match self {
570            GasCostsValues::V1(v1) => v1.not,
571            GasCostsValues::V2(v2) => v2.not,
572            GasCostsValues::V3(v3) => v3.not,
573            GasCostsValues::V4(v4) => v4.not,
574            GasCostsValues::V5(v5) => v5.not,
575        }
576    }
577
578    pub fn or(&self) -> Word {
579        match self {
580            GasCostsValues::V1(v1) => v1.or,
581            GasCostsValues::V2(v2) => v2.or,
582            GasCostsValues::V3(v3) => v3.or,
583            GasCostsValues::V4(v4) => v4.or,
584            GasCostsValues::V5(v5) => v5.or,
585        }
586    }
587
588    pub fn ori(&self) -> Word {
589        match self {
590            GasCostsValues::V1(v1) => v1.ori,
591            GasCostsValues::V2(v2) => v2.ori,
592            GasCostsValues::V3(v3) => v3.ori,
593            GasCostsValues::V4(v4) => v4.ori,
594            GasCostsValues::V5(v5) => v5.ori,
595        }
596    }
597
598    pub fn poph(&self) -> Word {
599        match self {
600            GasCostsValues::V1(v1) => v1.poph,
601            GasCostsValues::V2(v2) => v2.poph,
602            GasCostsValues::V3(v3) => v3.poph,
603            GasCostsValues::V4(v4) => v4.poph,
604            GasCostsValues::V5(v5) => v5.poph,
605        }
606    }
607
608    pub fn popl(&self) -> Word {
609        match self {
610            GasCostsValues::V1(v1) => v1.popl,
611            GasCostsValues::V2(v2) => v2.popl,
612            GasCostsValues::V3(v3) => v3.popl,
613            GasCostsValues::V4(v4) => v4.popl,
614            GasCostsValues::V5(v5) => v5.popl,
615        }
616    }
617
618    pub fn pshh(&self) -> Word {
619        match self {
620            GasCostsValues::V1(v1) => v1.pshh,
621            GasCostsValues::V2(v2) => v2.pshh,
622            GasCostsValues::V3(v3) => v3.pshh,
623            GasCostsValues::V4(v4) => v4.pshh,
624            GasCostsValues::V5(v5) => v5.pshh,
625        }
626    }
627
628    pub fn pshl(&self) -> Word {
629        match self {
630            GasCostsValues::V1(v1) => v1.pshl,
631            GasCostsValues::V2(v2) => v2.pshl,
632            GasCostsValues::V3(v3) => v3.pshl,
633            GasCostsValues::V4(v4) => v4.pshl,
634            GasCostsValues::V5(v5) => v5.pshl,
635        }
636    }
637
638    pub fn ret(&self) -> Word {
639        match self {
640            GasCostsValues::V1(v1) => v1.ret,
641            GasCostsValues::V2(v2) => v2.ret,
642            GasCostsValues::V3(v3) => v3.ret,
643            GasCostsValues::V4(v4) => v4.ret,
644            GasCostsValues::V5(v5) => v5.ret,
645        }
646    }
647
648    pub fn rvrt(&self) -> Word {
649        match self {
650            GasCostsValues::V1(v1) => v1.rvrt,
651            GasCostsValues::V2(v2) => v2.rvrt,
652            GasCostsValues::V3(v3) => v3.rvrt,
653            GasCostsValues::V4(v4) => v4.rvrt,
654            GasCostsValues::V5(v5) => v5.rvrt,
655        }
656    }
657
658    pub fn sb(&self) -> Word {
659        match self {
660            GasCostsValues::V1(v1) => v1.sb,
661            GasCostsValues::V2(v2) => v2.sb,
662            GasCostsValues::V3(v3) => v3.sb,
663            GasCostsValues::V4(v4) => v4.sb,
664            GasCostsValues::V5(v5) => v5.sb,
665        }
666    }
667
668    pub fn sll(&self) -> Word {
669        match self {
670            GasCostsValues::V1(v1) => v1.sll,
671            GasCostsValues::V2(v2) => v2.sll,
672            GasCostsValues::V3(v3) => v3.sll,
673            GasCostsValues::V4(v4) => v4.sll,
674            GasCostsValues::V5(v5) => v5.sll,
675        }
676    }
677
678    pub fn slli(&self) -> Word {
679        match self {
680            GasCostsValues::V1(v1) => v1.slli,
681            GasCostsValues::V2(v2) => v2.slli,
682            GasCostsValues::V3(v3) => v3.slli,
683            GasCostsValues::V4(v4) => v4.slli,
684            GasCostsValues::V5(v5) => v5.slli,
685        }
686    }
687
688    pub fn srl(&self) -> Word {
689        match self {
690            GasCostsValues::V1(v1) => v1.srl,
691            GasCostsValues::V2(v2) => v2.srl,
692            GasCostsValues::V3(v3) => v3.srl,
693            GasCostsValues::V4(v4) => v4.srl,
694            GasCostsValues::V5(v5) => v5.srl,
695        }
696    }
697
698    pub fn srli(&self) -> Word {
699        match self {
700            GasCostsValues::V1(v1) => v1.srli,
701            GasCostsValues::V2(v2) => v2.srli,
702            GasCostsValues::V3(v3) => v3.srli,
703            GasCostsValues::V4(v4) => v4.srli,
704            GasCostsValues::V5(v5) => v5.srli,
705        }
706    }
707
708    pub fn srw(&self) -> Word {
709        match self {
710            GasCostsValues::V1(v1) => v1.srw,
711            GasCostsValues::V2(v2) => v2.srw,
712            GasCostsValues::V3(v3) => v3.srw,
713            GasCostsValues::V4(v4) => v4.srw,
714            GasCostsValues::V5(v5) => v5.srw,
715        }
716    }
717
718    pub fn sub(&self) -> Word {
719        match self {
720            GasCostsValues::V1(v1) => v1.sub,
721            GasCostsValues::V2(v2) => v2.sub,
722            GasCostsValues::V3(v3) => v3.sub,
723            GasCostsValues::V4(v4) => v4.sub,
724            GasCostsValues::V5(v5) => v5.sub,
725        }
726    }
727
728    pub fn subi(&self) -> Word {
729        match self {
730            GasCostsValues::V1(v1) => v1.subi,
731            GasCostsValues::V2(v2) => v2.subi,
732            GasCostsValues::V3(v3) => v3.subi,
733            GasCostsValues::V4(v4) => v4.subi,
734            GasCostsValues::V5(v5) => v5.subi,
735        }
736    }
737
738    pub fn sw(&self) -> Word {
739        match self {
740            GasCostsValues::V1(v1) => v1.sw,
741            GasCostsValues::V2(v2) => v2.sw,
742            GasCostsValues::V3(v3) => v3.sw,
743            GasCostsValues::V4(v4) => v4.sw,
744            GasCostsValues::V5(v5) => v5.sw,
745        }
746    }
747
748    pub fn sww(&self) -> Word {
749        match self {
750            GasCostsValues::V1(v1) => v1.sww,
751            GasCostsValues::V2(v2) => v2.sww,
752            GasCostsValues::V3(v3) => v3.sww,
753            GasCostsValues::V4(v4) => v4.sww,
754            GasCostsValues::V5(v5) => v5.sww,
755        }
756    }
757
758    pub fn time(&self) -> Word {
759        match self {
760            GasCostsValues::V1(v1) => v1.time,
761            GasCostsValues::V2(v2) => v2.time,
762            GasCostsValues::V3(v3) => v3.time,
763            GasCostsValues::V4(v4) => v4.time,
764            GasCostsValues::V5(v5) => v5.time,
765        }
766    }
767
768    pub fn tr(&self) -> Word {
769        match self {
770            GasCostsValues::V1(v1) => v1.tr,
771            GasCostsValues::V2(v2) => v2.tr,
772            GasCostsValues::V3(v3) => v3.tr,
773            GasCostsValues::V4(v4) => v4.tr,
774            GasCostsValues::V5(v5) => v5.tr,
775        }
776    }
777
778    pub fn tro(&self) -> Word {
779        match self {
780            GasCostsValues::V1(v1) => v1.tro,
781            GasCostsValues::V2(v2) => v2.tro,
782            GasCostsValues::V3(v3) => v3.tro,
783            GasCostsValues::V4(v4) => v4.tro,
784            GasCostsValues::V5(v5) => v5.tro,
785        }
786    }
787
788    pub fn wdcm(&self) -> Word {
789        match self {
790            GasCostsValues::V1(v1) => v1.wdcm,
791            GasCostsValues::V2(v2) => v2.wdcm,
792            GasCostsValues::V3(v3) => v3.wdcm,
793            GasCostsValues::V4(v4) => v4.wdcm,
794            GasCostsValues::V5(v5) => v5.wdcm,
795        }
796    }
797
798    pub fn wqcm(&self) -> Word {
799        match self {
800            GasCostsValues::V1(v1) => v1.wqcm,
801            GasCostsValues::V2(v2) => v2.wqcm,
802            GasCostsValues::V3(v3) => v3.wqcm,
803            GasCostsValues::V4(v4) => v4.wqcm,
804            GasCostsValues::V5(v5) => v5.wqcm,
805        }
806    }
807
808    pub fn wdop(&self) -> Word {
809        match self {
810            GasCostsValues::V1(v1) => v1.wdop,
811            GasCostsValues::V2(v2) => v2.wdop,
812            GasCostsValues::V3(v3) => v3.wdop,
813            GasCostsValues::V4(v4) => v4.wdop,
814            GasCostsValues::V5(v5) => v5.wdop,
815        }
816    }
817
818    pub fn wqop(&self) -> Word {
819        match self {
820            GasCostsValues::V1(v1) => v1.wqop,
821            GasCostsValues::V2(v2) => v2.wqop,
822            GasCostsValues::V3(v3) => v3.wqop,
823            GasCostsValues::V4(v4) => v4.wqop,
824            GasCostsValues::V5(v5) => v5.wqop,
825        }
826    }
827
828    pub fn wdml(&self) -> Word {
829        match self {
830            GasCostsValues::V1(v1) => v1.wdml,
831            GasCostsValues::V2(v2) => v2.wdml,
832            GasCostsValues::V3(v3) => v3.wdml,
833            GasCostsValues::V4(v4) => v4.wdml,
834            GasCostsValues::V5(v5) => v5.wdml,
835        }
836    }
837
838    pub fn wqml(&self) -> Word {
839        match self {
840            GasCostsValues::V1(v1) => v1.wqml,
841            GasCostsValues::V2(v2) => v2.wqml,
842            GasCostsValues::V3(v3) => v3.wqml,
843            GasCostsValues::V4(v4) => v4.wqml,
844            GasCostsValues::V5(v5) => v5.wqml,
845        }
846    }
847
848    pub fn wddv(&self) -> Word {
849        match self {
850            GasCostsValues::V1(v1) => v1.wddv,
851            GasCostsValues::V2(v2) => v2.wddv,
852            GasCostsValues::V3(v3) => v3.wddv,
853            GasCostsValues::V4(v4) => v4.wddv,
854            GasCostsValues::V5(v5) => v5.wddv,
855        }
856    }
857
858    pub fn wqdv(&self) -> Word {
859        match self {
860            GasCostsValues::V1(v1) => v1.wqdv,
861            GasCostsValues::V2(v2) => v2.wqdv,
862            GasCostsValues::V3(v3) => v3.wqdv,
863            GasCostsValues::V4(v4) => v4.wqdv,
864            GasCostsValues::V5(v5) => v5.wqdv,
865        }
866    }
867
868    pub fn wdmd(&self) -> Word {
869        match self {
870            GasCostsValues::V1(v1) => v1.wdmd,
871            GasCostsValues::V2(v2) => v2.wdmd,
872            GasCostsValues::V3(v3) => v3.wdmd,
873            GasCostsValues::V4(v4) => v4.wdmd,
874            GasCostsValues::V5(v5) => v5.wdmd,
875        }
876    }
877
878    pub fn wqmd(&self) -> Word {
879        match self {
880            GasCostsValues::V1(v1) => v1.wqmd,
881            GasCostsValues::V2(v2) => v2.wqmd,
882            GasCostsValues::V3(v3) => v3.wqmd,
883            GasCostsValues::V4(v4) => v4.wqmd,
884            GasCostsValues::V5(v5) => v5.wqmd,
885        }
886    }
887
888    pub fn wdam(&self) -> Word {
889        match self {
890            GasCostsValues::V1(v1) => v1.wdam,
891            GasCostsValues::V2(v2) => v2.wdam,
892            GasCostsValues::V3(v3) => v3.wdam,
893            GasCostsValues::V4(v4) => v4.wdam,
894            GasCostsValues::V5(v5) => v5.wdam,
895        }
896    }
897
898    pub fn wqam(&self) -> Word {
899        match self {
900            GasCostsValues::V1(v1) => v1.wqam,
901            GasCostsValues::V2(v2) => v2.wqam,
902            GasCostsValues::V3(v3) => v3.wqam,
903            GasCostsValues::V4(v4) => v4.wqam,
904            GasCostsValues::V5(v5) => v5.wqam,
905        }
906    }
907
908    pub fn wdmm(&self) -> Word {
909        match self {
910            GasCostsValues::V1(v1) => v1.wdmm,
911            GasCostsValues::V2(v2) => v2.wdmm,
912            GasCostsValues::V3(v3) => v3.wdmm,
913            GasCostsValues::V4(v4) => v4.wdmm,
914            GasCostsValues::V5(v5) => v5.wdmm,
915        }
916    }
917
918    pub fn wqmm(&self) -> Word {
919        match self {
920            GasCostsValues::V1(v1) => v1.wqmm,
921            GasCostsValues::V2(v2) => v2.wqmm,
922            GasCostsValues::V3(v3) => v3.wqmm,
923            GasCostsValues::V4(v4) => v4.wqmm,
924            GasCostsValues::V5(v5) => v5.wqmm,
925        }
926    }
927
928    pub fn xor(&self) -> Word {
929        match self {
930            GasCostsValues::V1(v1) => v1.xor,
931            GasCostsValues::V2(v2) => v2.xor,
932            GasCostsValues::V3(v3) => v3.xor,
933            GasCostsValues::V4(v4) => v4.xor,
934            GasCostsValues::V5(v5) => v5.xor,
935        }
936    }
937
938    pub fn xori(&self) -> Word {
939        match self {
940            GasCostsValues::V1(v1) => v1.xori,
941            GasCostsValues::V2(v2) => v2.xori,
942            GasCostsValues::V3(v3) => v3.xori,
943            GasCostsValues::V4(v4) => v4.xori,
944            GasCostsValues::V5(v5) => v5.xori,
945        }
946    }
947
948    pub fn ecop(&self) -> Result<Word, GasCostNotDefined> {
949        match self {
950            GasCostsValues::V1(_) => Err(GasCostNotDefined),
951            GasCostsValues::V2(_) => Err(GasCostNotDefined),
952            GasCostsValues::V3(_) => Err(GasCostNotDefined),
953            GasCostsValues::V4(_) => Err(GasCostNotDefined),
954            GasCostsValues::V5(v5) => Ok(v5.ecop),
955        }
956    }
957
958    pub fn aloc(&self) -> DependentCost {
959        match self {
960            GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
961                base: v1.aloc,
962                gas_per_unit: 0,
963            },
964            GasCostsValues::V2(v2) => v2.aloc,
965            GasCostsValues::V3(v3) => v3.aloc,
966            GasCostsValues::V4(v4) => v4.aloc,
967            GasCostsValues::V5(v5) => v5.aloc,
968        }
969    }
970
971    pub fn cfe(&self) -> DependentCost {
972        match self {
973            GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
974                base: v1.cfei,
975                gas_per_unit: 0,
976            },
977            GasCostsValues::V2(v2) => DependentCost::HeavyOperation {
978                base: v2.cfei,
979                gas_per_unit: 0,
980            },
981            GasCostsValues::V3(v3) => v3.cfe,
982            GasCostsValues::V4(v4) => v4.cfe,
983            GasCostsValues::V5(v5) => v5.cfe,
984        }
985    }
986
987    pub fn cfei(&self) -> DependentCost {
988        match self {
989            GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
990                base: v1.cfei,
991                gas_per_unit: 0,
992            },
993            GasCostsValues::V2(v2) => DependentCost::HeavyOperation {
994                base: v2.cfei,
995                gas_per_unit: 0,
996            },
997            GasCostsValues::V3(v3) => v3.cfei,
998            GasCostsValues::V4(v4) => v4.cfei,
999            GasCostsValues::V5(v5) => v5.cfei,
1000        }
1001    }
1002
1003    pub fn call(&self) -> DependentCost {
1004        match self {
1005            GasCostsValues::V1(v1) => v1.call,
1006            GasCostsValues::V2(v2) => v2.call,
1007            GasCostsValues::V3(v3) => v3.call,
1008            GasCostsValues::V4(v4) => v4.call,
1009            GasCostsValues::V5(v5) => v5.call,
1010        }
1011    }
1012
1013    pub fn ccp(&self) -> DependentCost {
1014        match self {
1015            GasCostsValues::V1(v1) => v1.ccp,
1016            GasCostsValues::V2(v2) => v2.ccp,
1017            GasCostsValues::V3(v3) => v3.ccp,
1018            GasCostsValues::V4(v4) => v4.ccp,
1019            GasCostsValues::V5(v5) => v5.ccp,
1020        }
1021    }
1022
1023    pub fn croo(&self) -> DependentCost {
1024        match self {
1025            GasCostsValues::V1(v1) => v1.croo,
1026            GasCostsValues::V2(v2) => v2.croo,
1027            GasCostsValues::V3(v3) => v3.croo,
1028            GasCostsValues::V4(v4) => v4.croo,
1029            GasCostsValues::V5(v5) => v5.croo,
1030        }
1031    }
1032
1033    pub fn csiz(&self) -> DependentCost {
1034        match self {
1035            GasCostsValues::V1(v1) => v1.csiz,
1036            GasCostsValues::V2(v2) => v2.csiz,
1037            GasCostsValues::V3(v3) => v3.csiz,
1038            GasCostsValues::V4(v4) => v4.csiz,
1039            GasCostsValues::V5(v5) => v5.csiz,
1040        }
1041    }
1042
1043    pub fn ed19(&self) -> DependentCost {
1044        match self {
1045            GasCostsValues::V1(v1) => DependentCost::HeavyOperation {
1046                base: v1.ed19,
1047                gas_per_unit: 0,
1048            },
1049            GasCostsValues::V2(v2) => DependentCost::HeavyOperation {
1050                base: v2.ed19,
1051                gas_per_unit: 0,
1052            },
1053            GasCostsValues::V3(v3) => DependentCost::HeavyOperation {
1054                base: v3.ed19,
1055                gas_per_unit: 0,
1056            },
1057            GasCostsValues::V4(v4) => v4.ed19,
1058            GasCostsValues::V5(v5) => v5.ed19,
1059        }
1060    }
1061
1062    pub fn k256(&self) -> DependentCost {
1063        match self {
1064            GasCostsValues::V1(v1) => v1.k256,
1065            GasCostsValues::V2(v2) => v2.k256,
1066            GasCostsValues::V3(v3) => v3.k256,
1067            GasCostsValues::V4(v4) => v4.k256,
1068            GasCostsValues::V5(v5) => v5.k256,
1069        }
1070    }
1071
1072    pub fn ldc(&self) -> DependentCost {
1073        match self {
1074            GasCostsValues::V1(v1) => v1.ldc,
1075            GasCostsValues::V2(v2) => v2.ldc,
1076            GasCostsValues::V3(v3) => v3.ldc,
1077            GasCostsValues::V4(v4) => v4.ldc,
1078            GasCostsValues::V5(v5) => v5.ldc,
1079        }
1080    }
1081
1082    pub fn logd(&self) -> DependentCost {
1083        match self {
1084            GasCostsValues::V1(v1) => v1.logd,
1085            GasCostsValues::V2(v2) => v2.logd,
1086            GasCostsValues::V3(v3) => v3.logd,
1087            GasCostsValues::V4(v4) => v4.logd,
1088            GasCostsValues::V5(v5) => v5.logd,
1089        }
1090    }
1091
1092    pub fn mcl(&self) -> DependentCost {
1093        match self {
1094            GasCostsValues::V1(v1) => v1.mcl,
1095            GasCostsValues::V2(v2) => v2.mcl,
1096            GasCostsValues::V3(v3) => v3.mcl,
1097            GasCostsValues::V4(v4) => v4.mcl,
1098            GasCostsValues::V5(v5) => v5.mcl,
1099        }
1100    }
1101
1102    pub fn mcli(&self) -> DependentCost {
1103        match self {
1104            GasCostsValues::V1(v1) => v1.mcli,
1105            GasCostsValues::V2(v2) => v2.mcli,
1106            GasCostsValues::V3(v3) => v3.mcli,
1107            GasCostsValues::V4(v4) => v4.mcli,
1108            GasCostsValues::V5(v5) => v5.mcli,
1109        }
1110    }
1111
1112    pub fn mcp(&self) -> DependentCost {
1113        match self {
1114            GasCostsValues::V1(v1) => v1.mcp,
1115            GasCostsValues::V2(v2) => v2.mcp,
1116            GasCostsValues::V3(v3) => v3.mcp,
1117            GasCostsValues::V4(v4) => v4.mcp,
1118            GasCostsValues::V5(v5) => v5.mcp,
1119        }
1120    }
1121
1122    pub fn mcpi(&self) -> DependentCost {
1123        match self {
1124            GasCostsValues::V1(v1) => v1.mcpi,
1125            GasCostsValues::V2(v2) => v2.mcpi,
1126            GasCostsValues::V3(v3) => v3.mcpi,
1127            GasCostsValues::V4(v4) => v4.mcpi,
1128            GasCostsValues::V5(v5) => v5.mcpi,
1129        }
1130    }
1131
1132    pub fn meq(&self) -> DependentCost {
1133        match self {
1134            GasCostsValues::V1(v1) => v1.meq,
1135            GasCostsValues::V2(v2) => v2.meq,
1136            GasCostsValues::V3(v3) => v3.meq,
1137            GasCostsValues::V4(v4) => v4.meq,
1138            GasCostsValues::V5(v5) => v5.meq,
1139        }
1140    }
1141
1142    pub fn retd(&self) -> DependentCost {
1143        match self {
1144            GasCostsValues::V1(v1) => v1.retd,
1145            GasCostsValues::V2(v2) => v2.retd,
1146            GasCostsValues::V3(v3) => v3.retd,
1147            GasCostsValues::V4(v4) => v4.retd,
1148            GasCostsValues::V5(v5) => v5.retd,
1149        }
1150    }
1151
1152    pub fn s256(&self) -> DependentCost {
1153        match self {
1154            GasCostsValues::V1(v1) => v1.s256,
1155            GasCostsValues::V2(v2) => v2.s256,
1156            GasCostsValues::V3(v3) => v3.s256,
1157            GasCostsValues::V4(v4) => v4.s256,
1158            GasCostsValues::V5(v5) => v5.s256,
1159        }
1160    }
1161
1162    pub fn scwq(&self) -> DependentCost {
1163        match self {
1164            GasCostsValues::V1(v1) => v1.scwq,
1165            GasCostsValues::V2(v2) => v2.scwq,
1166            GasCostsValues::V3(v3) => v3.scwq,
1167            GasCostsValues::V4(v4) => v4.scwq,
1168            GasCostsValues::V5(v5) => v5.scwq,
1169        }
1170    }
1171
1172    pub fn smo(&self) -> DependentCost {
1173        match self {
1174            GasCostsValues::V1(v1) => v1.smo,
1175            GasCostsValues::V2(v2) => v2.smo,
1176            GasCostsValues::V3(v3) => v3.smo,
1177            GasCostsValues::V4(v4) => v4.smo,
1178            GasCostsValues::V5(v5) => v5.smo,
1179        }
1180    }
1181
1182    pub fn srwq(&self) -> DependentCost {
1183        match self {
1184            GasCostsValues::V1(v1) => v1.srwq,
1185            GasCostsValues::V2(v2) => v2.srwq,
1186            GasCostsValues::V3(v3) => v3.srwq,
1187            GasCostsValues::V4(v4) => v4.srwq,
1188            GasCostsValues::V5(v5) => v5.srwq,
1189        }
1190    }
1191
1192    pub fn swwq(&self) -> DependentCost {
1193        match self {
1194            GasCostsValues::V1(v1) => v1.swwq,
1195            GasCostsValues::V2(v2) => v2.swwq,
1196            GasCostsValues::V3(v3) => v3.swwq,
1197            GasCostsValues::V4(v4) => v4.swwq,
1198            GasCostsValues::V5(v5) => v5.swwq,
1199        }
1200    }
1201
1202    pub fn bsiz(&self) -> Result<DependentCost, GasCostNotDefined> {
1203        match self {
1204            GasCostsValues::V1(_v1) => Err(GasCostNotDefined),
1205            GasCostsValues::V2(_v2) => Err(GasCostNotDefined),
1206            GasCostsValues::V3(_v3) => Err(GasCostNotDefined),
1207            GasCostsValues::V4(v4) => Ok(v4.bsiz),
1208            GasCostsValues::V5(v5) => Ok(v5.bsiz),
1209        }
1210    }
1211
1212    pub fn bldd(&self) -> Result<DependentCost, GasCostNotDefined> {
1213        match self {
1214            GasCostsValues::V1(_v1) => Err(GasCostNotDefined),
1215            GasCostsValues::V2(_v2) => Err(GasCostNotDefined),
1216            GasCostsValues::V3(_v3) => Err(GasCostNotDefined),
1217            GasCostsValues::V4(v4) => Ok(v4.bldd),
1218            GasCostsValues::V5(v5) => Ok(v5.bldd),
1219        }
1220    }
1221
1222    pub fn epar(&self) -> Result<DependentCost, GasCostNotDefined> {
1223        match self {
1224            GasCostsValues::V1(_v1) => Err(GasCostNotDefined),
1225            GasCostsValues::V2(_v2) => Err(GasCostNotDefined),
1226            GasCostsValues::V3(_v3) => Err(GasCostNotDefined),
1227            GasCostsValues::V4(_v4) => Err(GasCostNotDefined),
1228            GasCostsValues::V5(v5) => Ok(v5.epar),
1229        }
1230    }
1231
1232    pub fn contract_root(&self) -> DependentCost {
1233        match self {
1234            GasCostsValues::V1(v1) => v1.contract_root,
1235            GasCostsValues::V2(v2) => v2.contract_root,
1236            GasCostsValues::V3(v3) => v3.contract_root,
1237            GasCostsValues::V4(v4) => v4.contract_root,
1238            GasCostsValues::V5(v5) => v5.contract_root,
1239        }
1240    }
1241
1242    pub fn state_root(&self) -> DependentCost {
1243        match self {
1244            GasCostsValues::V1(v1) => v1.state_root,
1245            GasCostsValues::V2(v2) => v2.state_root,
1246            GasCostsValues::V3(v3) => v3.state_root,
1247            GasCostsValues::V4(v4) => v4.state_root,
1248            GasCostsValues::V5(v5) => v5.state_root,
1249        }
1250    }
1251
1252    pub fn new_storage_per_byte(&self) -> Word {
1253        match self {
1254            GasCostsValues::V1(v1) => v1.new_storage_per_byte,
1255            GasCostsValues::V2(v2) => v2.new_storage_per_byte,
1256            GasCostsValues::V3(v3) => v3.new_storage_per_byte,
1257            GasCostsValues::V4(v4) => v4.new_storage_per_byte,
1258            GasCostsValues::V5(v5) => v5.new_storage_per_byte,
1259        }
1260    }
1261
1262    pub fn vm_initialization(&self) -> DependentCost {
1263        match self {
1264            GasCostsValues::V1(v1) => v1.vm_initialization,
1265            GasCostsValues::V2(v2) => v2.vm_initialization,
1266            GasCostsValues::V3(v3) => v3.vm_initialization,
1267            GasCostsValues::V4(v4) => v4.vm_initialization,
1268            GasCostsValues::V5(v5) => v5.vm_initialization,
1269        }
1270    }
1271}
1272
1273/// Gas costs for every op.
1274#[allow(missing_docs)]
1275#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
1276#[serde(default = "GasCostsValuesV1::unit")]
1277pub struct GasCostsValuesV1 {
1278    pub add: Word,
1279    pub addi: Word,
1280    pub aloc: Word,
1281    pub and: Word,
1282    pub andi: Word,
1283    pub bal: Word,
1284    pub bhei: Word,
1285    pub bhsh: Word,
1286    pub burn: Word,
1287    pub cb: Word,
1288    pub cfei: Word,
1289    pub cfsi: Word,
1290    pub div: Word,
1291    pub divi: Word,
1292    pub eck1: Word,
1293    pub ecr1: Word,
1294    pub ed19: Word,
1295    pub eq: Word,
1296    pub exp: Word,
1297    pub expi: Word,
1298    pub flag: Word,
1299    pub gm: Word,
1300    pub gt: Word,
1301    pub gtf: Word,
1302    pub ji: Word,
1303    pub jmp: Word,
1304    pub jne: Word,
1305    pub jnei: Word,
1306    pub jnzi: Word,
1307    pub jmpf: Word,
1308    pub jmpb: Word,
1309    pub jnzf: Word,
1310    pub jnzb: Word,
1311    pub jnef: Word,
1312    pub jneb: Word,
1313    pub lb: Word,
1314    pub log: Word,
1315    pub lt: Word,
1316    pub lw: Word,
1317    pub mint: Word,
1318    pub mlog: Word,
1319    #[serde(rename = "mod")]
1320    pub mod_op: Word,
1321    pub modi: Word,
1322    #[serde(rename = "move")]
1323    pub move_op: Word,
1324    pub movi: Word,
1325    pub mroo: Word,
1326    pub mul: Word,
1327    pub muli: Word,
1328    pub mldv: Word,
1329    pub noop: Word,
1330    pub not: Word,
1331    pub or: Word,
1332    pub ori: Word,
1333    pub poph: Word,
1334    pub popl: Word,
1335    pub pshh: Word,
1336    pub pshl: Word,
1337    #[serde(rename = "ret_contract")]
1338    pub ret: Word,
1339    #[serde(rename = "rvrt_contract")]
1340    pub rvrt: Word,
1341    pub sb: Word,
1342    pub sll: Word,
1343    pub slli: Word,
1344    pub srl: Word,
1345    pub srli: Word,
1346    pub srw: Word,
1347    pub sub: Word,
1348    pub subi: Word,
1349    pub sw: Word,
1350    pub sww: Word,
1351    pub time: Word,
1352    pub tr: Word,
1353    pub tro: Word,
1354    pub wdcm: Word,
1355    pub wqcm: Word,
1356    pub wdop: Word,
1357    pub wqop: Word,
1358    pub wdml: Word,
1359    pub wqml: Word,
1360    pub wddv: Word,
1361    pub wqdv: Word,
1362    pub wdmd: Word,
1363    pub wqmd: Word,
1364    pub wdam: Word,
1365    pub wqam: Word,
1366    pub wdmm: Word,
1367    pub wqmm: Word,
1368    pub xor: Word,
1369    pub xori: Word,
1370
1371    // Dependent
1372    pub call: DependentCost,
1373    pub ccp: DependentCost,
1374    pub croo: DependentCost,
1375    pub csiz: DependentCost,
1376    pub k256: DependentCost,
1377    pub ldc: DependentCost,
1378    pub logd: DependentCost,
1379    pub mcl: DependentCost,
1380    pub mcli: DependentCost,
1381    pub mcp: DependentCost,
1382    pub mcpi: DependentCost,
1383    pub meq: DependentCost,
1384    #[serde(rename = "retd_contract")]
1385    pub retd: DependentCost,
1386    pub s256: DependentCost,
1387    pub scwq: DependentCost,
1388    pub smo: DependentCost,
1389    pub srwq: DependentCost,
1390    pub swwq: DependentCost,
1391
1392    // Non-opcode costs
1393    pub contract_root: DependentCost,
1394    pub state_root: DependentCost,
1395    pub new_storage_per_byte: Word,
1396    pub vm_initialization: DependentCost,
1397}
1398
1399/// Gas costs for every op.
1400/// The difference with [`GasCostsValuesV1`]:
1401/// - `aloc` is a [`DependentCost`] instead of a [`Word`]
1402#[allow(missing_docs)]
1403#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
1404#[serde(default = "GasCostsValuesV2::unit")]
1405pub struct GasCostsValuesV2 {
1406    pub add: Word,
1407    pub addi: Word,
1408    pub and: Word,
1409    pub andi: Word,
1410    pub bal: Word,
1411    pub bhei: Word,
1412    pub bhsh: Word,
1413    pub burn: Word,
1414    pub cb: Word,
1415    pub cfei: Word,
1416    pub cfsi: Word,
1417    pub div: Word,
1418    pub divi: Word,
1419    pub eck1: Word,
1420    pub ecr1: Word,
1421    pub ed19: Word,
1422    pub eq: Word,
1423    pub exp: Word,
1424    pub expi: Word,
1425    pub flag: Word,
1426    pub gm: Word,
1427    pub gt: Word,
1428    pub gtf: Word,
1429    pub ji: Word,
1430    pub jmp: Word,
1431    pub jne: Word,
1432    pub jnei: Word,
1433    pub jnzi: Word,
1434    pub jmpf: Word,
1435    pub jmpb: Word,
1436    pub jnzf: Word,
1437    pub jnzb: Word,
1438    pub jnef: Word,
1439    pub jneb: Word,
1440    pub lb: Word,
1441    pub log: Word,
1442    pub lt: Word,
1443    pub lw: Word,
1444    pub mint: Word,
1445    pub mlog: Word,
1446    #[serde(rename = "mod")]
1447    pub mod_op: Word,
1448    pub modi: Word,
1449    #[serde(rename = "move")]
1450    pub move_op: Word,
1451    pub movi: Word,
1452    pub mroo: Word,
1453    pub mul: Word,
1454    pub muli: Word,
1455    pub mldv: Word,
1456    pub noop: Word,
1457    pub not: Word,
1458    pub or: Word,
1459    pub ori: Word,
1460    pub poph: Word,
1461    pub popl: Word,
1462    pub pshh: Word,
1463    pub pshl: Word,
1464    #[serde(rename = "ret_contract")]
1465    pub ret: Word,
1466    #[serde(rename = "rvrt_contract")]
1467    pub rvrt: Word,
1468    pub sb: Word,
1469    pub sll: Word,
1470    pub slli: Word,
1471    pub srl: Word,
1472    pub srli: Word,
1473    pub srw: Word,
1474    pub sub: Word,
1475    pub subi: Word,
1476    pub sw: Word,
1477    pub sww: Word,
1478    pub time: Word,
1479    pub tr: Word,
1480    pub tro: Word,
1481    pub wdcm: Word,
1482    pub wqcm: Word,
1483    pub wdop: Word,
1484    pub wqop: Word,
1485    pub wdml: Word,
1486    pub wqml: Word,
1487    pub wddv: Word,
1488    pub wqdv: Word,
1489    pub wdmd: Word,
1490    pub wqmd: Word,
1491    pub wdam: Word,
1492    pub wqam: Word,
1493    pub wdmm: Word,
1494    pub wqmm: Word,
1495    pub xor: Word,
1496    pub xori: Word,
1497
1498    // Dependent
1499    pub aloc: DependentCost,
1500    pub call: DependentCost,
1501    pub ccp: DependentCost,
1502    pub croo: DependentCost,
1503    pub csiz: DependentCost,
1504    pub k256: DependentCost,
1505    pub ldc: DependentCost,
1506    pub logd: DependentCost,
1507    pub mcl: DependentCost,
1508    pub mcli: DependentCost,
1509    pub mcp: DependentCost,
1510    pub mcpi: DependentCost,
1511    pub meq: DependentCost,
1512    #[serde(rename = "retd_contract")]
1513    pub retd: DependentCost,
1514    pub s256: DependentCost,
1515    pub scwq: DependentCost,
1516    pub smo: DependentCost,
1517    pub srwq: DependentCost,
1518    pub swwq: DependentCost,
1519
1520    // Non-opcode costs
1521    pub contract_root: DependentCost,
1522    pub state_root: DependentCost,
1523    pub new_storage_per_byte: Word,
1524    pub vm_initialization: DependentCost,
1525}
1526
1527/// Gas costs for every op.
1528/// The difference with [`GasCostsValuesV2`]:
1529/// - Added `cfe` as a [`DependentCost`]
1530/// - `cfei` is a [`DependentCost`] instead of a [`Word`]
1531#[allow(missing_docs)]
1532#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
1533#[serde(default = "GasCostsValuesV3::unit")]
1534pub struct GasCostsValuesV3 {
1535    pub add: Word,
1536    pub addi: Word,
1537    pub and: Word,
1538    pub andi: Word,
1539    pub bal: Word,
1540    pub bhei: Word,
1541    pub bhsh: Word,
1542    pub burn: Word,
1543    pub cb: Word,
1544    pub cfsi: Word,
1545    pub div: Word,
1546    pub divi: Word,
1547    pub eck1: Word,
1548    pub ecr1: Word,
1549    pub ed19: Word,
1550    pub eq: Word,
1551    pub exp: Word,
1552    pub expi: Word,
1553    pub flag: Word,
1554    pub gm: Word,
1555    pub gt: Word,
1556    pub gtf: Word,
1557    pub ji: Word,
1558    pub jmp: Word,
1559    pub jne: Word,
1560    pub jnei: Word,
1561    pub jnzi: Word,
1562    pub jmpf: Word,
1563    pub jmpb: Word,
1564    pub jnzf: Word,
1565    pub jnzb: Word,
1566    pub jnef: Word,
1567    pub jneb: Word,
1568    pub lb: Word,
1569    pub log: Word,
1570    pub lt: Word,
1571    pub lw: Word,
1572    pub mint: Word,
1573    pub mlog: Word,
1574    #[serde(rename = "mod")]
1575    pub mod_op: Word,
1576    pub modi: Word,
1577    #[serde(rename = "move")]
1578    pub move_op: Word,
1579    pub movi: Word,
1580    pub mroo: Word,
1581    pub mul: Word,
1582    pub muli: Word,
1583    pub mldv: Word,
1584    pub noop: Word,
1585    pub not: Word,
1586    pub or: Word,
1587    pub ori: Word,
1588    pub poph: Word,
1589    pub popl: Word,
1590    pub pshh: Word,
1591    pub pshl: Word,
1592    #[serde(rename = "ret_contract")]
1593    pub ret: Word,
1594    #[serde(rename = "rvrt_contract")]
1595    pub rvrt: Word,
1596    pub sb: Word,
1597    pub sll: Word,
1598    pub slli: Word,
1599    pub srl: Word,
1600    pub srli: Word,
1601    pub srw: Word,
1602    pub sub: Word,
1603    pub subi: Word,
1604    pub sw: Word,
1605    pub sww: Word,
1606    pub time: Word,
1607    pub tr: Word,
1608    pub tro: Word,
1609    pub wdcm: Word,
1610    pub wqcm: Word,
1611    pub wdop: Word,
1612    pub wqop: Word,
1613    pub wdml: Word,
1614    pub wqml: Word,
1615    pub wddv: Word,
1616    pub wqdv: Word,
1617    pub wdmd: Word,
1618    pub wqmd: Word,
1619    pub wdam: Word,
1620    pub wqam: Word,
1621    pub wdmm: Word,
1622    pub wqmm: Word,
1623    pub xor: Word,
1624    pub xori: Word,
1625
1626    // Dependent
1627    pub aloc: DependentCost,
1628    pub cfe: DependentCost,
1629    pub cfei: DependentCost,
1630    pub call: DependentCost,
1631    pub ccp: DependentCost,
1632    pub croo: DependentCost,
1633    pub csiz: DependentCost,
1634    pub k256: DependentCost,
1635    pub ldc: DependentCost,
1636    pub logd: DependentCost,
1637    pub mcl: DependentCost,
1638    pub mcli: DependentCost,
1639    pub mcp: DependentCost,
1640    pub mcpi: DependentCost,
1641    pub meq: DependentCost,
1642    #[serde(rename = "retd_contract")]
1643    pub retd: DependentCost,
1644    pub s256: DependentCost,
1645    pub scwq: DependentCost,
1646    pub smo: DependentCost,
1647    pub srwq: DependentCost,
1648    pub swwq: DependentCost,
1649
1650    // Non-opcode costs
1651    pub contract_root: DependentCost,
1652    pub state_root: DependentCost,
1653    pub new_storage_per_byte: Word,
1654    pub vm_initialization: DependentCost,
1655}
1656
1657/// Gas costs for every op.
1658/// The difference with [`GasCostsValuesV3`]:
1659/// - Added `bsiz`, `bldd` instructions
1660/// - Changed `ed19` to be `DependentCost`
1661#[allow(missing_docs)]
1662#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
1663#[serde(default = "GasCostsValuesV4::unit")]
1664pub struct GasCostsValuesV4 {
1665    pub add: Word,
1666    pub addi: Word,
1667    pub and: Word,
1668    pub andi: Word,
1669    pub bal: Word,
1670    pub bhei: Word,
1671    pub bhsh: Word,
1672    pub burn: Word,
1673    pub cb: Word,
1674    pub cfsi: Word,
1675    pub div: Word,
1676    pub divi: Word,
1677    pub eck1: Word,
1678    pub ecr1: Word,
1679    pub eq: Word,
1680    pub exp: Word,
1681    pub expi: Word,
1682    pub flag: Word,
1683    pub gm: Word,
1684    pub gt: Word,
1685    pub gtf: Word,
1686    pub ji: Word,
1687    pub jmp: Word,
1688    pub jne: Word,
1689    pub jnei: Word,
1690    pub jnzi: Word,
1691    pub jmpf: Word,
1692    pub jmpb: Word,
1693    pub jnzf: Word,
1694    pub jnzb: Word,
1695    pub jnef: Word,
1696    pub jneb: Word,
1697    pub lb: Word,
1698    pub log: Word,
1699    pub lt: Word,
1700    pub lw: Word,
1701    pub mint: Word,
1702    pub mlog: Word,
1703    #[serde(rename = "mod")]
1704    pub mod_op: Word,
1705    pub modi: Word,
1706    #[serde(rename = "move")]
1707    pub move_op: Word,
1708    pub movi: Word,
1709    pub mroo: Word,
1710    pub mul: Word,
1711    pub muli: Word,
1712    pub mldv: Word,
1713    pub noop: Word,
1714    pub not: Word,
1715    pub or: Word,
1716    pub ori: Word,
1717    pub poph: Word,
1718    pub popl: Word,
1719    pub pshh: Word,
1720    pub pshl: Word,
1721    #[serde(rename = "ret_contract")]
1722    pub ret: Word,
1723    #[serde(rename = "rvrt_contract")]
1724    pub rvrt: Word,
1725    pub sb: Word,
1726    pub sll: Word,
1727    pub slli: Word,
1728    pub srl: Word,
1729    pub srli: Word,
1730    pub srw: Word,
1731    pub sub: Word,
1732    pub subi: Word,
1733    pub sw: Word,
1734    pub sww: Word,
1735    pub time: Word,
1736    pub tr: Word,
1737    pub tro: Word,
1738    pub wdcm: Word,
1739    pub wqcm: Word,
1740    pub wdop: Word,
1741    pub wqop: Word,
1742    pub wdml: Word,
1743    pub wqml: Word,
1744    pub wddv: Word,
1745    pub wqdv: Word,
1746    pub wdmd: Word,
1747    pub wqmd: Word,
1748    pub wdam: Word,
1749    pub wqam: Word,
1750    pub wdmm: Word,
1751    pub wqmm: Word,
1752    pub xor: Word,
1753    pub xori: Word,
1754
1755    // Dependent
1756    pub aloc: DependentCost,
1757    pub bsiz: DependentCost,
1758    pub bldd: DependentCost,
1759    pub cfe: DependentCost,
1760    pub cfei: DependentCost,
1761    pub call: DependentCost,
1762    pub ccp: DependentCost,
1763    pub croo: DependentCost,
1764    pub csiz: DependentCost,
1765    pub ed19: DependentCost,
1766    pub k256: DependentCost,
1767    pub ldc: DependentCost,
1768    pub logd: DependentCost,
1769    pub mcl: DependentCost,
1770    pub mcli: DependentCost,
1771    pub mcp: DependentCost,
1772    pub mcpi: DependentCost,
1773    pub meq: DependentCost,
1774    #[serde(rename = "retd_contract")]
1775    pub retd: DependentCost,
1776    pub s256: DependentCost,
1777    pub scwq: DependentCost,
1778    pub smo: DependentCost,
1779    pub srwq: DependentCost,
1780    pub swwq: DependentCost,
1781
1782    // Non-opcode costs
1783    pub contract_root: DependentCost,
1784    pub state_root: DependentCost,
1785    pub new_storage_per_byte: Word,
1786    pub vm_initialization: DependentCost,
1787}
1788
1789/// Gas costs for every op.
1790/// The difference with [`GasCostsValuesV4`]:
1791/// - Added `ecop` and `epar` instructions
1792#[allow(missing_docs)]
1793#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
1794#[serde(default = "GasCostsValuesV5::unit")]
1795pub struct GasCostsValuesV5 {
1796    pub add: Word,
1797    pub addi: Word,
1798    pub and: Word,
1799    pub andi: Word,
1800    pub bal: Word,
1801    pub bhei: Word,
1802    pub bhsh: Word,
1803    pub burn: Word,
1804    pub cb: Word,
1805    pub cfsi: Word,
1806    pub div: Word,
1807    pub divi: Word,
1808    pub eck1: Word,
1809    pub ecr1: Word,
1810    pub eq: Word,
1811    pub exp: Word,
1812    pub expi: Word,
1813    pub flag: Word,
1814    pub gm: Word,
1815    pub gt: Word,
1816    pub gtf: Word,
1817    pub ji: Word,
1818    pub jmp: Word,
1819    pub jne: Word,
1820    pub jnei: Word,
1821    pub jnzi: Word,
1822    pub jmpf: Word,
1823    pub jmpb: Word,
1824    pub jnzf: Word,
1825    pub jnzb: Word,
1826    pub jnef: Word,
1827    pub jneb: Word,
1828    pub lb: Word,
1829    pub log: Word,
1830    pub lt: Word,
1831    pub lw: Word,
1832    pub mint: Word,
1833    pub mlog: Word,
1834    #[serde(rename = "mod")]
1835    pub mod_op: Word,
1836    pub modi: Word,
1837    #[serde(rename = "move")]
1838    pub move_op: Word,
1839    pub movi: Word,
1840    pub mroo: Word,
1841    pub mul: Word,
1842    pub muli: Word,
1843    pub mldv: Word,
1844    pub noop: Word,
1845    pub not: Word,
1846    pub or: Word,
1847    pub ori: Word,
1848    pub poph: Word,
1849    pub popl: Word,
1850    pub pshh: Word,
1851    pub pshl: Word,
1852    #[serde(rename = "ret_contract")]
1853    pub ret: Word,
1854    #[serde(rename = "rvrt_contract")]
1855    pub rvrt: Word,
1856    pub sb: Word,
1857    pub sll: Word,
1858    pub slli: Word,
1859    pub srl: Word,
1860    pub srli: Word,
1861    pub srw: Word,
1862    pub sub: Word,
1863    pub subi: Word,
1864    pub sw: Word,
1865    pub sww: Word,
1866    pub time: Word,
1867    pub tr: Word,
1868    pub tro: Word,
1869    pub wdcm: Word,
1870    pub wqcm: Word,
1871    pub wdop: Word,
1872    pub wqop: Word,
1873    pub wdml: Word,
1874    pub wqml: Word,
1875    pub wddv: Word,
1876    pub wqdv: Word,
1877    pub wdmd: Word,
1878    pub wqmd: Word,
1879    pub wdam: Word,
1880    pub wqam: Word,
1881    pub wdmm: Word,
1882    pub wqmm: Word,
1883    pub xor: Word,
1884    pub xori: Word,
1885    pub ecop: Word,
1886
1887    // Dependent
1888    pub aloc: DependentCost,
1889    pub bsiz: DependentCost,
1890    pub bldd: DependentCost,
1891    pub cfe: DependentCost,
1892    pub cfei: DependentCost,
1893    pub call: DependentCost,
1894    pub ccp: DependentCost,
1895    pub croo: DependentCost,
1896    pub csiz: DependentCost,
1897    pub ed19: DependentCost,
1898    pub k256: DependentCost,
1899    pub ldc: DependentCost,
1900    pub logd: DependentCost,
1901    pub mcl: DependentCost,
1902    pub mcli: DependentCost,
1903    pub mcp: DependentCost,
1904    pub mcpi: DependentCost,
1905    pub meq: DependentCost,
1906    #[serde(rename = "retd_contract")]
1907    pub retd: DependentCost,
1908    pub s256: DependentCost,
1909    pub scwq: DependentCost,
1910    pub smo: DependentCost,
1911    pub srwq: DependentCost,
1912    pub swwq: DependentCost,
1913    pub epar: DependentCost,
1914
1915    // Non-opcode costs
1916    pub contract_root: DependentCost,
1917    pub state_root: DependentCost,
1918    pub new_storage_per_byte: Word,
1919    pub vm_initialization: DependentCost,
1920}
1921
1922/// Dependent cost is a cost that depends on the number of units.
1923#[derive(
1924    Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize,
1925)]
1926pub enum DependentCost {
1927    /// When an operation is dependent on the magnitude of its inputs, and the
1928    /// time per unit of input is less than a single no-op operation
1929    LightOperation {
1930        /// The minimum that this operation can cost.
1931        base: Word,
1932        /// How many elements can be processed with a single gas. The
1933        /// higher the `units_per_gas`, the less additional cost you will incur
1934        /// for a given number of units, because you need more units to increase
1935        /// the total cost.
1936        /// This must be nonzero.
1937        units_per_gas: Word,
1938    },
1939
1940    /// When an operation is dependent on the magnitude of its inputs, and the
1941    /// time per unit of input is greater than a single no-op operation
1942    HeavyOperation {
1943        /// The minimum that this operation can cost.
1944        base: Word,
1945        /// How much gas is required to process a single unit.
1946        gas_per_unit: Word,
1947    },
1948}
1949
1950#[cfg(feature = "alloc")]
1951impl GasCosts {
1952    /// Create costs that are all set to zero.
1953    pub fn free() -> Self {
1954        Self(Arc::new(GasCostsValues::free()))
1955    }
1956
1957    /// Create costs that are all set to one.
1958    pub fn unit() -> Self {
1959        Self(Arc::new(GasCostsValues::unit()))
1960    }
1961}
1962
1963impl GasCostsValues {
1964    /// Create costs that are all set to zero.
1965    pub fn free() -> Self {
1966        GasCostsValuesV5::free().into()
1967    }
1968
1969    /// Create costs that are all set to one.
1970    pub fn unit() -> Self {
1971        GasCostsValuesV5::unit().into()
1972    }
1973}
1974
1975impl GasCostsValuesV1 {
1976    /// Create costs that are all set to zero.
1977    pub fn free() -> Self {
1978        Self {
1979            add: 0,
1980            addi: 0,
1981            aloc: 0,
1982            and: 0,
1983            andi: 0,
1984            bal: 0,
1985            bhei: 0,
1986            bhsh: 0,
1987            burn: 0,
1988            cb: 0,
1989            cfei: 0,
1990            cfsi: 0,
1991            div: 0,
1992            divi: 0,
1993            eck1: 0,
1994            ecr1: 0,
1995            ed19: 0,
1996            eq: 0,
1997            exp: 0,
1998            expi: 0,
1999            flag: 0,
2000            gm: 0,
2001            gt: 0,
2002            gtf: 0,
2003            ji: 0,
2004            jmp: 0,
2005            jne: 0,
2006            jnei: 0,
2007            jnzi: 0,
2008            jmpf: 0,
2009            jmpb: 0,
2010            jnzf: 0,
2011            jnzb: 0,
2012            jnef: 0,
2013            jneb: 0,
2014            lb: 0,
2015            log: 0,
2016            lt: 0,
2017            lw: 0,
2018            mint: 0,
2019            mlog: 0,
2020            mod_op: 0,
2021            modi: 0,
2022            move_op: 0,
2023            movi: 0,
2024            mroo: 0,
2025            mul: 0,
2026            muli: 0,
2027            mldv: 0,
2028            noop: 0,
2029            not: 0,
2030            or: 0,
2031            ori: 0,
2032            poph: 0,
2033            popl: 0,
2034            pshh: 0,
2035            pshl: 0,
2036            ret: 0,
2037            rvrt: 0,
2038            sb: 0,
2039            sll: 0,
2040            slli: 0,
2041            srl: 0,
2042            srli: 0,
2043            srw: 0,
2044            sub: 0,
2045            subi: 0,
2046            sw: 0,
2047            sww: 0,
2048            time: 0,
2049            tr: 0,
2050            tro: 0,
2051            wdcm: 0,
2052            wqcm: 0,
2053            wdop: 0,
2054            wqop: 0,
2055            wdml: 0,
2056            wqml: 0,
2057            wddv: 0,
2058            wqdv: 0,
2059            wdmd: 0,
2060            wqmd: 0,
2061            wdam: 0,
2062            wqam: 0,
2063            wdmm: 0,
2064            wqmm: 0,
2065            xor: 0,
2066            xori: 0,
2067            call: DependentCost::free(),
2068            ccp: DependentCost::free(),
2069            croo: DependentCost::free(),
2070            csiz: DependentCost::free(),
2071            k256: DependentCost::free(),
2072            ldc: DependentCost::free(),
2073            logd: DependentCost::free(),
2074            mcl: DependentCost::free(),
2075            mcli: DependentCost::free(),
2076            mcp: DependentCost::free(),
2077            mcpi: DependentCost::free(),
2078            meq: DependentCost::free(),
2079            retd: DependentCost::free(),
2080            s256: DependentCost::free(),
2081            scwq: DependentCost::free(),
2082            smo: DependentCost::free(),
2083            srwq: DependentCost::free(),
2084            swwq: DependentCost::free(),
2085
2086            // Non-opcode costs
2087            contract_root: DependentCost::free(),
2088            state_root: DependentCost::free(),
2089            new_storage_per_byte: 0,
2090            vm_initialization: DependentCost::free(),
2091        }
2092    }
2093
2094    /// Create costs that are all set to one.
2095    pub fn unit() -> Self {
2096        Self {
2097            add: 1,
2098            addi: 1,
2099            aloc: 1,
2100            and: 1,
2101            andi: 1,
2102            bal: 1,
2103            bhei: 1,
2104            bhsh: 1,
2105            burn: 1,
2106            cb: 1,
2107            cfei: 1,
2108            cfsi: 1,
2109            div: 1,
2110            divi: 1,
2111            eck1: 1,
2112            ecr1: 1,
2113            ed19: 1,
2114            eq: 1,
2115            exp: 1,
2116            expi: 1,
2117            flag: 1,
2118            gm: 1,
2119            gt: 1,
2120            gtf: 1,
2121            ji: 1,
2122            jmp: 1,
2123            jne: 1,
2124            jnei: 1,
2125            jnzi: 1,
2126            jmpf: 1,
2127            jmpb: 1,
2128            jnzf: 1,
2129            jnzb: 1,
2130            jnef: 1,
2131            jneb: 1,
2132            lb: 1,
2133            log: 1,
2134            lt: 1,
2135            lw: 1,
2136            mint: 1,
2137            mlog: 1,
2138            mod_op: 1,
2139            modi: 1,
2140            move_op: 1,
2141            movi: 1,
2142            mroo: 1,
2143            mul: 1,
2144            muli: 1,
2145            mldv: 1,
2146            noop: 1,
2147            not: 1,
2148            or: 1,
2149            ori: 1,
2150            ret: 1,
2151            poph: 1,
2152            popl: 1,
2153            pshh: 1,
2154            pshl: 1,
2155            rvrt: 1,
2156            sb: 1,
2157            sll: 1,
2158            slli: 1,
2159            srl: 1,
2160            srli: 1,
2161            srw: 1,
2162            sub: 1,
2163            subi: 1,
2164            sw: 1,
2165            sww: 1,
2166            time: 1,
2167            tr: 1,
2168            tro: 1,
2169            wdcm: 1,
2170            wqcm: 1,
2171            wdop: 1,
2172            wqop: 1,
2173            wdml: 1,
2174            wqml: 1,
2175            wddv: 1,
2176            wqdv: 1,
2177            wdmd: 1,
2178            wqmd: 1,
2179            wdam: 1,
2180            wqam: 1,
2181            wdmm: 1,
2182            wqmm: 1,
2183            xor: 1,
2184            xori: 1,
2185            call: DependentCost::unit(),
2186            ccp: DependentCost::unit(),
2187            croo: DependentCost::unit(),
2188            csiz: DependentCost::unit(),
2189            k256: DependentCost::unit(),
2190            ldc: DependentCost::unit(),
2191            logd: DependentCost::unit(),
2192            mcl: DependentCost::unit(),
2193            mcli: DependentCost::unit(),
2194            mcp: DependentCost::unit(),
2195            mcpi: DependentCost::unit(),
2196            meq: DependentCost::unit(),
2197            retd: DependentCost::unit(),
2198            s256: DependentCost::unit(),
2199            scwq: DependentCost::unit(),
2200            smo: DependentCost::unit(),
2201            srwq: DependentCost::unit(),
2202            swwq: DependentCost::unit(),
2203
2204            // Non-opcode costs
2205            contract_root: DependentCost::unit(),
2206            state_root: DependentCost::unit(),
2207            new_storage_per_byte: 1,
2208            vm_initialization: DependentCost::unit(),
2209        }
2210    }
2211}
2212
2213impl GasCostsValuesV2 {
2214    /// Create costs that are all set to zero.
2215    pub fn free() -> Self {
2216        Self {
2217            add: 0,
2218            addi: 0,
2219            and: 0,
2220            andi: 0,
2221            bal: 0,
2222            bhei: 0,
2223            bhsh: 0,
2224            burn: 0,
2225            cb: 0,
2226            cfei: 0,
2227            cfsi: 0,
2228            div: 0,
2229            divi: 0,
2230            eck1: 0,
2231            ecr1: 0,
2232            ed19: 0,
2233            eq: 0,
2234            exp: 0,
2235            expi: 0,
2236            flag: 0,
2237            gm: 0,
2238            gt: 0,
2239            gtf: 0,
2240            ji: 0,
2241            jmp: 0,
2242            jne: 0,
2243            jnei: 0,
2244            jnzi: 0,
2245            jmpf: 0,
2246            jmpb: 0,
2247            jnzf: 0,
2248            jnzb: 0,
2249            jnef: 0,
2250            jneb: 0,
2251            lb: 0,
2252            log: 0,
2253            lt: 0,
2254            lw: 0,
2255            mint: 0,
2256            mlog: 0,
2257            mod_op: 0,
2258            modi: 0,
2259            move_op: 0,
2260            movi: 0,
2261            mroo: 0,
2262            mul: 0,
2263            muli: 0,
2264            mldv: 0,
2265            noop: 0,
2266            not: 0,
2267            or: 0,
2268            ori: 0,
2269            poph: 0,
2270            popl: 0,
2271            pshh: 0,
2272            pshl: 0,
2273            ret: 0,
2274            rvrt: 0,
2275            sb: 0,
2276            sll: 0,
2277            slli: 0,
2278            srl: 0,
2279            srli: 0,
2280            srw: 0,
2281            sub: 0,
2282            subi: 0,
2283            sw: 0,
2284            sww: 0,
2285            time: 0,
2286            tr: 0,
2287            tro: 0,
2288            wdcm: 0,
2289            wqcm: 0,
2290            wdop: 0,
2291            wqop: 0,
2292            wdml: 0,
2293            wqml: 0,
2294            wddv: 0,
2295            wqdv: 0,
2296            wdmd: 0,
2297            wqmd: 0,
2298            wdam: 0,
2299            wqam: 0,
2300            wdmm: 0,
2301            wqmm: 0,
2302            xor: 0,
2303            xori: 0,
2304            aloc: DependentCost::free(),
2305            call: DependentCost::free(),
2306            ccp: DependentCost::free(),
2307            croo: DependentCost::free(),
2308            csiz: DependentCost::free(),
2309            k256: DependentCost::free(),
2310            ldc: DependentCost::free(),
2311            logd: DependentCost::free(),
2312            mcl: DependentCost::free(),
2313            mcli: DependentCost::free(),
2314            mcp: DependentCost::free(),
2315            mcpi: DependentCost::free(),
2316            meq: DependentCost::free(),
2317            retd: DependentCost::free(),
2318            s256: DependentCost::free(),
2319            scwq: DependentCost::free(),
2320            smo: DependentCost::free(),
2321            srwq: DependentCost::free(),
2322            swwq: DependentCost::free(),
2323
2324            // Non-opcode costs
2325            contract_root: DependentCost::free(),
2326            state_root: DependentCost::free(),
2327            new_storage_per_byte: 0,
2328            vm_initialization: DependentCost::free(),
2329        }
2330    }
2331
2332    /// Create costs that are all set to one.
2333    pub fn unit() -> Self {
2334        Self {
2335            add: 1,
2336            addi: 1,
2337            and: 1,
2338            andi: 1,
2339            bal: 1,
2340            bhei: 1,
2341            bhsh: 1,
2342            burn: 1,
2343            cb: 1,
2344            cfei: 1,
2345            cfsi: 1,
2346            div: 1,
2347            divi: 1,
2348            eck1: 1,
2349            ecr1: 1,
2350            ed19: 1,
2351            eq: 1,
2352            exp: 1,
2353            expi: 1,
2354            flag: 1,
2355            gm: 1,
2356            gt: 1,
2357            gtf: 1,
2358            ji: 1,
2359            jmp: 1,
2360            jne: 1,
2361            jnei: 1,
2362            jnzi: 1,
2363            jmpf: 1,
2364            jmpb: 1,
2365            jnzf: 1,
2366            jnzb: 1,
2367            jnef: 1,
2368            jneb: 1,
2369            lb: 1,
2370            log: 1,
2371            lt: 1,
2372            lw: 1,
2373            mint: 1,
2374            mlog: 1,
2375            mod_op: 1,
2376            modi: 1,
2377            move_op: 1,
2378            movi: 1,
2379            mroo: 1,
2380            mul: 1,
2381            muli: 1,
2382            mldv: 1,
2383            noop: 1,
2384            not: 1,
2385            or: 1,
2386            ori: 1,
2387            ret: 1,
2388            poph: 1,
2389            popl: 1,
2390            pshh: 1,
2391            pshl: 1,
2392            rvrt: 1,
2393            sb: 1,
2394            sll: 1,
2395            slli: 1,
2396            srl: 1,
2397            srli: 1,
2398            srw: 1,
2399            sub: 1,
2400            subi: 1,
2401            sw: 1,
2402            sww: 1,
2403            time: 1,
2404            tr: 1,
2405            tro: 1,
2406            wdcm: 1,
2407            wqcm: 1,
2408            wdop: 1,
2409            wqop: 1,
2410            wdml: 1,
2411            wqml: 1,
2412            wddv: 1,
2413            wqdv: 1,
2414            wdmd: 1,
2415            wqmd: 1,
2416            wdam: 1,
2417            wqam: 1,
2418            wdmm: 1,
2419            wqmm: 1,
2420            xor: 1,
2421            xori: 1,
2422            aloc: DependentCost::unit(),
2423            call: DependentCost::unit(),
2424            ccp: DependentCost::unit(),
2425            croo: DependentCost::unit(),
2426            csiz: DependentCost::unit(),
2427            k256: DependentCost::unit(),
2428            ldc: DependentCost::unit(),
2429            logd: DependentCost::unit(),
2430            mcl: DependentCost::unit(),
2431            mcli: DependentCost::unit(),
2432            mcp: DependentCost::unit(),
2433            mcpi: DependentCost::unit(),
2434            meq: DependentCost::unit(),
2435            retd: DependentCost::unit(),
2436            s256: DependentCost::unit(),
2437            scwq: DependentCost::unit(),
2438            smo: DependentCost::unit(),
2439            srwq: DependentCost::unit(),
2440            swwq: DependentCost::unit(),
2441
2442            // Non-opcode costs
2443            contract_root: DependentCost::unit(),
2444            state_root: DependentCost::unit(),
2445            new_storage_per_byte: 1,
2446            vm_initialization: DependentCost::unit(),
2447        }
2448    }
2449}
2450
2451impl GasCostsValuesV3 {
2452    /// Create costs that are all set to zero.
2453    pub fn free() -> Self {
2454        Self {
2455            add: 0,
2456            addi: 0,
2457            and: 0,
2458            andi: 0,
2459            bal: 0,
2460            bhei: 0,
2461            bhsh: 0,
2462            burn: 0,
2463            cb: 0,
2464            cfsi: 0,
2465            div: 0,
2466            divi: 0,
2467            eck1: 0,
2468            ecr1: 0,
2469            ed19: 0,
2470            eq: 0,
2471            exp: 0,
2472            expi: 0,
2473            flag: 0,
2474            gm: 0,
2475            gt: 0,
2476            gtf: 0,
2477            ji: 0,
2478            jmp: 0,
2479            jne: 0,
2480            jnei: 0,
2481            jnzi: 0,
2482            jmpf: 0,
2483            jmpb: 0,
2484            jnzf: 0,
2485            jnzb: 0,
2486            jnef: 0,
2487            jneb: 0,
2488            lb: 0,
2489            log: 0,
2490            lt: 0,
2491            lw: 0,
2492            mint: 0,
2493            mlog: 0,
2494            mod_op: 0,
2495            modi: 0,
2496            move_op: 0,
2497            movi: 0,
2498            mroo: 0,
2499            mul: 0,
2500            muli: 0,
2501            mldv: 0,
2502            noop: 0,
2503            not: 0,
2504            or: 0,
2505            ori: 0,
2506            poph: 0,
2507            popl: 0,
2508            pshh: 0,
2509            pshl: 0,
2510            ret: 0,
2511            rvrt: 0,
2512            sb: 0,
2513            sll: 0,
2514            slli: 0,
2515            srl: 0,
2516            srli: 0,
2517            srw: 0,
2518            sub: 0,
2519            subi: 0,
2520            sw: 0,
2521            sww: 0,
2522            time: 0,
2523            tr: 0,
2524            tro: 0,
2525            wdcm: 0,
2526            wqcm: 0,
2527            wdop: 0,
2528            wqop: 0,
2529            wdml: 0,
2530            wqml: 0,
2531            wddv: 0,
2532            wqdv: 0,
2533            wdmd: 0,
2534            wqmd: 0,
2535            wdam: 0,
2536            wqam: 0,
2537            wdmm: 0,
2538            wqmm: 0,
2539            xor: 0,
2540            xori: 0,
2541            aloc: DependentCost::free(),
2542            cfe: DependentCost::free(),
2543            cfei: DependentCost::free(),
2544            call: DependentCost::free(),
2545            ccp: DependentCost::free(),
2546            croo: DependentCost::free(),
2547            csiz: DependentCost::free(),
2548            k256: DependentCost::free(),
2549            ldc: DependentCost::free(),
2550            logd: DependentCost::free(),
2551            mcl: DependentCost::free(),
2552            mcli: DependentCost::free(),
2553            mcp: DependentCost::free(),
2554            mcpi: DependentCost::free(),
2555            meq: DependentCost::free(),
2556            retd: DependentCost::free(),
2557            s256: DependentCost::free(),
2558            scwq: DependentCost::free(),
2559            smo: DependentCost::free(),
2560            srwq: DependentCost::free(),
2561            swwq: DependentCost::free(),
2562
2563            // Non-opcode costs
2564            contract_root: DependentCost::free(),
2565            state_root: DependentCost::free(),
2566            new_storage_per_byte: 0,
2567            vm_initialization: DependentCost::free(),
2568        }
2569    }
2570
2571    /// Create costs that are all set to one.
2572    pub fn unit() -> Self {
2573        Self {
2574            add: 1,
2575            addi: 1,
2576            and: 1,
2577            andi: 1,
2578            bal: 1,
2579            bhei: 1,
2580            bhsh: 1,
2581            burn: 1,
2582            cb: 1,
2583            cfsi: 1,
2584            div: 1,
2585            divi: 1,
2586            eck1: 1,
2587            ecr1: 1,
2588            ed19: 1,
2589            eq: 1,
2590            exp: 1,
2591            expi: 1,
2592            flag: 1,
2593            gm: 1,
2594            gt: 1,
2595            gtf: 1,
2596            ji: 1,
2597            jmp: 1,
2598            jne: 1,
2599            jnei: 1,
2600            jnzi: 1,
2601            jmpf: 1,
2602            jmpb: 1,
2603            jnzf: 1,
2604            jnzb: 1,
2605            jnef: 1,
2606            jneb: 1,
2607            lb: 1,
2608            log: 1,
2609            lt: 1,
2610            lw: 1,
2611            mint: 1,
2612            mlog: 1,
2613            mod_op: 1,
2614            modi: 1,
2615            move_op: 1,
2616            movi: 1,
2617            mroo: 1,
2618            mul: 1,
2619            muli: 1,
2620            mldv: 1,
2621            noop: 1,
2622            not: 1,
2623            or: 1,
2624            ori: 1,
2625            ret: 1,
2626            poph: 1,
2627            popl: 1,
2628            pshh: 1,
2629            pshl: 1,
2630            rvrt: 1,
2631            sb: 1,
2632            sll: 1,
2633            slli: 1,
2634            srl: 1,
2635            srli: 1,
2636            srw: 1,
2637            sub: 1,
2638            subi: 1,
2639            sw: 1,
2640            sww: 1,
2641            time: 1,
2642            tr: 1,
2643            tro: 1,
2644            wdcm: 1,
2645            wqcm: 1,
2646            wdop: 1,
2647            wqop: 1,
2648            wdml: 1,
2649            wqml: 1,
2650            wddv: 1,
2651            wqdv: 1,
2652            wdmd: 1,
2653            wqmd: 1,
2654            wdam: 1,
2655            wqam: 1,
2656            wdmm: 1,
2657            wqmm: 1,
2658            xor: 1,
2659            xori: 1,
2660            aloc: DependentCost::unit(),
2661            cfe: DependentCost::unit(),
2662            cfei: DependentCost::unit(),
2663            call: DependentCost::unit(),
2664            ccp: DependentCost::unit(),
2665            croo: DependentCost::unit(),
2666            csiz: DependentCost::unit(),
2667            k256: DependentCost::unit(),
2668            ldc: DependentCost::unit(),
2669            logd: DependentCost::unit(),
2670            mcl: DependentCost::unit(),
2671            mcli: DependentCost::unit(),
2672            mcp: DependentCost::unit(),
2673            mcpi: DependentCost::unit(),
2674            meq: DependentCost::unit(),
2675            retd: DependentCost::unit(),
2676            s256: DependentCost::unit(),
2677            scwq: DependentCost::unit(),
2678            smo: DependentCost::unit(),
2679            srwq: DependentCost::unit(),
2680            swwq: DependentCost::unit(),
2681
2682            // Non-opcode costs
2683            contract_root: DependentCost::unit(),
2684            state_root: DependentCost::unit(),
2685            new_storage_per_byte: 1,
2686            vm_initialization: DependentCost::unit(),
2687        }
2688    }
2689}
2690
2691impl GasCostsValuesV4 {
2692    /// Create costs that are all set to zero.
2693    pub fn free() -> Self {
2694        Self {
2695            add: 0,
2696            addi: 0,
2697            and: 0,
2698            andi: 0,
2699            bal: 0,
2700            bhei: 0,
2701            bhsh: 0,
2702            burn: 0,
2703            cb: 0,
2704            cfsi: 0,
2705            div: 0,
2706            divi: 0,
2707            eck1: 0,
2708            ecr1: 0,
2709            eq: 0,
2710            exp: 0,
2711            expi: 0,
2712            flag: 0,
2713            gm: 0,
2714            gt: 0,
2715            gtf: 0,
2716            ji: 0,
2717            jmp: 0,
2718            jne: 0,
2719            jnei: 0,
2720            jnzi: 0,
2721            jmpf: 0,
2722            jmpb: 0,
2723            jnzf: 0,
2724            jnzb: 0,
2725            jnef: 0,
2726            jneb: 0,
2727            lb: 0,
2728            log: 0,
2729            lt: 0,
2730            lw: 0,
2731            mint: 0,
2732            mlog: 0,
2733            mod_op: 0,
2734            modi: 0,
2735            move_op: 0,
2736            movi: 0,
2737            mroo: 0,
2738            mul: 0,
2739            muli: 0,
2740            mldv: 0,
2741            noop: 0,
2742            not: 0,
2743            or: 0,
2744            ori: 0,
2745            poph: 0,
2746            popl: 0,
2747            pshh: 0,
2748            pshl: 0,
2749            ret: 0,
2750            rvrt: 0,
2751            sb: 0,
2752            sll: 0,
2753            slli: 0,
2754            srl: 0,
2755            srli: 0,
2756            srw: 0,
2757            sub: 0,
2758            subi: 0,
2759            sw: 0,
2760            sww: 0,
2761            time: 0,
2762            tr: 0,
2763            tro: 0,
2764            wdcm: 0,
2765            wqcm: 0,
2766            wdop: 0,
2767            wqop: 0,
2768            wdml: 0,
2769            wqml: 0,
2770            wddv: 0,
2771            wqdv: 0,
2772            wdmd: 0,
2773            wqmd: 0,
2774            wdam: 0,
2775            wqam: 0,
2776            wdmm: 0,
2777            wqmm: 0,
2778            xor: 0,
2779            xori: 0,
2780            aloc: DependentCost::free(),
2781            bsiz: DependentCost::free(),
2782            bldd: DependentCost::free(),
2783            cfe: DependentCost::free(),
2784            cfei: DependentCost::free(),
2785            call: DependentCost::free(),
2786            ccp: DependentCost::free(),
2787            croo: DependentCost::free(),
2788            csiz: DependentCost::free(),
2789            ed19: DependentCost::free(),
2790            k256: DependentCost::free(),
2791            ldc: DependentCost::free(),
2792            logd: DependentCost::free(),
2793            mcl: DependentCost::free(),
2794            mcli: DependentCost::free(),
2795            mcp: DependentCost::free(),
2796            mcpi: DependentCost::free(),
2797            meq: DependentCost::free(),
2798            retd: DependentCost::free(),
2799            s256: DependentCost::free(),
2800            scwq: DependentCost::free(),
2801            smo: DependentCost::free(),
2802            srwq: DependentCost::free(),
2803            swwq: DependentCost::free(),
2804
2805            // Non-opcode costs
2806            contract_root: DependentCost::free(),
2807            state_root: DependentCost::free(),
2808            new_storage_per_byte: 0,
2809            vm_initialization: DependentCost::free(),
2810        }
2811    }
2812
2813    /// Create costs that are all set to one.
2814    pub fn unit() -> Self {
2815        Self {
2816            add: 1,
2817            addi: 1,
2818            and: 1,
2819            andi: 1,
2820            bal: 1,
2821            bhei: 1,
2822            bhsh: 1,
2823            burn: 1,
2824            cb: 1,
2825            cfsi: 1,
2826            div: 1,
2827            divi: 1,
2828            eck1: 1,
2829            ecr1: 1,
2830            eq: 1,
2831            exp: 1,
2832            expi: 1,
2833            flag: 1,
2834            gm: 1,
2835            gt: 1,
2836            gtf: 1,
2837            ji: 1,
2838            jmp: 1,
2839            jne: 1,
2840            jnei: 1,
2841            jnzi: 1,
2842            jmpf: 1,
2843            jmpb: 1,
2844            jnzf: 1,
2845            jnzb: 1,
2846            jnef: 1,
2847            jneb: 1,
2848            lb: 1,
2849            log: 1,
2850            lt: 1,
2851            lw: 1,
2852            mint: 1,
2853            mlog: 1,
2854            mod_op: 1,
2855            modi: 1,
2856            move_op: 1,
2857            movi: 1,
2858            mroo: 1,
2859            mul: 1,
2860            muli: 1,
2861            mldv: 1,
2862            noop: 1,
2863            not: 1,
2864            or: 1,
2865            ori: 1,
2866            ret: 1,
2867            poph: 1,
2868            popl: 1,
2869            pshh: 1,
2870            pshl: 1,
2871            rvrt: 1,
2872            sb: 1,
2873            sll: 1,
2874            slli: 1,
2875            srl: 1,
2876            srli: 1,
2877            srw: 1,
2878            sub: 1,
2879            subi: 1,
2880            sw: 1,
2881            sww: 1,
2882            time: 1,
2883            tr: 1,
2884            tro: 1,
2885            wdcm: 1,
2886            wqcm: 1,
2887            wdop: 1,
2888            wqop: 1,
2889            wdml: 1,
2890            wqml: 1,
2891            wddv: 1,
2892            wqdv: 1,
2893            wdmd: 1,
2894            wqmd: 1,
2895            wdam: 1,
2896            wqam: 1,
2897            wdmm: 1,
2898            wqmm: 1,
2899            xor: 1,
2900            xori: 1,
2901            aloc: DependentCost::unit(),
2902            bsiz: DependentCost::unit(),
2903            bldd: DependentCost::unit(),
2904            cfe: DependentCost::unit(),
2905            cfei: DependentCost::unit(),
2906            call: DependentCost::unit(),
2907            ccp: DependentCost::unit(),
2908            croo: DependentCost::unit(),
2909            csiz: DependentCost::unit(),
2910            ed19: DependentCost::unit(),
2911            k256: DependentCost::unit(),
2912            ldc: DependentCost::unit(),
2913            logd: DependentCost::unit(),
2914            mcl: DependentCost::unit(),
2915            mcli: DependentCost::unit(),
2916            mcp: DependentCost::unit(),
2917            mcpi: DependentCost::unit(),
2918            meq: DependentCost::unit(),
2919            retd: DependentCost::unit(),
2920            s256: DependentCost::unit(),
2921            scwq: DependentCost::unit(),
2922            smo: DependentCost::unit(),
2923            srwq: DependentCost::unit(),
2924            swwq: DependentCost::unit(),
2925
2926            // Non-opcode costs
2927            contract_root: DependentCost::unit(),
2928            state_root: DependentCost::unit(),
2929            new_storage_per_byte: 1,
2930            vm_initialization: DependentCost::unit(),
2931        }
2932    }
2933}
2934
2935impl GasCostsValuesV5 {
2936    /// Create costs that are all set to zero.
2937    pub fn free() -> Self {
2938        Self {
2939            add: 0,
2940            addi: 0,
2941            and: 0,
2942            andi: 0,
2943            bal: 0,
2944            bhei: 0,
2945            bhsh: 0,
2946            burn: 0,
2947            cb: 0,
2948            cfsi: 0,
2949            div: 0,
2950            divi: 0,
2951            eck1: 0,
2952            ecr1: 0,
2953            eq: 0,
2954            exp: 0,
2955            expi: 0,
2956            flag: 0,
2957            gm: 0,
2958            gt: 0,
2959            gtf: 0,
2960            ji: 0,
2961            jmp: 0,
2962            jne: 0,
2963            jnei: 0,
2964            jnzi: 0,
2965            jmpf: 0,
2966            jmpb: 0,
2967            jnzf: 0,
2968            jnzb: 0,
2969            jnef: 0,
2970            jneb: 0,
2971            lb: 0,
2972            log: 0,
2973            lt: 0,
2974            lw: 0,
2975            mint: 0,
2976            mlog: 0,
2977            mod_op: 0,
2978            modi: 0,
2979            move_op: 0,
2980            movi: 0,
2981            mroo: 0,
2982            mul: 0,
2983            muli: 0,
2984            mldv: 0,
2985            noop: 0,
2986            not: 0,
2987            or: 0,
2988            ori: 0,
2989            poph: 0,
2990            popl: 0,
2991            pshh: 0,
2992            pshl: 0,
2993            ret: 0,
2994            rvrt: 0,
2995            sb: 0,
2996            sll: 0,
2997            slli: 0,
2998            srl: 0,
2999            srli: 0,
3000            srw: 0,
3001            sub: 0,
3002            subi: 0,
3003            sw: 0,
3004            sww: 0,
3005            time: 0,
3006            tr: 0,
3007            tro: 0,
3008            wdcm: 0,
3009            wqcm: 0,
3010            wdop: 0,
3011            wqop: 0,
3012            wdml: 0,
3013            wqml: 0,
3014            wddv: 0,
3015            wqdv: 0,
3016            wdmd: 0,
3017            wqmd: 0,
3018            wdam: 0,
3019            wqam: 0,
3020            wdmm: 0,
3021            wqmm: 0,
3022            xor: 0,
3023            xori: 0,
3024            ecop: 0,
3025            aloc: DependentCost::free(),
3026            bsiz: DependentCost::free(),
3027            bldd: DependentCost::free(),
3028            cfe: DependentCost::free(),
3029            cfei: DependentCost::free(),
3030            call: DependentCost::free(),
3031            ccp: DependentCost::free(),
3032            croo: DependentCost::free(),
3033            csiz: DependentCost::free(),
3034            ed19: DependentCost::free(),
3035            k256: DependentCost::free(),
3036            ldc: DependentCost::free(),
3037            logd: DependentCost::free(),
3038            mcl: DependentCost::free(),
3039            mcli: DependentCost::free(),
3040            mcp: DependentCost::free(),
3041            mcpi: DependentCost::free(),
3042            meq: DependentCost::free(),
3043            retd: DependentCost::free(),
3044            s256: DependentCost::free(),
3045            scwq: DependentCost::free(),
3046            smo: DependentCost::free(),
3047            srwq: DependentCost::free(),
3048            swwq: DependentCost::free(),
3049            epar: DependentCost::free(),
3050
3051            // Non-opcode costs
3052            contract_root: DependentCost::free(),
3053            state_root: DependentCost::free(),
3054            new_storage_per_byte: 0,
3055            vm_initialization: DependentCost::free(),
3056        }
3057    }
3058
3059    /// Create costs that are all set to one.
3060    pub fn unit() -> Self {
3061        Self {
3062            add: 1,
3063            addi: 1,
3064            and: 1,
3065            andi: 1,
3066            bal: 1,
3067            bhei: 1,
3068            bhsh: 1,
3069            burn: 1,
3070            cb: 1,
3071            cfsi: 1,
3072            div: 1,
3073            divi: 1,
3074            eck1: 1,
3075            ecr1: 1,
3076            eq: 1,
3077            exp: 1,
3078            expi: 1,
3079            flag: 1,
3080            gm: 1,
3081            gt: 1,
3082            gtf: 1,
3083            ji: 1,
3084            jmp: 1,
3085            jne: 1,
3086            jnei: 1,
3087            jnzi: 1,
3088            jmpf: 1,
3089            jmpb: 1,
3090            jnzf: 1,
3091            jnzb: 1,
3092            jnef: 1,
3093            jneb: 1,
3094            lb: 1,
3095            log: 1,
3096            lt: 1,
3097            lw: 1,
3098            mint: 1,
3099            mlog: 1,
3100            mod_op: 1,
3101            modi: 1,
3102            move_op: 1,
3103            movi: 1,
3104            mroo: 1,
3105            mul: 1,
3106            muli: 1,
3107            mldv: 1,
3108            noop: 1,
3109            not: 1,
3110            or: 1,
3111            ori: 1,
3112            ret: 1,
3113            poph: 1,
3114            popl: 1,
3115            pshh: 1,
3116            pshl: 1,
3117            rvrt: 1,
3118            sb: 1,
3119            sll: 1,
3120            slli: 1,
3121            srl: 1,
3122            srli: 1,
3123            srw: 1,
3124            sub: 1,
3125            subi: 1,
3126            sw: 1,
3127            sww: 1,
3128            time: 1,
3129            tr: 1,
3130            tro: 1,
3131            wdcm: 1,
3132            wqcm: 1,
3133            wdop: 1,
3134            wqop: 1,
3135            wdml: 1,
3136            wqml: 1,
3137            wddv: 1,
3138            wqdv: 1,
3139            wdmd: 1,
3140            wqmd: 1,
3141            wdam: 1,
3142            wqam: 1,
3143            wdmm: 1,
3144            wqmm: 1,
3145            xor: 1,
3146            xori: 1,
3147            ecop: 1,
3148            aloc: DependentCost::unit(),
3149            bsiz: DependentCost::unit(),
3150            bldd: DependentCost::unit(),
3151            cfe: DependentCost::unit(),
3152            cfei: DependentCost::unit(),
3153            call: DependentCost::unit(),
3154            ccp: DependentCost::unit(),
3155            croo: DependentCost::unit(),
3156            csiz: DependentCost::unit(),
3157            ed19: DependentCost::unit(),
3158            k256: DependentCost::unit(),
3159            ldc: DependentCost::unit(),
3160            logd: DependentCost::unit(),
3161            mcl: DependentCost::unit(),
3162            mcli: DependentCost::unit(),
3163            mcp: DependentCost::unit(),
3164            mcpi: DependentCost::unit(),
3165            meq: DependentCost::unit(),
3166            retd: DependentCost::unit(),
3167            s256: DependentCost::unit(),
3168            scwq: DependentCost::unit(),
3169            smo: DependentCost::unit(),
3170            srwq: DependentCost::unit(),
3171            swwq: DependentCost::unit(),
3172            epar: DependentCost::unit(),
3173
3174            // Non-opcode costs
3175            contract_root: DependentCost::unit(),
3176            state_root: DependentCost::unit(),
3177            new_storage_per_byte: 1,
3178            vm_initialization: DependentCost::unit(),
3179        }
3180    }
3181}
3182
3183impl DependentCost {
3184    /// Create costs that make operations free.
3185    pub fn free() -> Self {
3186        Self::HeavyOperation {
3187            base: 0,
3188            gas_per_unit: 0,
3189        }
3190    }
3191
3192    /// Create costs that make operations cost `1`.
3193    pub fn unit() -> Self {
3194        Self::HeavyOperation {
3195            base: 1,
3196            gas_per_unit: 0,
3197        }
3198    }
3199
3200    pub fn from_units_per_gas(base: Word, units_per_gas: Word) -> Self {
3201        debug_assert!(
3202            units_per_gas > 0,
3203            "Cannot create dependent gas cost with per-0-gas ratio"
3204        );
3205        DependentCost::LightOperation {
3206            base,
3207            units_per_gas,
3208        }
3209    }
3210
3211    pub fn from_gas_per_unit(base: Word, gas_per_unit: Word) -> Self {
3212        DependentCost::HeavyOperation { base, gas_per_unit }
3213    }
3214
3215    pub fn base(&self) -> Word {
3216        match self {
3217            DependentCost::LightOperation { base, .. } => *base,
3218            DependentCost::HeavyOperation { base, .. } => *base,
3219        }
3220    }
3221
3222    pub fn set_base(&mut self, value: Word) {
3223        match self {
3224            DependentCost::LightOperation { base, .. } => *base = value,
3225            DependentCost::HeavyOperation { base, .. } => *base = value,
3226        };
3227    }
3228
3229    pub fn resolve(&self, units: Word) -> Word {
3230        let base = self.base();
3231        let dependent_value = self.resolve_without_base(units);
3232        base.saturating_add(dependent_value)
3233    }
3234
3235    pub fn resolve_without_base(&self, units: Word) -> Word {
3236        match self {
3237            DependentCost::LightOperation { units_per_gas, .. } => {
3238                // Apply the linear transformation:
3239                //   f(x) = 1/m * x = x/m
3240                // where:
3241                //   x is the number of units
3242                //   1/m is the gas_per_unit
3243                units
3244                    .checked_div(*units_per_gas)
3245                    .expect("units_per_gas cannot be zero")
3246            }
3247            DependentCost::HeavyOperation { gas_per_unit, .. } => {
3248                // Apply the linear transformation:
3249                //   f(x) = mx
3250                // where:
3251                //   x is the number of units
3252                //   m is the gas per unit
3253                units.saturating_mul(*gas_per_unit)
3254            }
3255        }
3256    }
3257}
3258
3259#[cfg(feature = "alloc")]
3260impl Deref for GasCosts {
3261    type Target = GasCostsValues;
3262
3263    fn deref(&self) -> &Self::Target {
3264        &(self.0)
3265    }
3266}
3267
3268impl From<GasCostsValues> for GasCosts {
3269    fn from(i: GasCostsValues) -> Self {
3270        Self(Arc::new(i))
3271    }
3272}
3273
3274impl From<GasCosts> for GasCostsValues {
3275    fn from(i: GasCosts) -> Self {
3276        (*i.0).clone()
3277    }
3278}
3279
3280impl From<GasCostsValuesV1> for GasCostsValues {
3281    fn from(i: GasCostsValuesV1) -> Self {
3282        GasCostsValues::V1(i)
3283    }
3284}
3285
3286impl From<GasCostsValuesV2> for GasCostsValues {
3287    fn from(i: GasCostsValuesV2) -> Self {
3288        GasCostsValues::V2(i)
3289    }
3290}
3291
3292impl From<GasCostsValuesV3> for GasCostsValues {
3293    fn from(i: GasCostsValuesV3) -> Self {
3294        GasCostsValues::V3(i)
3295    }
3296}
3297impl From<GasCostsValuesV4> for GasCostsValues {
3298    fn from(i: GasCostsValuesV4) -> Self {
3299        GasCostsValues::V4(i)
3300    }
3301}
3302
3303impl From<GasCostsValuesV5> for GasCostsValues {
3304    fn from(i: GasCostsValuesV5) -> Self {
3305        GasCostsValues::V5(i)
3306    }
3307}
3308
3309#[cfg(test)]
3310mod tests {
3311    use crate::DependentCost;
3312
3313    #[test]
3314    fn light_operation_gas_cost_resolves_correctly() {
3315        // Create a linear gas cost function with a slope of 1/10
3316        let cost = DependentCost::from_units_per_gas(0, 10);
3317        let total = cost.resolve(0);
3318        assert_eq!(total, 0);
3319
3320        let total = cost.resolve(5);
3321        assert_eq!(total, 0);
3322
3323        let total = cost.resolve(10);
3324        assert_eq!(total, 1);
3325
3326        let total = cost.resolve(100);
3327        assert_eq!(total, 10);
3328
3329        let total = cost.resolve(721);
3330        assert_eq!(total, 72);
3331    }
3332
3333    #[test]
3334    fn heavy_operation_gas_cost_resolves_correctly() {
3335        // Create a linear gas cost function with a slope of 10
3336        let cost = DependentCost::from_gas_per_unit(0, 10);
3337        let total = cost.resolve(0);
3338        assert_eq!(total, 0);
3339
3340        let total = cost.resolve(5);
3341        assert_eq!(total, 50);
3342
3343        let total = cost.resolve(10);
3344        assert_eq!(total, 100);
3345
3346        let total = cost.resolve(100);
3347        assert_eq!(total, 1_000);
3348
3349        let total = cost.resolve(721);
3350        assert_eq!(total, 7_210);
3351    }
3352}