Skip to content

Commit

Permalink
Update ovn
Browse files Browse the repository at this point in the history
  • Loading branch information
cmester0 committed Mar 12, 2024
1 parent 4feb726 commit 96673f8
Show file tree
Hide file tree
Showing 7 changed files with 951 additions and 107 deletions.
2 changes: 1 addition & 1 deletion ovn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Lasse Letager Hanse <[email protected]>"]
edition = "2018"

[lib]
path = "src/ovn_group.rs"
path = "src/ovn_no_group.rs"

[dependencies]
hacspec-lib = { git = "https://github.com/hacspec/hacspec.git" }
Expand Down
12 changes: 5 additions & 7 deletions ovn/proofs/ssprove/extraction/Hacspec_ovn.v
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Equations cast_vote {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{ t_Ha
letb cast_vote_state_ret := f_clone state in
letb cast_vote_state_ret := Build_t_OvnContractState[cast_vote_state_ret] (f_g_pow_xi_yi_vis := update_at_usize (f_g_pow_xi_yi_vis cast_vote_state_ret) (cast_int (WS2 := _) (f_cvp_i params)) g_pow_xi_yi_vi) in
letb cast_vote_state_ret := Build_t_OvnContractState[cast_vote_state_ret] (f_zkp_vis := update_at_usize (f_zkp_vis cast_vote_state_ret) (cast_int (WS2 := _) (f_cvp_i params)) zkp_vi) in
Result_Ok (prod_b (f_accept (* (ret_both (tt : 'unit)) *),cast_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Result_Ok (prod_b (f_accept,cast_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Fail Next Obligation.

Equations commit_to_vote {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{ t_HasReceiveContext (impl_574521470_) ('unit)} (ctx : both (impl_574521470_)) (state : both (t_OvnContractState)) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)) :=
Expand All @@ -433,7 +433,7 @@ Equations commit_to_vote {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{
letb commit_vi := commit_to g_pow_xi_yi_vi in
letb commit_to_vote_state_ret := f_clone state in
letb commit_to_vote_state_ret := Build_t_OvnContractState[commit_to_vote_state_ret] (f_commit_vis := update_at_usize (f_commit_vis commit_to_vote_state_ret) (cast_int (WS2 := _) (f_cvp_i params)) commit_vi) in
Result_Ok (prod_b (f_accept (* (ret_both (tt : 'unit)) *),commit_to_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Result_Ok (prod_b (f_accept,commit_to_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Solve All Obligations with now intros ; destruct from_uint_size.
Fail Next Obligation.

Expand All @@ -459,7 +459,7 @@ Equations register_vote {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{ t
letb register_vote_state_ret := f_clone state in
letb register_vote_state_ret := Build_t_OvnContractState[register_vote_state_ret] (f_g_pow_xis := update_at_usize (f_g_pow_xis register_vote_state_ret) (cast_int (WS2 := _) (f_rp_i params)) g_pow_xi) in
letb register_vote_state_ret := Build_t_OvnContractState[register_vote_state_ret] (f_zkp_xis := update_at_usize (f_zkp_xis register_vote_state_ret) (cast_int (WS2 := _) (f_rp_i params)) zkp_xi) in
Result_Ok (prod_b (f_accept (* (ret_both (tt : 'unit)) *),register_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Result_Ok (prod_b (f_accept,register_vote_state_ret))))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Fail Next Obligation.

Equations tally_votes {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{ t_HasReceiveContext (impl_574521470_) ('unit)} (_ : both (impl_574521470_)) (state : both (t_OvnContractState)) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)) :=
Expand Down Expand Up @@ -491,7 +491,7 @@ Equations tally_votes {impl_574521470_ : _} `{ t_Sized (impl_574521470_)} `{ t_H
solve_lift (prod_b (curr,tally)) : both ((f_field_type × int32)))) (prod_b (curr,tally)) in
letb tally_votes_state_ret := f_clone state in
letb tally_votes_state_ret := Build_t_OvnContractState[tally_votes_state_ret] (f_tally := tally) in
Result_Ok (solve_lift (prod_b (f_accept (* (ret_both (tt : 'unit)) *),tally_votes_state_ret))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Result_Ok (solve_lift (prod_b (f_accept,tally_votes_state_ret))) : both (t_Result ((v_A × t_OvnContractState)) (t_ParseError)).
Solve All Obligations with now intros ; destruct from_uint_size.
Fail Next Obligation.

Expand Down Expand Up @@ -576,9 +576,7 @@ Next Obligation.
apply b.
Defined.
Fail Next Obligation.
Obligation Tactic := intros.

(* *)
Equations receive_OVN (chain : Chain) (ctx : ContractCallContext) (st : state_OVN) (msg : Datatypes.option (Msg_OVN)) : ResultMonad.result (state_OVN * list ActionBody) t_ParseError :=
receive_OVN chain ctx st msg :=
match msg with
Expand Down Expand Up @@ -609,7 +607,7 @@ Fail Next Obligation.

Ltac make_hacspec_serializable :=
(serialize_enum ; repeat (refine nseq_serializable ; serialize_enum)
; try ( exact f_group_type_Serializable
; try ( exact f_group_type_Serializable
|| exact f_field_type_Serializable
|| exact hacspec_int_serializable
|| exact bool_serializable
Expand Down
140 changes: 140 additions & 0 deletions ovn/proofs/ssprove/extraction/Hacspec_ovn_Ovn_z_89_.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
(* File automatically generated by Hacspec *)
Set Warnings "-notation-overridden,-ambiguous-paths".
From Crypt Require Import choice_type Package Prelude.
Import PackageNotation.
From extructures Require Import ord fset.
From mathcomp Require Import word_ssrZ word.
From Jasmin Require Import word.

From Coq Require Import ZArith.
From Coq Require Import Strings.String.
Import List.ListNotations.
Open Scope list_scope.
Open Scope Z_scope.
Open Scope bool_scope.

From Hacspec Require Import ChoiceEquality.
From Hacspec Require Import LocationUtility.
From Hacspec Require Import Hacspec_Lib_Comparable.
From Hacspec Require Import Hacspec_Lib_Pre.
From Hacspec Require Import Hacspec_Lib.

Open Scope hacspec_scope.
Import choice.Choice.Exports.

Obligation Tactic := (* try timeout 8 *) solve_ssprove_obligations.

Require Import Hacspec_ovn_Ovn_traits.
Export Hacspec_ovn_Ovn_traits.

Definition t_g_z_89_ : choice_type :=
'unit.
Equations Build_t_g_z_89_ : both (fset []) (fset []) (t_g_z_89_) :=
Build_t_g_z_89_ :=
solve_lift (ret_both (tt (* Empty tuple *) : (t_g_z_89_))) : both (fset []) (fset []) (t_g_z_89_).
Fail Next Obligation.

Definition t_z_89_ : choice_type :=
'unit.
Equations Build_t_z_89_ : both (fset []) (fset []) (t_z_89_) :=
Build_t_z_89_ :=
solve_lift (ret_both (tt (* Empty tuple *) : (t_z_89_))) : both (fset []) (fset []) (t_z_89_).
Fail Next Obligation.

#[global] Program Instance t_z_89__t_Z_Field : t_Z_Field t_z_89_ := _.
Next Obligation.
refine (
let f_field_type := int32 : choice_type in
let f_q := fun {L : {fset Location}} {I : Interface} => solve_lift (ret_both (89 : int32)) : both (L :|: fset []) I int32 in
let f_random_field_elem := fun {L1 : {fset Location}} {I1 : Interface} (random : both L1 I1 int32) => solve_lift (random .% ((f_q ) .- (ret_both (1 : int32)))) : both (L1 :|: fset []) I1 int32 in
let f_field_zero := fun {L : {fset Location}} {I : Interface} => solve_lift (ret_both (0 : int32)) : both (L :|: fset []) I int32 in
let f_field_one := fun {L : {fset Location}} {I : Interface} => solve_lift (ret_both (1 : int32)) : both (L :|: fset []) I int32 in
let f_add := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (x : both L1 I1 int32) (y : both L2 I2 int32) => solve_lift ((x .+ y) .% ((f_q ) .- (ret_both (1 : int32)))) : both (L1 :|: L2 :|: fset []) (I1 :|: I2) int32 in
let f_sub := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (x : both L1 I1 int32) (y : both L2 I2 int32) => solve_lift (((x .+ ((f_q ) .- (ret_both (1 : int32)))) .- y) .% ((f_q ) .- (ret_both (1 : int32)))) : both (L1 :|: L2 :|: fset []) (I1 :|: I2) int32 in
let f_mul := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (x : both L1 I1 int32) (y : both L2 I2 int32) => solve_lift ((x .* y) .% ((f_q ) .- (ret_both (1 : int32)))) : both (L1 :|: L2 :|: fset []) (I1 :|: I2) int32 in
{| f_field_type := (@f_field_type);
f_q_loc := (fset [] : {fset Location});
f_q := (@f_q);
f_random_field_elem_loc := (fset [] : {fset Location});
f_random_field_elem := (@f_random_field_elem);
f_field_zero_loc := (fset [] : {fset Location});
f_field_zero := (@f_field_zero);
f_field_one_loc := (fset [] : {fset Location});
f_field_one := (@f_field_one);
f_add_loc := (fset [] : {fset Location});
f_add := (@f_add);
f_sub_loc := (fset [] : {fset Location});
f_sub := (@f_sub);
f_mul_loc := (fset [] : {fset Location});
f_mul := (@f_mul)|}
).
easy.
easy.
easy.
easy.
easy.
exact int_eqdec.
easy.
easy.
Unshelve.
all: try normalize_fset.
all: try solve_single_fset_fsubset.

unfold f_parameter_cursor_loc.

Next Obligation.
unfold t_z_89__t_Z_Field_obligation_4.
Fail Next Obligation.
Hint Unfold t_z_89__t_Z_Field.

Definition res_loc : Location :=
(int32;0%nat).
Definition result_loc : Location :=
(int32;1%nat).
#[global] Program Instance t_g_z_89__t_Group : t_Group t_g_z_89_ t_z_89_ :=
let f_group_type := int32 : choice_type in
let f_g := fun {L : {fset Location}} {I : Interface} => solve_lift (ret_both (3 : int32)) : both (L :|: fset []) I int32 in
let f_hash := fun {L1 : {fset Location}} {I1 : Interface} (x : both L1 I1 (t_Vec int32 t_Global)) => letb res loc(res_loc) := f_field_one (ret_both (tt : 'unit)) in
letb _ := foldi_both_list (f_into_iter x) (fun y =>
ssp (fun _ =>
assign todo(term) : (both (*1*)(L1:|:fset [res_loc]) (I1) 'unit))) (ret_both (tt : 'unit)) in
solve_lift res : both (L1 :|: fset [res_loc]) I1 int32 in
let f_g_pow := fun {L1 : {fset Location}} {I1 : Interface} (x : both L1 I1 int32) => solve_lift (f_pow (f_g (ret_both (tt : 'unit))) x) : both (L1 :|: fset []) I1 int32 in
let f_pow := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (g : both L1 I1 int32) (x : both L2 I2 int32) => letb result loc(result_loc) := f_group_one (ret_both (tt : 'unit)) in
letb _ := foldi_both_list (f_into_iter (Build_t_Range (f_start := ret_both (0 : int32)) (f_end := x .% ((f_q (ret_both (tt : 'unit))) .- (ret_both (1 : int32)))))) (fun i =>
ssp (fun _ =>
assign todo(term) : (both (*1*)(L1:|:L2:|:fset [result_loc]) (I1:|:I2) 'unit))) (ret_both (tt : 'unit)) in
solve_lift result : both (L1 :|: L2 :|: fset [result_loc]) (I1 :|: I2) int32 in
let f_group_one := fun {L : {fset Location}} {I : Interface} => solve_lift (ret_both (1 : int32)) : both (L :|: fset []) I int32 in
let f_prod := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (x : both L1 I1 int32) (y : both L2 I2 int32) => solve_lift (((x .% (f_q (ret_both (tt : 'unit)))) .* (y .% (f_q (ret_both (tt : 'unit))))) .% (f_q (ret_both (tt : 'unit)))) : both (L1 :|: L2 :|: fset []) (I1 :|: I2) int32 in
let f_inv := fun {L1 : {fset Location}} {I1 : Interface} (x : both L1 I1 int32) => solve_lift (run (letb _ := foldi_both_list (f_into_iter (Build_t_Range (f_start := ret_both (0 : int32)) (f_end := ret_both (89 : int32)))) (fun j =>
ssp (fun _ =>
solve_lift (ifb (f_prod x j) =.? (f_group_one (ret_both (tt : 'unit)))
then letm[choice_typeMonad.result_bind_code int32] hoist1 := v_Break j in
ControlFlow_Continue (never_to_any hoist1)
else ()) : (both (*0*)(L1:|:fset []) (I1) (t_ControlFlow int32 'unit)))) (ret_both (tt : 'unit)) in
letb _ := ifb not (ret_both (false : 'bool))
then never_to_any (panic (ret_both (assertion failed: false : chString)))
else () in
letm[choice_typeMonad.result_bind_code int32] hoist2 := v_Break x in
ControlFlow_Continue (never_to_any hoist2))) : both (L1 :|: fset []) I1 int32 in
let f_div := fun {L1 : {fset Location}} {L2 : {fset Location}} {I1 : Interface} {I2 : Interface} (x : both L1 I1 int32) (y : both L2 I2 int32) => solve_lift (f_prod x (f_inv y)) : both (L1 :|: L2 :|: fset []) (I1 :|: I2) int32 in
{| f_group_type := (@f_group_type);
f_g_loc := (fset [] : {fset Location});
f_g := (@f_g);
f_hash_loc := (fset [res_loc] : {fset Location});
f_hash := (@f_hash);
f_g_pow_loc := (fset [] : {fset Location});
f_g_pow := (@f_g_pow);
f_pow_loc := (fset [result_loc] : {fset Location});
f_pow := (@f_pow);
f_group_one_loc := (fset [] : {fset Location});
f_group_one := (@f_group_one);
f_prod_loc := (fset [] : {fset Location});
f_prod := (@f_prod);
f_inv_loc := (fset [] : {fset Location});
f_inv := (@f_inv);
f_div_loc := (fset [] : {fset Location});
f_div := (@f_div)|}.
Fail Next Obligation.
Hint Unfold t_g_z_89__t_Group.
Loading

0 comments on commit 96673f8

Please sign in to comment.