Mina中的区块证明

1. 引言

  • exists:为向R1CS引入value,若request失败,则通过compute计算,若未提供compute,则返回失败。
    (** Introduce a value into the R1CS.
          - The [request] argument functions like {!val:request_witness}, creating
            a request and returning the result.
          - If no [request] argument is given, or if the [request] isn't handled,
            then [compute] is run to create a value.
    
          If [compute] is not given and [request] fails/is also not given, then
          this function raises a [Failure].
      *)
      val exists :
           ?request:'value Request.t As_prover.t
        -> ?compute:'value As_prover.t
        -> ('var, 'value) Typ.t
        -> 'var Checked.t
    
  • with_label:为constraint添加label,若验证该constraint为未satisfied,则该label将在错误消息中显示,
      (** Add a label to all of the constraints added in the checked computation.
          If a constraint is checked and isn't satisfied, this label will be shown
          in the error message.
      *)
      val with_label : string -> 'a Checked.t -> 'a Checked.t
    
  • run_state:为用于运行a checked computation的internal sate:
    (** The internal state used to run a checked computation. *)
    type 'field t =
      { system : 'field Constraint_system.t option
      ; input : 'field Vector.t
      ; aux : 'field Vector.t
      ; eval_constraints : bool
      ; num_inputs : int
      ; next_auxiliary : int ref
      ; has_witness : bool
      ; stack : string list
      ; handler : Request.Handler.t
      ; is_running : bool
      ; as_prover : bool ref
      ; log_constraint :
          (   ?at_label_boundary:[ `Start | `End ] * string
           -> ('field Cvar.t, 'field) Constraint.t
           -> unit)
          option
      }
    
    snark0.ml中将其初始状态设置为:
     let state =
      ref
        { system = None
        ; input = field_vec ()
        ; aux = field_vec ()
        ; eval_constraints = false
        ; num_inputs = 0
        ; next_auxiliary = ref 1
        ; has_witness = false
        ; stack = []
        ; handler = Request.Handler.fail
        ; is_running = false
        ; as_prover = ref false
        ; log_constraint = None
        }
    
  • Random_oracle_input.Chunked模块:定义了a random oracle的输入,由full field elements和‘chunks’ of fields结合为一个或多个field elements。chunks表示为[(field, length)],其中[0 <= field < 2^length]。这样可高效combine values in a known range。如:
    {[
    { field_elements= [||]; packeds= [|(x, 64); (y, 32); (z, 16)|] }
    ]}
    表示的为[x * 2^(32+16) + y * 2^(64) + z]。可通过pack_to_fields函数来实现。
    type 'field t =
    { field_elements : 'field array; packeds : ('field * int) array }
    [@@deriving sexp, compare]
    
    let append (t1 : _ t) (t2 : _ t) =
    { field_elements = Array.append t1.field_elements t2.field_elements
    ; packeds = Array.append t1.packeds t2.packeds
    }
    
  • Consensus_state_hooks.next_state_checked:对于特定的consensus state和snark transition,创建a constrainted, checked var for the next consensus state。为一个约束系统,见:let%snarkydef next_state_checked

附录1. Mina系列博客

Mina系列博客有:

猜你喜欢

转载自blog.csdn.net/mutourend/article/details/125185543