Draft: WIP: Documentation of the proof of the multisig contract
6 unresolved threads
6 unresolved threads
Document the multisig example of smart contract verification.
Edited by Raphaël Cauderlier
Merge request reports
Activity
added doc label
added 18 commits
-
3d1fc0a5...e2e399cd - 16 commits from branch
master
- 80be3ad7 - [Doc][Refactoring][Multisig] Document the multisig smart-contract verification
- a69f6db0 - Michocott: add coqdoc.sty in .gitignore
-
3d1fc0a5...e2e399cd - 16 commits from branch
added 51 commits
-
0dbd040f...90bcdb93 - 49 commits from branch
master
- ed4622b3 - [Doc][Refactoring][Multisig] Document the multisig smart-contract verification
- e22bd2c0 - Michocott: add coqdoc.sty in .gitignore
-
0dbd040f...90bcdb93 - 49 commits from branch
242 Definition parameter_ty := (pair (pair nat action_ty) (list_ (option_ signature))). 243 244 Definition storage_ty := pair nat (pair nat (list_ key)). 245 #+END_SRC 246 247 We then axiomatize the protocol environment required for typing and evaluating Michelson contracts. We use a Coq [[https://coq.inria.fr/distrib/current/refman/language/gallina-extensions.html#section-mechanism][section]] and [[https://coq.inria.fr/distrib/current/refman/language/gallina-specification-language.html#coq:cmd.variable][section variables]] for this. 248 249 #+BEGIN_SRC coq 250 Section multisig. 251 252 Variables (get_contract_type : contract_constant -> error.M type) (env : @proto_env get_contract_type parameter_ty). 253 254 Definition instruction := @syntax.instruction get_contract_type parameter_ty. 255 #+END_SRC 256 257 Coq uses a di 303 DROP ;; DROP ;; 304 305 DIP ( UNPAIR ;; PUSH nat (nat_constant 1%N) ;; ADD ;; PAIR ) ;; 306 307 NIL operation ;; SWAP ;; 308 IF_LEFT 309 ( UNPAIR ;; UNIT ;; TRANSFER_TOKENS ;; CONS ) 310 ( IF_LEFT (SET_DELEGATE ;; CONS ) 311 ( DIP ( SWAP ;; CAR ) ;; SWAP ;; PAIR ;; SWAP )) ;; 312 PAIR ). 313 #+END_SRC 314 315 316 ** Functional Specification 317 318 ** 122 311 312 (** [pack_ty] is the type of the data that is packed before being signed. *) 313 Definition pack_ty := pair address (pair nat action_ty). 314 315 (** [multisig_spec] is the functional specification of the multisig 316 contract. It is a relation between the inputs ([counter], [action], 317 [sigs], [stored_counter], [threshold], and [keys]) and the outputs 318 ([new_stored_counter], [new_threshold], [new_keys], and 319 [returned_operations]) of the contract. 320 321 The main result is the theorem [multisig_correct] below. It states 322 that, assuming enough fuel is provided to compute the contract, 323 [multisig] evaluates successfully if and only if its input and outputs are related by the [multisig_spec] relation. 324 325 *) 123 326 155 | inr (inl kh) => 358 | inr (inl kh_opt) => 156 359 new_threshold = threshold /\ 157 360 new_keys = keys /\ 158 returned_operations = (set_delegate env kh :: nil)%list 361 returned_operations = (set_delegate env kh_opt :: nil)%list 159 362 | inr (inr (nt, nks)) => 160 363 new_threshold = nt /\ 161 364 new_keys = nks /\ 162 365 returned_operations = nil 163 366 end. 164 367 165 Definition multisig_head (then_ : instruction (nat ::: list key ::: list (option signature) ::: bytes ::: action_ty ::: storage_ty ::: nil) (pair (list operation) storage_ty ::: nil)) : 368 369 (** To ease verification, we split the multisig contracts in the 6 parts presented above. *) 370 Suggestion: more suggestive names than part_1, part_2 ..., e.g.
1. multisig_part_1_pack_payload 2. multisig_part_2_check_counter 3. multisig_part_3_check_sigs 4. multisig_part_4_check_treshold 5. multisig_part_5_inc_counter 6. multisig_part_6_perform_action
Edited by Arvid Jakobsson
507 (** 508 [more_fuel] changes the proof state from 509 ... Hfuel : N <= fuel |- C(fuel) where N is a positive constant to 510 ... Hfuel : N-1 <= fuel |- C(S(fuel)). 511 *) 512 513 Ltac more_fuel := 514 match goal with 515 | Hfuel : (_ <= ?fuel) |- _ => 516 destruct fuel as [|fuel]; 517 [inversion Hfuel; fail 518 | apply le_S_n in Hfuel] 519 end. 520 521 (** We now prove each part of the multisig contract. *) 522 242 Definition parameter_ty := (pair (pair nat action_ty) (list_ (option_ signature))). 243 244 Definition storage_ty := pair nat (pair nat (list_ key)). 245 #+END_SRC 246 247 We then axiomatize the protocol environment required for typing and evaluating Michelson contracts. We use a Coq [[https://coq.inria.fr/distrib/current/refman/language/gallina-extensions.html#section-mechanism][section]] and [[https://coq.inria.fr/distrib/current/refman/language/gallina-specification-language.html#coq:cmd.variable][section variables]] for this. 248 249 #+BEGIN_SRC coq 250 Section multisig. 251 252 Variables (get_contract_type : contract_constant -> error.M type) (env : @proto_env get_contract_type parameter_ty). 253 254 Definition instruction := @syntax.instruction get_contract_type parameter_ty. 255 #+END_SRC 256 257 Coq uses a di added smart-contract verification label
Please register or sign in to reply