Skip to content

Commit b6e320a

Browse files
authored
Merge pull request #685 from formal-land/andreadlm@update-links-for-revm-eof-body
Update links for revm eof body
2 parents 4bf96a4 + bec3e5c commit b6e320a

File tree

9 files changed

+270
-12
lines changed

9 files changed

+270
-12
lines changed

CoqOfRust/alloc/vec/links/mod.v

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Require Import links.M.
44
Require core.links.clone.
55
Require core.links.default.
66
Require core.ops.links.deref.
7+
Require core.ops.links.index.
78

89
Import Run.
910

@@ -78,9 +79,7 @@ Module Impl_alloc_vec_Vec_T_A.
7879
Definition Self := Vec.t.
7980

8081
(*
81-
pub const fn new() -> Self {
82-
Vec { buf: RawVec::new(), len: 0 }
83-
}
82+
pub const fn new() -> Self
8483
*)
8584
Instance run_new {T A : Set} `{Link T} `{Link A} :
8685
Run.Trait (vec.Impl_alloc_vec_Vec_T_alloc_alloc_Global.new (Φ T)) [] [] [] (Self T A).
@@ -102,3 +101,20 @@ Module Impl_alloc_vec_Vec_T_A.
102101
Run.Trait (vec.Impl_alloc_vec_Vec_T_A.len (Φ T) (Φ A)) [] [] [φ self] Usize.t.
103102
Admitted.
104103
End Impl_alloc_vec_Vec_T_A.
104+
105+
Module Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
106+
Definition Self := Vec.t.
107+
108+
(*
109+
fn index(&self, index: I) -> &Self::Output
110+
*)
111+
Instance run_index {T I A Output : Set} `{Link T} `{Link I} `{Link A} `{Link Output}
112+
{self : Ref.t Pointer.Kind.Ref (Self T A)}
113+
{index : I} :
114+
Run.Trait (vec.Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.index (Φ T) (Φ I) (Φ A)) [] [Φ I] [φ self; φ index] (Ref.t Pointer.Kind.Ref Output).
115+
Admitted.
116+
117+
Definition run {T I A Output : Set} `{Link T} `{Link I} `{Link A} `{Link Output} :
118+
index.Index.Run (Self T A) I Output.
119+
Admitted.
120+
End Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.

CoqOfRust/core/links/cmp.v

+61-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Require Import CoqOfRust.CoqOfRust.
22
Require Import links.M.
33
Require Import core.cmp.
44
Require Import core.intrinsics.
5+
Require Import core.links.option.
56
Require core.ops.links.function.
67
Require Import core.links.intrinsics.
78
Require Export core.links.cmpOrdering.
@@ -182,4 +183,63 @@ Module Impl_Ord_for_u64.
182183
exact run_clamp.
183184
}
184185
Defined.
185-
End Impl_Ord_for_u64.
186+
End Impl_Ord_for_u64.
187+
188+
Module PartialOrd.
189+
(*
190+
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
191+
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
192+
fn lt(&self, other: &Rhs) -> bool;
193+
fn le(&self, other: &Rhs) -> bool;
194+
fn gt(&self, other: &Rhs) -> bool;
195+
fn ge(&self, other: &Rhs) -> bool;
196+
}
197+
*)
198+
Definition Run_partial_cmp (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set :=
199+
{partial_cmp @
200+
IsTraitMethod.t "core::cmp::PartialOrd" [] [] (Φ Self) "partial_cmp" partial_cmp *
201+
forall (self : Ref.t Pointer.Kind.Ref Self) (other: Ref.t Pointer.Kind.Ref Rhs),
202+
{{ partial_cmp [] [] [φ self; φ other] 🔽 option Ordering.t }}
203+
}.
204+
205+
Definition Run_lt (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set :=
206+
{lt @
207+
IsTraitMethod.t "core::cmp::PartialOrd" [] [] (Φ Self) "lt" lt *
208+
forall (self : Ref.t Pointer.Kind.Ref Self) (other: Ref.t Pointer.Kind.Ref Rhs),
209+
{{ lt [] [] [φ self; φ other] 🔽 bool }}
210+
}.
211+
212+
Definition Run_le (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set :=
213+
{le @
214+
IsTraitMethod.t "core::cmp::PartialOrd" [] [] (Φ Self) "le" le *
215+
forall (self : Ref.t Pointer.Kind.Ref Self) (other: Ref.t Pointer.Kind.Ref Rhs),
216+
{{ le [] [] [φ self; φ other] 🔽 bool }}
217+
}.
218+
219+
Definition Run_gt (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set :=
220+
{gt @
221+
IsTraitMethod.t "core::cmp::PartialOrd" [] [] (Φ Self) "gt" gt *
222+
forall (self : Ref.t Pointer.Kind.Ref Self) (other: Ref.t Pointer.Kind.Ref Rhs),
223+
{{ gt [] [] [φ self; φ other] 🔽 bool }}
224+
}.
225+
226+
Definition Run_ge (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set :=
227+
{ge @
228+
IsTraitMethod.t "core::cmp::PartialOrd" [] [] (Φ Self) "ge" ge *
229+
forall (self : Ref.t Pointer.Kind.Ref Self) (other: Ref.t Pointer.Kind.Ref Rhs),
230+
{{ ge [] [] [φ self; φ other] 🔽 bool }}
231+
}.
232+
233+
Record Run (Self Rhs : Set) `{Link Self} `{Link Rhs} : Set := {
234+
partial_cmp : Run_partial_cmp Self Rhs;
235+
lt : Run_lt Self Rhs;
236+
le : Run_le Self Rhs;
237+
gt : Run_gt Self Rhs;
238+
ge : Run_ge Self Rhs;
239+
}.
240+
241+
(* Instance run_partial_cmp {Self Rhs : Set} `{Link Self} `{Link Rhs}
242+
(self : Ref.t Pointer.Kind.Ref Self) (other : Ref.t Pointer.Kind.Ref Rhs) :
243+
Run.Trait cmp.Impl_core_cmp_PartialOrd_for_core_cmp_Ordering.partial_cmp [] [] [φ self; φ other] (option Ordering.t).
244+
Admitted. *)
245+
End PartialOrd.

CoqOfRust/core/links/result.v

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ Require Import CoqOfRust.CoqOfRust.
22
Require Import links.M.
33

44
Module Result.
5-
Global Instance IsLink (A B : Set) (_ : Link A) (_ : Link B) : Link (A + B) := {
6-
Φ := Ty.apply (Ty.path "core::result::Result") [] [Φ A; Φ B];
5+
Inductive t {T E : Set} : Set :=
6+
| Ok : T -> t
7+
| Err : E -> t.
8+
Arguments t : clear implicits.
9+
10+
Global Instance IsLink (T E : Set) `{Link T} `{Link E} : Link (t T E) := {
11+
Φ := Ty.apply (Ty.path "core::result::Result") [] [Φ T; Φ E];
712
φ x :=
813
match x with
9-
| inl x => Value.StructTuple "core::result::Result::Ok" [φ x]
10-
| inr e => Value.StructTuple "core::result::Result::Err" [φ e]
14+
| Ok x => Value.StructTuple "core::result::Result::Ok" [φ x]
15+
| Err x => Value.StructTuple "core::result::Result::Err" [φ x]
1116
end;
1217
}.
1318
End Result.

CoqOfRust/core/ops/links/index.v

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Require Import CoqOfRust.CoqOfRust.
2+
Require Import links.M.
3+
4+
(*
5+
pub trait Index<Idx: ?Sized> {
6+
type Output: ?Sized;
7+
8+
fn index(&self, index: Idx) -> &Self::Output;
9+
}
10+
*)
11+
Module Index.
12+
Definition run_index
13+
(Self : Set) `{Link Self}
14+
(Idx : Set) `{Link Idx}
15+
(Output : Set) `{Link Output} : Set :=
16+
{ index' @
17+
IsTraitMethod.t "core::ops::index::Index" [] [Φ Idx] (Φ Self) "index" index' *
18+
forall (self : Ref.t Pointer.Kind.Ref Self) (index : Idx),
19+
{{ index' [] [] [φ self; φ index] 🔽 Ref.t Pointer.Kind.Ref Output }}
20+
}.
21+
22+
Record Run
23+
(Self : Set) `{Link Self}
24+
(Idx : Set) `{Link Idx}
25+
(Output : Set) `{Link Output} :
26+
Set := {
27+
Output_IsAssociated :
28+
IsTraitAssociatedType
29+
"core::slice::index::SliceIndex" [] [Φ Idx] (Φ Self)
30+
"Output" (Φ Output);
31+
index : run_index Self Idx Output;
32+
}.
33+
End Index.

CoqOfRust/core/ops/links/range.v

+62
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Require Import CoqOfRust.CoqOfRust.
2+
Require Import core.links.cmp.
23
Require Import links.M.
34

45
(*
@@ -49,3 +50,64 @@ Module Bound.
4950
end;
5051
}.
5152
End Bound.
53+
54+
(*
55+
pub trait RangeBounds<T: ?Sized> {
56+
fn start_bound(&self) -> Bound<&T>;
57+
fn end_bound(&self) -> Bound<&T>;
58+
fn contains<U>(&self, item: &U) -> bool
59+
where
60+
T: PartialOrd<U>,
61+
U: ?Sized + PartialOrd<T>
62+
fn is_empty(&self) -> bool
63+
where
64+
T: PartialOrd;
65+
}
66+
*)
67+
Module RangeBounds.
68+
Definition Run_start_bound (Self : Set) `{Link Self}
69+
(T : Set) `{Link T} : Set :=
70+
{start_bound @
71+
IsTraitMethod.t "core::ops::RangeBounds" [] [] (Φ Self) "start_bound" start_bound *
72+
forall (self : Ref.t Pointer.Kind.Ref Self),
73+
{{ start_bound [] [] [φ self] 🔽 Bound.t (Ref.t Pointer.Kind.Ref T) }}
74+
}.
75+
76+
Definition Run_end_bound (Self : Set) `{Link Self}
77+
(T : Set) `{Link T} : Set :=
78+
{end_bound @
79+
IsTraitMethod.t "core::ops::RangeBounds" [] [] (Φ Self) "end_bound" end_bound *
80+
forall (self : Ref.t Pointer.Kind.Ref Self),
81+
{{ end_bound [] [] [φ self] 🔽 Bound.t (Ref.t Pointer.Kind.Ref T) }}
82+
}.
83+
84+
Definition Run_contains (Self : Set) `{Link Self}
85+
(T : Set) `{Link T} : Set :=
86+
{contains @
87+
IsTraitMethod.t "core::ops::RangeBounds" [] [] (Φ Self) "contains" contains *
88+
forall
89+
(self : Ref.t Pointer.Kind.Ref Self)
90+
(U : Set) `(Link U)
91+
(item : Ref.t Pointer.Kind.Ref U)
92+
(run_Ord_for_T : PartialOrd.Run T T)
93+
(run_Ord_for_U : PartialOrd.Run U U),
94+
{{ contains [] [] [φ self; φ item] 🔽 bool }}
95+
}.
96+
97+
Definition Run_is_empty (Self : Set) `{Link Self}
98+
(T : Set) `{Link T} : Set :=
99+
{is_empty @
100+
IsTraitMethod.t "core::ops::RangeBounds" [] [] (Φ Self) "is_empty" is_empty *
101+
forall (self : Ref.t Pointer.Kind.Ref Self)
102+
(run_Ord_for_T : PartialOrd.Run T T),
103+
{{ is_empty [] [] [φ self] 🔽 bool }}
104+
}.
105+
106+
Record Run (Self : Set) `{Link Self}
107+
{T : Set} `{Link T} : Set := {
108+
start_bound : Run_start_bound Self T;
109+
end_bound : Run_end_bound Self T;
110+
contains : Run_contains Self T;
111+
is_empty : Run_is_empty Self T;
112+
}.
113+
End RangeBounds.

CoqOfRust/revm/links/dependencies.v

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Require Import CoqOfRust.CoqOfRust.
22
Require Import CoqOfRust.links.M.
33
Require Import core.convert.links.mod.
44
Require Import core.links.array.
5+
Require Import core.ops.links.range.
56
Require core.links.clone.
67
Require core.links.default.
78
Require Import ruint.links.lib.
@@ -119,6 +120,20 @@ Module alloy_primitives.
119120

120121
Global Instance run_new : Run.Trait new [] [] [] Bytes.t.
121122
Admitted.
123+
124+
(* pub fn slice(&self, range: impl RangeBounds<usize>) -> Self *)
125+
Parameter slice : PolymorphicFunction.t.
126+
127+
Global Instance AssociatedFunction_slice :
128+
M.IsAssociatedFunction.Trait (Φ Self) "slice" slice.
129+
Admitted.
130+
131+
Global Instance run_slice {A : Set} `{Link A}
132+
(self : Ref.t Pointer.Kind.Ref Self)
133+
(range : A)
134+
(run_RangeBounds_for_A : RangeBounds.Run A) :
135+
Run.Trait slice [] [] [φ self; φ range] Self.
136+
Admitted.
122137
End Impl_Bytes.
123138

124139
Module Impl_Clone_for_Bytes.

CoqOfRust/revm/revm_bytecode/eof/links/body.v

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Require Import alloc.links.alloc.
44
Require Import alloc.vec.links.mod.
55
Require core.links.clone.
66
Require core.links.default.
7+
Require Import core.links.result.
78
Require Import core.links.option.
89
Require Import revm.links.dependencies.
910
Require Export revm.revm_bytecode.eof.links.body_EofBody.
@@ -13,8 +14,6 @@ Require Import revm.revm_bytecode.links.eof.
1314
Require Import revm_bytecode.eof.body.
1415
Require Import core.slice.links.mod.
1516

16-
Import Run.
17-
1817
Module EofBody.
1918
Record t : Set := {
2019
types_section: Vec.t revm_bytecode.eof.links.types_section.TypesSection.t Global.t;
@@ -233,6 +232,7 @@ Module Impl_EofBody.
233232
Import Impl_alloc_vec_Vec_T_A.
234233
Import Impl_EofHeader.
235234
Import Impl_Slice.
235+
Import Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
236236

237237
Definition Self : Set := EofBody.t.
238238

@@ -243,8 +243,12 @@ Module Impl_EofBody.
243243
Run.Trait body.eof.body.Impl_revm_bytecode_eof_body_EofBody.code [] [] [φ self; φ index] (option alloy_primitives.links.bytes_.Bytes.t).
244244
Proof.
245245
constructor.
246-
run_symbolic.
246+
destruct (vec.links.mod.Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.run (T := Usize.t) (I := Usize.t) (A := Global.t)) as [index' [H_index' run_index']].
247+
destruct (vec.links.mod.Impl_Deref_for_Vec.run (T := Usize.t) (A := Global.t)).
248+
destruct deref.
249+
run_symbolic.
247250
Admitted.
251+
248252

249253
(*
250254
pub fn encode(&self, buffer: &mut Vec<u8>)
@@ -281,4 +285,10 @@ Module Impl_EofBody.
281285
(*
282286
pub fn decode(input: &Bytes, header: &EofHeader) -> Result<Self, EofDecodeError>
283287
*)
288+
Instance run_decode (input : Ref.t Pointer.Kind.Ref alloy_primitives.links.bytes_.Bytes.t) (header : Ref.t Pointer.Kind.Ref EofHeader.t) :
289+
Run.Trait body.eof.body.Impl_revm_bytecode_eof_body_EofBody.decode [] [] [φ input; φ header] (Result.t EofBody.t EofDecodeError.t).
290+
Proof.
291+
constructor.
292+
run_symbolic.
293+
Admitted.
284294
End Impl_EofBody.

CoqOfRust/revm/revm_bytecode/eof/links/header.v

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ Module EofHeader.
3434
End EofHeader.
3535

3636
Module Impl_EofHeader.
37-
3837
Definition Self : Set := EofHeader.t.
3938

39+
(*
40+
pub fn size(&self) -> usize
41+
*)
42+
Instance run_size (self : Ref.t Pointer.Kind.Ref Self) :
43+
Run.Trait header.eof.header.Impl_revm_bytecode_eof_header_EofHeader.size [] [] [φ self] Usize.t.
44+
Admitted.
45+
4046
(*
4147
pub fn encode(&self, buffer: &mut Vec<u8>)
4248
*)

CoqOfRust/revm/revm_bytecode/links/eof.v

+51
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,54 @@ Module Eof.
2222
]
2323
}.
2424
End Eof.
25+
26+
Module EofDecodeError.
27+
Inductive t : Set :=
28+
| MissingInput : t
29+
| MissingBodyWithoutData : t
30+
| DanglingData : t
31+
| InvalidCodeInfo : t
32+
| InvalidCodeInfoSize : t
33+
| InvalidEOFMagicNumber : t
34+
| InvalidEOFVersion : t
35+
| InvalidTypesKind : t
36+
| InvalidCodeKind : t
37+
| InvalidTerminalByte : t
38+
| InvalidDataKind : t
39+
| InvalidKindAfterCode : t
40+
| MismatchCodeAndInfoSize : t
41+
| NonSizes : t
42+
| ShortInputForSizes : t
43+
| ZeroSize : t
44+
| TooManyCodeSections : t
45+
| ZeroCodeSections : t
46+
| TooManyContainerSections : t
47+
| InvalidEOFSize : t.
48+
49+
Global Instance IsLink : Link t := {
50+
Φ := Ty.apply (Ty.path "revm_bytecode::eof::EofDecodeError") [] [];
51+
φ x :=
52+
match x with
53+
| MissingInput => Value.StructTuple "revm_bytecode::eof::EofDecodeError::MissingInput" []
54+
| MissingBodyWithoutData => Value.StructTuple "revm_bytecode::eof::EofDecodeError::MissingBodyWithoutData" []
55+
| DanglingData => Value.StructTuple "revm_bytecode::eof::EofDecodeError::DanglingData" []
56+
| InvalidCodeInfo => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidCodeInfo" []
57+
| InvalidCodeInfoSize => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidCodeInfoSize" []
58+
| InvalidEOFMagicNumber => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidEOFMagicNumber" []
59+
| InvalidEOFVersion => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidEOFVersion" []
60+
| InvalidTypesKind => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidTypesKind" []
61+
| InvalidCodeKind => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidCodeKind" []
62+
| InvalidTerminalByte => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidTerminalByte" []
63+
| InvalidDataKind => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidDataKind" []
64+
| InvalidKindAfterCode => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidKindAfterCode" []
65+
| MismatchCodeAndInfoSize => Value.StructTuple "revm_bytecode::eof::EofDecodeError::MismatchCodeAndInfoSize" []
66+
| NonSizes => Value.StructTuple "revm_bytecode::eof::EofDecodeError::NonSizes" []
67+
| ShortInputForSizes => Value.StructTuple "revm_bytecode::eof::EofDecodeError::ShortInputForSizes" []
68+
| ZeroSize => Value.StructTuple "revm_bytecode::eof::EofDecodeError::ZeroSize" []
69+
| TooManyCodeSections => Value.StructTuple "revm_bytecode::eof::EofDecodeError::TooManyCodeSections" []
70+
| ZeroCodeSections => Value.StructTuple "revm_bytecode::eof::EofDecodeError::ZeroCodeSections" []
71+
| TooManyContainerSections => Value.StructTuple "revm_bytecode::eof::EofDecodeError::TooManyContainerSections" []
72+
| InvalidEOFSize => Value.StructTuple "revm_bytecode::eof::EofDecodeError::InvalidEOFSize" []
73+
end;
74+
}.
75+
End EofDecodeError.

0 commit comments

Comments
 (0)