@@ -7,6 +7,92 @@ Require Import revm.translations.interpreter.gas.
7
7
8
8
Import Run.
9
9
10
+ (*
11
+ pub struct MemoryGas {
12
+ /// Current memory length
13
+ pub words_num: usize,
14
+ /// Current memory expansion cost
15
+ pub expansion_cost: u64,
16
+ }
17
+ *)
18
+ Module MemoryGas.
19
+ Record t : Set := {
20
+ words_num : Usize.t;
21
+ expansion_cost : U64.t;
22
+ }.
23
+
24
+ Global Instance IsLink : Link t := {
25
+ Φ := Ty.path "revm_interpreter::gas::MemoryGas";
26
+ φ x :=
27
+ Value.StructRecord "revm_interpreter::gas::MemoryGas" [
28
+ ("words_num", φ x.(words_num));
29
+ ("expansion_cost", φ x.(expansion_cost))
30
+ ];
31
+ }.
32
+
33
+ Module SubPointer.
34
+ Definition get_words_num : SubPointer.Runner.t t Usize.t := {|
35
+ SubPointer.Runner.index :=
36
+ Pointer.Index.StructRecord "revm_interpreter::gas::MemoryGas" "words_num";
37
+ SubPointer.Runner.projection x := Some x.(words_num);
38
+ SubPointer.Runner.injection x y := Some (x <| words_num := y |>);
39
+ |}.
40
+
41
+ Lemma get_words_num_is_valid :
42
+ SubPointer.Runner.Valid.t get_words_num.
43
+ Proof .
44
+ now constructor.
45
+ Qed .
46
+
47
+ Definition get_expansion_cost : SubPointer.Runner.t t U64.t := {|
48
+ SubPointer.Runner.index :=
49
+ Pointer.Index.StructRecord "revm_interpreter::gas::MemoryGas" "expansion_cost";
50
+ SubPointer.Runner.projection x := Some x.(expansion_cost);
51
+ SubPointer.Runner.injection x y := Some (x <| expansion_cost := y |>);
52
+ |}.
53
+
54
+ Lemma get_expansion_cost_is_valid :
55
+ SubPointer.Runner.Valid.t get_expansion_cost.
56
+ Proof .
57
+ now constructor.
58
+ Qed .
59
+ End SubPointer.
60
+ End MemoryGas.
61
+
62
+ Module Impl_Default_for_MemoryGas.
63
+ Definition run_default : default.Default.Run_default MemoryGas.t.
64
+ Proof .
65
+ eexists; split.
66
+ { eapply IsTraitMethod.Explicit.
67
+ { apply gas.Impl_core_default_Default_for_revm_interpreter_gas_MemoryGas.Implements. }
68
+ { reflexivity. }
69
+ }
70
+ { intros; cbn.
71
+ destruct (default.Impl_Default_for_integer.run_default IntegerKind.Usize)
72
+ as [default_usize [H_default_usize run_default_usize]].
73
+ destruct (default.Impl_Default_for_integer.run_default IntegerKind.U64)
74
+ as [default_u64 [H_default_u64 run_default_u64]].
75
+ eapply Run.CallPrimitiveGetTraitMethod. {
76
+ apply H_default_usize.
77
+ }
78
+ eapply Run.CallClosure. {
79
+ apply run_default_usize.
80
+ }
81
+ intros; cbn.
82
+ eapply Run.CallPrimitiveGetTraitMethod. {
83
+ apply H_default_u64.
84
+ }
85
+ eapply Run.CallClosure. {
86
+ apply run_default_u64.
87
+ }
88
+ intros; cbn.
89
+ run_symbolic.
90
+ { apply MemoryGas.Build_t; assumption. }
91
+ { reflexivity. }
92
+ }
93
+ Defined .
94
+ End Impl_Default_for_MemoryGas.
95
+
10
96
(*
11
97
/// Represents the state of gas during execution.
12
98
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
@@ -18,6 +104,8 @@ Import Run.
18
104
remaining: u64,
19
105
/// Refunded gas. This is used only at the end of execution.
20
106
refunded: i64,
107
+ /// Memoisation of values for memory expansion cost.
108
+ memory: MemoryGas,
21
109
}
22
110
*)
23
111
@@ -26,6 +114,7 @@ Module Gas.
26
114
limit : U64.t;
27
115
remaining : U64.t;
28
116
refunded : I64.t;
117
+ memory : MemoryGas.t;
29
118
}.
30
119
31
120
Global Instance IsLink : Link t := {
@@ -34,7 +123,8 @@ Module Gas.
34
123
Value.StructRecord "revm_interpreter::gas::Gas" [
35
124
("limit", φ x.(limit));
36
125
("remaining", φ x.(remaining));
37
- ("refunded", φ x.(refunded))
126
+ ("refunded", φ x.(refunded));
127
+ ("memory", φ x.(memory))
38
128
];
39
129
}.
40
130
@@ -77,6 +167,19 @@ Module Gas.
77
167
Proof .
78
168
now constructor.
79
169
Qed .
170
+
171
+ Definition get_memory : SubPointer.Runner.t t MemoryGas.t := {|
172
+ SubPointer.Runner.index :=
173
+ Pointer.Index.StructRecord "revm_interpreter::gas::Gas" "memory";
174
+ SubPointer.Runner.projection x := Some x.(memory);
175
+ SubPointer.Runner.injection x y := Some (x <| memory := y |>);
176
+ |}.
177
+
178
+ Lemma get_memory_is_valid :
179
+ SubPointer.Runner.Valid.t get_memory.
180
+ Proof .
181
+ now constructor.
182
+ Qed .
80
183
End SubPointer.
81
184
End Gas.
82
185
@@ -93,7 +196,7 @@ Module Impl_Clone.
93
196
}
94
197
Defined .
95
198
96
- Definition run : clone.Clone.Run Gas.t (Φ Gas.t) .
199
+ Definition run : clone.Clone.Run Gas.t.
97
200
Proof .
98
201
constructor.
99
202
{ (* clone *)
@@ -103,18 +206,20 @@ Module Impl_Clone.
103
206
End Impl_Clone.
104
207
105
208
Module Impl_Default.
106
- Definition run_default : default.Default.Run_default Gas.t (Φ Gas.t) .
209
+ Definition run_default : default.Default.Run_default Gas.t.
107
210
Proof .
108
211
eexists; split.
109
212
{ eapply IsTraitMethod.Explicit.
110
213
{ apply gas.Impl_core_default_Default_for_revm_interpreter_gas_Gas.Implements. }
111
214
{ reflexivity. }
112
215
}
113
216
{ intros; cbn.
114
- destruct default.Impl_Default_for_u64 .run_default
217
+ destruct ( default.Impl_Default_for_integer .run_default IntegerKind.U64)
115
218
as [default_u64 [H_default_u64 run_default_u64]].
116
- destruct default.Impl_Default_for_i64 .run_default
219
+ destruct ( default.Impl_Default_for_integer .run_default IntegerKind.I64)
117
220
as [default_i64 [H_default_i64 run_default_i64]].
221
+ destruct (Impl_Default_for_MemoryGas.run_default)
222
+ as [default_memory_gas [H_default_memory_gas run_default_memory_gas]].
118
223
eapply Run.CallPrimitiveGetTraitMethod. {
119
224
apply H_default_u64.
120
225
}
@@ -136,12 +241,19 @@ Module Impl_Default.
136
241
apply run_default_i64.
137
242
}
138
243
intros; cbn.
139
- run_symbolic.
140
- now instantiate (1 := Gas.Build_t _ _ _).
244
+ eapply Run.CallPrimitiveGetTraitMethod. {
245
+ apply H_default_memory_gas.
246
+ }
247
+ eapply Run.CallClosure. {
248
+ apply run_default_memory_gas.
249
+ }
250
+ intros; cbn.
251
+ run_symbolic; [apply Gas.Build_t |].
252
+ all: try reflexivity.
141
253
}
142
254
Defined .
143
255
144
- Definition run : default.Default.Run Gas.t (Φ Gas.t) .
256
+ Definition run : default.Default.Run Gas.t.
145
257
Proof .
146
258
constructor.
147
259
{ (* default *)
@@ -150,6 +262,7 @@ Module Impl_Default.
150
262
Defined .
151
263
End Impl_Default.
152
264
265
+ (*
153
266
Module Impl_revm_interpreter_gas_Gas.
154
267
Definition Self : Set := Gas.t.
155
268
@@ -162,13 +275,16 @@ Module Impl_revm_interpreter_gas_Gas.
162
275
}
163
276
}
164
277
*)
165
- Definition run_new (limit : Z ) :
278
+ Definition run_new (limit : U64.t ) :
166
279
{{
167
280
gas.Impl_revm_interpreter_gas_Gas.new [] [] [φ limit] ⇓
168
281
fun (v : Self) => inl (φ v)
169
282
}}.
170
283
Proof.
171
284
run_symbolic.
285
+ eapply CallPrimitiveGetAssociatedFunction. {
286
+ (* TODO *)
287
+ }
172
288
now instantiate (1 := Gas.Build_t _ _ _).
173
289
Defined.
174
290
@@ -394,3 +510,4 @@ Module Impl_revm_interpreter_gas_Gas.
394
510
}
395
511
intros; run_symbolic.
396
512
End Impl_revm_interpreter_gas_Gas.
513
+ *)
0 commit comments