Skip to content

Commit 4bf96a4

Browse files
authored
Merge pull request #683 from formal-land/guillaume-claret@add-translation-of-ruint
Add a translation of ruint
2 parents fd754c8 + 35c24e8 commit 4bf96a4

File tree

42 files changed

+75574
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+75574
-69
lines changed

.github/workflows/rust.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ jobs:
139139
cd ..
140140
cd ../../..
141141
endGroup
142+
startGroup "Translate ruint"
143+
cd third-party/uint
144+
cp ../../rust-toolchain ./
145+
cargo coq-of-rust
146+
touch src/lib.rs
147+
cargo coq-of-rust
148+
rsync -rcv src/ ../../CoqOfRust/ruint/ --include='*/' --include='*.v' --exclude='*'
149+
cd ../..
150+
endGroup
142151
startGroup "Translate Move Sui"
143152
cd third-party/move-sui
144153
cp ../../rust-toolchain ./

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "third-party/move-sui"]
1111
path = third-party/move-sui
1212
url = https://github.com/formal-land/move-sui.git
13+
[submodule "third-party/uint"]
14+
path = third-party/uint
15+
url = https://github.com/recmo/uint.git

CoqOfRust/revm/links/dependencies.v

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,7 @@ Require Import core.convert.links.mod.
44
Require Import core.links.array.
55
Require core.links.clone.
66
Require core.links.default.
7-
Import Run.
8-
9-
Module ruint.
10-
Module Uint.
11-
Parameter t : Usize.t -> Usize.t -> Set.
12-
13-
Parameter to_value : forall {BITS LIMBS : Usize.t}, t BITS LIMBS -> Value.t.
14-
15-
Global Instance IsLink : forall {BITS LIMBS : Usize.t}, Link (t BITS LIMBS) := {
16-
Φ := Ty.apply (Ty.path "ruint::Uint") [ φ BITS; φ LIMBS ] [];
17-
φ := to_value;
18-
}.
19-
20-
Definition of_ty (BITS' LIMBS' : Value.t) (BITS LIMBS : Usize.t) :
21-
BITS' = φ BITS ->
22-
LIMBS' = φ LIMBS ->
23-
OfTy.t (Ty.apply (Ty.path "ruint::Uint") [ BITS' ; LIMBS' ] []).
24-
Proof. intros. eapply OfTy.Make with (A := t BITS LIMBS). now subst. Defined.
25-
Smpl Add eapply of_ty : of_ty.
26-
End Uint.
27-
28-
Module Impl_Uint.
29-
(* Uint<BITS, LIMBS> *)
30-
Definition Self (BITS LIMBS : Usize.t) : Set :=
31-
Uint.t BITS LIMBS.
32-
33-
Definition Self_ty (BITS LIMBS : Value.t) : Ty.t :=
34-
Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [].
35-
36-
(* pub fn wrapping_add(self, rhs: Self) -> Self *)
37-
Parameter wrapping_add : forall (BITS LIMBS : Value.t), PolymorphicFunction.t.
38-
39-
Global Instance wrapping_add_IsAssociated :
40-
forall (BITS LIMBS : Value.t),
41-
M.IsAssociatedFunction.Trait
42-
(Self_ty BITS LIMBS)
43-
"wrapping_add"
44-
(wrapping_add BITS LIMBS).
45-
Admitted.
46-
47-
Global Instance run_wrapping_add :
48-
forall (BITS LIMBS : Usize.t),
49-
forall (x1 x2 : Self BITS LIMBS),
50-
Run.Trait
51-
(wrapping_add (φ BITS) (φ LIMBS)) [] [] [ φ x1; φ x2 ]
52-
(Self BITS LIMBS).
53-
Admitted.
54-
55-
(* pub const fn to_be_bytes<const BYTES: usize>(&self) -> [u8; BYTES] *)
56-
Parameter to_be_bytes : forall (BITS LIMBS : Value.t), PolymorphicFunction.t.
57-
58-
Global Instance to_be_bytes_IsAssociated :
59-
forall (BITS LIMBS : Value.t),
60-
M.IsAssociatedFunction.Trait
61-
(Self_ty BITS LIMBS)
62-
"to_be_bytes"
63-
(to_be_bytes BITS LIMBS).
64-
Admitted.
65-
66-
Global Instance run_to_be_bytes :
67-
forall (BITS LIMBS BYTES : Usize.t),
68-
forall (x : Ref.t Pointer.Kind.Ref (Self BITS LIMBS)),
69-
Run.Trait
70-
(to_be_bytes (φ BITS) (φ LIMBS)) [ φ BYTES ] [] [ φ x ]
71-
(array.t U8.t BYTES).
72-
Admitted.
73-
End Impl_Uint.
74-
End ruint.
7+
Require Import ruint.links.lib.
758

769
Module alloy_primitives.
7710
Module bits.
@@ -254,7 +187,7 @@ End FixedBytes.
254187

255188
Module U256.
256189
Definition t : Set :=
257-
ruint.Uint.t {| Integer.value := 256 |} {| Integer.value := 4 |}.
190+
Uint.t {| Integer.value := 256 |} {| Integer.value := 4 |}.
258191
End U256.
259192

260193
Module B256.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ Require Import revm.revm_interpreter.links.gas.
55
Require Import revm.revm_interpreter.links.interpreter.
66
Require Import revm.revm_interpreter.links.interpreter_types.
77
Require Import revm.revm_interpreter.instructions.arithmetic.
8+
Require Import ruint.links.add.
89

910
Import Impl_Gas.
11+
Import Impl_Uint.
1012

1113
(*
1214
pub fn add<WIRE: InterpreterTypes, H: Host + ?Sized>(

CoqOfRust/revm/revm_interpreter/instructions/links/utility.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Require Import CoqOfRust.links.M.
33
Require Import core.convert.links.mod.
44
Require Import revm.revm_interpreter.instructions.utility.
55
Require Import revm.links.dependencies.
6+
Require Import ruint.links.bytes.
7+
8+
Import bytes.Impl_Uint.
69

710
(*
811
pub trait IntoAddress {

0 commit comments

Comments
 (0)