Skip to content

Commit ecbec35

Browse files
committed
revm: fix compilation
1 parent 2aba071 commit ecbec35

File tree

4 files changed

+132
-25
lines changed

4 files changed

+132
-25
lines changed

CoqOfRust/links/M.v

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ Proof.
630630
}
631631
Defined.
632632

633-
(*
634633
Ltac run_symbolic_state_alloc :=
635634
(
636635
(* We hope the allocated value to be in a form that is already the image of a [φ] conversion. *)
@@ -673,7 +672,8 @@ Ltac run_symbolic_one_step :=
673672

674673
(** We should use this tactic instead of the ones above, as this one calls all the others. *)
675674
Ltac run_symbolic :=
676-
repeat run_symbolic_one_step.
675+
(* Ideally, we should have the information about which kind of pointer to use. TODO: add it! *)
676+
unshelve (repeat run_symbolic_one_step); try exact Pointer.Kind.Ref.
677677

678678
(** For the specific case of sub-pointers, we still do it by hand by providing the corresponding
679679
validity statement for the index that we access. *)
@@ -701,4 +701,3 @@ Module Function2.
701701
{{ f [ φ a1; φ a2 ] ⇓ output_to_value }};
702702
}.
703703
End Function2.
704-
*)

CoqOfRust/revm/links/interpreter/interpreter.v

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Require Import CoqOfRust.revm.links.interpreter.interpreter_action.
5757

5858
Module Interpreter.
5959
Record t : Set := {
60-
instruction_pointer : Z;
60+
instruction_pointer : Ref.t Pointer.Kind.ConstPointer U8.t;
6161
gas : Gas.t;
6262
contract : Contract.t;
6363
instruction_result : InstructionResult.t;
@@ -72,11 +72,8 @@ Module Interpreter.
7272
next_action : InterpreterAction.t;
7373
}.
7474

75-
Global Instance IsToTy : ToTy t := {
75+
Global Instance IsLink : Link t := {
7676
Φ := Ty.path "revm_interpreter::interpreter::Interpreter";
77-
}.
78-
79-
Global Instance IsToValue : ToValue t := {
8077
φ x :=
8178
Value.StructRecord "revm_interpreter::interpreter::Interpreter" [
8279
("instruction_pointer", φ x.(instruction_pointer));

CoqOfRust/revm/links/interpreter/interpreter/gas.v

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,92 @@ Require Import revm.translations.interpreter.gas.
77

88
Import Run.
99

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+
1096
(*
1197
/// Represents the state of gas during execution.
1298
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
@@ -18,6 +104,8 @@ Import Run.
18104
remaining: u64,
19105
/// Refunded gas. This is used only at the end of execution.
20106
refunded: i64,
107+
/// Memoisation of values for memory expansion cost.
108+
memory: MemoryGas,
21109
}
22110
*)
23111

@@ -26,6 +114,7 @@ Module Gas.
26114
limit : U64.t;
27115
remaining : U64.t;
28116
refunded : I64.t;
117+
memory : MemoryGas.t;
29118
}.
30119

31120
Global Instance IsLink : Link t := {
@@ -34,7 +123,8 @@ Module Gas.
34123
Value.StructRecord "revm_interpreter::gas::Gas" [
35124
("limit", φ x.(limit));
36125
("remaining", φ x.(remaining));
37-
("refunded", φ x.(refunded))
126+
("refunded", φ x.(refunded));
127+
("memory", φ x.(memory))
38128
];
39129
}.
40130

@@ -77,6 +167,19 @@ Module Gas.
77167
Proof.
78168
now constructor.
79169
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.
80183
End SubPointer.
81184
End Gas.
82185

@@ -93,7 +196,7 @@ Module Impl_Clone.
93196
}
94197
Defined.
95198

96-
Definition run : clone.Clone.Run Gas.t (Φ Gas.t).
199+
Definition run : clone.Clone.Run Gas.t.
97200
Proof.
98201
constructor.
99202
{ (* clone *)
@@ -103,18 +206,20 @@ Module Impl_Clone.
103206
End Impl_Clone.
104207

105208
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.
107210
Proof.
108211
eexists; split.
109212
{ eapply IsTraitMethod.Explicit.
110213
{ apply gas.Impl_core_default_Default_for_revm_interpreter_gas_Gas.Implements. }
111214
{ reflexivity. }
112215
}
113216
{ intros; cbn.
114-
destruct default.Impl_Default_for_u64.run_default
217+
destruct (default.Impl_Default_for_integer.run_default IntegerKind.U64)
115218
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)
117220
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]].
118223
eapply Run.CallPrimitiveGetTraitMethod. {
119224
apply H_default_u64.
120225
}
@@ -136,12 +241,19 @@ Module Impl_Default.
136241
apply run_default_i64.
137242
}
138243
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.
141253
}
142254
Defined.
143255

144-
Definition run : default.Default.Run Gas.t (Φ Gas.t).
256+
Definition run : default.Default.Run Gas.t.
145257
Proof.
146258
constructor.
147259
{ (* default *)
@@ -150,6 +262,7 @@ Module Impl_Default.
150262
Defined.
151263
End Impl_Default.
152264

265+
(*
153266
Module Impl_revm_interpreter_gas_Gas.
154267
Definition Self : Set := Gas.t.
155268
@@ -162,13 +275,16 @@ Module Impl_revm_interpreter_gas_Gas.
162275
}
163276
}
164277
*)
165-
Definition run_new (limit : Z) :
278+
Definition run_new (limit : U64.t) :
166279
{{
167280
gas.Impl_revm_interpreter_gas_Gas.new [] [] [φ limit] ⇓
168281
fun (v : Self) => inl (φ v)
169282
}}.
170283
Proof.
171284
run_symbolic.
285+
eapply CallPrimitiveGetAssociatedFunction. {
286+
(* TODO *)
287+
}
172288
now instantiate (1 := Gas.Build_t _ _ _).
173289
Defined.
174290
@@ -394,3 +510,4 @@ Module Impl_revm_interpreter_gas_Gas.
394510
}
395511
intros; run_symbolic.
396512
End Impl_revm_interpreter_gas_Gas.
513+
*)

CoqOfRust/revm/links/interpreter/interpreter_action.v

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ Module InterpreterResult.
2828
gas : Gas.t;
2929
}.
3030

31-
Global Instance IsToTy : ToTy t := {
31+
Global Instance IsLink : Link t := {
3232
Φ := Ty.path "revm_interpreter::interpreter::InterpreterResult";
33-
}.
34-
35-
Global Instance IsToValue : ToValue t := {
3633
φ x :=
3734
Value.StructRecord "revm_interpreter::interpreter::InterpreterResult" [
3835
("result", φ x.(result));
@@ -70,11 +67,8 @@ Module InterpreterAction.
7067
| Return : InterpreterResult.t -> t
7168
| None.
7269

73-
Global Instance IsToTy : ToTy t := {
70+
Global Instance IsLink : Link t := {
7471
Φ := Ty.path "revm_interpreter::interpreter_action::InterpreterAction";
75-
}.
76-
77-
Global Instance IsToValue : ToValue t := {
7872
φ x :=
7973
match x with
8074
| Call x => Value.StructRecord "revm_interpreter::interpreter_action::InterpreterAction::Call" [("inputs", φ x)]

0 commit comments

Comments
 (0)