Skip to content

Add bitwise translation #732

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

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions CoqOfRust/core/intrinsics/links/mod.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,26 @@ Instance run_saturating_sub (integer_kind : IntegerKind.t) (x y : Integer.t inte
Proof.
Admitted.

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

(* pub const unsafe fn transmute<Src, Dst>(_src: Src) -> Dst *)
Instance run_transmute (Src Dst : Set) `{Link Src} `{Link Dst} (src : Src) :
Run.Trait
intrinsics.transmute [] [ Φ Src; Φ Dst ] [ φ src ] Dst.
Proof.
Admitted.

Instance run_discriminant_value (ref : Ref.t Pointer.Kind.Ref Ordering.t) :
Run.Trait intrinsics.discriminant_value [] [Φ Ordering.t] [φ ref]
(Integer.t IntegerKind.I8).
Proof.
Admitted.
8 changes: 8 additions & 0 deletions CoqOfRust/core/links/cmp.v
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,11 @@ Module PartialOrd.
ge : Run_ge Self Rhs;
}.
End PartialOrd.

Module Impl_PartialEq_for_Ordering.
Definition Self : Set := Ordering.t.

Instance run : PartialEq.Run Self Self.
Admitted.
End Impl_PartialEq_for_Ordering.
Export Impl_PartialEq_for_Ordering.
16 changes: 0 additions & 16 deletions CoqOfRust/revm/revm_context_interface/links/host.v
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,4 @@ Module Host.
log : Run_log Self;
selfdestruct : Run_selfdestruct Self;
}.

Ltac destruct_run :=
cbn;
eapply Run.Rewrite; [
progress repeat erewrite IsTraitAssociatedType_eq
by match goal with
| H : Run _ _ |- _ => apply H
end;
reflexivity
|];
match goal with
| H : Run _ _ |- _ =>
(* We make a duplicate for future calls *)
pose H;
destruct H
end.
End Host.
262 changes: 262 additions & 0 deletions CoqOfRust/revm/revm_interpreter/instructions/links/bitwise.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
Require Import CoqOfRust.CoqOfRust.
Require Import CoqOfRust.links.M.
Require Import core.convert.links.num.
Require Import core.links.cmp.
Require Import core.links.result.
Require Import core.num.links.error.
Require Import core.num.links.mod.
Require Import revm.revm_interpreter.gas.links.constants.
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.links.i256.
Require Import revm.revm_interpreter.instructions.bitwise.
Require Import revm.revm_specification.links.hardfork.
Require Import ruint.links.bits.
Require Import ruint.links.cmp.
Require Import ruint.links.from.
Require Import ruint.links.lib.

(*
pub fn lt<WIRE: InterpreterTypes, H: Host + ?Sized>(
interpreter: &mut Interpreter<WIRE>,
_host: &mut H,
)
*)
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.
destruct run_InterpreterTypes_for_WIRE.
destruct run_LoopControl_for_Control.
destruct run_StackTrait_for_Stack.
destruct (Impl_PartialOrd_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_gt
{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.gt [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_LoopControl_for_Control.
destruct run_StackTrait_for_Stack.
destruct (Impl_PartialOrd_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_slt
{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.slt [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_LoopControl_for_Control.
destruct run_StackTrait_for_Stack.
destruct Impl_PartialEq_for_Ordering.run.
run_symbolic.
Defined.

Instance run_sgt
{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.sgt [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_LoopControl_for_Control.
destruct run_StackTrait_for_Stack.
destruct Impl_PartialEq_for_Ordering.run.
run_symbolic.
Defined.

Instance run_bitwise_eq
{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.eq [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct (Impl_PartialEq_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_is_zero
{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.iszero [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
run_symbolic.
Defined.

Instance run_bitwise_bitand
{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.bitand [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct (Impl_BitAnd_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_bitor
{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.bitor [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct (Impl_BitOr_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_bitxor
{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.bitxor [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct (Impl_BitXor_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_not
{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.not [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct (Impl_Not_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_sar
{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.sar [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct run_RuntimeFlag_for_RuntimeFlag.
destruct Impl_TryFrom_u64_for_usize.run.
run_symbolic.
Defined.

Instance run_bitwise_shl
{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.shl [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct run_RuntimeFlag_for_RuntimeFlag.
destruct Impl_TryFrom_u64_for_usize.run.
destruct (Impl_Shl_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.

Instance run_bitwise_shr
{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.shr [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ]
unit.
Proof.
constructor.
destruct run_InterpreterTypes_for_WIRE.
destruct run_StackTrait_for_Stack.
destruct run_LoopControl_for_Control.
destruct run_RuntimeFlag_for_RuntimeFlag.
destruct Impl_TryFrom_u64_for_usize.run.
destruct (Impl_Shr_for_Uint.run {| Integer.value := 256 |} {| Integer.value := 4 |}).
run_symbolic.
Defined.
1 change: 1 addition & 0 deletions CoqOfRust/revm/revm_interpreter/instructions/links/i256.v
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Module Sign.
apply of_value_with_Zero.
Defined.
Smpl Add apply of_value_Zero : of_value.

Definition of_value_Plus :
OfValue.t (Value.StructTuple "revm_interpreter::instructions::i256::Sign::Plus" []).
Proof.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
- [x] `exp`
- [x] `signextend`

## Bitwise

- [x] `lt`
- [x] `gt`
- [x] `slt`
- [x] `sgt`
- [x] `bitwise_eq`
- [x] `bitwise_is_zero`
- [x] `bitwise_bitand`
- [x] `bitwise_bitor`
- [x] `bitwise_bitxor`
- [x] `bitwise_not`
- [x] `bitwise_sar`
- [x] `bitwise_shl`
- [x] `bitwise_shr`

## Block_info

- [x] `chainid`
Expand Down Expand Up @@ -147,7 +163,7 @@

## Summary

- Total: 107
- Total: 120
- Admitted: 37
- Defined: 70
- Percentage: 65.42%
- Defined: 83
- Percentage: 69.17%
Loading
Loading