Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formalizing bitwise.rs #677

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b94d30f
Advancing proof
romefeller Mar 4, 2025
c0ced32
Merge remote-tracking branch 'origin/main' into alexandre-oliveira@bi…
romefeller Mar 4, 2025
87d7b44
Problem with a mutable ref
romefeller Mar 4, 2025
fe0474b
Bool problem
romefeller Mar 5, 2025
f2cb674
Minor change
clarus Mar 6, 2025
7a1559f
Merge pull request #680 from formal-land/guillaume-claret@alexandre-o…
romefeller Mar 6, 2025
0a271bb
lt and gt defined
romefeller Mar 7, 2025
1d56b16
partial eq ordering problem
romefeller Mar 7, 2025
4b0decb
Merge remote-tracking branch 'origin/main' into alexandre-oliveira@bi…
romefeller Mar 8, 2025
c091a40
introducing i256
romefeller Mar 8, 2025
a183f7f
run_slt defined
romefeller Mar 11, 2025
f616336
run_sgt defined
romefeller Mar 11, 2025
8cdb782
Defined more functions
romefeller Mar 11, 2025
5ea7e72
Defined bin op functions
romefeller Mar 11, 2025
45ec5f5
Defining not
romefeller Mar 12, 2025
72c09a9
Subpointer problem
romefeller Mar 12, 2025
e8dd81f
TryFrom not found problem
romefeller Mar 17, 2025
d27fc0d
Merge with main
romefeller Mar 18, 2025
f2f8747
Fixes after merge
romefeller Mar 18, 2025
393eb3b
Adapting to the new main branch
romefeller Mar 19, 2025
5100ebb
Defining more links
romefeller Mar 19, 2025
ff95b8d
More deifinitions and shl error
romefeller Mar 19, 2025
536f755
Only a few admits to end
romefeller Mar 20, 2025
09517fd
Advancing a little bit more
romefeller Mar 20, 2025
113a620
Another merge
romefeller Mar 22, 2025
87390e5
Adapting the merge
romefeller Mar 23, 2025
b5729e4
Advancing a little bit
romefeller Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CoqOfRust/core/links/intrinsics.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ Instance run_saturating_add (integer_kind : IntegerKind.t) (x y : Integer.t inte
(Integer.t integer_kind).
Proof.
Admitted.

Instance run_sub_with_overflow
(x y : Integer.t IntegerKind.U64) :
Run.Trait
intrinsics.intrinsics.sub_with_overflow
[]
[ Φ (Integer.t IntegerKind.U64) ]
[ φ x; φ y ]
(Integer.t IntegerKind.U64 * bool).
Proof.
Admitted.

50 changes: 50 additions & 0 deletions CoqOfRust/revm/links/dependencies.v
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,56 @@ Module ruint.
(array.t U8.t BYTES).
Admitted.
End Impl_Uint.
Module Impl_from_Uint.
Definition Self (BITS LIMBS : Usize.t) : Set :=
ruint.Uint.t BITS LIMBS.

Definition Self_ty (BITS LIMBS : Value.t) : Ty.t :=
Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [].

(* pub const fn from(value: Usize.t) -> Self *)
Parameter from : forall (BITS LIMBS : Value.t), PolymorphicFunction.t.

Global Instance from_IsAssociated :
forall (BITS LIMBS : Value.t),
M.IsAssociatedFunction.Trait
(Self_ty BITS LIMBS)
"from"
(from BITS LIMBS).
Admitted.

Parameter run_from :
forall (BITS LIMBS : Usize.t) (value : Usize.t),
{{ from (φ BITS) (φ LIMBS) [] [] [ φ value ] 🔽 Self BITS LIMBS }}.
End Impl_from_Uint.

Module Impl_PartialOrd_for_Uint.
Definition Self (BITS LIMBS : Value.t) : Ty.t :=
Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [].

Parameter lt : forall (BITS LIMBS : Value.t), PolymorphicFunction.t.

Axiom Implements :
forall (BITS LIMBS : Value.t) (trait_tys : list Ty.t),
M.IsTraitInstance
"core::cmp::PartialOrd"
(* Trait polymorphic consts *) []
(* Trait polymorphic types *) trait_tys
(Self BITS LIMBS)
(* Instance *) [ ("lt", InstanceField.Method (lt BITS LIMBS)) ].

Definition run_lt :
forall (BITS LIMBS : Usize.t),
forall (x1 x2 : ruint.Uint.t BITS LIMBS),
{{ lt (φ BITS) (φ LIMBS) [] [] [ φ x1; φ x2 ] 🔽 bool }}.
Admitted.

Definition run (BITS LIMBS : Value.t) :
PolymorphicFunction.t.
Proof.
exact (lt BITS LIMBS).
Defined.
End Impl_PartialOrd_for_Uint.
End ruint.

Module alloy_primitives.
Expand Down
75 changes: 75 additions & 0 deletions CoqOfRust/revm/revm_interpreter/instructions/links/bitwise.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Require Import CoqOfRust.CoqOfRust.
Require Import CoqOfRust.links.lib.
Require Import CoqOfRust.links.M.
Require Import core.links.intrinsics.
Require Import revm.revm_context_interface.links.host.
Require revm.links.dependencies.
Import revm.links.dependencies.ruint.
Require Import revm.revm_interpreter.links.gas.
Require Import revm.revm_interpreter.links.interpreter.
Require Import revm.revm_interpreter.links.interpreter_types.
Require Import revm.revm_interpreter.instructions.bitwise.

Import Run.
(*
pub fn lt<WIRE: InterpreterTypes, H: Host + ?Sized>(
interpreter: &mut Interpreter<WIRE>,
_host: &mut H,
)
*)

Ltac solve_one_branch e :=
constructor;
cbn;
eapply Run.Rewrite; [
repeat erewrite IsTraitAssociatedType_eq by apply e;
reflexivity
|
];
run_symbolic.

Instance run_lt
{WIRE H : Set} `{Link WIRE} `{Link H}
{WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types}
(run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types)
(interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types))
(_host : Ref.t Pointer.Kind.MutRef H) :
Run.Trait
instructions.bitwise.lt [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
cbn.
eapply Run.Rewrite. {
repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE.
reflexivity.
}
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct popn_top as [popn_top [H_popn_top run_popn_top]].
destruct run_LoopControl_for_Control.
destruct gas as [gas [H_gas run_gas]].
destruct set_instruction_result as [set_instruction_result [H_set_instruction_result run_set_instruction_result]].
run_symbolic. {
repeat solve_one_branch run_InterpreterTypes_for_WIRE.
}
eapply Run.CallPrimitiveGetTraitMethod.
- eapply IsTraitMethod.Defined.
+ specialize (Impl_PartialOrd_for_Uint.Implements
(Value.Integer IntegerKind.Usize 256)
(Value.Integer IntegerKind.Usize 4)).
intros.
unfold Impl_PartialOrd_for_Uint.Self in H3.
apply H3 with (trait_tys := [Ty.apply (Ty.path "ruint::Uint")
[Value.Integer IntegerKind.Usize 256;
Value.Integer IntegerKind.Usize 4] []]).
+ simpl.
reflexivity.
- run_symbolic.
+

Qed.




Loading