package tezos-protocol-alpha
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=43723d096307603703a1a89ed1b2eb202b365f5e7824b96b0cbf813b343a6cf7
sha512=b2a637f2e965000d3d49ad85277ca24d6cb07a1a7cf2bc69d296d8b03ad78c3eaa8e21e94b9162e62c2e11649cd03bc845b2a3dafe623b91065df69d47dc8e4f
doc/tezos-protocol-alpha.raw/Tezos_raw_protocol_alpha/Zk_rollup_apply/index.html
Module Tezos_raw_protocol_alpha.Zk_rollup_applySource
This module handles all the validation/application of any operation related to the ZK Rollup. All of the functions defined in this module require that the ZKRU feature flag is enabled.
In the ZK Rollup, L2 operations are validated in two steps:
- The Protocol does the first pass of (light) validation and appends the L2 operation to a pending list.
- The ZKRU Operator does the second pass of validation for a prefix of the pending list and posts a proof on chain of the validity of each of them. Based on this proof, the Protocol is going to remove the prefix from the pending list, and apply their effect on the ZKRU L2 state and on the L1 balances.
The first step of validation is split into two cases, depending on the type of L2 operation that is being submitted:
- If the application of said L2 operation results in a transfer of a ticket from L1 to L2 (i.e. it is a ZKRU deposit), the L2 operation has to be submitted through a call to the ZKRU
%depositentrypoint from a smart contract. This constraint is imposed by the fact that implicit accounts cannot transfer tickets. Then, the validation of these L2 operations will be performed when applying the internal Tezos operation emitted by the call to the ZKRU's deposit entrypoint. This is implemented by thetransaction_to_zk_rollupfunction in this module. - If its application results in a ticket transfer from L2 to L1 (i.e. it is a ZKRU withdrawal) or it has no transfer between layers, the L2 operation has to be submitted through a
Zk_rollup_publishexternal Tezos operation. The checks for these L2 operations will be perform upon application of said external Tezos operation, whose logic is implemented by thepublishfunction in this module.
Although L2 operations are mostly opaque, they expose a header that is transparent to the Protocol (see Zk_rollup_operation_repr.t). In this header there's a field for the price of an L2 operation, which will expose its kind. Concretely, the price encodes the net ticket transfer from L1 to L2 caused by an L2 operation. Then, deposits have a positive price, withdrawals a negative one, and pure L2 operations must have a price of zero.
An L2 operation's price also encodes which ticket is being transferred, by storing the ticket's hash (see Ticket_hash_repr). These hashes are used as token identifiers inside the ZKRU. In both cases, the L2 operations with a non-zero price (i.e. deposits and withdrawals) will be submitted alongside the values describing the ticket being transferred (see Zk_rollup_ticket_repr). These values have to be consistent with the token identifier used in the L2 operation's price.
NB: if ticket transfers by implicit accounts was supported, these two cases could be unified into the application of the Zk_rollup_publish operation.
These errors are only to be matched in tests.
val assert_feature_enabled :
Alpha_context.t ->
unit Tezos_protocol_environment_alpha.Error_monad.tzresultassert_feature_enabled ctxt asserts that the ZK Rollup feature flag is activated.
May fail with:
Zk_rollup_feature_disabledif the ZKRU feature flag is not activated.
val originate :
ctxt_before_op:Alpha_context.t ->
ctxt:Alpha_context.t ->
public_parameters:Tezos_protocol_environment_alpha.Plonk.public_parameters ->
circuits_info:
[ `Public | `Private | `Fee ] Alpha_context.Zk_rollup.Account.SMap.t ->
init_state:Alpha_context.Zk_rollup.State.t ->
nb_ops:int ->
(Alpha_context.t
* Alpha_context.Kind.zk_rollup_origination
Apply_results.successful_manager_operation_result
* Script_typed_ir.packed_internal_operation list)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.toriginate ~ctxt_before_op ~ctxt ~public_parameters ~transcript ~circuits_info ~init_state ~nb_ops applies the origination operation for a ZK rollup. See Zk_rollup_storage:originate.
May fail with:
Zk_rollup_feature_disabledif the ZKRU feature flag is not activated.Zk_rollup_negative_nb_opsifnb_opsis negative.
val publish :
ctxt_before_op:Alpha_context.t ->
ctxt:Alpha_context.t ->
zk_rollup:Alpha_context.Zk_rollup.t ->
l2_ops:
(Alpha_context.Zk_rollup.Operation.t
* Alpha_context.Zk_rollup.Ticket.t option)
list ->
(Alpha_context.t
* Alpha_context.Kind.zk_rollup_publish
Apply_results.successful_manager_operation_result
* Script_typed_ir.packed_internal_operation list)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.tpublish ~ctxt_before_op ~ctxt ~zk_rollup ~l2_ops applies a publish operation to zk_rollup by adding l2_ops to its pending list.
All L2 operations in l2_ops must claim a non-positive price (see Zk_rollup_operation_repr). In other words, no deposit is allowed in this operation, as those must go through an internal transaction.
This function will first perform a series of validation checks over the L2 operations in l2_ops. If all of them are successful, these L2 operations will be added to dst_rollup's pending list.
May fail with:
Zk_rollup_feature_disabledif the ZKRU feature flag is not activated.Zk_rollup.Errors.Deposit_as_externalif the price of an L2 operation fromopsis positive.Zk_rollup.Errors.Invalid_deposit_amountif an L2 operation declares no ticket but has a non-zero price or if it declares a ticket with a price of zero.Zk_rollup.Errors.Invalid_deposit_ticketif an L2 operation's ticket identifier (seeZk_rollup_operation_repr) is different from the hash of its corresponding ticket andl1_dst.Zk_rollup_storage.Zk_rollup_invalid_op_code op_codeif theop_codeof one of theoperationsis greater or equal to the number of declared operations for thiszk_rollup.
val transaction_to_zk_rollup :
ctxt:Alpha_context.t ->
parameters_ty:
(('a Script_typed_ir.ticket, bytes) Script_typed_ir.pair, 'b)
Script_typed_ir.ty ->
parameters:('a Script_typed_ir.ticket, bytes) Script_typed_ir.pair ->
dst_rollup:Alpha_context.Zk_rollup.t ->
since:Alpha_context.t ->
(Alpha_context.t
* Alpha_context.Kind.transaction
Apply_internal_results.successful_internal_operation_result
* Script_typed_ir.packed_internal_operation list)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.ttransaction_to_zk_rollup ~ctxt ~parameters_ty ~parameters ~payer ~dst_rollup ~since applies an internal transaction to a ZK dst_rollup.
Internal transactions are used for deposits into ZK rollups, which can be seen as a special case of the publish ZK rollup operation. The parameters should include a ticket and a ZKRU L2 operation, as explained in the Zk_rollup_parameters module's documentation.
This function will first perform a series of validation checks. If successful, the L2 operation from the parameters will be added to dst_rollup's pending list, and payer will pay for the added storage.
May fail with:
Zk_rollup_feature_disabledif the ZKRU feature flag is not activated.Zk_rollup.Errors.Ticket_payload_size_limit_exceededif the ticket found in theparametersexceeds the maximum ticket size.Script_tc_errors.Forbidden_zero_ticket_quantityif the ticket amount is zero.Zk_rollup.Errors.Invalid_deposit_amountif the amount of the ticket transferred to thedst_rollupis different from theprice(seeZk_rollup_operation_repr) claimed by the L2 operation.Zk_rollup.Errors.Invalid_deposit_ticketif the L2 operation's ticket identifier (seeZk_rollup_operation_repr) is different to the hash of the transferred ticket anddst_rollup.Zk_rollup_storage.Zk_rollup_invalid_op_code op_codeif theop_codeof the operation from theparametersis greater or equal to the number of declared operations for this rollup.Zk_rollup.Errors.Wrong_deposit_parametersif theparametersare not of the expected type. SeeZk_rollup_parameters.
val update :
ctxt_before_op:Alpha_context.t ->
ctxt:Alpha_context.t ->
zk_rollup:Alpha_context.Zk_rollup.t ->
update:Alpha_context.Zk_rollup.Update.t ->
(Alpha_context.t
* Alpha_context.Kind.zk_rollup_update
Apply_results.successful_manager_operation_result
* Script_typed_ir.packed_internal_operation list)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.tupdate ~ctxt_before_op ~ctxt ~zk_rollup ~update ~source_contract applies an update to zk_rollup.
A ZKRU update will verify three sorts of ZK circuits:
- Public operation circuits, that handle a single L2 operation from the pending list.
- Private batch circuits, that handle a batch of private L2 operations.
- Fee circuit, which credits the ZKRU operator with all the aggregated fees from the update.
The update provides some inputs required to perform this verification, alongside the proof. See Zk_rollup_update_repr.
If the verification is successful, the zk_rollup's state is updated, a prefix of its pending list is dropped and the exits from the ZKRU are performed.
May fail with:
Zk_rollup_feature_disabledif the ZKRU feature flag is not activated.Zk_rollup.Errors.Pending_boundif theupdateprocesses fewer public operation than allowed.Zk_rollup.Errors.Inconsistent_state_updateif theupdatedeclares a new state of incorrect length.Zk_rollup.Errors.Invalid_circuitif a public operation circuit is ran as private.Zk_rollup.Errors.Invalid_verificationif the PlonK verification fails.Zk_rollup.Errors.Invalid_deposit_amountif an L2 operation without a corresponding ticket in the pending list has a non-zero price.Zk_rollup_storage.Zk_rollup_pending_list_too_shortif theupdatetries to process more public operations than those in the pending list.