123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)typeerror+=Tx_rollup_message_proof_too_largeof{limit:int;actual:int}let()=register_error_kind~id:"tx_rollup.node.message_proof_too_large"~title:"Message's application proof is too large"~description:"The proof associated to the application of the message is too large"~pp:(funppf(limit,actual)->Format.fprintfppf"The message produces a proof of size %d where the protocol limit is \
%d. It will be rejected by the protocol."limitactual)`PermanentData_encoding.(obj2(req"limit"int31)(req"actual"int31))(function|Tx_rollup_message_proof_too_large{limit;actual}->Some(limit,actual)|_->None)(fun(limit,actual)->Tx_rollup_message_proof_too_large{limit;actual})(** Interpret a message in the context. The function needs to be synchronised
with the [Tx_rollup_l2_verifier] module of the protocol, in particular
the proof size boundaries. *)letinterpret_message~rejection_max_proof_sizectxtl2_parametersmessage=letopenLwt_result_syntaxinlet*proof,res=Prover_apply.apply_messagectxtl2_parametersmessageinletproof_size=Prover_apply.proof_sizeproofinletmessage_size=Data_encoding.Binary.lengthProtocol.Alpha_context.Tx_rollup_message.encodingmessageinletresult=ifproof_size>rejection_max_proof_size-message_sizethen(* The proof is too large, we can not commit this state. The
result is discarded. *)Inbox.Discarded[Tx_rollup_message_proof_too_large{limit=rejection_max_proof_size;actual=proof_size};]elseres.Context.resultinreturn(res.Context.tree,result)letinterpret_messages~rejection_max_proof_sizectxtl2_parametersmessages=letopenLwt_result_syntaxinletctxt_hash=Context.hashctxtinlet*tree_hash=Context.tree_hash_of_contextctxtinlet+ctxt,_ctxt_hash,_tree_hash,rev_contents=List.fold_left_es(fun(ctxt,ctxt_hash,tree_hash,acc)message->let*tree,result=interpret_message~rejection_max_proof_sizectxtl2_parametersmessageinlet*ctxt,ctxt_hash,tree_hash=matchresultwith|Inbox.Interpreted_->(* The message was successfully interpreted but the status in
[result] may indicate that the application failed. The context
may have been modified with e.g. updated counters. *)lettree_hash=Context.hash_treetreeinlet*!ctxt,ctxt_hash=Context.add_treectxttreeinreturn(ctxt,ctxt_hash,tree_hash)|Inbox.Discarded_->(* The message was discarded before attempting to interpret it. The
context is not modified. For instance if a batch is unparsable,
or the BLS signature is incorrect, or a counter is wrong, etc. *)return(ctxt,ctxt_hash,tree_hash)inletinbox_message=Inbox.{message;result;l2_context_hash={irmin_hash=ctxt_hash;tree_hash};}inreturn(ctxt,ctxt_hash,tree_hash,inbox_message::acc))(ctxt,ctxt_hash,tree_hash,[])messagesinmatchrev_contentswith|[]->(ctxt,None)|_->letcontents=List.revrev_contentsin(ctxt,Somecontents)letinterpret_batch~rejection_max_proof_sizectxtl2_parametersbatch=letopenLwt_result_syntaxinletbatch_bytes=Data_encoding.Binary.to_string_exnProtocol.Tx_rollup_l2_batch.encodingbatchinletmessage,_=Protocol.Alpha_context.Tx_rollup_message.make_batchbatch_bytesinlet*_tree,result=interpret_message~rejection_max_proof_sizectxtl2_parametersmessageinmatchresultwithInbox.Discardedtrace->failtrace|_->return()