Skip to content

Test: compute of the add function #10

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Definition add : MS? Evm.t Exception.t unit :=
letS? y := StateError.lift_lens Evm.Lens.stack pop in

(* GAS *)
letS? _ := charge_gas GAS_VERY_LOW in
(* letS? _ := charge_gas GAS_VERY_LOW in *)

(* OPERATION *)
let result := U256.wrapping_add x y in
Expand All @@ -43,3 +43,40 @@ Definition add : MS? Evm.t Exception.t unit :=
(inl tt, Uint.__add__ pc (Uint.Make 1))) in

returnS? tt.

Axiom environment : __init__.Environment.t.
Axiom message : __init__.Message.t Evm.t.

Definition empty_evm : Evm.t :=
Evm.Make message {|
Evm.Rest.pc := Uint.Make 0;
Evm.Rest.stack := [];
Evm.Rest.memory := [];
Evm.Rest.code := __init__.Bytes.Make [];
Evm.Rest.gas_left := Uint.Make 0;
Evm.Rest.env := environment;
Evm.Rest.valid_jump_destinations := [];
Evm.Rest.logs := [];
Evm.Rest.refund_counter := 0;
Evm.Rest.running := true;
Evm.Rest.output := __init__.Bytes.Make [];
Evm.Rest.accounts_to_delete := [];
Evm.Rest.touched_accounts := [];
Evm.Rest.return_data := __init__.Bytes.Make [];
Evm.Rest.error := None;
Evm.Rest.accessed_addresses := [];
Evm.Rest.accessed_storage_keys := [];
|}.

Definition evm_with_gas : Evm.t :=
Evm.Lens.gas_left.(Lens.write) empty_evm GAS_VERY_LOW.

Definition evm_with_stack : Evm.t :=
Evm.Lens.stack.(Lens.write) evm_with_gas [
U256.of_Z 12;
U256.of_Z 23
].

(* The term does not fully evaluate as the `charge_gas` function is still an axiom, so we have to
comment its call in the code above. *)
Compute (add evm_with_stack).
10 changes: 10 additions & 0 deletions CoqOfPython/ethereum/paris/vm/simulations/__init__.v
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,15 @@ Module Evm.
Lens.read '(Make _ rest) := rest.(Rest.memory);
Lens.write '(Make message rest) memory := Make message rest<|Rest.memory := memory|>;
|}.

Definition code : Lens.t t Bytes.t := {|
Lens.read '(Make _ rest) := rest.(Rest.code);
Lens.write '(Make message rest) code := Make message rest<|Rest.code := code|>;
|}.

Definition gas_left : Lens.t t Uint.t := {|
Lens.read '(Make _ rest) := rest.(Rest.gas_left);
Lens.write '(Make message rest) gas_left := Make message rest<|Rest.gas_left := gas_left|>;
|}.
End Lens.
End Evm.
Loading