multisigv2 with less user uncertainty
This commit is contained in:
parent
b82383751c
commit
c8eb1a3fa6
@ -75,8 +75,8 @@ let e'_bytes b : expression' result =
|
||||
let e_bytes ?loc b : expression result =
|
||||
let%bind e' = e'_bytes b in
|
||||
ok @@ location_wrap ?loc e'
|
||||
let e_bytes_ofbytes ?loc (b: bytes) : expression result =
|
||||
ok @@ location_wrap ?loc @@ E_literal (Literal_bytes b)
|
||||
let e_bytes_ofbytes ?loc (b: bytes) : expression =
|
||||
location_wrap ?loc @@ E_literal (Literal_bytes b)
|
||||
let e_big_map ?loc lst : expression = location_wrap ?loc @@ E_big_map lst
|
||||
let e_record ?loc map : expression = location_wrap ?loc @@ E_record map
|
||||
let e_tuple ?loc lst : expression = location_wrap ?loc @@ E_tuple lst
|
||||
|
@ -61,7 +61,7 @@ val e_chain_id : ?loc:Location.t -> string -> expression
|
||||
val e_mutez : ?loc:Location.t -> int -> expression
|
||||
val e'_bytes : string -> expression' result
|
||||
val e_bytes : ?loc:Location.t -> string -> expression result
|
||||
val e_bytes_ofbytes : ?loc:Location.t -> bytes -> expression result
|
||||
val e_bytes_ofbytes : ?loc:Location.t -> bytes -> expression
|
||||
val e_big_map : ?loc:Location.t -> ( expr * expr ) list -> expression
|
||||
(*
|
||||
val e_record : ?loc:Location.t -> ( expr * expr ) list -> expression
|
||||
|
@ -2,11 +2,13 @@
|
||||
type threshold_t is nat
|
||||
type max_proposal_t is nat
|
||||
type max_message_size_t is nat
|
||||
type state_hash_t is bytes
|
||||
type addr_set_t is set(address)
|
||||
type message_store_t is map(bytes,addr_set_t)
|
||||
type counter_store_t is map(address,nat)
|
||||
|
||||
type storage_t is record
|
||||
state_hash : state_hash_t ;
|
||||
threshold : threshold_t ;
|
||||
max_proposal : max_proposal_t ;
|
||||
max_message_size : max_message_size_t ;
|
||||
@ -16,7 +18,7 @@ type storage_t is record
|
||||
end
|
||||
|
||||
// I/O types
|
||||
type message_t is (unit -> list(operation))
|
||||
type message_t is (bytes -> list(operation))
|
||||
type send_pt is message_t
|
||||
type withdraw_pt is message_t
|
||||
|
||||
@ -56,7 +58,8 @@ function send (const param : send_pt; const s : storage_t) : contract_return_t i
|
||||
|
||||
if size(new_store) >= s.threshold then block {
|
||||
remove packed_msg from map s.message_store ;
|
||||
ret_ops := message(unit) ;
|
||||
ret_ops := message(s.state_hash) ;
|
||||
s.state_hash := sha_256 ( bytes_concat (s.state_hash , packed_msg) ) ;
|
||||
s.counter_store[sender] := abs (sender_proposal_counter - 1n) ;
|
||||
} else
|
||||
s.message_store[packed_msg] := new_store
|
||||
|
@ -25,23 +25,24 @@ open Ast_simplified
|
||||
let empty_op_list =
|
||||
(e_typed_list [] t_operation)
|
||||
let empty_message = e_lambda "arguments"
|
||||
(Some t_unit) (Some (t_list t_operation))
|
||||
(Some t_bytes) (Some (t_list t_operation))
|
||||
empty_op_list
|
||||
let empty_message2 = e_lambda "arguments"
|
||||
(Some t_unit) (Some (t_list t_operation))
|
||||
(Some t_bytes) (Some (t_list t_operation))
|
||||
( e_let_in ("foo",Some t_unit) (e_unit ()) empty_op_list)
|
||||
|
||||
let send_param msg = e_constructor "Send" msg
|
||||
let withdraw_param = e_constructor "Withdraw" empty_message
|
||||
|
||||
type st_type = {
|
||||
state_hash : bytes ;
|
||||
threshold:int ;
|
||||
max_proposal:int ;
|
||||
max_msg_size:int ;
|
||||
id_counter_list: (int * int) list ;
|
||||
msg_store_list: (expression * expression) list ;
|
||||
}
|
||||
let storage {threshold ; max_proposal ; max_msg_size ; id_counter_list ; msg_store_list} =
|
||||
let storage {state_hash ; threshold ; max_proposal ; max_msg_size ; id_counter_list ; msg_store_list} =
|
||||
let auth_set,counter_store = List.fold_left
|
||||
(fun (auth_set,counter_st) (id,ctr) ->
|
||||
let addr_exp = e_address @@ addr id in
|
||||
@ -49,6 +50,7 @@ let storage {threshold ; max_proposal ; max_msg_size ; id_counter_list ; msg_sto
|
||||
([],[])
|
||||
id_counter_list in
|
||||
e_ez_record [
|
||||
("state_hash" , e_bytes_ofbytes state_hash ) ;
|
||||
("threshold" , e_nat threshold ) ;
|
||||
("max_proposal" , e_nat max_proposal ) ;
|
||||
("max_message_size", e_nat max_msg_size ) ;
|
||||
@ -61,7 +63,7 @@ let storage {threshold ; max_proposal ; max_msg_size ; id_counter_list ; msg_sto
|
||||
let wrong_addr () =
|
||||
let%bind program,_ = get_program () in
|
||||
let init_storage = storage {
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 1 ;
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 1 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,0 ; 2,0] ;
|
||||
msg_store_list = []
|
||||
} in
|
||||
@ -77,7 +79,7 @@ let wrong_addr () =
|
||||
let message_size_exceeded () =
|
||||
let%bind program,_ = get_program () in
|
||||
let init_storage = storage {
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 1 ;
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 1 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,0] ;
|
||||
msg_store_list = []
|
||||
} in
|
||||
@ -93,9 +95,9 @@ let message_size_exceeded () =
|
||||
let maximum_number_of_proposal () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload1 = pack_payload program (send_param empty_message) in
|
||||
let%bind bytes1 = e_bytes_ofbytes packed_payload1 in
|
||||
let bytes1 = e_bytes_ofbytes packed_payload1 in
|
||||
let init_storage = storage {
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 15 ;
|
||||
threshold = 1 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,1] ;
|
||||
msg_store_list = [(bytes1, e_set [e_address@@ addr 1])]
|
||||
} in
|
||||
@ -111,9 +113,9 @@ let maximum_number_of_proposal () =
|
||||
let send_already_accounted () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload = pack_payload program empty_message in
|
||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||
let bytes = e_bytes_ofbytes packed_payload in
|
||||
let init_storage = storage {
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ;
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,1 ; 2,0] ;
|
||||
msg_store_list = [(bytes, e_set [e_address@@ addr 1])]
|
||||
} in
|
||||
@ -127,9 +129,9 @@ let send_already_accounted () =
|
||||
let send_never_accounted () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload = pack_payload program empty_message in
|
||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||
let bytes = e_bytes_ofbytes packed_payload in
|
||||
let init_storage' = {
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ;
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,0 ; 2,0] ;
|
||||
msg_store_list = []
|
||||
} in
|
||||
@ -148,10 +150,10 @@ let send_never_accounted () =
|
||||
let withdraw_already_accounted_one () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload = pack_payload program empty_message in
|
||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||
let bytes = e_bytes_ofbytes packed_payload in
|
||||
let param = withdraw_param in
|
||||
let init_storage' = {
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 1 ;
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 1 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,1 ; 2,0] ;
|
||||
msg_store_list = [(bytes, e_set [e_address@@ addr 1])] ;
|
||||
} in
|
||||
@ -169,10 +171,10 @@ let withdraw_already_accounted_one () =
|
||||
let withdraw_already_accounted_two () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload = pack_payload program empty_message in
|
||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||
let bytes = e_bytes_ofbytes packed_payload in
|
||||
let param = withdraw_param in
|
||||
let init_storage' = {
|
||||
threshold = 2 ; max_proposal = 2 ; max_msg_size = 1 ;
|
||||
threshold = 2 ; max_proposal = 2 ; max_msg_size = 1 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,1 ; 2,1] ;
|
||||
msg_store_list = [(bytes, e_set [e_address@@ addr 1; e_address@@ addr 2])] ;
|
||||
} in
|
||||
@ -191,7 +193,7 @@ let withdraw_never_accounted () =
|
||||
let%bind program,_ = get_program () in
|
||||
let param = withdraw_param in
|
||||
let init_storage = storage {
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 1 ;
|
||||
threshold = 2 ; max_proposal = 1 ; max_msg_size = 1 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,0 ; 2,0] ;
|
||||
msg_store_list = [] ;
|
||||
} in
|
||||
@ -205,9 +207,9 @@ let withdraw_never_accounted () =
|
||||
let succeeded_storing () =
|
||||
let%bind program,_ = get_program () in
|
||||
let%bind packed_payload = pack_payload program empty_message in
|
||||
let%bind bytes = e_bytes_ofbytes packed_payload in
|
||||
let bytes = e_bytes_ofbytes packed_payload in
|
||||
let init_storage th = {
|
||||
threshold = th ; max_proposal = 1 ; max_msg_size = 15 ;
|
||||
threshold = th ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ;
|
||||
id_counter_list = [1,0 ; 2,0 ; 3,0] ;
|
||||
msg_store_list = [(bytes, e_typed_set [] t_address)] ;
|
||||
} in
|
||||
@ -220,11 +222,13 @@ let succeeded_storing () =
|
||||
ok @@ e_pair (send_param empty_message) init_storage
|
||||
)
|
||||
(fun th ->
|
||||
let final_id_counter, final_msg_store, ret = match th with
|
||||
| 1 -> [1,0 ; 2,0 ; 3,0] , [] , empty_op_list
|
||||
| 2 -> [1,1 ; 2,0 ; 3,0] , [(bytes, e_set [e_address@@ addr 1])] , empty_op_list
|
||||
let hash_after_msg = sha_256_hash (Bytes.concat Bytes.empty [Bytes.empty ; packed_payload]) in
|
||||
let final_id_counter, final_msg_store, ret, final_state_hash = match th with
|
||||
| 1 -> [1,0 ; 2,0 ; 3,0] , [] , empty_op_list , hash_after_msg
|
||||
| 2 -> [1,1 ; 2,0 ; 3,0] , [(bytes, e_set [e_address@@ addr 1])] , empty_op_list , (init_storage th).state_hash
|
||||
| _ -> assert false in
|
||||
let final_storage = storage { (init_storage th) with
|
||||
state_hash = final_state_hash ;
|
||||
msg_store_list = final_msg_store ;
|
||||
id_counter_list = final_id_counter } in
|
||||
ok @@ e_pair ret final_storage
|
||||
|
@ -70,6 +70,10 @@ let str_keys (raw_pkh, raw_pk, raw_sk) =
|
||||
let pkh_str = Signature.Public_key_hash.to_b58check raw_pkh in
|
||||
(pkh_str,pk_str,sk_str)
|
||||
|
||||
let sha_256_hash pl =
|
||||
let open Proto_alpha_utils.Memory_proto_alpha.Alpha_environment in
|
||||
Raw_hashes.sha256 pl
|
||||
|
||||
open Ast_simplified.Combinators
|
||||
|
||||
let expect ?options program entry_point input expecter =
|
||||
|
Loading…
Reference in New Issue
Block a user