1. 引言

前序博客有:

  • Mina中的支付交易snark(针对Payment交易)
  • Mina的zkApp
  • Mina中的树结构 ——账号树

Mina中的user_command交易目前有:

  • 1)Signed_command交易:

    • 1.1)Payment交易
    • 1.2)Stake_delegation交易
  • 2)Parties交易

2. Parties交易结构

Parties.Stable.V1.t结构为:

 type t ={ fee_payer : Party.Fee_payer.Stable.V1.t; other_parties :( Party.Stable.V1.t, Digest.Party.Stable.V1.t, Digest.Forest.Stable.V1.t )Call_forest.Stable.V1.t; memo : Signed_command_memo.Stable.V1.t (* 为string *)}

其中:

  • 1)fee_payer字段,Party.Fee_payer.Stable.V1.t结构为:

    type t ={ body : Body.Fee_payer.Stable.V1.t; authorization : Signature.Stable.V1.t (* 为Schnorr签名:Field.t * Inner_curve.Scalar.t *)}
    
    • 1.1)fee_payer.body字段,Body.Fee_payer.Stable.V1.t结构为:

      (* 《1》 body字段,Body.Fee_payer.Stable.V1.t结构为: *)type t ={ public_key : Public_key.Compressed.Stable.V1.t (* 压缩公钥 *); update : Update.Stable.V1.t (* 包含app_state、delegate、verification_key、permissions、zkapp_uri、token_symbol、timing、voting_for这8个字段。 *); fee : Fee.Stable.V1.t (* 为Unsigned.UInt64.t *); events : Events'.Stable.V1.t (* 为Pickles.Backend.Tick.Field.Stable.V1.t array list *); sequence_events : Events'.Stable.V1.t (* 为Pickles.Backend.Tick.Field.Stable.V1.t array list *); protocol_state_precondition :Zkapp_precondition.Protocol_state.Stable.V1.t (* 包含snarked_ledger_hash、timestamp、blockchain_length、min_window_density、last_vrf_output、total_currency、global_slot_since_hard_fork、global_slot_since_genesis、staking_epoch_data和next_epoch_data这10个字段。 *)[@name "networkPrecondition"]; nonce : Account_nonce.Stable.V1.t (* 为Unsigned_extended.UInt32.t *)}
      (* 《1.1》 body.update字段,Update.Stable.V1.t结构为: *)type t ={ app_state :F.Stable.V1.t Set_or_keep.Stable.V1.t Zkapp_state.V.Stable.V1.t (* 为8 fields(Set或Keep类型) of 32 bytes each of arbitrary storage *); delegate : Public_key.Compressed.Stable.V1.t Set_or_keep.Stable.V1.t (* 为Set或Keep类型的压缩公钥 *); verification_key :( Pickles.Side_loaded.Verification_key.Stable.V2.t, F.Stable.V1.t )With_hash.Stable.V1.tSet_or_keep.Stable.V1.t (* 为Set或Keep类型,可包含data(包含max_width、wrap_index和wrap_vk三个字段)和hash两个字段。 *); permissions : Permissions.Stable.V2.t Set_or_keep.Stable.V1.t (* 为Set或Keep类型,包含edit_state、send、receive、set_delegate、set_permissions、set_verification_key、set_zkapp_uri、edit_sequence_state、set_token_symbol、increment_nonce、set_voting_for共11个字段,均为Auth_required枚举类型:None | Either | Proof | Signature | Impossible。 *); zkapp_uri : string Set_or_keep.Stable.V1.t (* 为Set或Keep类型,string *); token_symbol :Account.Token_symbol.Stable.V1.t Set_or_keep.Stable.V1.t  (* 为Set或Keep类型,string *); timing : Timing_info.Stable.V1.t Set_or_keep.Stable.V1.t (* 为Set或Keep类型,包含:initial_minimum_balance(为Unsigned.UInt64.t类型)、cliff_time(为global_slot,Unsigned_extended.UInt32.t类型)、cliff_amount(为Unsigned.UInt64.t类型)、vesting_period(为global_slot,Unsigned_extended.UInt32.t类型)、vesting_increment(为Unsigned.UInt64.t类型)这5个字段。; voting_for : State_hash.Stable.V1.t Set_or_keep.Stable.V1.t (* 为Set或Keep类型,Field.t哈希值。 *)}
      (* 《1.1.1》body.update.verification_key字段,为With_hash.Stable.V1.t  Set_or_keep.Stable.V1.t,其中With_hash.Stable.V1.t结构为: *)type ('a, 'h) t = { data : 'a; hash : 'h } (* hash字段为F.t结构 *)(* 其中data字段,为 Side_loaded_verification_key.Stable.V2.t结构为:*)type t =( G.Stable.V1.t (* 为曲线上的point。 *), unit )Pickles_base.Side_loaded_verification_key.Poly.Stable.V2.ttype ('g, 'vk) t = (* 其中‘vk为 uint。 *){ max_width : Width.Stable.V1.t (* 对应为char类型 *); wrap_index : 'g Plonk_verification_key_evals.Stable.V2.t (* 包含sigma_comm/coefficients_comm/generic_comm/psm_comm/complete_add_comm/mul_comm/emul_comm/endomul_scalar_comm这8个字段。 *); wrap_vk : 'vk option (* 其中‘vk为 uint。 *)}(* wrap_index字段,为Plonk_verification_key_evals.Stable.V2.t结构: *)type 'comm t = (* 'comm对应为 G.Stable.V1.t结构 *){ sigma_comm : 'comm Plonk_types.Permuts_vec.Stable.V1.t; coefficients_comm : 'comm Plonk_types.Columns_vec.Stable.V1.t; generic_comm : 'comm; psm_comm : 'comm; complete_add_comm : 'comm; mul_comm : 'comm; emul_comm : 'comm; endomul_scalar_comm : 'comm}
      (* 《1.1.2》body.update.permissions字段,为 Permissions.Stable.V2.t Set_or_keep.Stable.V1.t结构,其中Permissions.Stable.V2.t 结构为: *)
      type t = Auth_required.Stable.V2.t Poly.Stable.V2.t
      type 'controller t =  (* 此处 'controller 为 Auth_required为枚举类型:None | Either | Proof | Signature | Impossible *){ edit_state : 'controller; send : 'controller; receive : 'controller (* TODO: Consider having fee *); set_delegate : 'controller; set_permissions : 'controller; set_verification_key : 'controller; set_zkapp_uri : 'controller; edit_sequence_state : 'controller; set_token_symbol : 'controller; increment_nonce : 'controller; set_voting_for : 'controller}
      (* 《1.2》 body.protocol_state_precondition,为Zkapp_precondition.Protocol_state.Stable.V1.t结构: *)
      type t =( Frozen_ledger_hash.Stable.V1.t Hash.Stable.V1.t (* 哈希值,为Check of Field 或 Ignore类型。 *), Block_time.Stable.V1.t Numeric.Stable.V1.t (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *), Length.Stable.V1.t Numeric.Stable.V1.t  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *), unit (* TODO *), Global_slot.Stable.V1.t Numeric.Stable.V1.t  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *), Currency.Amount.Stable.V1.t Numeric.Stable.V1.t (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *), Epoch_data.Stable.V1.t ) (* 包含ledger、seed、start_checkpoint、lock_checkpoint、epoch_length这5个字段。 *)Poly.Stable.V1.t
      type ( 'snarked_ledger_hash (* 哈希值,为Check of Field 或 Ignore类型。 *), 'time  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *), 'length  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *), 'vrf_output (* 为unit *), 'global_slot  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *), 'amount (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *), 'epoch_data ) (* 包含ledger、seed、start_checkpoint、lock_checkpoint、epoch_length这5个字段。 *)t ={ (* TODO:We should include staged ledger hash again! It only changes once perblock. *)snarked_ledger_hash : 'snarked_ledger_hash (* 哈希值,为Check of Field 或 Ignore类型。 *); timestamp : 'time  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *); blockchain_length : 'length  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *)(* TODO: This previously had epoch_count but I removed it as I believe it is redundantwith global_slot_since_hard_fork.epoch_count in [a, b]should be equivalent toglobal_slot_since_hard_fork in [slots_per_epoch * a, slots_per_epoch * b]*); min_window_density : 'length  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *); last_vrf_output : 'vrf_output [@skip] (* 为unit *); total_currency : 'amount  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned.UInt64.t类型 *); global_slot_since_hard_fork : 'global_slot  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *); global_slot_since_genesis : 'global_slot  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *); staking_epoch_data : 'epoch_data (* 包含ledger、seed、start_checkpoint、lock_checkpoint、epoch_length这5个字段。 *); next_epoch_data : 'epoch_data (* 包含ledger、seed、start_checkpoint、lock_checkpoint、epoch_length这5个字段。 *)}
      (* 《1.2.1》 staking_epoch_data和next_epoch_data字段,为Epoch_data.Stable.V1.t结构: *)type t =( ( Frozen_ledger_hash.Stable.V1.t Hash.Stable.V1.t , Currency.Amount.Stable.V1.t Numeric.Stable.V1.t ) (* 为Check或Ignore类型,为二元结构,分别为Field.t哈希值 和  包含lower和upper字段(均为Unsigned.UInt64.t类型)的Currency.Amount *)Epoch_ledger.Poly.Stable.V1.t (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *), Epoch_seed.Stable.V1.t Hash.Stable.V1.t (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *), State_hash.Stable.V1.t Hash.Stable.V1.t (* 为Check或Ignore类型,为Field.t *), State_hash.Stable.V1.t Hash.Stable.V1.t (* 为Check或Ignore类型,为Field.t *), Length.Stable.V1.t Numeric.Stable.V1.t ) (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *)Poly.Stable.V1.t
      type ( 'epoch_ledger (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *), 'epoch_seed (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *), 'start_checkpoint (* 为Check或Ignore类型,为Field.t *), 'lock_checkpoint (* 为Check或Ignore类型,为Field.t *), 'length )  (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *)t ={ ledger : 'epoch_ledger (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *); seed : 'epoch_seed (* 为Check或Ignore类型,为Snark_params.Tick.Field.t *); start_checkpoint : 'start_checkpoint (* 为Check或Ignore类型,为Field.t *)(* The lock checkpoint is the hash of the latest state in the seed update range, not includingthe current state. *); lock_checkpoint : 'lock_checkpoint (* 为Check或Ignore类型,为Field.t *); epoch_length : 'length (* 为Check或Ignore类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t类型 *)}
      
  • 2)other_parties字段,Call_forest.Stable.V1.t结构为:
    other_parties :( Party.Stable.V1.t (* 包含body和authorization两个字段 *), Digest.Party.Stable.V1.t (* 为Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t *), Digest.Forest.Stable.V1.t ) (* 为Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t *)Call_forest.Stable.V1.t
    

    其中other_parties字段为树list结构(即forest):

    type ('party, 'party_digest, 'digest) t =( ('party, 'party_digest, 'digest) Tree.Stable.V1.t, 'digest )With_stack_hash.Stable.V1.t (* 包含elt(为树结构) 和  stack_hash(为Digest.Forest结构)*)list
    

    其中的 Tree.Stable.V1.t结构为:

            type ('party, 'party_digest, 'digest) t ={ party : 'party; party_digest : 'party_digest; calls :( ('party, 'party_digest, 'digest) t (* 包含elt(为树结构) 和  stack_hash(为Digest.Forest结构)*), 'digest )With_stack_hash.Stable.V1.tlist}
    

    其中Party.Stable.V1.t结构为(A party to a zkApp transaction):

    (** A party to a zkApp transaction *)type t = { body : Body.Stable.V1.t; authorization : Control.Stable.V2.t }
    (* 《1》authorization 字段,Control.Stable.V2.t结构为: *)
    type t =| Proof of Pickles.Side_loaded.Proof.Stable.V2.t| Signature of Signature.Stable.V1.t (* Mina的Schnorr签名 *)| None_given(* Proof枚举类型时,【本质为Wrap proof(Base.Wrap.t结构)】Pickles.Side_loaded.Proof.Stable.V2.t结构为: *)
    type t =(Verification_key.Max_width.n, Verification_key.Max_width.n) Proof.t
    type t =( ( Tock.Inner_curve.Affine.Stable.V1.t, Reduced_me_only.Wrap.Challenges_vector.Stable.V2.tSide_loaded_verification_key.Width.Max_vector.Stable.V1.t )Types.Wrap.Proof_state.Me_only.Stable.V1.t, ( unit, Tock.Curve.Affine.tSide_loaded_verification_key.Width.Max_at_most.Stable.V1.t, Limb_vector.Constant.Hex64.Stable.V1.t Vector.Vector_2.Stable.V1.tScalar_challenge.Stable.V2.tBulletproof_challenge.Stable.V1.tStep_bp_vec.Stable.V1.tSide_loaded_verification_key.Width.Max_at_most.Stable.V1.t )Base.Me_only.Step.Stable.V1.t )Base.Wrap.Stable.V2.t
    type ('dlog_me_only, 'step_me_only) t ={ statement :( Limb_vector.Constant.Hex64.Stable.V1.tVector.Vector_2.Stable.V1.t, Limb_vector.Constant.Hex64.Stable.V1.tVector.Vector_2.Stable.V1.tScalar_challenge.Stable.V2.t, Tick.Field.Stable.V1.t Shifted_value.Type1.Stable.V1.t, Tock.Field.Stable.V1.t, 'dlog_me_only, Digest.Constant.Stable.V1.t, 'step_me_only, Limb_vector.Constant.Hex64.Stable.V1.tVector.Vector_2.Stable.V1.tScalar_challenge.Stable.V2.tBulletproof_challenge.Stable.V1.tStep_bp_vec.Stable.V1.t, Branch_data.Stable.V1.t )Types.Wrap.Statement.Minimal.Stable.V1.t; prev_evals :( Tick.Field.Stable.V1.t, Tick.Field.Stable.V1.t array )Plonk_types.All_evals.Stable.V1.t; proof : Tock.Proof.Stable.V2.t}
    (* 《2》body字段,Body.Stable.V1.t结构为: *)
    type t ={ public_key : Public_key.Compressed.Stable.V1.t (* 压缩公钥 *); token_id : Token_id.Stable.V1.t (* 为:Pickles.Backend.Tick.Field.Stable.V1.t结构 *); update : Update.Stable.V1.t  (* 见上面,同fee_payer.body.update字段,包含app_state、delegate、verification_key、permissions、zkapp_uri、token_symbol、timing、voting_for这8个字段。 *); balance_change :(Amount.Stable.V1.t, Sgn.Stable.V1.t) Signed_poly.Stable.V1.t (* 包含magnitude(为Unsigned.UInt64.t)和sgn(为Pos或Neg枚举类型)两个字段 *); increment_nonce : bool; events : Events'.Stable.V1.t (* 为Pickles.Backend.Tick.Field.Stable.V1.t array list *); sequence_events : Events'.Stable.V1.t (* 为Pickles.Backend.Tick.Field.Stable.V1.t array list *); call_data : Pickles.Backend.Tick.Field.Stable.V1.t; preconditions : Preconditions.Stable.V1.t (* 包含network和account这2个字段。 *); use_full_commitment : bool; caller : Token_id.Stable.V1.t (* 为:Pickles.Backend.Tick.Field.Stable.V1.t结构 *)}
    (* preconditions 字段,Preconditions.Stable.V1.t结构为: *)
    type t ={ network : Zkapp_precondition.Protocol_state.Stable.V1.t (* 同fee_payer.body.protocol_state_precondition字段,包含snarked_ledger_hash、timestamp、blockchain_length、min_window_density、last_vrf_output、total_currency、global_slot_since_hard_fork、global_slot_since_genesis、staking_epoch_data和next_epoch_data这10个字段。 *); account : Account_precondition.Stable.V1.t (* 为Full、Nonce或Accept枚举类型 *)}
    (* account字段,Account_precondition.Stable.V1.t结构为: *)
    type t =| Full of Zkapp_precondition.Account.Stable.V2.t (*  *)| Nonce of Account.Nonce.Stable.V1.t (* 为Unsigned_extended.UInt32.t *)| Accept
    (* Full枚举类型对应的,Zkapp_precondition.Account.Stable.V2.t 结构为: *)
    type t ={ balance : Balance.Stable.V1.t Numeric.Stable.V1.t (* Ignore或Check类型,包含lower和upper字段,均为Unsigned.UInt64.t *); nonce : Account_nonce.Stable.V1.t Numeric.Stable.V1.t (* Ignore或Check类型,包含lower和upper字段,均为Unsigned_extended.UInt32.t *); receipt_chain_hash : Receipt.Chain_hash.Stable.V1.t Hash.Stable.V1.t (* Ignore或Check类型,哈希值,Field.t *); delegate : Public_key.Compressed.Stable.V1.t Eq_data.Stable.V1.t  (* Ignore或Check类型,压缩公钥 *); state : F.Stable.V1.t Eq_data.Stable.V1.t Zkapp_state.V.Stable.V1.t  (* Ignore或Check类型,为8 fields(Set或Keep类型) of 32 bytes each of arbitrary storage *); sequence_state : F.Stable.V1.t Eq_data.Stable.V1.t (* Ignore或Check类型,F.t *); proved_state : bool Eq_data.Stable.V1.t (* Ignore或Check类型,bool *)}
    

2.1 Parties_segment.Witness.t结构

Parties_segment.Witness.t结构为:

type t ={ global_ledger : Sparse_ledger.Stable.V2.t (* 为Account树 *); local_state_init :( ( Token_id.Stable.V1.t, unit Parties.Call_forest.With_hashes.Stable.V1.t )Stack_frame.Stable.V1.t (* 包含caller、caller_caller、calls三个字段,其中calller和caller_caller均为token_id,calls为Parties。 *), ( ( ( Token_id.Stable.V1.t, unit Parties.Call_forest.With_hashes.Stable.V1.t )Stack_frame.Stable.V1.t, Stack_frame.Digest.Stable.V1.t )With_hash.t (* 包含data和hash字段。 *), Call_stack_digest.Stable.V1.t )With_stack_hash.Stable.V1.tlist, Token_id.Stable.V1.t, (Amount.Stable.V1.t, Sgn.Stable.V1.t) Signed_poly.Stable.V1.t, Sparse_ledger.Stable.V2.t (* 包含elt和stack_hash字段 *), bool, Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t, Transaction_status.Failure.Collection.Stable.V1.t )Mina_transaction_logic.Parties_logic.Local_state.Stable.V1.t (* 包含stack_frame/call_stack/transaction_commitment/full_transaction_commitment/token_id/excess/ledger/success/failure_status_tbl字段。 *); start_parties :( Parties.Stable.V1.t, Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t )Mina_transaction_logic.Parties_logic.Start_data.Stable.V1.t (* 包含parties和memo_hash字段。 *)list; state_body : Mina_state.Protocol_state.Body.Value.Stable.V2.t (包含genesis_state_hash/blockchain_state/consensus_state/constants这4个字段。); init_stack : Pending_coinbase.Stack_versioned.Stable.V1.t (其中data字段为Field.t,state字段(包含init/curr)也均为Field.t)}

2.2 Parties_segment.Basic.t结构

Parties_segment.Basic.t结构为枚举类型:

 type t = Opt_signed_opt_signed | Opt_signed | Proved

2.3 Zkapp_statement.t结构

Zkapp_statement.t结构为:

type t = Parties.Transaction_commitment.Stable.V1.t Poly.Stable.V1.t (* transaction和at_party字段均为F.t结构。 *)
type 'comm t = { transaction : 'comm; at_party : 'comm }

2.4 Transaction_applied.Parties_applied.t结构

Transaction_applied.Parties_applied.t结构为:

 type t ={ accounts :(Account_id.Stable.V2.t * Account.Stable.V2.t option) list (* 由account_id和account二元结构组成的list *); command : Parties.Stable.V1.t With_status.Stable.V2.t (* 包含data和status字段,其中data为Parties交易结构,status表示该Parties交易的状态,为Applied | Failed of Failure.Collection.Stable.V1.t *); previous_empty_accounts : Account_id.Stable.V2.t list (* 为account_id list *)}

3. Parties交易snark流程

Parties交易snark流程见src/lib/snark_worker/prod.ml中的perform_single函数。
其中:

  • input为Transaction_snark.Statement.t类型(包含source、target、supply_increase、fee_excess、sok_digest五个字段)。
  • w为Transaction_witness.t类型(包含transaction、ledger、protocol_state_body、init_stack和status五个字段)。
process (fun () ->match w.transaction with| Command (Parties parties) -> (let%bind witnesses_specs_stmts =Or_error.try_with (fun () ->Transaction_snark.parties_witnesses_exn~constraint_constants:M.constraint_constants (* 调用Transaction_snark.Make (struct。。。时指定的。 *)~state_body:w.protocol_state_body~fee_excess:Currency.Amount.Signed.zero(`Sparse_ledger w.ledger)[ ( `Pending_coinbase_init_stack w.init_stack, `Pending_coinbase_of_statement{ Transaction_snark.Pending_coinbase_stack_state.source =input.source.pending_coinbase_stack; target =input.target.pending_coinbase_stack}, parties )]|> fst |> List.rev )|> Result.map_error ~f:(fun e ->Error.createf!"Failed to generate inputs for parties : \%s: %s"( Parties.to_yojson parties|> Yojson.Safe.to_string )(Error.to_string_hum e) )|> Deferred.returninlet log_base_snark f ~statement ~spec ~all_inputs =match%map.DeferredDeferred.Or_error.try_with (fun () ->f ~statement ~spec )with| Ok p ->Ok p| Error e ->[%log fatal]"Transaction snark failed for input $spec \$statement. All inputs: $inputs. Error:  \$error"~metadata:[ ( "spec", Transaction_snark.Parties_segment.Basic.to_yojson spec ); ( "statement", Transaction_snark.Statement.With_sok.to_yojson statement ); ("error", `String (Error.to_string_hum e)); ( "inputs", parties_inputs_to_yojson all_inputs )] ;Error einlet log_merge_snark ~sok_digest prev curr ~all_inputs=match%map.DeferredM.merge ~sok_digest prev currwith| Ok p ->Ok p| Error e ->[%log fatal]"Merge snark failed for $stmt1 $stmt2. All \inputs: $inputs. Error:  $error"~metadata:[ ( "stmt1", Transaction_snark.Statement.to_yojson(Ledger_proof.statement prev) ); ( "stmt2", Transaction_snark.Statement.to_yojson(Ledger_proof.statement curr) ); ("error", `String (Error.to_string_hum e)); ( "inputs", parties_inputs_to_yojson all_inputs )] ;Error einmatch witnesses_specs_stmts with| [] ->Deferred.Or_error.error_string"no witnesses generated"| (witness, spec, stmt, snapp_statement) :: rest asinputs ->let%bind (p1 : Ledger_proof.t) =log_base_snark~statement:{ stmt with sok_digest } ~spec~all_inputs:inputs(M.of_parties_segment_exn ~snapp_statement~witness )inlet%map (p : Ledger_proof.t) =Deferred.List.fold ~init:(Ok p1) rest~f:(funacc(witness, spec, stmt, snapp_statement)->let%bind (prev : Ledger_proof.t) =Deferred.return accinlet%bind (curr : Ledger_proof.t) =log_base_snark~statement:{ stmt with sok_digest }~spec ~all_inputs:inputs(M.of_parties_segment_exn~snapp_statement ~witness )inlog_merge_snark ~sok_digest prev curr~all_inputs:inputs )inifTransaction_snark.Statement.equal(Ledger_proof.statement p) inputthen pelse ([%log fatal]"Parties transaction final statement \mismatch Expected $expected Got $got. All \inputs: $inputs"~metadata:[ ( "got", Transaction_snark.Statement.to_yojson(Ledger_proof.statement p) ); ( "expected", Transaction_snark.Statement.to_yojsoninput ); ("inputs", parties_inputs_to_yojson inputs)] ;failwith"Parties transaction final statement mismatch") )。。。。。

parties_witnesses_exn函数,

(** [parties_witnesses_exn ledger partiess] generates the parties segment witnessesand corresponding statements needed to prove the application of eachparties transaction in [partiess] on top of ledger. If multiple parties aregiven, they are applied in order and grouped together to minimise thenumber of transaction proofs that would be required.There must be at least one parties transaction in [parties].The returned value is a list of tuples, each corresponding to a singleproof for some parts of some parties transactions, comprising:* the witness information for the segment, to be passed to the prover* the segment kind, identifying the type of proof that will be generated* the proof statement, describing the transition between the states beforeand after the segment* the list of calculated 'snapp statements', corresponding to the expectedpublic input of any snapp parties in the current segment.WARNING: This function calls the transaction logic internally, and thus mayraise an exception if the transaction logic would also do so. This functionshould only be used on parties that are already known to pass transactionlogic without an exception.
*)
val parties_witnesses_exn :constraint_constants:Genesis_constants.Constraint_constants.t-> state_body:Transaction_protocol_state.Block_data.t-> fee_excess:Currency.Amount.Signed.t-> [ `Ledger of Mina_ledger.Ledger.t| `Sparse_ledger of Mina_ledger.Sparse_ledger.t ]-> ( [ `Pending_coinbase_init_stack of Pending_coinbase.Stack.t ] (* 其中data字段为Field.t,state字段(包含init/curr)也均为Field.t)。 *)* [ `Pending_coinbase_of_statement of Pending_coinbase_stack_state.t ] (* 包含source和target字段,均为Pending_coinbase.Stack.t结构。 *)* Parties.t )list-> ( Parties_segment.Witness.t* Parties_segment.Basic.t* Statement.With_sok.t* (int * Zkapp_statement.t) option )list* Mina_ledger.Sparse_ledger.t (* `parties_witnesses_exn`函数输出结果类型 *)

附录1. Mina系列博客

Mina系列博客有:

  • Mina概览
  • Mina的支付流程
  • Mina的zkApp
  • Mina中的Pasta(Pallas和Vesta)曲线
  • Mina中的Schnorr signature
  • Mina中的Pickles SNARK
  • Mina中的Kimchi SNARK
  • Mina Kimchi SNARK 代码解析
  • Mina Berkeley QANet测试网zkApp初体验
  • Mina中的Poseidon hash
  • Mina中的多项式承诺方案
  • Recursive SNARKs总览
  • Mina技术白皮书
  • Mina代码解析
  • Mina中的Snark Worker
  • Mina中的Scan State
  • Mina中的VRF
  • Mina中的delta_transition_chain_proof/delta_block_chain_proof
  • Mina中的stake delegation
  • Mina如何实现22KB?
  • Mina中的stake_proof
  • Mina中的genesis_proof
  • Mina中的交易及经济白皮书
  • Mina中的ledger proof
  • Mina中的基于DLG的Plonk polynomial commitment scheme代码解析
  • Mina中的约束系统代码解析
  • Mina中的scan state代码解析
  • Mina中的区块证明
  • Mina中的wrap snark
  • Mina中的支付交易snark
  • Mina中的树结构

Mina中的zkApp交易snark相关推荐

  1. Mina中的支付交易snark

    1. 引言 前序博客有: Mina的支付流程 Mina中目前的交易类型主要有: Coinbase交易:给产块者激励和手续费的交易,为内部交易. Fee_transfer交易:给snark worker ...

  2. Mina中的Snark Worker

    1. 引言 Mina系列博客有: Mina概览 Mina的支付流程 Mina的zkApp Mina中的Pasta(Pallas和Vesta)曲线 Mina中的Schnorr signature Min ...

  3. Mina中的Kimchi SNARK

    1. 引言 Mina系列博客有: Mina概览 Mina的支付流程 Mina的zkApp Mina中的Pasta(Pallas和Vesta)曲线 Mina中的Schnorr signature Min ...

  4. Mina中的wrap snark

    1. 引言 前序博客有: Mina技术白皮书 所谓wrap snark,是将Tick snark(Mina代码中称为step proof)包裹为Tock snark(Mina代码中称为wrap pro ...

  5. Mina中的Pickles SNARK

    1. 引言 Mina系列博客有: Mina概览 Mina的支付流程 Mina的zkApp Mina中的Pasta(Pallas和Vesta)曲线 Mina中的Schnorr signature 视频可 ...

  6. Mina中的区块证明

    1. 引言 Mina的Pickles支持2种类型的tag: Side_loaded Compiled type ('var, 'value, 'n1, 'n2) t ={ kind : kind; i ...

  7. Mina中的stake delegation

    1. 引言 为支持将某人的质押委托给另一人,增加受托人赢的几率. 质押委托的设计目标为: 从网络安全的角度来看,希望质押或委托的金额越多越好. 应不会too expensive inside the ...

  8. Mina中的Pasta(Pallas和Vesta)曲线

    1. 引言 Mina系列博客有: Mina概览 Mina的支付流程 Mina的zkApp Mina采用Zcash团队发明的Pallas curve和Vesta curve(统称为Pasta曲线).其中 ...

  9. mina 中的IoBufer(一)

    为什么80%的码农都做不了架构师?>>>    IoBuffer 是 MINA 中的独有接口,主要继承实现的是 java NIO 中的 ByteBuffer ,所以从使用方法上来看二 ...

最新文章

  1. Found option without preceding group in config file E:\mysql\mysql-5.7.23-winx64\my.ini at line 1!
  2. centos6.5 rsync+inotify同步配置笔记
  3. 给写新疆开放互联网一周纪念
  4. mysql自增主键到头了怎么办_自增主键用完了怎么办
  5. LeetCode训练
  6. WP7开发小技巧之快捷键
  7. php企业应用,PHP企业级应用缓存技术详解
  8. 免费的安卓录屏、录音软件(无需root)
  9. 爬取豆瓣网新书传递信息,关系型数据库的储存
  10. 学习python自动化测试的好处
  11. 解决能登录微信却登不上网页的问题
  12. 手把手教你摆地摊之摆摊卖什么
  13. 句子成分分析(C++)
  14. linux命令里的xz是干嘛的,Ubuntu中的xz命令使用
  15. 卸载windows 自带 内置软件应用 2022,windows垃圾清理技巧
  16. Java系统记一次排查生产环境邮件突然就发不出来的问题
  17. 报错:Expected singleton
  18. 数字人民币问答-什么是数字人名币?
  19. windows php client,Installation and using elasticsearch php client on Windows Xampp
  20. 从零开始编写SAT求解器(一)

热门文章

  1. 通俗易懂、细致入微讲解卡尔曼滤波
  2. vue/JS实现输入框失焦
  3. linux cpu 降频,archlinux 给cpu降频
  4. iOS 加粗字体方法 (不改变字体字号只加粗文字)
  5. 计算机在医学影像学的应用,计算机图像数字化与医学影像学之应用探析
  6. 支付业务与技术架构学习总结(10)——第三方支付账务系统论述
  7. 卷三十一 汉纪二十三
  8. 024_spacemacs支持org-pomodoro的声音提示
  9. Python爬虫获取豆瓣电影TOP250
  10. python代码直接关机_关机信号在python脚本中运行代码