12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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. *)(* *)(*****************************************************************************)openAlpha_contextopenGasmoduleCost_of=structmoduleZ_syntax=struct(* This is a good enough approximation. Z.numbits 0 = 0 *)letlog2x=Z.of_int(1+Z.numbitsx)let(+)=Z.addlet(*)=Z.mullet(lsr)=Z.shift_rightendletz_bytes(z:Z.t)=letbits=Z.numbitszin(7+bits)/8letint_bytes(z:'aScript_int.num)=z_bytes(Script_int.to_zintz)lettimestamp_bytes(t:Script_timestamp.t)=letz=Script_timestamp.to_zinttinz_bytesz(* For now, returns size in bytes, but this could get more complicated... *)letrecsize_of_comparable:typeab.(a,b)Script_typed_ir.comparable_struct->a->Z.t=funwitv->matchwitwith|Int_key_->Z.of_int(int_bytesv)|Nat_key_->Z.of_int(int_bytesv)|String_key_->Z.of_int(String.lengthv)|Bytes_key_->Z.of_int(MBytes.lengthv)|Bool_key_->Z.of_int8|Key_hash_key_->Z.of_intSignature.Public_key_hash.size|Timestamp_key_->Z.of_int(timestamp_bytesv)|Address_key_->Z.of_intSignature.Public_key_hash.size|Mutez_key_->Z.of_int8|Pair_key((l,_),(r,_),_)->let(lval,rval)=vinZ.add(size_of_comparablellval)(size_of_comparablerrval)letmanager_operation=step_cost@@Z.of_int1_000(* FIXME: hardcoded constant, available in next environment version.
Set to a reasonable upper bound. *)letpublic_key_size=64moduleGenerated_costs_007=struct(* Automatically generated costs functions. *)(* model N_Abs_int *)(* Approximating 0.068306 x term *)letcost_N_Abs_intsize=Z.of_int@@(80+(sizelsr4))(* model N_Add_intint *)(* Approximating 0.082158 x term *)letcost_N_Add_intintsize1size2=letv0=Compare.Int.maxsize1size2inZ.of_int(80+((v0lsr4)+(v0lsr6)))(* model N_Add_tez *)letcost_N_Add_tez=Z.of_int100(* model N_And *)letcost_N_And=Z.of_int100(* model N_And_nat *)(* Approximating 0.079325 x term *)letcost_N_And_natsize1size2=letv0=Compare.Int.minsize1size2inZ.of_int(80+((v0lsr4)+(v0lsr6)))(* model N_Blake2b *)(* Approximating 1.366428 x term *)letcost_N_Blake2bsize=letopenZ_syntaxinletsize=Z.of_intsizeinZ.of_int500+(size+(sizelsr2))(* model N_Car *)letcost_N_Car=Z.of_int80(* model N_Cdr *)letcost_N_Cdr=Z.of_int80(* model N_Check_signature_ed25519 *)(* Approximating 1.372685 x term *)letcost_N_Check_signature_ed25519size=letopenZ_syntaxinletsize=Z.of_intsizeinZ.of_int270_000+(size+(sizelsr2))(* model N_Check_signature_p256 *)(* Approximating 1.385771 x term *)letcost_N_Check_signature_p256size=letopenZ_syntaxinletsize=Z.of_intsizeinZ.of_int600_000+(size+(sizelsr2)+(sizelsr3))(* model N_Check_signature_secp256k1 *)(* Approximating 1.372411 x term *)letcost_N_Check_signature_secp256k1size=letopenZ_syntaxinletsize=Z.of_intsizeinZ.of_int60_000+(size+(sizelsr2))(* model N_Compare_address *)letcost_N_Compare_addresssize1size2=Z.of_int(80+(2*Compare.Int.minsize1size2))(* model N_Compare_bool *)letcost_N_Compare_boolsize1size2=Z.of_int(80+(128*Compare.Int.minsize1size2))(* model N_Compare_int *)(* Approximating 0.073657 x term *)letcost_N_Compare_intsize1size2=letv0=Compare.Int.minsize1size2inZ.of_int(150+((v0lsr4)+(v0lsr7)))(* model N_Compare_key_hash *)letcost_N_Compare_key_hashsize1size2=Z.of_int(80+(2*Compare.Int.minsize1size2))(* model N_Compare_mutez *)letcost_N_Compare_mutezsize1size2=Z.of_int(13*Compare.Int.minsize1size2)(* model N_Compare_string *)(* Approximating 0.039389 x term *)letcost_N_Compare_stringsize1size2=letv0=Compare.Int.minsize1size2inZ.of_int(120+((v0lsr5)+(v0lsr7)))(* model N_Compare_timestamp *)(* Approximating 0.072483 x term *)letcost_N_Compare_timestampsize1size2=letv0=Compare.Int.minsize1size2inZ.of_int(140+((v0lsr4)+(v0lsr7)))(* model N_Concat_string_pair *)(* Approximating 0.068808 x term *)letcost_N_Concat_string_pairsize1size2=letopenZ_syntaxinletv0=Z.of_intsize1+Z.of_intsize2inZ.of_int80+(v0lsr4)(* model N_Cons_list *)letcost_N_Cons_list=Z.of_int80(* model N_Cons_none *)letcost_N_Cons_none=Z.of_int80(* model N_Cons_pair *)letcost_N_Cons_pair=Z.of_int80(* model N_Cons_some *)letcost_N_Cons_some=Z.of_int80(* model N_Const *)letcost_N_Const=Z.of_int80(* model N_Dig *)letcost_N_Digsize=Z.of_int(100+(4*size))(* model N_Dip *)letcost_N_Dip=Z.of_int100(* model N_DipN *)letcost_N_DipNsize=Z.of_int(100+(4*size))(* model N_Drop *)letcost_N_Drop=Z.of_int80(* model N_DropN *)letcost_N_DropNsize=Z.of_int(100+(4*size))(* model N_Dug *)letcost_N_Dugsize=Z.of_int(100+(4*size))(* model N_Dup *)letcost_N_Dup=Z.of_int80(* model N_Ediv_natnat *)(* Approximating 0.001599 x term *)letcost_N_Ediv_natnatsize1size2=letq=size1-size2inifCompare.Int.(q<0)thenZ.of_int300elseletopenZ_syntaxinletv0=Z.of_intq*Z.of_intsize2inZ.of_int300+(v0lsr10)+(v0lsr11)+(v0lsr13)(* model N_Ediv_tez *)letcost_N_Ediv_tez=Z.of_int200(* model N_Ediv_teznat *)(* Extracted by hand from the empirical data *)letcost_N_Ediv_teznat=Z.of_int300(* model N_Empty_map *)letcost_N_Empty_map=Z.of_int240(* model N_Empty_set *)letcost_N_Empty_set=Z.of_int240(* model N_Eq *)letcost_N_Eq=Z.of_int80(* model N_If *)letcost_N_If=Z.of_int60(* model N_If_cons *)letcost_N_If_cons=Z.of_int110(* model N_If_left *)letcost_N_If_left=Z.of_int90(* model N_If_none *)letcost_N_If_none=Z.of_int80(* model N_Int_nat *)letcost_N_Int_nat=Z.of_int80(* model N_Is_nat *)letcost_N_Is_nat=Z.of_int80(* model N_Left *)letcost_N_Left=Z.of_int80(* model N_List_iter *)letcost_N_List_itersize=letopenZ_syntaxinZ.of_int500+(Z.of_int7*Z.of_intsize)(* model N_List_map *)letcost_N_List_mapsize=letopenZ_syntaxinZ.of_int500+(Z.of_int12*Z.of_intsize)(* model N_List_size *)letcost_N_List_size=Z.of_int80(* model N_Loop *)letcost_N_Loop=Z.of_int70(* model N_Loop_left *)letcost_N_Loop_left=Z.of_int80(* model N_Lsl_nat *)(* Approximating 0.129443 x term *)letcost_N_Lsl_natsize=Z.of_int(150+(sizelsr3))(* model N_Lsr_nat *)(* Approximating 0.129435 x term *)letcost_N_Lsr_natsize=Z.of_int(150+(sizelsr3))(* model N_Map_get *)(* Approximating 0.057548 x term *)letcost_N_Map_getsize1size2=letopenZ_syntaxinletv0=size1*log2(Z.of_intsize2)inZ.of_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Map_iter *)letcost_N_Map_itersize=letopenZ_syntaxinZ.of_int80+(Z.of_int40*Z.of_intsize)(* model N_Map_map *)letcost_N_Map_mapsize=letopenZ_syntaxinZ.of_int80+(Z.of_int761*Z.of_intsize)(* model N_Map_mem *)(* Approximating 0.058563 x term *)letcost_N_Map_memsize1size2=letopenZ_syntaxinletv0=size1*log2(Z.of_intsize2)inZ.of_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Map_size *)letcost_N_Map_size=Z.of_int90(* model N_Map_update *)(* Approximating 0.119968 x term *)letcost_N_Map_updatesize1size2=letopenZ_syntaxinletv0=size1*log2(Z.of_intsize2)inZ.of_int80+(v0lsr4)+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Mul_intint *)letcost_N_Mul_intintsize1size2=letopenZ_syntaxinleta=Z.of_intsize1+Z.of_intsize2inZ.of_int80+(a*log2a)(* model N_Mul_teznat *)letcost_N_Mul_teznatsize=letopenZ_syntaxinZ.of_int200+(Z.of_int133*Z.of_intsize)(* model N_Neg_int *)(* Approximating 0.068419 x term *)letcost_N_Neg_intsize=Z.of_int(80+(sizelsr4))(* model N_Neq *)letcost_N_Neq=Z.of_int80(* model N_Nil *)letcost_N_Nil=Z.of_int80(* model N_Nop *)letcost_N_Nop=Z.of_int70(* model N_Not *)letcost_N_Not=Z.of_int90(* model N_Not_int *)(* Approximating 0.076564 x term *)letcost_N_Not_intsize=Z.of_int(55+((sizelsr4)+(sizelsr7)))(* model N_Or *)letcost_N_Or=Z.of_int90(* model N_Or_nat *)(* Approximating 0.078718 x term *)letcost_N_Or_natsize1size2=letv0=Compare.Int.maxsize1size2inZ.of_int(80+((v0lsr4)+(v0lsr6)))(* model N_Right *)letcost_N_Right=Z.of_int80(* model N_Seq *)letcost_N_Seq=Z.of_int60(* model N_Set_iter *)letcost_N_Set_itersize=letopenZ_syntaxinZ.of_int80+(Z.of_int36*Z.of_intsize)(* model N_Set_mem *)(* Approximating 0.059410 x term *)letcost_N_Set_memsize1size2=letopenZ_syntaxinletv0=size1*log2(Z.of_intsize2)inZ.of_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)+(v0lsr8)(* model N_Set_size *)letcost_N_Set_size=Z.of_int80(* model N_Set_update *)(* Approximating 0.126260 x term *)letcost_N_Set_updatesize1size2=letopenZ_syntaxinletv0=size1*log2(Z.of_intsize2)inZ.of_int80+(v0lsr3)(* model N_Sha256 *)letcost_N_Sha256size=letopenZ_syntaxinZ.of_int500+(Z.of_int5*Z.of_intsize)(* model N_Sha512 *)letcost_N_Sha512size=letopenZ_syntaxinZ.of_int500+(Z.of_int3*Z.of_intsize)(* model N_Slice_string *)(* Approximating 0.067048 x term *)letcost_N_Slice_stringsize=Z.of_int(80+(sizelsr4))(* model N_String_size *)letcost_N_String_size=Z.of_int80(* model N_Sub_int *)(* Approximating 0.082399 x term *)letcost_N_Sub_intsize1size2=letv0=Compare.Int.maxsize1size2inZ.of_int(80+((v0lsr4)+(v0lsr6)))(* model N_Sub_tez *)letcost_N_Sub_tez=Z.of_int80(* model N_Swap *)letcost_N_Swap=Z.of_int70(* model N_Xor *)letcost_N_Xor=Z.of_int100(* model N_Xor_nat *)(* Approximating 0.078258 x term *)letcost_N_Xor_natsize1size2=letv0=Compare.Int.maxsize1size2inZ.of_int(80+((v0lsr4)+(v0lsr6)))(* model B58CHECK_DECODING_CHAIN_ID *)letcost_B58CHECK_DECODING_CHAIN_ID=Z.of_int1_500(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_ed25519 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_ed25519=Z.of_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_p256 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_p256=Z.of_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_secp256k1=Z.of_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_ed25519 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_ed25519=Z.of_int4_300(* model B58CHECK_DECODING_PUBLIC_KEY_p256 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_p256=Z.of_int29_000(* model B58CHECK_DECODING_PUBLIC_KEY_secp256k1 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_secp256k1=Z.of_int9_400(* model B58CHECK_DECODING_SIGNATURE_ed25519 *)letcost_B58CHECK_DECODING_SIGNATURE_ed25519=Z.of_int6_600(* model B58CHECK_DECODING_SIGNATURE_p256 *)letcost_B58CHECK_DECODING_SIGNATURE_p256=Z.of_int6_600(* model B58CHECK_DECODING_SIGNATURE_secp256k1 *)letcost_B58CHECK_DECODING_SIGNATURE_secp256k1=Z.of_int6_600(* model B58CHECK_ENCODING_CHAIN_ID *)letcost_B58CHECK_ENCODING_CHAIN_ID=Z.of_int1_600(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_ed25519 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_ed25519=Z.of_int3_300(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_p256 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_p256=Z.of_int3_750(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_secp256k1=Z.of_int3_300(* model B58CHECK_ENCODING_PUBLIC_KEY_ed25519 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_ed25519=Z.of_int4_500(* model B58CHECK_ENCODING_PUBLIC_KEY_p256 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_p256=Z.of_int5_300(* model B58CHECK_ENCODING_PUBLIC_KEY_secp256k1 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_secp256k1=Z.of_int5_000(* model B58CHECK_ENCODING_SIGNATURE_ed25519 *)letcost_B58CHECK_ENCODING_SIGNATURE_ed25519=Z.of_int8_700(* model B58CHECK_ENCODING_SIGNATURE_p256 *)letcost_B58CHECK_ENCODING_SIGNATURE_p256=Z.of_int8_700(* model B58CHECK_ENCODING_SIGNATURE_secp256k1 *)letcost_B58CHECK_ENCODING_SIGNATURE_secp256k1=Z.of_int8_700(* model DECODING_CHAIN_ID *)letcost_DECODING_CHAIN_ID=Z.of_int50(* model DECODING_PUBLIC_KEY_HASH_ed25519 *)letcost_DECODING_PUBLIC_KEY_HASH_ed25519=Z.of_int50(* model DECODING_PUBLIC_KEY_HASH_p256 *)letcost_DECODING_PUBLIC_KEY_HASH_p256=Z.of_int60(* model DECODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_DECODING_PUBLIC_KEY_HASH_secp256k1=Z.of_int60(* model DECODING_PUBLIC_KEY_ed25519 *)letcost_DECODING_PUBLIC_KEY_ed25519=Z.of_int60(* model DECODING_PUBLIC_KEY_p256 *)letcost_DECODING_PUBLIC_KEY_p256=Z.of_int25_000(* model DECODING_PUBLIC_KEY_secp256k1 *)letcost_DECODING_PUBLIC_KEY_secp256k1=Z.of_int5_300(* model DECODING_SIGNATURE_ed25519 *)letcost_DECODING_SIGNATURE_ed25519=Z.of_int30(* model DECODING_SIGNATURE_p256 *)letcost_DECODING_SIGNATURE_p256=Z.of_int30(* model DECODING_SIGNATURE_secp256k1 *)letcost_DECODING_SIGNATURE_secp256k1=Z.of_int30(* model ENCODING_CHAIN_ID *)letcost_ENCODING_CHAIN_ID=Z.of_int50(* model ENCODING_PUBLIC_KEY_HASH_ed25519 *)letcost_ENCODING_PUBLIC_KEY_HASH_ed25519=Z.of_int70(* model ENCODING_PUBLIC_KEY_HASH_p256 *)letcost_ENCODING_PUBLIC_KEY_HASH_p256=Z.of_int80(* model ENCODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_ENCODING_PUBLIC_KEY_HASH_secp256k1=Z.of_int70(* model ENCODING_PUBLIC_KEY_ed25519 *)letcost_ENCODING_PUBLIC_KEY_ed25519=Z.of_int80(* model ENCODING_PUBLIC_KEY_p256 *)letcost_ENCODING_PUBLIC_KEY_p256=Z.of_int450(* model ENCODING_PUBLIC_KEY_secp256k1 *)letcost_ENCODING_PUBLIC_KEY_secp256k1=Z.of_int490(* model ENCODING_SIGNATURE_ed25519 *)letcost_ENCODING_SIGNATURE_ed25519=Z.of_int40(* model ENCODING_SIGNATURE_p256 *)letcost_ENCODING_SIGNATURE_p256=Z.of_int40(* model ENCODING_SIGNATURE_secp256k1 *)letcost_ENCODING_SIGNATURE_secp256k1=Z.of_int40(* model TIMESTAMP_READABLE_DECODING *)letcost_TIMESTAMP_READABLE_DECODING=Z.of_int130(* model TIMESTAMP_READABLE_ENCODING *)letcost_TIMESTAMP_READABLE_ENCODING=Z.of_int900(* model CHECK_PRINTABLE *)letcost_CHECK_PRINTABLEsize=letopenZ_syntaxinZ.of_int14+(Z.of_int10*Z.of_intsize)(* model MERGE_TYPES
This is the estimated cost of one iteration of merge_types, extracted
and copied manually from the parameter fit for the MERGE_TYPES benchmark
(the model is parametric on the size of the type, which we don't have
access to in O(1)). *)letcost_MERGE_TYPES=Z.of_int130(* model TYPECHECKING_CODE
This is the cost of one iteration of parse_instr, extracted by hand from the
parameter fit for the TYPECHECKING_CODE benchmark. *)letcost_TYPECHECKING_CODE=Z.of_int375(* model UNPARSING_CODE
This is the cost of one iteration of unparse_instr, extracted by hand from the
parameter fit for the UNPARSING_CODE benchmark. *)letcost_UNPARSING_CODE=Z.of_int200(* model TYPECHECKING_DATA
This is the cost of one iteration of parse_data, extracted by hand from the
parameter fit for the TYPECHECKING_DATA benchmark. *)letcost_TYPECHECKING_DATA=Z.of_int240(* model UNPARSING_DATA
This is the cost of one iteration of unparse_data, extracted by hand from the
parameter fit for the UNPARSING_DATA benchmark. *)letcost_UNPARSING_DATA=Z.of_int140(* model PARSE_TYPE
This is the cost of one iteration of parse_ty, extracted by hand from the
parameter fit for the PARSE_TYPE benchmark. *)letcost_PARSE_TYPE=Z.of_int170(* model UNPARSE_TYPE
This is the cost of one iteration of unparse_ty, extracted by hand from the
parameter fit for the UNPARSE_TYPE benchmark. *)letcost_UNPARSE_TYPE=Z.of_int185endmoduleInterpreter=structopenGenerated_costs_007letdrop=atomic_step_costcost_N_Dropletdup=atomic_step_costcost_N_Dupletswap=atomic_step_costcost_N_Swapletpush=atomic_step_costcost_N_Constletcons_some=atomic_step_costcost_N_Cons_someletcons_none=atomic_step_costcost_N_Cons_noneletif_none=atomic_step_costcost_N_If_noneletcons_pair=atomic_step_costcost_N_Cons_pairletcar=atomic_step_costcost_N_Carletcdr=atomic_step_costcost_N_Cdrletcons_left=atomic_step_costcost_N_Leftletcons_right=atomic_step_costcost_N_Rightletif_left=atomic_step_costcost_N_If_leftletcons_list=atomic_step_costcost_N_Cons_listletnil=atomic_step_costcost_N_Nilletif_cons=atomic_step_costcost_N_If_consletlist_map:'aScript_typed_ir.boxed_list->Gas.cost=fun{length;_}->atomic_step_cost(cost_N_List_maplength)letlist_size=atomic_step_costcost_N_List_sizeletlist_iter:'aScript_typed_ir.boxed_list->Gas.cost=fun{length;_}->atomic_step_cost(cost_N_List_iterlength)letempty_set=atomic_step_costcost_N_Empty_setletset_iter(typea)((moduleBox):aScript_typed_ir.set)=atomic_step_cost(cost_N_Set_iterBox.size)letset_mem(typea)(elt:a)((moduleBox):aScript_typed_ir.set)=letelt_size=size_of_comparableBox.elt_tyeltinatomic_step_cost(cost_N_Set_memelt_sizeBox.size)letset_update(typea)(elt:a)((moduleBox):aScript_typed_ir.set)=letelt_size=size_of_comparableBox.elt_tyeltinatomic_step_cost(cost_N_Set_updateelt_sizeBox.size)letset_size=atomic_step_costcost_N_Set_sizeletempty_map=atomic_step_costcost_N_Empty_mapletmap_map(typekv)((moduleBox):(k,v)Script_typed_ir.map)=atomic_step_cost(cost_N_Map_map(sndBox.boxed))letmap_iter(typekv)((moduleBox):(k,v)Script_typed_ir.map)=atomic_step_cost(cost_N_Map_iter(sndBox.boxed))letmap_mem(typekv)(elt:k)((moduleBox):(k,v)Script_typed_ir.map)=letelt_size=size_of_comparableBox.key_tyeltinatomic_step_cost(cost_N_Map_memelt_size(sndBox.boxed))letmap_get(typekv)(elt:k)((moduleBox):(k,v)Script_typed_ir.map)=letelt_size=size_of_comparableBox.key_tyeltinatomic_step_cost(cost_N_Map_getelt_size(sndBox.boxed))letmap_update(typekv)(elt:k)((moduleBox):(k,v)Script_typed_ir.map)=letelt_size=size_of_comparableBox.key_tyeltinatomic_step_cost(cost_N_Map_updateelt_size(sndBox.boxed))letmap_size=atomic_step_costcost_N_Map_sizeletadd_seconds_timestamp:'aScript_int.num->Script_timestamp.t->Gas.cost=funsecondstimestamp->letseconds_bytes=int_bytessecondsinlettimestamp_bytes=z_bytes(Script_timestamp.to_zinttimestamp)inatomic_step_cost(cost_N_Add_intintseconds_bytestimestamp_bytes)letsub_seconds_timestamp:'aScript_int.num->Script_timestamp.t->Gas.cost=funsecondstimestamp->letseconds_bytes=int_bytessecondsinlettimestamp_bytes=z_bytes(Script_timestamp.to_zinttimestamp)inatomic_step_cost(cost_N_Sub_intseconds_bytestimestamp_bytes)letdiff_timestampst1t2=lett1_bytes=z_bytes(Script_timestamp.to_zintt1)inlett2_bytes=z_bytes(Script_timestamp.to_zintt2)inatomic_step_cost(cost_N_Sub_intt1_bytest2_bytes)letconcat_string_pairs1s2=atomic_step_cost(cost_N_Concat_string_pair(String.lengths1)(String.lengths2))letslice_strings=atomic_step_cost(cost_N_Slice_string(String.lengths))letstring_size=atomic_step_costcost_N_String_sizeletconcat_bytes_pairb1b2=atomic_step_cost(cost_N_Concat_string_pair(MBytes.lengthb1)(MBytes.lengthb2))letslice_bytesb=atomic_step_cost(cost_N_Slice_string(MBytes.lengthb))letbytes_size=atomic_step_costcost_N_String_sizeletadd_tez=atomic_step_costcost_N_Add_tezletsub_tez=atomic_step_costcost_N_Sub_tezletmul_teznatn=atomic_step_cost(cost_N_Mul_teznat(int_bytesn))letbool_or=atomic_step_costcost_N_Orletbool_and=atomic_step_costcost_N_Andletbool_xor=atomic_step_costcost_N_Xorletbool_not=atomic_step_costcost_N_Notletis_nat=atomic_step_costcost_N_Is_natletabs_inti=atomic_step_cost(cost_N_Abs_int(int_bytesi))letint_nat=atomic_step_costcost_N_Int_natletneg_inti=atomic_step_cost(cost_N_Neg_int(int_bytesi))letneg_natn=atomic_step_cost(cost_N_Neg_int(int_bytesn))letadd_biginti1i2=atomic_step_cost(cost_N_Add_intint(int_bytesi1)(int_bytesi2))letsub_biginti1i2=atomic_step_cost(cost_N_Sub_int(int_bytesi1)(int_bytesi2))letmul_biginti1i2=atomic_step_cost(cost_N_Mul_intint(int_bytesi1)(int_bytesi2))letediv_teznat_tez_n=atomic_step_costcost_N_Ediv_teznatletediv_tez=atomic_step_costcost_N_Ediv_tezletediv_biginti1i2=atomic_step_cost(cost_N_Ediv_natnat(int_bytesi1)(int_bytesi2))leteq=atomic_step_costcost_N_Eqletlsl_natshifted=atomic_step_cost(cost_N_Lsl_nat(int_bytesshifted))letlsr_natshifted=atomic_step_cost(cost_N_Lsr_nat(int_bytesshifted))letor_natn1n2=atomic_step_cost(cost_N_Or_nat(int_bytesn1)(int_bytesn2))letand_natn1n2=atomic_step_cost(cost_N_And_nat(int_bytesn1)(int_bytesn2))letxor_natn1n2=atomic_step_cost(cost_N_Xor_nat(int_bytesn1)(int_bytesn2))letnot_inti=atomic_step_cost(cost_N_Not_int(int_bytesi))letnot_nat=not_intletseq=atomic_step_costcost_N_Seqletif_=atomic_step_costcost_N_Ifletloop=atomic_step_costcost_N_Loopletloop_left=atomic_step_costcost_N_Loop_leftletdip=atomic_step_costcost_N_Dipletcheck_signature(pkey:Signature.public_key)b=letcost=matchpkeywith|Ed25519_->cost_N_Check_signature_ed25519(MBytes.lengthb)|Secp256k1_->cost_N_Check_signature_secp256k1(MBytes.lengthb)|P256_->cost_N_Check_signature_p256(MBytes.lengthb)inatomic_step_costcostletblake2bb=atomic_step_cost(cost_N_Blake2b(MBytes.lengthb))letsha256b=atomic_step_cost(cost_N_Sha256(MBytes.lengthb))letsha512b=atomic_step_cost(cost_N_Sha512(MBytes.lengthb))letdignn=atomic_step_cost(cost_N_Dign)letdugnn=atomic_step_cost(cost_N_Dugn)letdipnn=atomic_step_cost(cost_N_DipNn)letdropnn=atomic_step_cost(cost_N_DropNn)letneq=atomic_step_costcost_N_Neqletnop=atomic_step_costcost_N_Nop(* --------------------------------------------------------------------- *)(* Semi-hand-crafted models *)letcompare_bool=atomic_step_cost(cost_N_Compare_bool11)letcompare_strings1s2=atomic_step_cost(cost_N_Compare_string(String.lengths1)(String.lengths2))letcompare_bytesb1b2=atomic_step_cost(cost_N_Compare_string(MBytes.lengthb1)(MBytes.lengthb2))letcompare_mutez=atomic_step_cost(cost_N_Compare_mutez88)letcompare_inti1i2=atomic_step_cost(cost_N_Compare_int(int_bytesi1)(int_bytesi2))letcompare_natn1n2=atomic_step_cost(cost_N_Compare_int(int_bytesn1)(int_bytesn2))letcompare_key_hash=letsz=Signature.Public_key_hash.sizeinatomic_step_cost(cost_N_Compare_key_hashszsz)letcompare_timestampt1t2=atomic_step_cost(cost_N_Compare_timestamp(z_bytes(Script_timestamp.to_zintt1))(z_bytes(Script_timestamp.to_zintt2)))letcompare_address=letsz=Signature.Public_key_hash.size+Chain_id.sizeinatomic_step_cost(cost_N_Compare_addressszsz)letreccompare:typeas.(a,s)Script_typed_ir.comparable_struct->a->a->cost=funtyxy->matchtywith|Bool_key_->compare_bool|String_key_->compare_stringxy|Bytes_key_->compare_bytesxy|Mutez_key_->compare_mutez|Int_key_->compare_intxy|Nat_key_->compare_natxy|Key_hash_key_->compare_key_hash|Timestamp_key_->compare_timestampxy|Address_key_->compare_address|Pair_key((tl,_),(tr,_),_)->(* Reasonable over-approximation of the cost of lexicographic comparison. *)let(xl,xr)=xinlet(yl,yr)=yincomparetlxlyl+@comparetrxryr(* --------------------------------------------------------------------- *)(* Hand-crafted models *)(* The cost functions below where not benchmarked, a cost model was derived
from looking at similar instructions. *)(* Creating an empty big map involves converting a type to a comparable
and allocating an empty map. Since the user already paied at typechecking
time for writing this type, we charge a constant overhead here. *)letempty_big_map=atomic_step_cost(Z.add(Z.of_int100)cost_N_Empty_map)(* Cost for Concat_string is paid in two steps: when entering the interpreter,
the user pays for the cost of computing the information necessary to compute
the actual gas (so it's meta-gas): indeed, one needs to run through the
list of strings to compute the total allocated cost.
[concat_string_precheck] corresponds to the meta-gas cost of this computation.
*)letconcat_string_precheck(l:'aScript_typed_ir.boxed_list)=(* we set the precheck to be slightly more expensive than cost_N_List_iter *)atomic_step_cost(Z.mul(Z.of_intl.length)(Z.of_int10))(* This is the cost of allocating a string and blitting existing ones into it. *)letconcat_stringtotal_bytes=atomic_step_costZ.(add(of_int100)(fst(ediv_remtotal_bytes(of_int10))))(* Same story as Concat_string. *)letconcat_bytestotal_bytes=atomic_step_costZ.(add(of_int100)(fst(ediv_remtotal_bytes(of_int10))))(* Cost of additional call to logger + overhead of setting up call to [interp]. *)letexec=atomic_step_cost(Z.of_int100)(* Heavy computation happens in the [unparse_data], [unparse_ty]
functions which are carbonated. We must account for allocating
the Micheline lambda wrapper. *)letapply=atomic_step_cost(Z.of_int1000)(* Pushing a pointer on the stack. *)letlambda=push(* Pusing an address on the stack. *)letaddress=push(* Most computation happens in [parse_contract_from_script], which is carbonated.
Account for pushing on the stack. *)letcontract=push(* Most computation happens in [collect_lazy_storage], [extract_lazy_storage_diff]
and [unparse_data] which are carbonated. The instruction-specific overhead
is mostly that of updating the internal nonce, which we approximate by the
cost of a push. *)lettransfer_tokens=Gas.(push+@push)(* Wrapping a value and pushing it on the stack. *)letimplicit_account=push(* As for [transfer_token], most computation happens elsewhere.
We still account for the overhead of updating the internal_nonce. *)letcreate_contract=Gas.(push+@push)(* Increments the internal_nonce counter. *)letset_delegate=Gas.(push+@push)(* Cost of access taken care of in Contract_storage.get_balance_carbonated *)letbalance=Gas.free(* Accessing the raw_context, Small arithmetic & pushing on the stack. *)letlevel=atomic_step_cost(Z.mul(Z.of_int2)cost_N_Const)(* Same as [cost_level] *)letnow=level(* Public keys are hashed with Blake2b *)lethash_key_pk=atomic_step_cost(cost_N_Blake2bpublic_key_size)(* Pushes on the stack an element from the [step_constants] record. *)letsource=push(* Same as cost_source *)letsender=source(* Same as cost_source *)letself=source(* Same as cost_source *)letself_address=source(* Same as cost_source *)letamount=source(* Same as cost_source *)letchain_id=source(* FIXME: imported from 006, needs proper benchmarks *)letunpack_failedbytes=(* We cannot instrument failed deserialization,
so we take worst case fees: a set of size 1 bytes values. *)letlen=Z.of_int(MBytes.lengthbytes)in(len*@alloc_mbytes_cost1)+@len*@(Z.of_int(Z.numbitslen)*@(alloc_cost(Z.of_int3)+@step_costZ.one))endmoduleTypechecking=structopenGenerated_costs_007letpublic_key_optimized=atomic_step_cost@@Compare.Z.(maxcost_DECODING_PUBLIC_KEY_ed25519(maxcost_DECODING_PUBLIC_KEY_secp256k1cost_DECODING_PUBLIC_KEY_p256))letpublic_key_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_DECODING_PUBLIC_KEY_ed25519(maxcost_B58CHECK_DECODING_PUBLIC_KEY_secp256k1cost_B58CHECK_DECODING_PUBLIC_KEY_p256))letkey_hash_optimized=atomic_step_cost@@Compare.Z.(maxcost_DECODING_PUBLIC_KEY_HASH_ed25519(maxcost_DECODING_PUBLIC_KEY_HASH_secp256k1cost_DECODING_PUBLIC_KEY_HASH_p256))letkey_hash_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_ed25519(maxcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_secp256k1cost_B58CHECK_DECODING_PUBLIC_KEY_HASH_p256))letsignature_optimized=atomic_step_cost@@Compare.Z.(maxcost_DECODING_SIGNATURE_ed25519(maxcost_DECODING_SIGNATURE_secp256k1cost_DECODING_SIGNATURE_p256))letsignature_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_DECODING_SIGNATURE_ed25519(maxcost_B58CHECK_DECODING_SIGNATURE_secp256k1cost_B58CHECK_DECODING_SIGNATURE_p256))letchain_id_optimized=atomic_step_costcost_DECODING_CHAIN_IDletchain_id_readable=atomic_step_costcost_B58CHECK_DECODING_CHAIN_ID(* Reasonable approximation *)letaddress_optimized=key_hash_optimized(* Reasonable approximation *)letcontract_optimized=key_hash_optimized(* Reasonable approximation *)letcontract_readable=key_hash_readableletcheck_printables=atomic_step_cost(cost_CHECK_PRINTABLE(String.lengths))letmerge_cycle=atomic_step_costcost_MERGE_TYPESletparse_type_cycle=atomic_step_costcost_PARSE_TYPEletparse_instr_cycle=atomic_step_costcost_TYPECHECKING_CODEletparse_data_cycle=atomic_step_costcost_TYPECHECKING_DATAletbool=freeletunit=freelettimestamp_readable=atomic_step_costcost_TIMESTAMP_READABLE_DECODING(* Reasonable estimate. *)letcontract=Gas.(Z.of_int2*@public_key_readable)(* Assuming unflattened storage: /contracts/hash1/.../hash6/key/balance,
balance stored on 64 bits *)letcontract_exists=Gas.cost_of_repr@@Storage_costs.read_access~path_length:9~read_bytes:8(* Constructing proof arguments consists in a decreasing loop in the result
monad, allocating at each step. We charge a reasonable overapproximation. *)letproof_argumentn=atomic_step_cost(Z.mul(Z.of_intn)(Z.of_int50))endmoduleUnparsing=structopenGenerated_costs_007letpublic_key_optimized=atomic_step_cost@@Compare.Z.(maxcost_ENCODING_PUBLIC_KEY_ed25519(maxcost_ENCODING_PUBLIC_KEY_secp256k1cost_ENCODING_PUBLIC_KEY_p256))letpublic_key_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_ed25519(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_secp256k1cost_B58CHECK_ENCODING_PUBLIC_KEY_p256))letkey_hash_optimized=atomic_step_cost@@Compare.Z.(maxcost_ENCODING_PUBLIC_KEY_HASH_ed25519(maxcost_ENCODING_PUBLIC_KEY_HASH_secp256k1cost_ENCODING_PUBLIC_KEY_HASH_p256))letkey_hash_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_ed25519(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_secp256k1cost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_p256))letsignature_optimized=atomic_step_cost@@Compare.Z.(maxcost_ENCODING_SIGNATURE_ed25519(maxcost_ENCODING_SIGNATURE_secp256k1cost_ENCODING_SIGNATURE_p256))letsignature_readable=atomic_step_cost@@Compare.Z.(maxcost_B58CHECK_ENCODING_SIGNATURE_ed25519(maxcost_B58CHECK_ENCODING_SIGNATURE_secp256k1cost_B58CHECK_ENCODING_SIGNATURE_p256))letchain_id_optimized=atomic_step_costcost_ENCODING_CHAIN_IDletchain_id_readable=atomic_step_costcost_B58CHECK_ENCODING_CHAIN_IDlettimestamp_readable=atomic_step_costcost_TIMESTAMP_READABLE_ENCODING(* Reasonable approximation *)letaddress_optimized=key_hash_optimized(* Reasonable approximation *)letcontract_optimized=key_hash_optimized(* Reasonable approximation *)letcontract_readable=key_hash_readableletunparse_type_cycle=atomic_step_costcost_UNPARSE_TYPEletunparse_instr_cycle=atomic_step_costcost_UNPARSING_CODEletunparse_data_cycle=atomic_step_costcost_UNPARSING_DATAletunit=Gas.free(* Reasonable estimate. *)letcontract=Gas.(Z.of_int2*@public_key_readable)(* Reuse 006 costs. *)letoperationbytes=Script.bytes_node_costbytesendend