Skip to content

Commit cbe71bc

Browse files
committed
simulations: more wip
1 parent e57e990 commit cbe71bc

File tree

3 files changed

+76
-22
lines changed

3 files changed

+76
-22
lines changed

CoqOfRust/revm/revm_interpreter/instructions/simulations/arithmetic.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ Proof.
2222
constructor.
2323
destruct run_InterpreterTypes_for_WIRE.
2424
destruct run_StackTrait_for_Stack, run_LoopControl_for_Control.
25+
simulate_one_step.
2526
simulate.
27+
{ admit. }
28+
{
29+
30+
}
2631
Defined.
2732

2833
(*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Require Import CoqOfRust.CoqOfRust.
2+
Require Import CoqOfRust.links.M.
3+
Require Import CoqOfRust.simulations.M.
4+
Require Import revm.revm_interpreter.links.interpreter.
5+
6+
Module Impl_Interpreter.
7+
Definition Self
8+
(IW : Set) `{Link IW}
9+
{IW_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks IW_types}
10+
(run_InterpreterTypes_for_IW : InterpreterTypes.Run IW IW_types) :
11+
Set :=
12+
Interpreter.t IW IW_types.
13+
14+
Instance run_step
15+
(IW : Set) `{Link IW}
16+
{IW_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks IW_types}
17+
(run_InterpreterTypes_for_IW : InterpreterTypes.Run IW IW_types)
18+
(H_ : Set) `{Link H_}
19+
(FN : Set) `{Link FN}
20+
(run_CustomInstruction_for_FN : CustomInstruction.Run FN IW IW_types H_)
21+
(self : Ref.t Pointer.Kind.MutRef (Self IW run_InterpreterTypes_for_IW))
22+
(instruction_table : Ref.t Pointer.Kind.Ref (array.t FN {| Integer.value := 256 |}))
23+
(host : Ref.t Pointer.Kind.MutRef H_) :
24+
Run.Trait
25+
(interpreter.Impl_revm_interpreter_interpreter_Interpreter_IW.step (Φ IW))
26+
[]
27+
[ Φ FN; Φ H_ ]
28+
[ φ self; φ instruction_table; φ host ]
29+
unit.
30+
Proof.
31+
constructor.
32+
cbn.
33+
eapply Run.Rewrite. {
34+
erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_IW.
35+
reflexivity.
36+
}
37+
destruct run_InterpreterTypes_for_IW.
38+
destruct run_Jumps_for_Bytecode.
39+
destruct run_CustomInstruction_for_FN.
40+
destruct exec as [exec [H_exec run_exec]].
41+
run_symbolic.
42+
Defined.
43+
End Impl_Interpreter.

CoqOfRust/simulations/M.v

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ Module Stack.
613613
end
614614
end.
615615

616-
Axiom admit_access_for_now :
616+
(* Axiom admit_access_for_now :
617617
forall {A : Set} `{Link A} (Stack : Stack.t) (ref_core : Ref.Core.t A),
618-
t Stack ref_core.
618+
t Stack ref_core. *)
619619

620620
Ltac infer :=
621621
cbn ||
@@ -624,8 +624,7 @@ Module Stack.
624624
apply (runner r)
625625
end ||
626626
assumption ||
627-
apply Stack.CanAccess.Immediate ||
628-
apply admit_access_for_now.
627+
apply Stack.CanAccess.Immediate.
629628
End CanAccess.
630629
End Stack.
631630

@@ -813,12 +812,26 @@ Module Run.
813812
(e : LowM.t R Output')
814813
(k : Output.t R (Ref.t Pointer.Kind.Raw Output') -> LowM.t R Output)
815814
(H_e : {{ StackIn 🌲 e }})
816-
(H_k : forall (ref_or_exception : Output.t R (Ref.t Pointer.Kind.Raw Output')),
815+
(H_k : forall (value_or_exception : Output.t R Output'),
817816
let StackIn' :=
818-
match ref_or_exception with
817+
match value_or_exception with
819818
| Output.Success _ => StackIn ++ [Output']
820819
| Output.Exception _ => StackIn
821820
end in
821+
let ref_or_exception : Output.t R (Ref.t Pointer.Kind.Raw Output') :=
822+
match value_or_exception with
823+
| Output.Success _ =>
824+
Output.Success {|
825+
Ref.core :=
826+
Ref.Core.Mutable
827+
(List.length StackIn)
828+
[]
829+
φ
830+
Some
831+
(fun _ => Some)
832+
|}
833+
| Output.Exception exception => Output.Exception exception
834+
end in
822835
{{ StackIn' 🌲 k ref_or_exception }}
823836
) :
824837
{{ StackIn 🌲 LowM.LetAlloc e k }}
@@ -883,29 +896,22 @@ Proof.
883896
}
884897
{ (* LetAlloc *)
885898
refine (
886-
let '(output', stack_in') := evaluate _ _ _ _ run stack_in in
899+
let '(value_or_exception, stack_in') := evaluate _ _ _ _ run stack_in in
900+
_
901+
).
902+
refine (
903+
let result := H_k value_or_exception in
887904
_
888905
).
889-
destruct output' as [output' | exception].
906+
destruct value_or_exception as [value | exception].
890907
{ refine (
891-
let ref_core :=
892-
Ref.Core.Mutable
893-
(List.length StackIn)
894-
[]
895-
φ
896-
Some
897-
(fun _ => Some) in
898-
let ref : Ref.t Pointer.Kind.Raw Output' := {| Ref.core := ref_core |} in
899-
_
900-
).
901-
refine (
902908
let '(output, stack_out) := _ in
903909
(output, fst (Stack.dealloc (A := Output') stack_out))
904910
).
905-
unshelve eapply (evaluate _ _ _ _ (H_k (Output.Success ref)) _).
906-
exact (Stack.alloc stack_in' output').
911+
unshelve eapply (evaluate _ _ _ _ result _).
912+
exact (Stack.alloc stack_in' value).
907913
}
908-
{ exact (evaluate _ _ _ _ (H_k (Output.Exception exception)) stack_in'). }
914+
{ exact (evaluate _ _ _ _ result stack_in'). }
909915
}
910916
Defined.
911917

0 commit comments

Comments
 (0)