Skip to content

Commit 3a88b5e

Browse files
committed
simulations: special case for the stack with a single element
1 parent 5febecb commit 3a88b5e

File tree

2 files changed

+56
-34
lines changed
  • CoqOfRust
    • revm/revm_interpreter/simulations
    • simulations

2 files changed

+56
-34
lines changed

CoqOfRust/revm/revm_interpreter/simulations/gas.v

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Module Impl_Gas.
112112
set (ref_core := Ref.Core.Mutable _ _ _ _ _).
113113
epose proof (Run.GetSubPointer _ _ ref_core Gas.SubPointer.get_limit).
114114
apply H; clear H.
115-
cbn; intros.
116115
apply Run.StateRead. {
116+
cbn.
117117
epose proof (
118118
Stack.CanRead.Mutable
119119
[Self]
@@ -128,10 +128,38 @@ Module Impl_Gas.
128128
apply Run.Pure.
129129
Defined.
130130

131-
Lemma limit_eq (gas : Gas.t) :
132-
M.evaluate run_limit (gas, tt) =
133-
(Output.Success gas.(Gas.limit), (gas, tt)).
131+
Lemma limit_eq (self : Self) :
132+
M.evaluate run_limit self =
133+
(Output.Success self.(Gas.limit), self).
134134
Proof.
135135
reflexivity.
136136
Qed.
137+
138+
(*
139+
pub fn erase_cost(&mut self, returned: u64) {
140+
self.remaining += returned;
141+
}
142+
*)
143+
Definition run_erase_cost (returned : U64.t) :
144+
let self := {| Ref.core := Ref.Core.Mutable 0%nat [] φ Some (fun _ => Some) |} in
145+
{{ [Self] 🌲 links.M.evaluate (Impl_Gas.run_erase_cost self returned).(Run.run_f) }}.
146+
Proof.
147+
cbn.
148+
set (ref_core := Ref.Core.Mutable _ _ _ _ _).
149+
epose proof (Run.GetSubPointer _ _ ref_core Gas.SubPointer.get_remaining).
150+
apply H; clear H.
151+
apply Run.StateRead. {
152+
cbn.
153+
epose proof (
154+
Stack.CanRead.Mutable
155+
[Self]
156+
0%nat
157+
_
158+
_
159+
(fun big_a : links.gas.Impl_Gas.Self => Some big_a.(Gas.remaining))
160+
).
161+
apply H.
162+
}
163+
cbn; intros.
164+
Admitted.
137165
End Impl_Gas.

CoqOfRust/simulations/M.v

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -462,46 +462,40 @@ Module Stack.
462462
Definition t : Type :=
463463
list Set.
464464

465-
Fixpoint to_Set (stack : t) : Set :=
466-
match stack with
465+
Fixpoint to_Set_aux (A : Set) (Stack : t) : Set :=
466+
match Stack with
467+
| [] => A
468+
| B :: Stack => A * to_Set_aux B Stack
469+
end.
470+
471+
Definition to_Set (Stack : t) : Set :=
472+
match Stack with
467473
| [] => unit
468-
| A :: stack => A * to_Set stack
474+
| A :: Stack => to_Set_aux A Stack
469475
end.
470476

471477
Definition read_Set (Stack : t) (index : nat) : Set :=
472478
List.nth index Stack unit.
473479

474-
Fixpoint read {Stack : t} (stack : to_Set Stack) (index : nat) : read_Set Stack index.
480+
Fixpoint read_aux {A : Set} {Stack : t}
481+
(stack : to_Set_aux A Stack)
482+
(index : nat)
483+
{struct Stack} :
484+
read_Set (A :: Stack) index.
475485
Proof.
476-
destruct Stack as [|A Stack], index as [|index]; cbn in *.
477-
{ exact tt. }
478-
{ exact tt. }
486+
destruct Stack as [|B Stack], index as [|index]; cbn in *.
487+
{ exact stack. }
488+
{ destruct index; exact tt. }
479489
{ exact (fst stack). }
480-
{ exact (read _ (snd stack) index). }
490+
{ exact (read_aux _ _ (snd stack) index). }
481491
Defined.
482492

483-
(* Module Read.
484-
Inductive t {A : Set} `{Link A} {Stack : Stack.t} (stack : to_Set Stack) :
485-
Ref.Core.t A ->
486-
option A ->
487-
Set :=
488-
| Immediate
489-
(value : option A) :
490-
t stack
491-
(Ref.Core.Immediate value)
492-
value
493-
| Mutable
494-
(index : nat)
495-
(path : Pointer.Path.t)
496-
(big_to_value : read_Set Stack index -> Value.t)
497-
(projection : read_Set Stack index -> option A)
498-
(injection : read_Set Stack index -> A -> option (read_Set Stack index)) :
499-
t stack
500-
(Ref.Core.Mutable (Address := nat) (Big_A := read_Set Stack index)
501-
index path big_to_value projection injection
502-
)
503-
(projection (read stack index)).
504-
End Read. *)
493+
Definition read {Stack : t} (stack : to_Set Stack) (index : nat) : read_Set Stack index.
494+
Proof.
495+
destruct Stack; cbn in *.
496+
{ destruct index; exact tt. }
497+
{ apply (read_aux stack). }
498+
Defined.
505499

506500
Module CanRead.
507501
Inductive t {A : Set} `{Link A} (Stack : Stack.t) : Ref.Core.t A -> Set :=

0 commit comments

Comments
 (0)