123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 TriliTech, <contact@trili.tech> *)(* Copyright (c) 2023 Marigold, <contact@marigold.dev> *)(* *)(* 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. *)(* *)(*****************************************************************************)(* TODO: https://gitlab.com/tezos/tezos/-/issues/5073
Update Certificate repr to handle a dynamic dac.
*)moduleV0=struct(** Current version of the [Certificate]
must be equal to the version of the module, 0 in this case. *)letversion=0(** Representation of a Data Availibility Committee Certificate.
Type is private to make sure correct [version] is used.
Use [make] function to create a [Certificate_repr.V0.t] *)typet={root_hash:Dac_plugin.raw_hash;aggregate_signature:Tezos_crypto.Aggregate_signature.signature;witnesses:Z.t;(* TODO: https://gitlab.com/tezos/tezos/-/issues/4853
Use BitSet for witnesses field in external message
*)}letmakeroot_hashaggregate_signaturewitnesses={root_hash;aggregate_signature;witnesses}letencoding=letobj_enc=Data_encoding.(obj4(req"version"Data_encoding.uint8)(req"root_hash"Dac_plugin.raw_hash_encoding)(req"aggregate_signature"Tezos_crypto.Aggregate_signature.encoding)(req"witnesses"z))inData_encoding.(conv_with_guard(fun{root_hash;aggregate_signature;witnesses}->(0,root_hash,aggregate_signature,witnesses))(fun(version,root_hash,aggregate_signature,witnesses)->ifversion==0thenOk{root_hash;aggregate_signature;witnesses}elseError"invalid version of certificate.")obj_enc)letall_committee_members_have_signedcommittee_members{witnesses;_}=letlength=List.lengthcommittee_membersin(* TODO: https://gitlab.com/tezos/tezos/-/issues/4562
The following is equivalent to Bitset.fill length. The Bitset module
should be used once it is moved from the protocol to the environment. *)letexpected_witnesses=Z.(pred(shift_leftonelength))in(* Equivalent to Bitset.diff expected_witnesses witnesses. *)letmissing_witnesses=Z.logandexpected_witnesses(Z.lognotwitnesses)inZ.(equalmissing_witnesseszero)moduleProtocol_dependant=struct(** Very similar to V0.t but using a [root_hash] related to the
active protocol. *)typet={root_hash:Dac_plugin.hash;aggregate_signature:Tezos_crypto.Aggregate_signature.signature;witnesses:Z.t;}(** This encoding is protocol dependant. It should not be on
DAC side, but this is the easiest/faster way to handle it. *)letcertificate_client_encodingroot_hash_encoding=letuntagged=Data_encoding.(conv(fun{root_hash;aggregate_signature;witnesses}->(root_hash,aggregate_signature,witnesses))(fun(root_hash,aggregate_signature,witnesses)->{root_hash;aggregate_signature;witnesses})(obj3(req"root_hash"root_hash_encoding)(req"aggregate_signature"Tezos_crypto.Aggregate_signature.encoding)(req"witnesses"z)))inData_encoding.(union~tag_size:`Uint8[case~title:"certificate_V0"(Tagversion)untagged(funcertificate->Somecertificate)(funcertificate->certificate);])letserialize_certificateroot_hash_encoding~root_hash~aggregate_signature~witnesses=letbytes_as_result=Data_encoding.Binary.to_bytes(certificate_client_encodingroot_hash_encoding){root_hash;aggregate_signature;witnesses}inmatchbytes_as_resultwith|Okserialized_certificate->serialized_certificate|Error_->Stdlib.failwith"Error while serializing the certificate"endendtypet=V0ofV0.tletencoding=letopenData_encodinginunion[case~title:"certificate_repr_V0"(Tag0)V0.encoding(functionV0s->Somes)(funs->V0s);]letget_root_hasht=matchtwithV0t->t.root_hashletget_aggregate_signaturet=matchtwithV0t->t.aggregate_signatureletget_witnessest=matchtwithV0t->t.witnessesletget_versiont=matchtwithV0_t->V0.versionletall_committee_members_have_signedcommittee_memberscertificate=matchcertificatewith|V0certificate->V0.all_committee_members_have_signedcommittee_memberscertificate