123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(* Every function of this file should check the feature flag. *)openAlpha_contextopenDal_errorsletassert_dal_feature_enabledctxt=letopenConstantsinletParametric.{dal={feature_enable;_};_}=parametricctxtinerror_unlessCompare.Bool.(feature_enable=true)Dal_feature_disabledletonly_if_dal_feature_enabledctxt~defaultf=letopenConstantsinletParametric.{dal={feature_enable;_};_}=parametricctxtiniffeature_enablethenfctxtelsedefaultctxtletslot_of_int_e~number_of_slotsn=letopenResult_syntaxinmatchDal.Slot_index.of_int_opt~number_of_slotsnwith|None->tzfail@@Dal_errors.Dal_slot_index_above_hard_limit{given=n;limit=number_of_slots-1}|Someslot_index->returnslot_index(* Use this function to select the pkh used in the DAL committee. As long as an
epoch does not span across multiple cycles, we could use as well the pkh of
the consensus key. *)letpkh_of_consensus_key(consensus_key:Consensus_key.pk)=consensus_key.delegateletvalidate_attestationctxtlevelslotconsensus_keyattestation=letopenLwt_result_syntaxinlet*?()=assert_dal_feature_enabledctxtinletnumber_of_slots=Dal.number_of_slotsctxtinlet*?max_index=number_of_slots-1|>slot_of_int_e~number_of_slotsinletmaximum_size=Dal.Attestation.expected_size_in_bits~max_indexinletsize=Dal.Attestation.occupied_size_in_bitsattestationinlet*?()=error_unlessCompare.Int.(size<=maximum_size)(Dal_attestation_size_limit_exceeded{maximum_size;got=size})inletnumber_of_shards=Dal.number_of_shardsctxtinfail_whenCompare.Int.(Slot.to_intslot>=number_of_shards)(letattester=pkh_of_consensus_keyconsensus_keyinDal_data_availibility_attester_not_in_committee{attester;level;slot})letapply_attestationctxtattestation~power=letopenResult_syntaxinlet*()=assert_dal_feature_enabledctxtinreturn(Dal.Attestation.record_number_of_attested_shardsctxtattestationpower)(* This function should fail if we don't want the operation to be
propagated over the L1 gossip network. Because this is a manager
operation, there are already checks to ensure the source of
operation has enough fees. Among the various checks, there are
checks that cannot fail unless the source of the operation is
malicious (or if there is a bug). In that case, it is better to
ensure fees will be taken. *)letvalidate_publish_commitmentctxt_operation=assert_dal_feature_enabledctxtletapply_publish_commitmentctxtoperation=letopenResult_syntaxinlet*ctxt=Gas.consumectxtDal_costs.cost_Dal_publish_commitmentinletnumber_of_slots=Dal.number_of_slotsctxtinlet*ctxt,cryptobox=Dal.makectxtinletcurrent_level=(Level.currentctxt).levelinlet*slot_header=Dal.Operations.Publish_commitment.slot_header~cryptobox~number_of_slots~current_leveloperationinlet*ctxt=Dal.Slot.register_slot_headerctxtslot_headerinreturn(ctxt,slot_header)letfinalisationctxt=letopenLwt_result_syntaxinonly_if_dal_feature_enabledctxt~default:(functxt->return(ctxt,Dal.Attestation.empty))(functxt->let*!ctxt=Dal.Slot.finalize_current_slot_headersctxtin(* The fact that slots confirmation is done at finalization is very
important for the assumptions made by the Dal refutation game. In fact:
- {!Dal.Slot.finalize_current_slot_headers} updates the Dal skip list
at block finalization, by inserting newly confirmed slots;
- {!Sc_rollup.Game.initial}, called when applying a manager operation
that starts a refutation game, makes a snapshot of the Dal skip list
to use it as a reference if the refutation proof involves a Dal input.
If confirmed Dal slots are inserted into the skip list during operations
application, adapting how refutation games are made might be needed
to e.g.,
- use the same snapshotted skip list as a reference by L1 and rollup-node;
- disallow proofs involving pages of slots that have been confirmed at the
level where the game started.
*)letnumber_of_slots=(Constants.parametricctxt).dal.number_of_slotsinlet+ctxt,attestation=Dal.Slot.finalize_pending_slot_headersctxt~number_of_slotsin(ctxt,attestation))