1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2019-2020 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2020 Metastate AG <hello@metastate.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. *)(* *)(*****************************************************************************)openAlpha_contextopenGasmoduleS=Saturation_reprmoduleCost_of=structmoduleS_syntax=struct(* This is a good enough approximation. S.numbits 0 = 0 *)letlog2x=S.safe_int(1+Z.numbits(S.to_zx))let(+)=S.addlet(*)=S.mullet(lsr)=S.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(* Upper-bound on the time to compare the given value.
For now, returns size in bytes, but this could get more complicated... *)letrecsize_of_comparable:typea.aScript_typed_ir.comparable_ty->a->S.may_saturateS.t=funwitv->match(wit,v)with|(Unit_key_,_)->S.safe_int1|(Never_key_,_)->.|(Int_key_,_)->S.safe_int@@int_bytesv|(Nat_key_,_)->S.safe_int@@int_bytesv|(Signature_key_,_)->S.safe_intSignature.size|(String_key_,_)->S.safe_int@@String.lengthv|(Bytes_key_,_)->S.safe_int@@Bytes.lengthv|(Bool_key_,_)->S.safe_int8|(Key_hash_key_,_)->S.safe_intSignature.Public_key_hash.size|(Key_key_,k)->S.safe_int@@Signature.Public_key.sizek|(Timestamp_key_,_)->S.safe_int@@timestamp_bytesv|(Address_key_,_)->S.safe_intSignature.Public_key_hash.size|(Mutez_key_,_)->S.safe_int8|(Chain_id_key_,_)->S.safe_intChain_id.size|(Pair_key((l,_),(r,_),_),(lval,rval))->S.add(size_of_comparablellval)(size_of_comparablerrval)|(Union_key((t,_),_,_),Lx)->S.add(S.safe_int1)(size_of_comparabletx)|(Union_key(_,(t,_),_),Rx)->S.add(S.safe_int1)(size_of_comparabletx)|(Option_key_,None)->S.safe_int1|(Option_key(t,_),Somex)->S.add(S.safe_int1)(size_of_comparabletx)letmanager_operation=step_cost@@S.safe_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=S.safe_int@@(80+(sizelsr4))(* model N_Add_bls12_381_fr *)letcost_N_Add_bls12_381_fr=S.safe_int200(* model N_Add_bls12_381_g1 *)letcost_N_Add_bls12_381_g1=S.safe_int8_300(* model N_Add_bls12_381_g2 *)letcost_N_Add_bls12_381_g2=S.safe_int11_450(* model N_Add_intint *)(* Approximating 0.082158 x term *)letcost_N_Add_intintsize1size2=letv0=Compare.Int.maxsize1size2inS.safe_int(80+((v0lsr4)+(v0lsr6)))(* model N_Add_tez *)letcost_N_Add_tez=S.safe_int55(* model N_And *)letcost_N_And=S.safe_int50(* model N_And_nat *)(* Approximating 0.079325 x term *)letcost_N_And_natsize1size2=letv0=Compare.Int.minsize1size2inS.safe_int(80+((v0lsr4)+(v0lsr6)))(* model N_Blake2b *)(* Approximating 1.366428 x term *)letcost_N_Blake2bsize=letopenS_syntaxinletsize=S.safe_intsizeinS.safe_int500+(size+(sizelsr2))(* model N_Car *)letcost_N_Car=S.safe_int50(* model N_Cdr *)letcost_N_Cdr=S.safe_int50(* model N_Check_signature_ed25519 *)(* Approximating 1.372685 x term *)letcost_N_Check_signature_ed25519size=letopenS_syntaxinletsize=S.safe_intsizeinS.safe_int270_000+(size+(sizelsr2))(* model N_Check_signature_p256 *)(* Approximating 1.385771 x term *)letcost_N_Check_signature_p256size=letopenS_syntaxinletsize=S.safe_intsizeinS.safe_int600_000+(size+(sizelsr2)+(sizelsr3))(* model N_Check_signature_secp256k1 *)(* Approximating 1.372411 x term *)letcost_N_Check_signature_secp256k1size=letopenS_syntaxinletsize=S.safe_intsizeinS.safe_int60_000+(size+(sizelsr2))(* model N_Comb *)(* Approximating 3.275337 x term *)letcost_N_Combsize=S.safe_int(80+((3*size)+(sizelsr2)))(* model N_Comb_get *)(* Approximating 0.553178 x term *)letcost_N_Comb_getsize=S.safe_int(80+((sizelsr1)+(sizelsr4)))(* model N_Comb_set *)(* Approximating 1.282976 x term *)letcost_N_Comb_setsize=S.safe_int(80+(size+(sizelsr2)))(* model N_Compare_address *)letcost_N_Compare_addresssize1size2=S.safe_int(80+(2*Compare.Int.minsize1size2))(* model N_Compare_bool *)letcost_N_Compare_boolsize1size2=S.safe_int(80+(128*Compare.Int.minsize1size2))(* model N_Compare_int *)(* Approximating 0.073657 x term *)letcost_N_Compare_intsize1size2=letv0=Compare.Int.minsize1size2inS.safe_int(150+((v0lsr4)+(v0lsr7)))(* model N_Compare_key_hash *)letcost_N_Compare_key_hashsize1size2=S.safe_int(80+(2*Compare.Int.minsize1size2))(* model N_Compare_mutez *)letcost_N_Compare_mutezsize1size2=S.safe_int(13*Compare.Int.minsize1size2)(* model N_Compare_string *)(* Approximating 0.039389 x term *)letcost_N_Compare_stringsize1size2=letv0=Compare.Int.minsize1size2inS.safe_int(120+((v0lsr5)+(v0lsr7)))(* model N_Compare_timestamp *)(* Approximating 0.072483 x term *)letcost_N_Compare_timestampsize1size2=letv0=Compare.Int.minsize1size2inS.safe_int(140+((v0lsr4)+(v0lsr7)))(* model N_Concat_string_pair *)(* Approximating 0.068808 x term *)letcost_N_Concat_string_pairsize1size2=letopenS_syntaxinletv0=S.safe_intsize1+S.safe_intsize2inS.safe_int80+(v0lsr4)(* model N_Cons_list *)letcost_N_Cons_list=S.safe_int50(* model N_Cons_none *)letcost_N_Cons_none=S.safe_int45(* model N_Cons_pair *)letcost_N_Cons_pair=S.safe_int45(* model N_Cons_some *)letcost_N_Cons_some=S.safe_int45(* model N_Const *)letcost_N_Const=S.safe_int45(* model N_Dig *)letcost_N_Digsize=S.safe_int(100+(4*size))(* model N_Dip *)letcost_N_Dip=S.safe_int45(* model N_DipN *)letcost_N_DipNsize=S.safe_int(100+(4*size))(* model N_Drop *)letcost_N_Drop=S.safe_int45(* model N_DropN *)letcost_N_DropNsize=S.safe_int(100+(4*size))(* model N_Dug *)letcost_N_Dugsize=S.safe_int(100+(4*size))(* model N_Dup *)letcost_N_Dup=S.safe_int50(* model N_DupN *)(* Approximating 1.299969 x term *)letcost_N_DupNsize=S.safe_int(60+size+(sizelsr2))(* model N_Ediv_natnat *)(* Approximating 0.001599 x term *)letcost_N_Ediv_natnatsize1size2=letq=size1-size2inifCompare.Int.(q<0)thenS.safe_int300elseletopenS_syntaxinletv0=S.safe_intq*S.safe_intsize2inS.safe_int300+(v0lsr10)+(v0lsr11)+(v0lsr13)(* model N_Ediv_tez *)letcost_N_Ediv_tez=S.safe_int200(* model N_Ediv_teznat *)(* Extracted by hand from the empirical data *)letcost_N_Ediv_teznat=S.safe_int300(* model N_Empty_map *)letcost_N_Empty_map=S.safe_int200(* model N_Empty_set *)letcost_N_Empty_set=S.safe_int200(* model N_Eq *)letcost_N_Eq=S.safe_int50(* model N_If *)letcost_N_If=S.safe_int25(* model N_If_cons *)letcost_N_If_cons=S.safe_int30(* model N_If_left *)letcost_N_If_left=S.safe_int30(* model N_If_none *)letcost_N_If_none=S.safe_int30(* model N_Int_nat *)letcost_N_Int_nat=S.safe_int45(* model N_Is_nat *)letcost_N_Is_nat=S.safe_int50(* model N_Keccak *)letcost_N_Keccaksize=letopenS_syntaxinS.safe_int1_400+(S.safe_int30*S.safe_intsize)(* model N_Left *)letcost_N_Left=S.safe_int45(* model N_List_iter *)letcost_N_List_itersize=letopenS_syntaxinS.safe_int500+(S.safe_int7*S.safe_intsize)(* model N_List_map *)letcost_N_List_mapsize=letopenS_syntaxinS.safe_int500+(S.safe_int12*S.safe_intsize)(* model N_List_size *)letcost_N_List_size=S.safe_int50(* model N_Loop *)letcost_N_Loop=S.safe_int40(* model N_Loop_left *)letcost_N_Loop_left=S.safe_int45(* model N_Lsl_nat *)(* Approximating 0.129443 x term *)letcost_N_Lsl_natsize=S.safe_int(150+(sizelsr3))(* model N_Lsr_nat *)(* Approximating 0.129435 x term *)letcost_N_Lsr_natsize=S.safe_int(150+(sizelsr3))(* model N_Map_get *)(* Approximating 0.057548 x term *)letcost_N_Map_getsize1size2=letopenS_syntaxinletv0=size1*log2size2inS.safe_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Map_iter *)letcost_N_Map_itersize=letopenS_syntaxinS.safe_int80+(S.safe_int40*S.safe_intsize)(* model N_Map_map *)letcost_N_Map_mapsize=letopenS_syntaxinS.safe_int80+(S.safe_int761*S.safe_intsize)(* model N_Map_mem *)(* Approximating 0.058563 x term *)letcost_N_Map_memsize1size2=letopenS_syntaxinletv0=size1*log2size2inS.safe_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Map_size *)letcost_N_Map_size=S.safe_int50(* model N_Map_update *)(* Approximating 0.119968 x term *)letcost_N_Map_updatesize1size2=letopenS_syntaxinletv0=size1*log2size2inS.safe_int80+(v0lsr4)+(v0lsr5)+(v0lsr6)+(v0lsr7)(* model N_Mul_bls12_381_fr *)letcost_N_Mul_bls12_381_fr=S.safe_int250(* model N_Mul_bls12_381_g1 *)letcost_N_Mul_bls12_381_g1=S.safe_int242_000(* model N_Mul_bls12_381_g2 *)letcost_N_Mul_bls12_381_g2=S.safe_int785_500(* Converting fr from/to S.t *)letcost_bls12_381_fr_of_z=S.safe_int130letcost_bls12_381_fr_to_z=S.safe_int30letcost_N_Mul_bls12_381_fr_z=S.addcost_bls12_381_fr_of_zcost_N_Mul_bls12_381_frletcost_N_Int_bls12_381_fr=cost_bls12_381_fr_to_z(* model N_Mul_intint *)letcost_N_Mul_intintsize1size2=letopenS_syntaxinleta=S.add(S.safe_intsize1)(S.safe_intsize2)inS.safe_int80+(a*log2a)(* model N_Mul_teznat *)letcost_N_Mul_teznatsize=letopenS_syntaxinS.safe_int200+(S.safe_int133*S.safe_intsize)(* model N_Neg_bls12_381_fr *)letcost_N_Neg_bls12_381_fr=S.safe_int150(* model N_Neg_bls12_381_g1 *)letcost_N_Neg_bls12_381_g1=S.safe_int350(* model N_Neg_bls12_381_g2 *)letcost_N_Neg_bls12_381_g2=S.safe_int600(* model N_Neg_int *)(* Approximating 0.068419 x term *)letcost_N_Neg_intsize=S.safe_int(80+(sizelsr4))(* model N_Neq *)letcost_N_Neq=S.safe_int45(* model N_Nil *)letcost_N_Nil=S.safe_int45(* model N_Nop *)letcost_N_Nop=S.safe_int45(* model N_Not *)letcost_N_Not=S.safe_int50(* model N_Not_int *)(* Approximating 0.076564 x term *)letcost_N_Not_intsize=S.safe_int(55+((sizelsr4)+(sizelsr7)))(* model N_Or *)letcost_N_Or=S.safe_int50(* model N_Or_nat *)(* Approximating 0.078718 x term *)letcost_N_Or_natsize1size2=letv0=Compare.Int.maxsize1size2inS.safe_int(80+((v0lsr4)+(v0lsr6)))(* model N_Pairing_check_bls12_381 *)letcost_N_Pairing_check_bls12_381size=S.add(S.safe_int1_550_000)(S.mul(S.safe_int510_000)(S.safe_intsize))(* model N_Right *)letcost_N_Right=S.safe_int45(* model N_Seq *)letcost_N_Seq=S.safe_int30(* model N_Set_iter *)letcost_N_Set_itersize=letopenS_syntaxinS.safe_int80+(S.safe_int36*S.safe_intsize)(* model N_Set_mem *)(* Approximating 0.059410 x term *)letcost_N_Set_memsize1size2=letopenS_syntaxinletv0=size1*log2(S.safe_intsize2)inS.safe_int80+(v0lsr5)+(v0lsr6)+(v0lsr7)+(v0lsr8)(* model N_Set_size *)letcost_N_Set_size=S.safe_int50(* model N_Set_update *)(* Approximating 0.126260 x term *)letcost_N_Set_updatesize1size2=letopenS_syntaxinletv0=size1*log2(S.safe_intsize2)inS.safe_int80+(v0lsr3)(* model N_Sha256 *)letcost_N_Sha256size=letopenS_syntaxinS.safe_int500+(S.safe_int5*S.safe_intsize)(* model N_Sha3 *)letcost_N_Sha3size=letopenS_syntaxinS.safe_int1_400+(S.safe_int32*S.safe_intsize)(* model N_Sha512 *)letcost_N_Sha512size=letopenS_syntaxinS.safe_int500+(S.safe_int3*S.safe_intsize)(* model N_Slice_string *)(* Approximating 0.067048 x term *)letcost_N_Slice_stringsize=S.safe_int(80+(sizelsr4))(* model N_String_size *)letcost_N_String_size=S.safe_int50(* model N_Sub_int *)(* Approximating 0.082399 x term *)letcost_N_Sub_intsize1size2=letv0=Compare.Int.maxsize1size2inS.safe_int(80+((v0lsr4)+(v0lsr6)))(* model N_Sub_tez *)letcost_N_Sub_tez=S.safe_int55(* model N_Swap *)letcost_N_Swap=S.safe_int40(* model N_Total_voting_power *)letcost_N_Total_voting_power=S.safe_int400(* model N_Uncomb *)(* Approximating 3.666332 x term *)letcost_N_Uncombsize=S.safe_int(80+((3*size)+(sizelsr1)+(sizelsr3)))(* model N_Unpair *)letcost_N_Unpair=S.safe_int50(* model N_Voting_power *)letcost_N_Voting_power=S.safe_int400(* model N_Xor *)letcost_N_Xor=S.safe_int50(* model N_Xor_nat *)(* Approximating 0.078258 x term *)letcost_N_Xor_natsize1size2=letv0=Compare.Int.maxsize1size2inS.safe_int(80+((v0lsr4)+(v0lsr6)))(* model DECODING_BLS_FR *)letcost_DECODING_BLS_FR=S.safe_int50(* model DECODING_BLS_G1 *)letcost_DECODING_BLS_G1=S.safe_int230_000(* model DECODING_BLS_G2 *)letcost_DECODING_BLS_G2=S.safe_int740_000(* model B58CHECK_DECODING_CHAIN_ID *)letcost_B58CHECK_DECODING_CHAIN_ID=S.safe_int1_500(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_ed25519 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_ed25519=S.safe_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_p256 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_p256=S.safe_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_HASH_secp256k1=S.safe_int3_300(* model B58CHECK_DECODING_PUBLIC_KEY_ed25519 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_ed25519=S.safe_int4_300(* model B58CHECK_DECODING_PUBLIC_KEY_p256 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_p256=S.safe_int29_000(* model B58CHECK_DECODING_PUBLIC_KEY_secp256k1 *)letcost_B58CHECK_DECODING_PUBLIC_KEY_secp256k1=S.safe_int9_400(* model B58CHECK_DECODING_SIGNATURE_ed25519 *)letcost_B58CHECK_DECODING_SIGNATURE_ed25519=S.safe_int6_600(* model B58CHECK_DECODING_SIGNATURE_p256 *)letcost_B58CHECK_DECODING_SIGNATURE_p256=S.safe_int6_600(* model B58CHECK_DECODING_SIGNATURE_secp256k1 *)letcost_B58CHECK_DECODING_SIGNATURE_secp256k1=S.safe_int6_600(* model ENCODING_BLS_FR *)letcost_ENCODING_BLS_FR=S.safe_int30(* model ENCODING_BLS_G1 *)letcost_ENCODING_BLS_G1=S.safe_int30(* model ENCODING_BLS_G2 *)letcost_ENCODING_BLS_G2=S.safe_int30(* model B58CHECK_ENCODING_CHAIN_ID *)letcost_B58CHECK_ENCODING_CHAIN_ID=S.safe_int1_600(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_ed25519 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_ed25519=S.safe_int3_300(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_p256 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_p256=S.safe_int3_750(* model B58CHECK_ENCODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_HASH_secp256k1=S.safe_int3_300(* model B58CHECK_ENCODING_PUBLIC_KEY_ed25519 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_ed25519=S.safe_int4_500(* model B58CHECK_ENCODING_PUBLIC_KEY_p256 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_p256=S.safe_int5_300(* model B58CHECK_ENCODING_PUBLIC_KEY_secp256k1 *)letcost_B58CHECK_ENCODING_PUBLIC_KEY_secp256k1=S.safe_int5_000(* model B58CHECK_ENCODING_SIGNATURE_ed25519 *)letcost_B58CHECK_ENCODING_SIGNATURE_ed25519=S.safe_int8_700(* model B58CHECK_ENCODING_SIGNATURE_p256 *)letcost_B58CHECK_ENCODING_SIGNATURE_p256=S.safe_int8_700(* model B58CHECK_ENCODING_SIGNATURE_secp256k1 *)letcost_B58CHECK_ENCODING_SIGNATURE_secp256k1=S.safe_int8_700(* model DECODING_CHAIN_ID *)letcost_DECODING_CHAIN_ID=S.safe_int50(* model DECODING_PUBLIC_KEY_HASH_ed25519 *)letcost_DECODING_PUBLIC_KEY_HASH_ed25519=S.safe_int50(* model DECODING_PUBLIC_KEY_HASH_p256 *)letcost_DECODING_PUBLIC_KEY_HASH_p256=S.safe_int60(* model DECODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_DECODING_PUBLIC_KEY_HASH_secp256k1=S.safe_int60(* model DECODING_PUBLIC_KEY_ed25519 *)letcost_DECODING_PUBLIC_KEY_ed25519=S.safe_int60(* model DECODING_PUBLIC_KEY_p256 *)letcost_DECODING_PUBLIC_KEY_p256=S.safe_int25_000(* model DECODING_PUBLIC_KEY_secp256k1 *)letcost_DECODING_PUBLIC_KEY_secp256k1=S.safe_int5_300(* model DECODING_SIGNATURE_ed25519 *)letcost_DECODING_SIGNATURE_ed25519=S.safe_int30(* model DECODING_SIGNATURE_p256 *)letcost_DECODING_SIGNATURE_p256=S.safe_int30(* model DECODING_SIGNATURE_secp256k1 *)letcost_DECODING_SIGNATURE_secp256k1=S.safe_int30(* model ENCODING_CHAIN_ID *)letcost_ENCODING_CHAIN_ID=S.safe_int50(* model ENCODING_PUBLIC_KEY_HASH_ed25519 *)letcost_ENCODING_PUBLIC_KEY_HASH_ed25519=S.safe_int70(* model ENCODING_PUBLIC_KEY_HASH_p256 *)letcost_ENCODING_PUBLIC_KEY_HASH_p256=S.safe_int80(* model ENCODING_PUBLIC_KEY_HASH_secp256k1 *)letcost_ENCODING_PUBLIC_KEY_HASH_secp256k1=S.safe_int70(* model ENCODING_PUBLIC_KEY_ed25519 *)letcost_ENCODING_PUBLIC_KEY_ed25519=S.safe_int80(* model ENCODING_PUBLIC_KEY_p256 *)letcost_ENCODING_PUBLIC_KEY_p256=S.safe_int450(* model ENCODING_PUBLIC_KEY_secp256k1 *)letcost_ENCODING_PUBLIC_KEY_secp256k1=S.safe_int490(* model ENCODING_SIGNATURE_ed25519 *)letcost_ENCODING_SIGNATURE_ed25519=S.safe_int40(* model ENCODING_SIGNATURE_p256 *)letcost_ENCODING_SIGNATURE_p256=S.safe_int40(* model ENCODING_SIGNATURE_secp256k1 *)letcost_ENCODING_SIGNATURE_secp256k1=S.safe_int40(* model TIMESTAMP_READABLE_DECODING *)letcost_TIMESTAMP_READABLE_DECODING=S.safe_int130(* model TIMESTAMP_READABLE_ENCODING *)letcost_TIMESTAMP_READABLE_ENCODING=S.safe_int900(* model CHECK_PRINTABLE *)letcost_CHECK_PRINTABLEsize=letopenS_syntaxinS.safe_int14+(S.safe_int10*S.safe_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=S.safe_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=S.safe_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=S.safe_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=S.safe_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=S.safe_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=S.safe_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=S.safe_int185(* TODO: benchmark *)letcost_COMPARABLE_TY_OF_TY=S.safe_int120(* model SAPLING_TRANSACTION_ENCODING *)letcost_SAPLING_TRANSACTION_ENCODING~inputs~outputs=S.safe_int(1500+(inputs*160)+(outputs*320))(* model SAPLING_DIFF_ENCODING *)letcost_SAPLING_DIFF_ENCODING~nfs~cms=S.safe_int((nfs*22)+(cms*215))endmoduleInterpreter=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_pairletunpair=atomic_step_costcost_N_Unpairletcar=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(S.safe_int(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(S.safe_int(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(S.safe_int(sndBox.boxed)))letmap_get_and_update(typekv)(elt:k)(m:(k,v)Script_typed_ir.map)=map_geteltm+@map_updateeltmletmap_size=atomic_step_costcost_N_Map_sizeletbig_map_elt_size=S.safe_intScript_expr_hash.sizeletbig_map_mem({size;_}:_Script_typed_ir.big_map_overlay)=atomic_step_cost(cost_N_Map_membig_map_elt_size(S.safe_intsize))letbig_map_get({size;_}:_Script_typed_ir.big_map_overlay)=atomic_step_cost(cost_N_Map_getbig_map_elt_size(S.safe_intsize))letbig_map_update({size;_}:_Script_typed_ir.big_map_overlay)=atomic_step_cost(cost_N_Map_updatebig_map_elt_size(S.safe_intsize))letbig_map_get_and_updatem=big_map_getm+@big_map_updatemletadd_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(Bytes.lengthb1)(Bytes.lengthb2))letslice_bytesb=atomic_step_cost(cost_N_Slice_string(Bytes.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(Bytes.lengthb)|Secp256k1_->cost_N_Check_signature_secp256k1(Bytes.lengthb)|P256_->cost_N_Check_signature_p256(Bytes.lengthb)inatomic_step_costcostletblake2bb=atomic_step_cost(cost_N_Blake2b(Bytes.lengthb))letsha256b=atomic_step_cost(cost_N_Sha256(Bytes.lengthb))letsha512b=atomic_step_cost(cost_N_Sha512(Bytes.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)letvoting_power=atomic_step_costcost_N_Voting_powerlettotal_voting_power=atomic_step_costcost_N_Total_voting_powerletkeccakb=atomic_step_cost(cost_N_Keccak(Bytes.lengthb))letsha3b=atomic_step_cost(cost_N_Sha3(Bytes.lengthb))letadd_bls12_381_g1=atomic_step_costcost_N_Add_bls12_381_g1letadd_bls12_381_g2=atomic_step_costcost_N_Add_bls12_381_g2letadd_bls12_381_fr=atomic_step_costcost_N_Add_bls12_381_frletmul_bls12_381_g1=atomic_step_costcost_N_Mul_bls12_381_g1letmul_bls12_381_g2=atomic_step_costcost_N_Mul_bls12_381_g2letmul_bls12_381_fr=atomic_step_costcost_N_Mul_bls12_381_frletmul_bls12_381_fr_z=atomic_step_costcost_N_Mul_bls12_381_fr_zletint_bls12_381_fr=atomic_step_costcost_N_Int_bls12_381_frletneg_bls12_381_g1=atomic_step_costcost_N_Neg_bls12_381_g1letneg_bls12_381_g2=atomic_step_costcost_N_Neg_bls12_381_g2letneg_bls12_381_fr=atomic_step_costcost_N_Neg_bls12_381_frletneq=atomic_step_costcost_N_Neqletnop=atomic_step_costcost_N_Nopletpairing_check_bls12_381(l:'aScript_typed_ir.boxed_list)=atomic_step_cost(cost_N_Pairing_check_bls12_381l.length)letcombn=atomic_step_cost(cost_N_Combn)letuncombn=atomic_step_cost(cost_N_Uncombn)letcomb_getn=atomic_step_cost(cost_N_Comb_getn)letcomb_setn=atomic_step_cost(cost_N_Comb_setn)letdupnn=atomic_step_cost(cost_N_DupNn)letsapling_verify_update~inputs~outputs=letopenS_syntaxinatomic_step_cost(S.safe_int85_000+(S.safe_intinputs*S.safe_int4)+(S.safe_intoutputs*S.safe_int30))(* --------------------------------------------------------------------- *)(* Semi-hand-crafted models *)letcompare_unit=atomic_step_cost(S.safe_int10)letcompare_union_tag=atomic_step_cost(S.safe_int10)letcompare_option_tag=atomic_step_cost(S.safe_int10)letcompare_bool=atomic_step_cost(cost_N_Compare_bool11)letcompare_signature=atomic_step_cost(S.safe_int92)letcompare_strings1s2=atomic_step_cost(cost_N_Compare_string(String.lengths1)(String.lengths2))letcompare_bytesb1b2=atomic_step_cost(cost_N_Compare_string(Bytes.lengthb1)(Bytes.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_key=atomic_step_cost(S.safe_int92)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)letcompare_chain_id=atomic_step_cost(S.safe_int30)letreccompare:typea.aScript_typed_ir.comparable_ty->a->a->cost=funtyxy->matchtywith|Unit_key_->compare_unit|Never_key_->(matchxwith_->.)|Bool_key_->compare_bool|String_key_->compare_stringxy|Signature_key_->compare_signature|Bytes_key_->compare_bytesxy|Mutez_key_->compare_mutez|Int_key_->compare_intxy|Nat_key_->compare_natxy|Key_hash_key_->compare_key_hash|Key_key_->compare_key|Timestamp_key_->compare_timestampxy|Address_key_->compare_address|Chain_id_key_->compare_chain_id|Pair_key((tl,_),(tr,_),_)->(* Reasonable over-approximation of the cost of lexicographic comparison. *)let(xl,xr)=xinlet(yl,yr)=yincomparetlxlyl+@comparetrxryr|Union_key((tl,_),(tr,_),_)->(compare_union_tag+@match(x,y)with|(Lx,Ly)->comparetlxy|(L_,R_)->free|(R_,L_)->free|(Rx,Ry)->comparetrxy)|Option_key(t,_)->(compare_option_tag+@match(x,y)with|(None,None)->free|(None,Some_)->free|(Some_,None)->free|(Somex,Somey)->comparetxy)(* --------------------------------------------------------------------- *)(* Hand-crafted models *)(* The cost functions below where not benchmarked, a cost model was derived
from looking at similar instructions. *)letsapling_empty_state=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(S.mul(S.safe_intl.length)(S.safe_int10))(* This is the cost of allocating a string and blitting existing ones into it. *)letconcat_stringtotal_bytes=atomic_step_costS.(add(S.safe_int100)(S.edivtotal_bytes(S.safe_int10)))(* Same story as Concat_string. *)letconcat_bytestotal_bytes=atomic_step_costS.(add(S.safe_int100)(S.edivtotal_bytes(S.safe_int10)))(* Cost of additional call to logger + overhead of setting up call to [interp]. *)letexec=atomic_step_cost(S.safe_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(S.safe_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(S.mul(S.safe_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(* TODO benchmark *)(* 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. *)letblen=Bytes.lengthbytesinletlen=S.safe_intbleninletd=Z.numbits(Z.of_intblen)in(len*@alloc_mbytes_cost1)+@len*@(S.safe_intd*@(alloc_cost(S.safe_int3)+@step_cost(S.safe_int1)))letticket=atomic_step_cost(S.safe_int80)letread_ticket=atomic_step_cost(S.safe_int80)letsplit_ticketticket_amountamount_aamount_b=ticket+@add_bigintamount_aamount_b+@compare_natticket_amountticket_amountletjoin_tickets:'aScript_typed_ir.comparable_ty->'aScript_typed_ir.ticket->'aScript_typed_ir.ticket->Gas.cost=funtyticket_aticket_b->ticket+@compare_address+@add_bigintticket_a.amountticket_b.amount+@comparetyticket_a.contentsticket_b.contentsendmoduleTypechecking=structopenGenerated_costs_007letpublic_key_optimized=atomic_step_cost@@S.(maxcost_DECODING_PUBLIC_KEY_ed25519(maxcost_DECODING_PUBLIC_KEY_secp256k1cost_DECODING_PUBLIC_KEY_p256))letpublic_key_readable=atomic_step_cost@@S.(maxcost_B58CHECK_DECODING_PUBLIC_KEY_ed25519(maxcost_B58CHECK_DECODING_PUBLIC_KEY_secp256k1cost_B58CHECK_DECODING_PUBLIC_KEY_p256))letkey_hash_optimized=atomic_step_cost@@S.(maxcost_DECODING_PUBLIC_KEY_HASH_ed25519(maxcost_DECODING_PUBLIC_KEY_HASH_secp256k1cost_DECODING_PUBLIC_KEY_HASH_p256))letkey_hash_readable=atomic_step_cost@@S.(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@@S.(maxcost_DECODING_SIGNATURE_ed25519(maxcost_DECODING_SIGNATURE_secp256k1cost_DECODING_SIGNATURE_p256))letsignature_readable=atomic_step_cost@@S.(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_readableletbls12_381_g1=atomic_step_costcost_DECODING_BLS_G1letbls12_381_g2=atomic_step_costcost_DECODING_BLS_G2letbls12_381_fr=atomic_step_costcost_DECODING_BLS_FRletcheck_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_DATAletcomparable_ty_of_ty_cycle=atomic_step_costcost_COMPARABLE_TY_OF_TY(* Cost of a cycle of checking that a type is dupable *)(* TODO: bench *)letcheck_dupable_cycle=atomic_step_costcost_TYPECHECKING_DATAletbool=freeletunit=freelettimestamp_readable=atomic_step_costcost_TIMESTAMP_READABLE_DECODING(* Reasonable estimate. *)letcontract=Gas.(S.safe_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(S.mul(S.safe_intn)(S.safe_int50))endmoduleUnparsing=structopenGenerated_costs_007letpublic_key_optimized=atomic_step_cost@@S.(maxcost_ENCODING_PUBLIC_KEY_ed25519(maxcost_ENCODING_PUBLIC_KEY_secp256k1cost_ENCODING_PUBLIC_KEY_p256))letpublic_key_readable=atomic_step_cost@@S.(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_ed25519(maxcost_B58CHECK_ENCODING_PUBLIC_KEY_secp256k1cost_B58CHECK_ENCODING_PUBLIC_KEY_p256))letkey_hash_optimized=atomic_step_cost@@S.(maxcost_ENCODING_PUBLIC_KEY_HASH_ed25519(maxcost_ENCODING_PUBLIC_KEY_HASH_secp256k1cost_ENCODING_PUBLIC_KEY_HASH_p256))letkey_hash_readable=atomic_step_cost@@S.(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@@S.(maxcost_ENCODING_SIGNATURE_ed25519(maxcost_ENCODING_SIGNATURE_secp256k1cost_ENCODING_SIGNATURE_p256))letsignature_readable=atomic_step_cost@@S.(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_readableletbls12_381_g1=atomic_step_costcost_ENCODING_BLS_G1letbls12_381_g2=atomic_step_costcost_ENCODING_BLS_G2letbls12_381_fr=atomic_step_costcost_ENCODING_BLS_FRletunparse_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.(S.safe_int2*@public_key_readable)(* Reuse 006 costs. *)letoperationbytes=Script.bytes_node_costbytesletsapling_transaction(t:Sapling.transaction)=letinputs=List.lengtht.inputsinletoutputs=List.lengtht.outputsinatomic_step_cost(cost_SAPLING_TRANSACTION_ENCODING~inputs~outputs)letsapling_diff(d:Sapling.diff)=letnfs=List.lengthd.nullifiersinletcms=List.lengthd.commitments_and_ciphertextsinatomic_step_cost(cost_SAPLING_DIFF_ENCODING~nfs~cms)endend