Skip to content
Snippets Groups Projects

Draft: WIP: Documentation of the proof of the multisig contract

Open Raphaël Cauderlier requested to merge raphael@tuto into master
6 unresolved threads

Document the multisig example of smart contract verification.

Edited by Raphaël Cauderlier

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 **
  • Arvid Jakobsson
    Arvid Jakobsson @arvidnl started a thread on commit ed4622b3
  • 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
  • Arvid Jakobsson
    Arvid Jakobsson @arvidnl started a thread on commit ed4622b3
  • 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
    • Please register or sign in to reply
  • Arvid Jakobsson
    Arvid Jakobsson @arvidnl started a thread on commit ed4622b3
  • 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
  • Bruno B
    Bruno B @onurb started a thread on an outdated change in commit ed4622b3
  • 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
  • Raphaël Cauderlier marked as a Work In Progress

    marked as a Work In Progress

  • Raphaël Cauderlier marked this merge request as draft

    marked this merge request as draft

  • Please register or sign in to reply
    Loading