diff --git a/crates/uplc/src/flat/data.rs b/crates/uplc/src/flat/data.rs index d5d659aa0..b86faa375 100644 --- a/crates/uplc/src/flat/data.rs +++ b/crates/uplc/src/flat/data.rs @@ -303,9 +303,6 @@ impl minicbor::encode::Encode for PlutusData<'_> { #[cfg(test)] mod tests { use super::*; - use crate::binder::DeBruijn; - use crate::flat::decode; - use bumpalo::Bump; #[test] fn encode_empty_record() { @@ -314,7 +311,7 @@ mod tests { fields: &[], }; let mut v = vec![]; - minicbor::encode(d, &mut v); + minicbor::encode(d, &mut v).expect("invalid PlutusData"); assert_eq!(hex::encode(v), "d87980"); } @@ -327,7 +324,7 @@ mod tests { fields: &[&b1, &b2], }; let mut v = vec![]; - minicbor::encode(d, &mut v); + minicbor::encode(d, &mut v).expect("invalid PlutusData"); assert_eq!(hex::encode(v), "d87a9f4100420001ff"); } @@ -340,7 +337,7 @@ mod tests { fields: &[&PlutusData::Integer(&zero), &PlutusData::Integer(&one)], }; let mut v = vec![]; - minicbor::encode(d, &mut v); + minicbor::encode(d, &mut v).expect("invalid PlutusData"); assert_eq!(hex::encode(v), "d8668218809f0001ff"); } @@ -355,7 +352,7 @@ mod tests { fields: &[&PlutusData::Integer(&big)], }; let mut v = vec![]; - minicbor::encode(d, &mut v); + minicbor::encode(d, &mut v).expect("invalid PlutusData"); assert_eq!(hex::encode(v), "d8799fc24c033b2e3c9fd0803ce7ffffffff"); } @@ -369,7 +366,7 @@ mod tests { fields: &[&PlutusData::List(&list)], }; let mut v = vec![]; - minicbor::encode(d, &mut v); + minicbor::encode(d, &mut v).expect("invalid PlutusData"); assert_eq!(hex::encode(v), "d8799f9f0001ffff"); } } diff --git a/crates/uplc/src/flat/decode/mod.rs b/crates/uplc/src/flat/decode/mod.rs index b0d281260..0a595d651 100644 --- a/crates/uplc/src/flat/decode/mod.rs +++ b/crates/uplc/src/flat/decode/mod.rs @@ -262,7 +262,7 @@ mod tests { &Term::Constant(&Constant::Integer(&BigInt::from(129))) ); } - Err(e) => { + Err(_) => { assert!(false); } } diff --git a/crates/uplc/src/flat/encode/mod.rs b/crates/uplc/src/flat/encode/mod.rs index 4b46fe30c..f44cfcb16 100644 --- a/crates/uplc/src/flat/encode/mod.rs +++ b/crates/uplc/src/flat/encode/mod.rs @@ -289,12 +289,12 @@ mod tests { Ok(roundtripped) => { assert_eq!(bytes_hex, hex::encode(roundtripped)); } - Err(e) => { + Err(_) => { assert!(false); } } } - Err(e) => { + Err(_) => { assert!(false); } } @@ -320,7 +320,6 @@ mod tests { // ]) let bytes_hex = "0101003370090011bad357426aae78dd526112d8799fc24c033b2e3c9fd0803ce7ffffffff0001"; - let bytes = hex::decode(bytes_hex).unwrap(); let bytes = hex::decode(&bytes_hex).unwrap(); let arena = Bump::new(); let program: Result<&Program, _> = decode(&arena, &bytes); @@ -361,7 +360,6 @@ mod tests { // ] // ]) let bytes_hex = "0101003370490021bad357426ae88dd62601049f070eff0001"; - let bytes = hex::decode(bytes_hex).unwrap(); let bytes = hex::decode(&bytes_hex).unwrap(); let arena = Bump::new(); let program: Result<&Program, _> = decode(&arena, &bytes); diff --git a/crates/uplc/src/machine/cek.rs b/crates/uplc/src/machine/cek.rs index 1905a4e08..339a6a8b3 100644 --- a/crates/uplc/src/machine/cek.rs +++ b/crates/uplc/src/machine/cek.rs @@ -2,7 +2,10 @@ use bumpalo::{collections::Vec as BumpVec, Bump}; use crate::{ binder::Eval, - machine::{context::Context, env::Env, state::MachineState}, + machine::{ + context::Context, cost_model::builtin_costs::BuiltinCostModel, env::Env, + state::MachineState, + }, term::Term, }; @@ -15,21 +18,21 @@ use super::{ CostModel, ExBudget, MachineError, }; -pub struct Machine<'a> { +pub struct Machine<'a, B: BuiltinCostModel> { pub(super) arena: &'a Bump, ex_budget: ExBudget, unbudgeted_steps: [u8; 10], - pub(super) costs: CostModel, + pub(super) costs: CostModel, slippage: u8, pub(super) logs: Vec, pub(super) semantics: BuiltinSemantics, } -impl<'a> Machine<'a> { +impl<'a, B: BuiltinCostModel> Machine<'a, B> { pub fn new( arena: &'a Bump, initial_budget: ExBudget, - costs: CostModel, + costs: CostModel, semantics: BuiltinSemantics, ) -> Self { Machine { @@ -54,7 +57,7 @@ impl<'a> Machine<'a> { where V: Eval<'a>, { - self.spend_budget(ExBudget::start_up())?; + self.spend_budget(self.costs.machine_startup)?; let initial_context = Context::no_frame(self.arena); diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs.rs deleted file mode 100644 index c42cbdc30..000000000 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ /dev/null @@ -1,1091 +0,0 @@ -use crate::machine::ExBudget; - -use super::costing::{ - Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, TwoArgumentsCosting, -}; - -#[derive(Debug, PartialEq)] -pub struct BuiltinCosts { - add_integer: TwoArgumentsCosting, - subtract_integer: TwoArgumentsCosting, - multiply_integer: TwoArgumentsCosting, - divide_integer: TwoArgumentsCosting, - quotient_integer: TwoArgumentsCosting, - remainder_integer: TwoArgumentsCosting, - mod_integer: TwoArgumentsCosting, - equals_integer: TwoArgumentsCosting, - less_than_integer: TwoArgumentsCosting, - less_than_equals_integer: TwoArgumentsCosting, - // Bytestrings - append_byte_string: TwoArgumentsCosting, - cons_byte_string: TwoArgumentsCosting, - slice_byte_string: ThreeArgumentsCosting, - length_of_byte_string: OneArgumentCosting, - index_byte_string: TwoArgumentsCosting, - equals_byte_string: TwoArgumentsCosting, - less_than_byte_string: TwoArgumentsCosting, - less_than_equals_byte_string: TwoArgumentsCosting, - // Cryptography and hashes - sha2_256: OneArgumentCosting, - sha3_256: OneArgumentCosting, - blake2b_224: OneArgumentCosting, - blake2b_256: OneArgumentCosting, - keccak_256: OneArgumentCosting, - verify_ed25519_signature: ThreeArgumentsCosting, - verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting, - verify_schnorr_secp256k1_signature: ThreeArgumentsCosting, - // Strings - append_string: TwoArgumentsCosting, - equals_string: TwoArgumentsCosting, - encode_utf8: OneArgumentCosting, - decode_utf8: OneArgumentCosting, - // Bool - if_then_else: ThreeArgumentsCosting, - // Unit - choose_unit: TwoArgumentsCosting, - // Tracing - trace: TwoArgumentsCosting, - // Pairs - fst_pair: OneArgumentCosting, - snd_pair: OneArgumentCosting, - // Lists - choose_list: ThreeArgumentsCosting, - mk_cons: TwoArgumentsCosting, - head_list: OneArgumentCosting, - tail_list: OneArgumentCosting, - null_list: OneArgumentCosting, - // Data - choose_data: SixArgumentsCosting, - constr_data: TwoArgumentsCosting, - map_data: OneArgumentCosting, - list_data: OneArgumentCosting, - i_data: OneArgumentCosting, - b_data: OneArgumentCosting, - un_constr_data: OneArgumentCosting, - un_map_data: OneArgumentCosting, - un_list_data: OneArgumentCosting, - un_i_data: OneArgumentCosting, - un_b_data: OneArgumentCosting, - equals_data: TwoArgumentsCosting, - // Misc constructors - mk_pair_data: TwoArgumentsCosting, - mk_nil_data: OneArgumentCosting, - mk_nil_pair_data: OneArgumentCosting, - serialise_data: OneArgumentCosting, - // BLST - bls12_381_g1_add: TwoArgumentsCosting, - bls12_381_g1_neg: OneArgumentCosting, - bls12_381_g1_scalar_mul: TwoArgumentsCosting, - bls12_381_g1_equal: TwoArgumentsCosting, - bls12_381_g1_compress: OneArgumentCosting, - bls12_381_g1_uncompress: OneArgumentCosting, - bls12_381_g1_hash_to_group: TwoArgumentsCosting, - bls12_381_g2_add: TwoArgumentsCosting, - bls12_381_g2_neg: OneArgumentCosting, - bls12_381_g2_scalar_mul: TwoArgumentsCosting, - bls12_381_g2_equal: TwoArgumentsCosting, - bls12_381_g2_compress: OneArgumentCosting, - bls12_381_g2_uncompress: OneArgumentCosting, - bls12_381_g2_hash_to_group: TwoArgumentsCosting, - bls12_381_miller_loop: TwoArgumentsCosting, - bls12_381_mul_ml_result: TwoArgumentsCosting, - bls12_381_final_verify: TwoArgumentsCosting, - // bitwise - integer_to_byte_string: ThreeArgumentsCosting, - byte_string_to_integer: TwoArgumentsCosting, - and_byte_string: ThreeArgumentsCosting, - or_byte_string: ThreeArgumentsCosting, - xor_byte_string: ThreeArgumentsCosting, - complement_byte_string: OneArgumentCosting, - read_bit: TwoArgumentsCosting, - write_bits: ThreeArgumentsCosting, - replicate_byte: TwoArgumentsCosting, - shift_byte_string: TwoArgumentsCosting, - rotate_byte_string: TwoArgumentsCosting, - count_set_bits: OneArgumentCosting, - find_first_set_bit: OneArgumentCosting, - ripemd_160: OneArgumentCosting, - - exp_mod_integer: ThreeArgumentsCosting, - drop_list: TwoArgumentsCosting, - length_of_array: OneArgumentCosting, - list_to_array: TwoArgumentsCosting, - index_array: TwoArgumentsCosting, -} - -impl Default for BuiltinCosts { - fn default() -> Self { - BuiltinCosts::v3() - } -} - -impl BuiltinCosts { - pub fn add_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.add_integer.mem.cost(args), - self.add_integer.cpu.cost(args), - ) - } - - pub fn subtract_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.subtract_integer.mem.cost(args), - self.subtract_integer.cpu.cost(args), - ) - } - - pub fn equals_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.equals_integer.mem.cost(args), - self.equals_integer.cpu.cost(args), - ) - } - - pub fn less_than_equals_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.less_than_equals_integer.mem.cost(args), - self.less_than_equals_integer.cpu.cost(args), - ) - } - - pub fn multiply_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.multiply_integer.mem.cost(args), - self.multiply_integer.cpu.cost(args), - ) - } - - pub fn divide_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.divide_integer.mem.cost(args), - self.divide_integer.cpu.cost(args), - ) - } - - pub fn quotient_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.quotient_integer.mem.cost(args), - self.quotient_integer.cpu.cost(args), - ) - } - - pub fn remainder_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.remainder_integer.mem.cost(args), - self.remainder_integer.cpu.cost(args), - ) - } - - pub fn mod_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.mod_integer.mem.cost(args), - self.mod_integer.cpu.cost(args), - ) - } - - pub fn less_than_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.less_than_integer.mem.cost(args), - self.less_than_integer.cpu.cost(args), - ) - } - - pub fn append_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.append_byte_string.mem.cost(args), - self.append_byte_string.cpu.cost(args), - ) - } - - pub fn equals_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.equals_byte_string.mem.cost(args), - self.equals_byte_string.cpu.cost(args), - ) - } - - pub fn cons_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.cons_byte_string.mem.cost(args), - self.cons_byte_string.cpu.cost(args), - ) - } - - pub fn slice_byte_string(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.slice_byte_string.mem.cost(args), - self.slice_byte_string.cpu.cost(args), - ) - } - - pub fn length_of_byte_string(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.length_of_byte_string.mem.cost(args), - self.length_of_byte_string.cpu.cost(args), - ) - } - - pub fn index_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.index_byte_string.mem.cost(args), - self.index_byte_string.cpu.cost(args), - ) - } - - pub fn less_than_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.less_than_byte_string.mem.cost(args), - self.less_than_byte_string.cpu.cost(args), - ) - } - - pub fn less_than_equals_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.less_than_equals_byte_string.mem.cost(args), - self.less_than_equals_byte_string.cpu.cost(args), - ) - } - - pub fn sha2_256(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.sha2_256.mem.cost(args), self.sha2_256.cpu.cost(args)) - } - - pub fn sha3_256(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.sha3_256.mem.cost(args), self.sha3_256.cpu.cost(args)) - } - - pub fn blake2b_256(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.blake2b_256.mem.cost(args), - self.blake2b_256.cpu.cost(args), - ) - } - - pub fn keccak_256(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.keccak_256.mem.cost(args), - self.keccak_256.cpu.cost(args), - ) - } - - pub fn blake2b_224(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.blake2b_224.mem.cost(args), - self.blake2b_224.cpu.cost(args), - ) - } - - pub fn verify_ed25519_signature(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.verify_ed25519_signature.mem.cost(args), - self.verify_ed25519_signature.cpu.cost(args), - ) - } - - pub fn verify_ecdsa_secp256k1_signature(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.verify_ecdsa_secp256k1_signature.mem.cost(args), - self.verify_ecdsa_secp256k1_signature.cpu.cost(args), - ) - } - - pub fn verify_schnorr_secp256k1_signature(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.verify_schnorr_secp256k1_signature.mem.cost(args), - self.verify_schnorr_secp256k1_signature.cpu.cost(args), - ) - } - - pub fn append_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.append_string.mem.cost(args), - self.append_string.cpu.cost(args), - ) - } - - pub fn equals_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.equals_string.mem.cost(args), - self.equals_string.cpu.cost(args), - ) - } - - pub fn encode_utf8(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.encode_utf8.mem.cost(args), - self.encode_utf8.cpu.cost(args), - ) - } - - pub fn decode_utf8(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.decode_utf8.mem.cost(args), - self.decode_utf8.cpu.cost(args), - ) - } - - pub fn if_then_else(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.if_then_else.mem.cost(args), - self.if_then_else.cpu.cost(args), - ) - } - - pub fn choose_unit(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.choose_unit.mem.cost(args), - self.choose_unit.cpu.cost(args), - ) - } - - pub fn trace(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new(self.trace.mem.cost(args), self.trace.cpu.cost(args)) - } - - pub fn fst_pair(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.fst_pair.mem.cost(args), self.fst_pair.cpu.cost(args)) - } - - pub fn snd_pair(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.snd_pair.mem.cost(args), self.snd_pair.cpu.cost(args)) - } - - pub fn choose_list(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.choose_list.mem.cost(args), - self.choose_list.cpu.cost(args), - ) - } - - pub fn mk_cons(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new(self.mk_cons.mem.cost(args), self.mk_cons.cpu.cost(args)) - } - - pub fn head_list(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.head_list.mem.cost(args), self.head_list.cpu.cost(args)) - } - - pub fn tail_list(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.tail_list.mem.cost(args), self.tail_list.cpu.cost(args)) - } - - pub fn null_list(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.null_list.mem.cost(args), self.null_list.cpu.cost(args)) - } - - pub fn choose_data(&self, args: [i64; 6]) -> ExBudget { - ExBudget::new( - self.choose_data.mem.cost(args), - self.choose_data.cpu.cost(args), - ) - } - - pub fn constr_data(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.constr_data.mem.cost(args), - self.constr_data.cpu.cost(args), - ) - } - - pub fn map_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.map_data.mem.cost(args), self.map_data.cpu.cost(args)) - } - - pub fn list_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.list_data.mem.cost(args), self.list_data.cpu.cost(args)) - } - - pub fn i_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.i_data.mem.cost(args), self.i_data.cpu.cost(args)) - } - - pub fn b_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.b_data.mem.cost(args), self.b_data.cpu.cost(args)) - } - - pub fn un_constr_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.un_constr_data.mem.cost(args), - self.un_constr_data.cpu.cost(args), - ) - } - - pub fn un_map_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.un_map_data.mem.cost(args), - self.un_map_data.cpu.cost(args), - ) - } - - pub fn un_list_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.un_list_data.mem.cost(args), - self.un_list_data.cpu.cost(args), - ) - } - - pub fn un_i_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.un_i_data.mem.cost(args), self.un_i_data.cpu.cost(args)) - } - - pub fn un_b_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new(self.un_b_data.mem.cost(args), self.un_b_data.cpu.cost(args)) - } - - pub fn equals_data(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.equals_data.mem.cost(args), - self.equals_data.cpu.cost(args), - ) - } - - pub fn mk_pair_data(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.mk_pair_data.mem.cost(args), - self.mk_pair_data.cpu.cost(args), - ) - } - - pub fn mk_nil_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.mk_nil_data.mem.cost(args), - self.mk_nil_data.cpu.cost(args), - ) - } - - pub fn mk_nil_pair_data(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.mk_nil_pair_data.mem.cost(args), - self.mk_nil_pair_data.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_add(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_add.mem.cost(args), - self.bls12_381_g1_add.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_neg(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_neg.mem.cost(args), - self.bls12_381_g1_neg.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_scalar_mul(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_scalar_mul.mem.cost(args), - self.bls12_381_g1_scalar_mul.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_equal(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_equal.mem.cost(args), - self.bls12_381_g1_equal.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_compress(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_compress.mem.cost(args), - self.bls12_381_g1_compress.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_uncompress(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_uncompress.mem.cost(args), - self.bls12_381_g1_uncompress.cpu.cost(args), - ) - } - - pub fn bls12_381_g1_hash_to_group(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g1_hash_to_group.mem.cost(args), - self.bls12_381_g1_hash_to_group.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_add(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_add.mem.cost(args), - self.bls12_381_g2_add.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_neg(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_neg.mem.cost(args), - self.bls12_381_g2_neg.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_scalar_mul(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_scalar_mul.mem.cost(args), - self.bls12_381_g2_scalar_mul.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_equal(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_equal.mem.cost(args), - self.bls12_381_g2_equal.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_compress(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_compress.mem.cost(args), - self.bls12_381_g2_compress.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_uncompress(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_uncompress.mem.cost(args), - self.bls12_381_g2_uncompress.cpu.cost(args), - ) - } - - pub fn bls12_381_g2_hash_to_group(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_g2_hash_to_group.mem.cost(args), - self.bls12_381_g2_hash_to_group.cpu.cost(args), - ) - } - - pub fn bls12_381_miller_loop(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_miller_loop.mem.cost(args), - self.bls12_381_miller_loop.cpu.cost(args), - ) - } - - pub fn bls12_381_mul_ml_result(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_mul_ml_result.mem.cost(args), - self.bls12_381_mul_ml_result.cpu.cost(args), - ) - } - - pub fn bls12_381_final_verify(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.bls12_381_final_verify.mem.cost(args), - self.bls12_381_final_verify.cpu.cost(args), - ) - } - - pub fn integer_to_byte_string(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.integer_to_byte_string.mem.cost(args), - self.integer_to_byte_string.cpu.cost(args), - ) - } - - pub fn byte_string_to_integer(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.byte_string_to_integer.mem.cost(args), - self.byte_string_to_integer.cpu.cost(args), - ) - } - - pub fn and_byte_string(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.and_byte_string.mem.cost(args), - self.and_byte_string.cpu.cost(args), - ) - } - - pub fn or_byte_string(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.or_byte_string.mem.cost(args), - self.or_byte_string.cpu.cost(args), - ) - } - - pub fn xor_byte_string(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.xor_byte_string.mem.cost(args), - self.xor_byte_string.cpu.cost(args), - ) - } - - pub fn complement_byte_string(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.complement_byte_string.mem.cost(args), - self.complement_byte_string.cpu.cost(args), - ) - } - - pub fn read_bit(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new(self.read_bit.mem.cost(args), self.read_bit.cpu.cost(args)) - } - - pub fn write_bits(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.write_bits.mem.cost(args), - self.write_bits.cpu.cost(args), - ) - } - - pub fn replicate_byte(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.replicate_byte.mem.cost(args), - self.replicate_byte.cpu.cost(args), - ) - } - - pub fn shift_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.shift_byte_string.mem.cost(args), - self.shift_byte_string.cpu.cost(args), - ) - } - - pub fn rotate_byte_string(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.rotate_byte_string.mem.cost(args), - self.rotate_byte_string.cpu.cost(args), - ) - } - - pub fn count_set_bits(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.count_set_bits.mem.cost(args), - self.count_set_bits.cpu.cost(args), - ) - } - - pub fn find_first_set_bit(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.find_first_set_bit.mem.cost(args), - self.find_first_set_bit.cpu.cost(args), - ) - } - - pub fn ripemd_160(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.ripemd_160.mem.cost(args), - self.ripemd_160.cpu.cost(args), - ) - } - - pub fn exp_mod_integer(&self, args: [i64; 3]) -> ExBudget { - ExBudget::new( - self.exp_mod_integer.mem.cost(args), - self.exp_mod_integer.cpu.cost(args), - ) - } - - pub fn drop_list(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new(self.drop_list.mem.cost(args), self.drop_list.cpu.cost(args)) - } - - pub fn length_of_array(&self, args: [i64; 1]) -> ExBudget { - ExBudget::new( - self.length_of_array.mem.cost(args), - self.length_of_array.cpu.cost(args), - ) - } - - pub fn list_to_array(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.list_to_array.mem.cost(args), - self.list_to_array.cpu.cost(args), - ) - } - - pub fn index_array(&self, args: [i64; 2]) -> ExBudget { - ExBudget::new( - self.index_array.mem.cost(args), - self.index_array.cpu.cost(args), - ) - } - - pub fn v3() -> Self { - Self { - add_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::max_size(1, 1), - TwoArgumentsCosting::max_size(100788, 420), - ), - subtract_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::max_size(1, 1), - TwoArgumentsCosting::max_size(100788, 420), - ), - - multiply_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::multiplied_sizes(90434, 519), - ), - divide_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::subtracted_sizes(0, 1, 1), - TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( - 85848, 85848, 123203, 7305, -900, 1716, 549, 57, - ), - ), - quotient_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::subtracted_sizes(0, 1, 1), - TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( - 85848, 85848, 123203, 7305, -900, 1716, 549, 57, - ), - ), - remainder_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_y(0, 1), - TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( - 85848, 85848, 123203, 7305, -900, 1716, 549, 57, - ), - ), - mod_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_y(0, 1), - TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( - 85848, 85848, 123203, 7305, -900, 1716, 549, 57, - ), - ), - equals_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(51775, 558), - ), - less_than_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(44749, 541), - ), - less_than_equals_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(43285, 552), - ), - append_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::added_sizes(1000, 173), - ), - cons_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::linear_in_y(72010, 178), - ), - slice_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_z(4, 0), - ThreeArgumentsCosting::linear_in_z(20467, 1), - ), - length_of_byte_string: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(10), - OneArgumentCosting::constant_cost(22100), - ), - index_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(4), - TwoArgumentsCosting::constant_cost(13169), - ), - equals_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::linear_on_diagonal(24548, 29498, 38), - ), - less_than_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(28999, 74), - ), - less_than_equals_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(28999, 74), - ), - sha2_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(270652, 22588), - ), - sha3_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(1457325, 64566), - ), - blake2b_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(201305, 8356), - ), - verify_ed25519_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::linear_in_y(53384111, 14333), - ), - verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::constant_cost(43053543), - ), - verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::linear_in_y(43574283, 26308), - ), - append_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::added_sizes(4, 1), - TwoArgumentsCosting::added_sizes(1000, 59957), - ), - equals_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::linear_on_diagonal(39184, 1000, 60594), - ), - encode_utf8: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(4, 2), - OneArgumentCosting::linear_cost(1000, 42921), - ), - decode_utf8: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(4, 2), - OneArgumentCosting::linear_cost(91189, 769), - ), - if_then_else: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(1), - ThreeArgumentsCosting::constant_cost(76049), - ), - choose_unit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(4), - TwoArgumentsCosting::constant_cost(61462), - ), - trace: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(59498), - ), - fst_pair: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(141895), - ), - snd_pair: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(141992), - ), - choose_list: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(32), - ThreeArgumentsCosting::constant_cost(132994), - ), - mk_cons: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(72362), - ), - head_list: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(83150), - ), - tail_list: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(81663), - ), - null_list: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(74433), - ), - choose_data: SixArgumentsCosting::new( - SixArgumentsCosting::constant_cost(32), - SixArgumentsCosting::constant_cost(94375), - ), - constr_data: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(22151), - ), - map_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(68246), - ), - list_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(33852), - ), - i_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(15299), - ), - b_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(11183), - ), - un_constr_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(24588), - ), - un_map_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(24623), - ), - un_list_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(25933), - ), - un_i_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(20744), - ), - un_b_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(20142), - ), - equals_data: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(898148, 27279), - ), - mk_pair_data: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(11546), - ), - mk_nil_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(7243), - ), - mk_nil_pair_data: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(7391), - ), - - serialise_data: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(0, 2), - OneArgumentCosting::linear_cost(955506, 213312), - ), - blake2b_224: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(207616, 8310), - ), - keccak_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(2261318, 64571), - ), - bls12_381_g1_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::constant_cost(962335), - ), - bls12_381_g1_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(267929), - ), - bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(76433006, 8868), - ), - bls12_381_g1_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(442008), - ), - bls12_381_g1_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(6), - OneArgumentCosting::constant_cost(2780678), - ), - bls12_381_g1_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(52948122), - ), - bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(52538055, 3756), - ), - bls12_381_g2_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::constant_cost(1995836), - ), - bls12_381_g2_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(284546), - ), - bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(158_221_314, 26_549), - ), - bls12_381_g2_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(901_022), - ), - bls12_381_g2_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(12), - OneArgumentCosting::constant_cost(3_227_919), - ), - bls12_381_g2_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(74_698_472), - ), - bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(166_917_843, 4_307), - ), - bls12_381_miller_loop: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(254006273), - ), - bls12_381_mul_ml_result: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(2174038), - ), - bls12_381_final_verify: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(333849714), - ), - integer_to_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::literal_in_y_or_linear_in_z(0, 1), - ThreeArgumentsCosting::quadratic_in_z(1293828, 28716, 63), - ), - byte_string_to_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_y(0, 1), - TwoArgumentsCosting::quadratic_in_y(1006041, 43623, 251), - ), - and_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), - ), - or_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), - ), - xor_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), - ), - complement_byte_string: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(0, 1), - OneArgumentCosting::linear_cost(107878, 680), - ), - read_bit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(95336), - ), - write_bits: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_x(0, 1), - ThreeArgumentsCosting::linear_in_y(281145, 18848), - ), - replicate_byte: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(1, 1), - TwoArgumentsCosting::linear_in_x(180194, 159), - ), - shift_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(158519, 8942), - ), - rotate_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(159378, 8813), - ), - count_set_bits: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(107490, 3298), - ), - find_first_set_bit: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(106057, 655), - ), - ripemd_160: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(3), - OneArgumentCosting::linear_cost(1964219, 24520), - ), - exp_mod_integer: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_z(0, 1), - ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), - ), - drop_list: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(4), - TwoArgumentsCosting::linear_in_x(116711, 1957), - ), - length_of_array: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(10), - OneArgumentCosting::constant_cost(198994), - ), - list_to_array: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(7, 1), - TwoArgumentsCosting::linear_in_x(307802, 8496), - ), - index_array: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(194922), - ), - } - } -} diff --git a/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v1.rs b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v1.rs new file mode 100644 index 000000000..e8bd83d44 --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v1.rs @@ -0,0 +1,857 @@ +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, + }, + ExBudget, + }, +}; + +#[derive(Debug, PartialEq)] +pub struct BuiltinCostsV1 { + add_integer: TwoArgumentsCosting, + subtract_integer: TwoArgumentsCosting, + multiply_integer: TwoArgumentsCosting, + divide_integer: TwoArgumentsCosting, + quotient_integer: TwoArgumentsCosting, + remainder_integer: TwoArgumentsCosting, + mod_integer: TwoArgumentsCosting, + equals_integer: TwoArgumentsCosting, + less_than_integer: TwoArgumentsCosting, + less_than_equals_integer: TwoArgumentsCosting, + // Bytestrings + append_byte_string: TwoArgumentsCosting, + cons_byte_string: TwoArgumentsCosting, + slice_byte_string: ThreeArgumentsCosting, + length_of_byte_string: OneArgumentCosting, + index_byte_string: TwoArgumentsCosting, + equals_byte_string: TwoArgumentsCosting, + less_than_byte_string: TwoArgumentsCosting, + less_than_equals_byte_string: TwoArgumentsCosting, + // Cryptography and hashes + sha2_256: OneArgumentCosting, + sha3_256: OneArgumentCosting, + blake2b_256: OneArgumentCosting, + verify_ed25519_signature: ThreeArgumentsCosting, + // Strings + append_string: TwoArgumentsCosting, + equals_string: TwoArgumentsCosting, + encode_utf8: OneArgumentCosting, + decode_utf8: OneArgumentCosting, + // Bool + if_then_else: ThreeArgumentsCosting, + // Unit + choose_unit: TwoArgumentsCosting, + // Tracing + trace: TwoArgumentsCosting, + // Pairs + fst_pair: OneArgumentCosting, + snd_pair: OneArgumentCosting, + // Lists + choose_list: ThreeArgumentsCosting, + mk_cons: TwoArgumentsCosting, + head_list: OneArgumentCosting, + tail_list: OneArgumentCosting, + null_list: OneArgumentCosting, + // Data + choose_data: SixArgumentsCosting, + constr_data: TwoArgumentsCosting, + map_data: OneArgumentCosting, + list_data: OneArgumentCosting, + i_data: OneArgumentCosting, + b_data: OneArgumentCosting, + un_constr_data: OneArgumentCosting, + un_map_data: OneArgumentCosting, + un_list_data: OneArgumentCosting, + un_i_data: OneArgumentCosting, + un_b_data: OneArgumentCosting, + equals_data: TwoArgumentsCosting, + // Misc constructors + mk_pair_data: TwoArgumentsCosting, + mk_nil_data: OneArgumentCosting, + mk_nil_pair_data: OneArgumentCosting, +} + +impl Default for BuiltinCostsV1 { + fn default() -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::multiplied_sizes(90434, 519), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(51775, 558), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(44749, 541), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(43285, 552), + ), + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::added_sizes(1000, 173), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::linear_in_y(72010, 178), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(4, 0), + ThreeArgumentsCosting::linear_in_z(20467, 1), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(22100), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(13169), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(24548, 29498, 38), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(270652, 22588), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(1457325, 64566), + ), + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(201305, 8356), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(53384111, 14333), + ), + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(4, 1), + TwoArgumentsCosting::added_sizes(1000, 59957), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(39184, 1000, 60594), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(1000, 42921), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(91189, 769), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(1), + ThreeArgumentsCosting::constant_cost(76049), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(61462), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(59498), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141895), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141992), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(32), + ThreeArgumentsCosting::constant_cost(132994), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(72362), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(83150), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(81663), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(74433), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(32), + SixArgumentsCosting::constant_cost(94375), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(22151), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(68246), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(33852), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(15299), + ), + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(11183), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24588), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24623), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(25933), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20744), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20142), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(898148, 27279), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(11546), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7243), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7391), + ), + } + } +} + +impl BuiltinCostModel for BuiltinCostsV1 { + fn initialize(cost_map: &CostMap) -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["add_integer-mem-arguments-intercept"], + cost_map["add_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["add_integer-cpu-arguments-intercept"], + cost_map["add_integer-cpu-arguments-slope"], + ), + ), + + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-mem-arguments-intercept"], + cost_map["append_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-cpu-arguments-intercept"], + cost_map["append_byte_string-cpu-arguments-slope"], + ), + ), + + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_string-mem-arguments-intercept"], + cost_map["append_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_string-cpu-arguments-intercept"], + cost_map["append_string-cpu-arguments-slope"], + ), + ), + + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["b_data-cpu-arguments"]), + ), + + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["blake2b_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["blake2b_256-cpu-arguments-intercept"], + cost_map["blake2b_256-cpu-arguments-slope"], + ), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(cost_map["choose_data-mem-arguments"]), + SixArgumentsCosting::constant_cost(cost_map["choose_data-cpu-arguments"]), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-cpu-arguments"]), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-cpu-arguments"]), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["cons_byte_string-mem-arguments-intercept"], + cost_map["cons_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_y( + cost_map["cons_byte_string-cpu-arguments-intercept"], + cost_map["cons_byte_string-cpu-arguments-slope"], + ), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["constr_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["constr_data-cpu-arguments"]), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-mem-arguments-intercept"], + cost_map["decode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-cpu-arguments-intercept"], + cost_map["decode_utf8-cpu-arguments-slope"], + ), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["divide_integer-mem-arguments-intercept"], + cost_map["divide_integer-mem-arguments-minimum"], + cost_map["divide_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["divide_integer-cpu-arguments-constant"], + cost_map["divide_integer-cpu-arguments-model-arguments-intercept"], + cost_map["divide_integer-cpu-arguments-model-arguments-slope"], + ), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-mem-arguments-intercept"], + cost_map["encode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-cpu-arguments-intercept"], + cost_map["encode_utf8-cpu-arguments-slope"], + ), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_byte_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_byte_string-cpu-arguments-constant"], + cost_map["equals_byte_string-cpu-arguments-intercept"], + cost_map["equals_byte_string-cpu-arguments-slope"], + ), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_data-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_data-cpu-arguments-intercept"], + cost_map["equals_data-cpu-arguments-slope"], + ), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_integer-cpu-arguments-intercept"], + cost_map["equals_integer-cpu-arguments-slope"], + ), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_string-cpu-arguments-constant"], + cost_map["equals_string-cpu-arguments-intercept"], + cost_map["equals_string-cpu-arguments-slope"], + ), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["fst_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["fst_pair-cpu-arguments"]), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["head_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["head_list-cpu-arguments"]), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["i_data-cpu-arguments"]), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-cpu-arguments"]), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-cpu-arguments"]), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-cpu-arguments"]), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_byte_string-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_byte_string-cpu-arguments-intercept"], + cost_map["less_than_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_byte_string-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_byte_string-cpu-arguments-intercept"], + cost_map["less_than_equals_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_integer-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_integer-cpu-arguments-intercept"], + cost_map["less_than_equals_integer-cpu-arguments-slope"], + ), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_integer-cpu-arguments-intercept"], + cost_map["less_than_integer-cpu-arguments-slope"], + ), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["list_data-cpu-arguments"]), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["map_data-cpu-arguments"]), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-cpu-arguments"]), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-cpu-arguments"]), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-cpu-arguments"]), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-cpu-arguments"]), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["mod_integer-mem-arguments-intercept"], + cost_map["mod_integer-mem-arguments-slope"], + cost_map["mod_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["mod_integer-cpu-arguments-constant"], + cost_map["mod_integer-cpu-arguments-model-arguments-intercept"], + cost_map["mod_integer-cpu-arguments-model-arguments-slope"], + ), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["multiply_integer-mem-arguments-intercept"], + cost_map["multiply_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::multiplied_sizes( + cost_map["multiply_integer-cpu-arguments-intercept"], + cost_map["multiply_integer-cpu-arguments-slope"], + ), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["null_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["null_list-cpu-arguments"]), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["quotient_integer-mem-arguments-intercept"], + cost_map["quotient_integer-mem-arguments-slope"], + cost_map["quotient_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["quotient_integer-cpu-arguments-constant"], + cost_map["quotient_integer-cpu-arguments-model-arguments-intercept"], + cost_map["quotient_integer-cpu-arguments-model-arguments-slope"], + ), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["remainder_integer-mem-arguments-intercept"], + cost_map["remainder_integer-mem-arguments-slope"], + cost_map["remainder_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["remainder_integer-cpu-arguments-constant"], + cost_map["remainder_integer-cpu-arguments-model-arguments-intercept"], + cost_map["remainder_integer-cpu-arguments-model-arguments-slope"], + ), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha2_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha2_256-cpu-arguments-intercept"], + cost_map["sha2_256-cpu-arguments-slope"], + ), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha3_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha3_256-cpu-arguments-intercept"], + cost_map["sha3_256-cpu-arguments-slope"], + ), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-mem-arguments-intercept"], + cost_map["slice_byte_string-mem-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-cpu-arguments-intercept"], + cost_map["slice_byte_string-cpu-arguments-slope"], + ), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["snd_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["snd_pair-cpu-arguments"]), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-mem-arguments-intercept"], + cost_map["subtract_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-cpu-arguments-intercept"], + cost_map["subtract_integer-cpu-arguments-slope"], + ), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["tail_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["tail_list-cpu-arguments"]), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["trace-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["trace-cpu-arguments"]), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_b_data-cpu-arguments"]), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_constr_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_constr_data-cpu-arguments"]), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_i_data-cpu-arguments"]), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_list_data-cpu-arguments"]), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_map_data-cpu-arguments"]), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ed25519_signature-mem-arguments"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["verify_ed25519_signature-cpu-arguments-intercept"], + cost_map["verify_ed25519_signature-cpu-arguments-slope"], + ), + ), + } + } + + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { + match builtin { + DefaultFunction::AddInteger => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SubtractInteger => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MultiplyInteger => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::DivideInteger => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::QuotientInteger => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::RemainderInteger => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ModInteger => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsInteger => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanInteger => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsInteger => Some(ExBudget::new( + self.less_than_equals_integer.mem.cost([args[0], args[1]]), + self.less_than_equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::AppendByteString => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ConsByteString => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SliceByteString => Some(ExBudget::new( + self.slice_byte_string.mem.cost([args[0], args[1], args[2]]), + self.slice_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::LengthOfByteString => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + DefaultFunction::IndexByteString => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsByteString => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanByteString => Some(ExBudget::new( + self.less_than_byte_string.mem.cost([args[0], args[1]]), + self.less_than_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( + self.less_than_equals_byte_string + .mem + .cost([args[0], args[1]]), + self.less_than_equals_byte_string + .cpu + .cost([args[0], args[1]]), + )), + DefaultFunction::Sha2_256 => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + DefaultFunction::Sha3_256 => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + DefaultFunction::Blake2b_256 => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( + self.verify_ed25519_signature + .mem + .cost([args[0], args[1], args[2]]), + self.verify_ed25519_signature + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::AppendString => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsString => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::IfThenElse => Some(ExBudget::new( + self.if_then_else.mem.cost([args[0], args[1], args[2]]), + self.if_then_else.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ChooseUnit => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Trace => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::FstPair => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + DefaultFunction::SndPair => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseList => Some(ExBudget::new( + self.choose_list.mem.cost([args[0], args[1], args[2]]), + self.choose_list.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::MkCons => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::HeadList => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + DefaultFunction::TailList => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + DefaultFunction::NullList => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseData => Some(ExBudget::new( + self.choose_data + .mem + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + self.choose_data + .cpu + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + )), + DefaultFunction::ConstrData => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MapData => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + DefaultFunction::ListData => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + DefaultFunction::IData => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + DefaultFunction::BData => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnConstrData => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnMapData => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnListData => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnIData => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnBData => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + DefaultFunction::EqualsData => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkPairData => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkNilData => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + DefaultFunction::MkNilPairData => Some(ExBudget::new( + self.mk_nil_pair_data.mem.cost([args[0]]), + self.mk_nil_pair_data.cpu.cost([args[0]]), + )), + _ => None, + } + } +} diff --git a/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v2.rs b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v2.rs new file mode 100644 index 000000000..cea2eb324 --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v2.rs @@ -0,0 +1,903 @@ +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, + }, + ExBudget, + }, +}; + +#[derive(Debug, PartialEq)] +pub struct BuiltinCostsV2 { + add_integer: TwoArgumentsCosting, + subtract_integer: TwoArgumentsCosting, + multiply_integer: TwoArgumentsCosting, + divide_integer: TwoArgumentsCosting, + quotient_integer: TwoArgumentsCosting, + remainder_integer: TwoArgumentsCosting, + mod_integer: TwoArgumentsCosting, + equals_integer: TwoArgumentsCosting, + less_than_integer: TwoArgumentsCosting, + less_than_equals_integer: TwoArgumentsCosting, + // Bytestrings + append_byte_string: TwoArgumentsCosting, + cons_byte_string: TwoArgumentsCosting, + slice_byte_string: ThreeArgumentsCosting, + length_of_byte_string: OneArgumentCosting, + index_byte_string: TwoArgumentsCosting, + equals_byte_string: TwoArgumentsCosting, + less_than_byte_string: TwoArgumentsCosting, + less_than_equals_byte_string: TwoArgumentsCosting, + // Cryptography and hashes + sha2_256: OneArgumentCosting, + sha3_256: OneArgumentCosting, + blake2b_256: OneArgumentCosting, + verify_ed25519_signature: ThreeArgumentsCosting, + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting, + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting, + // Strings + append_string: TwoArgumentsCosting, + equals_string: TwoArgumentsCosting, + encode_utf8: OneArgumentCosting, + decode_utf8: OneArgumentCosting, + // Bool + if_then_else: ThreeArgumentsCosting, + // Unit + choose_unit: TwoArgumentsCosting, + // Tracing + trace: TwoArgumentsCosting, + // Pairs + fst_pair: OneArgumentCosting, + snd_pair: OneArgumentCosting, + // Lists + choose_list: ThreeArgumentsCosting, + mk_cons: TwoArgumentsCosting, + head_list: OneArgumentCosting, + tail_list: OneArgumentCosting, + null_list: OneArgumentCosting, + // Data + choose_data: SixArgumentsCosting, + constr_data: TwoArgumentsCosting, + map_data: OneArgumentCosting, + list_data: OneArgumentCosting, + i_data: OneArgumentCosting, + b_data: OneArgumentCosting, + un_constr_data: OneArgumentCosting, + un_map_data: OneArgumentCosting, + un_list_data: OneArgumentCosting, + un_i_data: OneArgumentCosting, + un_b_data: OneArgumentCosting, + equals_data: TwoArgumentsCosting, + // Misc constructors + mk_pair_data: TwoArgumentsCosting, + mk_nil_data: OneArgumentCosting, + mk_nil_pair_data: OneArgumentCosting, + serialise_data: OneArgumentCosting, +} + +impl Default for BuiltinCostsV2 { + fn default() -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::multiplied_sizes(90434, 519), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(51775, 558), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(44749, 541), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(43285, 552), + ), + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::added_sizes(1000, 173), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::linear_in_y(72010, 178), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(4, 0), + ThreeArgumentsCosting::linear_in_z(20467, 1), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(22100), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(13169), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(24548, 29498, 38), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(270652, 22588), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(1457325, 64566), + ), + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(201305, 8356), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(53384111, 14333), + ), + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::constant_cost(43053543), + ), + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(43574283, 26308), + ), + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(4, 1), + TwoArgumentsCosting::added_sizes(1000, 59957), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(39184, 1000, 60594), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(1000, 42921), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(91189, 769), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(1), + ThreeArgumentsCosting::constant_cost(76049), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(61462), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(59498), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141895), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141992), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(32), + ThreeArgumentsCosting::constant_cost(132994), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(72362), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(83150), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(81663), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(74433), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(32), + SixArgumentsCosting::constant_cost(94375), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(22151), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(68246), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(33852), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(15299), + ), + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(11183), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24588), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24623), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(25933), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20744), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20142), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(898148, 27279), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(11546), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7243), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7391), + ), + serialise_data: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(0, 2), + OneArgumentCosting::linear_cost(955506, 213312), + ), + } + } +} +impl BuiltinCostModel for BuiltinCostsV2 { + fn initialize(cost_map: &CostMap) -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["add_integer-mem-arguments-intercept"], + cost_map["add_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["add_integer-cpu-arguments-intercept"], + cost_map["add_integer-cpu-arguments-slope"], + ), + ), + + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-mem-arguments-intercept"], + cost_map["append_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-cpu-arguments-intercept"], + cost_map["append_byte_string-cpu-arguments-slope"], + ), + ), + + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_string-mem-arguments-intercept"], + cost_map["append_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_string-cpu-arguments-intercept"], + cost_map["append_string-cpu-arguments-slope"], + ), + ), + + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["b_data-cpu-arguments"]), + ), + + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["blake2b_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["blake2b_256-cpu-arguments-intercept"], + cost_map["blake2b_256-cpu-arguments-slope"], + ), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(cost_map["choose_data-mem-arguments"]), + SixArgumentsCosting::constant_cost(cost_map["choose_data-cpu-arguments"]), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-cpu-arguments"]), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-cpu-arguments"]), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["cons_byte_string-mem-arguments-intercept"], + cost_map["cons_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_y( + cost_map["cons_byte_string-cpu-arguments-intercept"], + cost_map["cons_byte_string-cpu-arguments-slope"], + ), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["constr_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["constr_data-cpu-arguments"]), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-mem-arguments-intercept"], + cost_map["decode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-cpu-arguments-intercept"], + cost_map["decode_utf8-cpu-arguments-slope"], + ), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["divide_integer-mem-arguments-intercept"], + cost_map["divide_integer-mem-arguments-minimum"], + cost_map["divide_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["divide_integer-cpu-arguments-constant"], + cost_map["divide_integer-cpu-arguments-model-arguments-intercept"], + cost_map["divide_integer-cpu-arguments-model-arguments-slope"], + ), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-mem-arguments-intercept"], + cost_map["encode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-cpu-arguments-intercept"], + cost_map["encode_utf8-cpu-arguments-slope"], + ), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_byte_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_byte_string-cpu-arguments-constant"], + cost_map["equals_byte_string-cpu-arguments-intercept"], + cost_map["equals_byte_string-cpu-arguments-slope"], + ), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_data-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_data-cpu-arguments-intercept"], + cost_map["equals_data-cpu-arguments-slope"], + ), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_integer-cpu-arguments-intercept"], + cost_map["equals_integer-cpu-arguments-slope"], + ), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_string-cpu-arguments-constant"], + cost_map["equals_string-cpu-arguments-intercept"], + cost_map["equals_string-cpu-arguments-slope"], + ), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["fst_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["fst_pair-cpu-arguments"]), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["head_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["head_list-cpu-arguments"]), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["i_data-cpu-arguments"]), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-cpu-arguments"]), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-cpu-arguments"]), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-cpu-arguments"]), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_byte_string-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_byte_string-cpu-arguments-intercept"], + cost_map["less_than_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_byte_string-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_byte_string-cpu-arguments-intercept"], + cost_map["less_than_equals_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_integer-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_integer-cpu-arguments-intercept"], + cost_map["less_than_equals_integer-cpu-arguments-slope"], + ), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_integer-cpu-arguments-intercept"], + cost_map["less_than_integer-cpu-arguments-slope"], + ), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["list_data-cpu-arguments"]), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["map_data-cpu-arguments"]), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-cpu-arguments"]), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-cpu-arguments"]), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-cpu-arguments"]), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-cpu-arguments"]), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["mod_integer-mem-arguments-intercept"], + cost_map["mod_integer-mem-arguments-slope"], + cost_map["mod_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["mod_integer-cpu-arguments-constant"], + cost_map["mod_integer-cpu-arguments-model-arguments-intercept"], + cost_map["mod_integer-cpu-arguments-model-arguments-slope"], + ), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["multiply_integer-mem-arguments-intercept"], + cost_map["multiply_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::multiplied_sizes( + cost_map["multiply_integer-cpu-arguments-intercept"], + cost_map["multiply_integer-cpu-arguments-slope"], + ), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["null_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["null_list-cpu-arguments"]), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["quotient_integer-mem-arguments-intercept"], + cost_map["quotient_integer-mem-arguments-slope"], + cost_map["quotient_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["quotient_integer-cpu-arguments-constant"], + cost_map["quotient_integer-cpu-arguments-model-arguments-intercept"], + cost_map["quotient_integer-cpu-arguments-model-arguments-slope"], + ), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["remainder_integer-mem-arguments-intercept"], + cost_map["remainder_integer-mem-arguments-slope"], + cost_map["remainder_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + cost_map["remainder_integer-cpu-arguments-constant"], + cost_map["remainder_integer-cpu-arguments-model-arguments-intercept"], + cost_map["remainder_integer-cpu-arguments-model-arguments-slope"], + ), + ), + serialise_data: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["serialise_data-mem-arguments-intercept"], + cost_map["serialise_data-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["serialise_data-cpu-arguments-intercept"], + cost_map["serialise_data-cpu-arguments-slope"], + ), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha2_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha2_256-cpu-arguments-intercept"], + cost_map["sha2_256-cpu-arguments-slope"], + ), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha3_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha3_256-cpu-arguments-intercept"], + cost_map["sha3_256-cpu-arguments-slope"], + ), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-mem-arguments-intercept"], + cost_map["slice_byte_string-mem-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-cpu-arguments-intercept"], + cost_map["slice_byte_string-cpu-arguments-slope"], + ), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["snd_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["snd_pair-cpu-arguments"]), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-mem-arguments-intercept"], + cost_map["subtract_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-cpu-arguments-intercept"], + cost_map["subtract_integer-cpu-arguments-slope"], + ), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["tail_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["tail_list-cpu-arguments"]), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["trace-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["trace-cpu-arguments"]), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_b_data-cpu-arguments"]), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_constr_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_constr_data-cpu-arguments"]), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_i_data-cpu-arguments"]), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_list_data-cpu-arguments"]), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_map_data-cpu-arguments"]), + ), + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ecdsa_secp256k1_signature-mem-arguments"], + ), + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ecdsa_secp256k1_signature-cpu-arguments"], + ), + ), + + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ed25519_signature-mem-arguments"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["verify_ed25519_signature-cpu-arguments-intercept"], + cost_map["verify_ed25519_signature-cpu-arguments-slope"], + ), + ), + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_schnorr_secp256k1_signature-mem-arguments"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["verify_schnorr_secp256k1_signature-cpu-arguments-intercept"], + cost_map["verify_schnorr_secp256k1_signature-cpu-arguments-slope"], + ), + ), + } + } + + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { + match builtin { + DefaultFunction::AddInteger => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SubtractInteger => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MultiplyInteger => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::DivideInteger => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::QuotientInteger => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::RemainderInteger => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ModInteger => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsInteger => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanInteger => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsInteger => Some(ExBudget::new( + self.less_than_equals_integer.mem.cost([args[0], args[1]]), + self.less_than_equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::AppendByteString => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ConsByteString => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SliceByteString => Some(ExBudget::new( + self.slice_byte_string.mem.cost([args[0], args[1], args[2]]), + self.slice_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::LengthOfByteString => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + DefaultFunction::IndexByteString => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsByteString => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanByteString => Some(ExBudget::new( + self.less_than_byte_string.mem.cost([args[0], args[1]]), + self.less_than_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( + self.less_than_equals_byte_string + .mem + .cost([args[0], args[1]]), + self.less_than_equals_byte_string + .cpu + .cost([args[0], args[1]]), + )), + DefaultFunction::Sha2_256 => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + DefaultFunction::Sha3_256 => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + DefaultFunction::Blake2b_256 => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( + self.verify_ed25519_signature + .mem + .cost([args[0], args[1], args[2]]), + self.verify_ed25519_signature + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::AppendString => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsString => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::IfThenElse => Some(ExBudget::new( + self.if_then_else.mem.cost([args[0], args[1], args[2]]), + self.if_then_else.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ChooseUnit => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Trace => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::FstPair => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + DefaultFunction::SndPair => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseList => Some(ExBudget::new( + self.choose_list.mem.cost([args[0], args[1], args[2]]), + self.choose_list.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::MkCons => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::HeadList => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + DefaultFunction::TailList => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + DefaultFunction::NullList => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseData => Some(ExBudget::new( + self.choose_data + .mem + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + self.choose_data + .cpu + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + )), + DefaultFunction::ConstrData => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MapData => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + DefaultFunction::ListData => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + DefaultFunction::IData => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + DefaultFunction::BData => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnConstrData => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnMapData => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnListData => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnIData => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnBData => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + DefaultFunction::EqualsData => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkPairData => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkNilData => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + DefaultFunction::MkNilPairData => Some(ExBudget::new( + self.mk_nil_pair_data.mem.cost([args[0]]), + self.mk_nil_pair_data.cpu.cost([args[0]]), + )), + DefaultFunction::SerialiseData => Some(ExBudget::new( + self.serialise_data.mem.cost([args[0]]), + self.serialise_data.cpu.cost([args[0]]), + )), + _ => None, + } + } +} diff --git a/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs new file mode 100644 index 000000000..284892e65 --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs @@ -0,0 +1,1591 @@ +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, + }, + ExBudget, + }, +}; + +#[derive(Debug, PartialEq)] +pub struct BuiltinCostsV3 { + add_integer: TwoArgumentsCosting, + subtract_integer: TwoArgumentsCosting, + multiply_integer: TwoArgumentsCosting, + divide_integer: TwoArgumentsCosting, + quotient_integer: TwoArgumentsCosting, + remainder_integer: TwoArgumentsCosting, + mod_integer: TwoArgumentsCosting, + equals_integer: TwoArgumentsCosting, + less_than_integer: TwoArgumentsCosting, + less_than_equals_integer: TwoArgumentsCosting, + // Bytestrings + append_byte_string: TwoArgumentsCosting, + cons_byte_string: TwoArgumentsCosting, + slice_byte_string: ThreeArgumentsCosting, + length_of_byte_string: OneArgumentCosting, + index_byte_string: TwoArgumentsCosting, + equals_byte_string: TwoArgumentsCosting, + less_than_byte_string: TwoArgumentsCosting, + less_than_equals_byte_string: TwoArgumentsCosting, + // Cryptography and hashes + sha2_256: OneArgumentCosting, + sha3_256: OneArgumentCosting, + blake2b_224: OneArgumentCosting, + blake2b_256: OneArgumentCosting, + keccak_256: OneArgumentCosting, + verify_ed25519_signature: ThreeArgumentsCosting, + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting, + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting, + // Strings + append_string: TwoArgumentsCosting, + equals_string: TwoArgumentsCosting, + encode_utf8: OneArgumentCosting, + decode_utf8: OneArgumentCosting, + // Bool + if_then_else: ThreeArgumentsCosting, + // Unit + choose_unit: TwoArgumentsCosting, + // Tracing + trace: TwoArgumentsCosting, + // Pairs + fst_pair: OneArgumentCosting, + snd_pair: OneArgumentCosting, + // Lists + choose_list: ThreeArgumentsCosting, + mk_cons: TwoArgumentsCosting, + head_list: OneArgumentCosting, + tail_list: OneArgumentCosting, + null_list: OneArgumentCosting, + // Data + choose_data: SixArgumentsCosting, + constr_data: TwoArgumentsCosting, + map_data: OneArgumentCosting, + list_data: OneArgumentCosting, + i_data: OneArgumentCosting, + b_data: OneArgumentCosting, + un_constr_data: OneArgumentCosting, + un_map_data: OneArgumentCosting, + un_list_data: OneArgumentCosting, + un_i_data: OneArgumentCosting, + un_b_data: OneArgumentCosting, + equals_data: TwoArgumentsCosting, + // Misc constructors + mk_pair_data: TwoArgumentsCosting, + mk_nil_data: OneArgumentCosting, + mk_nil_pair_data: OneArgumentCosting, + serialise_data: OneArgumentCosting, + // BLST + bls12_381_g1_add: TwoArgumentsCosting, + bls12_381_g1_neg: OneArgumentCosting, + bls12_381_g1_scalar_mul: TwoArgumentsCosting, + bls12_381_g1_equal: TwoArgumentsCosting, + bls12_381_g1_compress: OneArgumentCosting, + bls12_381_g1_uncompress: OneArgumentCosting, + bls12_381_g1_hash_to_group: TwoArgumentsCosting, + bls12_381_g2_add: TwoArgumentsCosting, + bls12_381_g2_neg: OneArgumentCosting, + bls12_381_g2_scalar_mul: TwoArgumentsCosting, + bls12_381_g2_equal: TwoArgumentsCosting, + bls12_381_g2_compress: OneArgumentCosting, + bls12_381_g2_uncompress: OneArgumentCosting, + bls12_381_g2_hash_to_group: TwoArgumentsCosting, + bls12_381_miller_loop: TwoArgumentsCosting, + bls12_381_mul_ml_result: TwoArgumentsCosting, + bls12_381_final_verify: TwoArgumentsCosting, + // bitwise + integer_to_byte_string: ThreeArgumentsCosting, + byte_string_to_integer: TwoArgumentsCosting, + and_byte_string: ThreeArgumentsCosting, + or_byte_string: ThreeArgumentsCosting, + xor_byte_string: ThreeArgumentsCosting, + complement_byte_string: OneArgumentCosting, + read_bit: TwoArgumentsCosting, + write_bits: ThreeArgumentsCosting, + replicate_byte: TwoArgumentsCosting, + shift_byte_string: TwoArgumentsCosting, + rotate_byte_string: TwoArgumentsCosting, + count_set_bits: OneArgumentCosting, + find_first_set_bit: OneArgumentCosting, + ripemd_160: OneArgumentCosting, + + exp_mod_integer: ThreeArgumentsCosting, + drop_list: TwoArgumentsCosting, + length_of_array: OneArgumentCosting, + list_to_array: TwoArgumentsCosting, + index_array: TwoArgumentsCosting, +} + +impl Default for BuiltinCostsV3 { + fn default() -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(100788, 420), + ), + + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::multiplied_sizes(90434, 519), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + 85848, 85848, 123203, 7305, -900, 1716, 549, 57, + ), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + 85848, 85848, 123203, 7305, -900, 1716, 549, 57, + ), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y(0, 1), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + 85848, 85848, 123203, 7305, -900, 1716, 549, 57, + ), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y(0, 1), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + 85848, 85848, 123203, 7305, -900, 1716, 549, 57, + ), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(51775, 558), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(44749, 541), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(43285, 552), + ), + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::added_sizes(1000, 173), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::linear_in_y(72010, 178), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(4, 0), + ThreeArgumentsCosting::linear_in_z(20467, 1), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(22100), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(13169), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(24548, 29498, 38), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(28999, 74), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(270652, 22588), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(1457325, 64566), + ), + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(201305, 8356), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(53384111, 14333), + ), + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::constant_cost(43053543), + ), + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(43574283, 26308), + ), + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(4, 1), + TwoArgumentsCosting::added_sizes(1000, 59957), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(39184, 1000, 60594), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(1000, 42921), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(91189, 769), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(1), + ThreeArgumentsCosting::constant_cost(76049), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(61462), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(59498), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141895), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(141992), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(32), + ThreeArgumentsCosting::constant_cost(132994), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(72362), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(83150), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(81663), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(74433), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(32), + SixArgumentsCosting::constant_cost(94375), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(22151), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(68246), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(33852), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(15299), + ), + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(11183), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24588), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(24623), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(25933), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20744), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(20142), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(898148, 27279), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(11546), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7243), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(7391), + ), + + serialise_data: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(0, 2), + OneArgumentCosting::linear_cost(955506, 213312), + ), + blake2b_224: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(207616, 8310), + ), + keccak_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(2261318, 64571), + ), + bls12_381_g1_add: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(18), + TwoArgumentsCosting::constant_cost(962335), + ), + bls12_381_g1_neg: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(18), + OneArgumentCosting::constant_cost(267929), + ), + bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(18), + TwoArgumentsCosting::linear_in_x(76433006, 8868), + ), + bls12_381_g1_equal: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::constant_cost(442008), + ), + bls12_381_g1_compress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(6), + OneArgumentCosting::constant_cost(2780678), + ), + bls12_381_g1_uncompress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(18), + OneArgumentCosting::constant_cost(52948122), + ), + bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(18), + TwoArgumentsCosting::linear_in_x(52538055, 3756), + ), + bls12_381_g2_add: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(36), + TwoArgumentsCosting::constant_cost(1995836), + ), + bls12_381_g2_neg: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(36), + OneArgumentCosting::constant_cost(284546), + ), + bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(36), + TwoArgumentsCosting::linear_in_x(158_221_314, 26_549), + ), + bls12_381_g2_equal: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::constant_cost(901_022), + ), + bls12_381_g2_compress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(12), + OneArgumentCosting::constant_cost(3_227_919), + ), + bls12_381_g2_uncompress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(36), + OneArgumentCosting::constant_cost(74_698_472), + ), + bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(36), + TwoArgumentsCosting::linear_in_x(166_917_843, 4_307), + ), + bls12_381_miller_loop: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(72), + TwoArgumentsCosting::constant_cost(254006273), + ), + bls12_381_mul_ml_result: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(72), + TwoArgumentsCosting::constant_cost(2174038), + ), + bls12_381_final_verify: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::constant_cost(333849714), + ), + integer_to_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::literal_in_y_or_linear_in_z(0, 1), + ThreeArgumentsCosting::quadratic_in_z(1293828, 28716, 63), + ), + byte_string_to_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y(0, 1), + TwoArgumentsCosting::quadratic_in_y(1006041, 43623, 251), + ), + and_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z(0, 1), + ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ), + or_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z(0, 1), + ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ), + xor_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z(0, 1), + ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ), + complement_byte_string: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(0, 1), + OneArgumentCosting::linear_cost(107878, 680), + ), + read_bit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::constant_cost(95336), + ), + write_bits: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_x(0, 1), + ThreeArgumentsCosting::linear_in_y(281145, 18848), + ), + replicate_byte: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x(1, 1), + TwoArgumentsCosting::linear_in_x(180194, 159), + ), + shift_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x(0, 1), + TwoArgumentsCosting::linear_in_x(158519, 8942), + ), + rotate_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x(0, 1), + TwoArgumentsCosting::linear_in_x(159378, 8813), + ), + count_set_bits: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(1), + OneArgumentCosting::linear_cost(107490, 3298), + ), + find_first_set_bit: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(1), + OneArgumentCosting::linear_cost(106057, 655), + ), + ripemd_160: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(3), + OneArgumentCosting::linear_cost(1964219, 24520), + ), + exp_mod_integer: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(0, 1), + ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), + ), + drop_list: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::linear_in_x(116711, 1957), + ), + length_of_array: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(198994), + ), + list_to_array: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x(7, 1), + TwoArgumentsCosting::linear_in_x(307802, 8496), + ), + index_array: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(194922), + ), + } + } +} + +impl BuiltinCostModel for BuiltinCostsV3 { + fn initialize(cost_map: &CostMap) -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["add_integer-mem-arguments-intercept"], + cost_map["add_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["add_integer-cpu-arguments-intercept"], + cost_map["add_integer-cpu-arguments-slope"], + ), + ), + + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-mem-arguments-intercept"], + cost_map["append_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_byte_string-cpu-arguments-intercept"], + cost_map["append_byte_string-cpu-arguments-slope"], + ), + ), + + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["append_string-mem-arguments-intercept"], + cost_map["append_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::added_sizes( + cost_map["append_string-cpu-arguments-intercept"], + cost_map["append_string-cpu-arguments-slope"], + ), + ), + + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["b_data-cpu-arguments"]), + ), + + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["blake2b_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["blake2b_256-cpu-arguments-intercept"], + cost_map["blake2b_256-cpu-arguments-slope"], + ), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(cost_map["choose_data-mem-arguments"]), + SixArgumentsCosting::constant_cost(cost_map["choose_data-cpu-arguments"]), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["choose_list-cpu-arguments"]), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["choose_unit-cpu-arguments"]), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["cons_byte_string-mem-arguments-intercept"], + cost_map["cons_byte_string-mem-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_y( + cost_map["cons_byte_string-cpu-arguments-intercept"], + cost_map["cons_byte_string-cpu-arguments-slope"], + ), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["constr_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["constr_data-cpu-arguments"]), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-mem-arguments-intercept"], + cost_map["decode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["decode_utf8-cpu-arguments-intercept"], + cost_map["decode_utf8-cpu-arguments-slope"], + ), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["divide_integer-mem-arguments-intercept"], + cost_map["divide_integer-mem-arguments-minimum"], + cost_map["divide_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + cost_map["divide_integer-cpu-arguments-constant"], + cost_map["divide_integer-cpu-arguments-minimum"], + cost_map["divide_integer-cpu-arguments-c00"], + cost_map["divide_integer-cpu-arguments-c01"], + cost_map["divide_integer-cpu-arguments-c02"], + cost_map["divide_integer-cpu-arguments-c10"], + cost_map["divide_integer-cpu-arguments-c11"], + cost_map["divide_integer-cpu-arguments-c20"], + ), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-mem-arguments-intercept"], + cost_map["encode_utf8-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["encode_utf8-cpu-arguments-intercept"], + cost_map["encode_utf8-cpu-arguments-slope"], + ), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_byte_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_byte_string-cpu-arguments-constant"], + cost_map["equals_byte_string-cpu-arguments-intercept"], + cost_map["equals_byte_string-cpu-arguments-slope"], + ), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_data-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_data-cpu-arguments-intercept"], + cost_map["equals_data-cpu-arguments-slope"], + ), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["equals_integer-cpu-arguments-intercept"], + cost_map["equals_integer-cpu-arguments-slope"], + ), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["equals_string-mem-arguments"]), + TwoArgumentsCosting::linear_on_diagonal( + cost_map["equals_string-cpu-arguments-constant"], + cost_map["equals_string-cpu-arguments-intercept"], + cost_map["equals_string-cpu-arguments-slope"], + ), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["fst_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["fst_pair-cpu-arguments"]), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["head_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["head_list-cpu-arguments"]), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["i_data-cpu-arguments"]), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-mem-arguments"]), + ThreeArgumentsCosting::constant_cost(cost_map["if_then_else-cpu-arguments"]), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["index_byte_string-cpu-arguments"]), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["length_of_byte_string-cpu-arguments"]), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_byte_string-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_byte_string-cpu-arguments-intercept"], + cost_map["less_than_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_byte_string-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_byte_string-cpu-arguments-intercept"], + cost_map["less_than_equals_byte_string-cpu-arguments-slope"], + ), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["less_than_equals_integer-mem-arguments"], + ), + TwoArgumentsCosting::min_size( + cost_map["less_than_equals_integer-cpu-arguments-intercept"], + cost_map["less_than_equals_integer-cpu-arguments-slope"], + ), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["less_than_integer-mem-arguments"]), + TwoArgumentsCosting::min_size( + cost_map["less_than_integer-cpu-arguments-intercept"], + cost_map["less_than_integer-cpu-arguments-slope"], + ), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["list_data-cpu-arguments"]), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["map_data-cpu-arguments"]), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_cons-cpu-arguments"]), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_data-cpu-arguments"]), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["mk_nil_pair_data-cpu-arguments"]), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["mk_pair_data-cpu-arguments"]), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y( + cost_map["mod_integer-mem-arguments-intercept"], + cost_map["mod_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + cost_map["mod_integer-cpu-arguments-constant"], + cost_map["mod_integer-cpu-arguments-minimum"], + cost_map["mod_integer-cpu-arguments-c00"], + cost_map["mod_integer-cpu-arguments-c01"], + cost_map["mod_integer-cpu-arguments-c02"], + cost_map["mod_integer-cpu-arguments-c10"], + cost_map["mod_integer-cpu-arguments-c11"], + cost_map["mod_integer-cpu-arguments-c20"], + ), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes( + cost_map["multiply_integer-mem-arguments-intercept"], + cost_map["multiply_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::multiplied_sizes( + cost_map["multiply_integer-cpu-arguments-intercept"], + cost_map["multiply_integer-cpu-arguments-slope"], + ), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["null_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["null_list-cpu-arguments"]), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes( + cost_map["quotient_integer-mem-arguments-intercept"], + cost_map["quotient_integer-mem-arguments-slope"], + cost_map["quotient_integer-mem-arguments-minimum"], + ), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + cost_map["quotient_integer-cpu-arguments-constant"], + cost_map["quotient_integer-cpu-arguments-minimum"], + cost_map["quotient_integer-cpu-arguments-c00"], + cost_map["quotient_integer-cpu-arguments-c01"], + cost_map["quotient_integer-cpu-arguments-c02"], + cost_map["quotient_integer-cpu-arguments-c10"], + cost_map["quotient_integer-cpu-arguments-c11"], + cost_map["quotient_integer-cpu-arguments-c20"], + ), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y( + cost_map["remainder_integer-mem-arguments-intercept"], + cost_map["remainder_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y( + cost_map["remainder_integer-cpu-arguments-constant"], + cost_map["remainder_integer-cpu-arguments-minimum"], + cost_map["remainder_integer-cpu-arguments-c00"], + cost_map["remainder_integer-cpu-arguments-c01"], + cost_map["remainder_integer-cpu-arguments-c02"], + cost_map["remainder_integer-cpu-arguments-c10"], + cost_map["remainder_integer-cpu-arguments-c11"], + cost_map["remainder_integer-cpu-arguments-c20"], + ), + ), + serialise_data: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["serialise_data-mem-arguments-intercept"], + cost_map["serialise_data-mem-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["serialise_data-cpu-arguments-intercept"], + cost_map["serialise_data-cpu-arguments-slope"], + ), + ), + + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha2_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha2_256-cpu-arguments-intercept"], + cost_map["sha2_256-cpu-arguments-slope"], + ), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["sha3_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["sha3_256-cpu-arguments-intercept"], + cost_map["sha3_256-cpu-arguments-slope"], + ), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-mem-arguments-intercept"], + cost_map["slice_byte_string-mem-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_z( + cost_map["slice_byte_string-cpu-arguments-intercept"], + cost_map["slice_byte_string-cpu-arguments-slope"], + ), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["snd_pair-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["snd_pair-cpu-arguments"]), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-mem-arguments-intercept"], + cost_map["subtract_integer-mem-arguments-slope"], + ), + TwoArgumentsCosting::max_size( + cost_map["subtract_integer-cpu-arguments-intercept"], + cost_map["subtract_integer-cpu-arguments-slope"], + ), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["tail_list-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["tail_list-cpu-arguments"]), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["trace-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["trace-cpu-arguments"]), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_b_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_b_data-cpu-arguments"]), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_constr_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_constr_data-cpu-arguments"]), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_i_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_i_data-cpu-arguments"]), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_list_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_list_data-cpu-arguments"]), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["un_map_data-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["un_map_data-cpu-arguments"]), + ), + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ecdsa_secp256k1_signature-mem-arguments"], + ), + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ecdsa_secp256k1_signature-cpu-arguments"], + ), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_ed25519_signature-mem-arguments"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["verify_ed25519_signature-cpu-arguments-intercept"], + cost_map["verify_ed25519_signature-cpu-arguments-slope"], + ), + ), + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost( + cost_map["verify_schnorr_secp256k1_signature-mem-arguments"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["verify_schnorr_secp256k1_signature-cpu-arguments-intercept"], + cost_map["verify_schnorr_secp256k1_signature-cpu-arguments-slope"], + ), + ), + + bls12_381_g1_add: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G1_add-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G1_add-cpu-arguments"]), + ), + + bls12_381_g1_compress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["bls12_381_G1_compress-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["bls12_381_G1_compress-cpu-arguments"]), + ), + + bls12_381_g1_equal: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G1_equal-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G1_equal-cpu-arguments"]), + ), + + bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_G1_hashToGroup-mem-arguments"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["bls12_381_G1_hashToGroup-cpu-arguments-intercept"], + cost_map["bls12_381_G1_hashToGroup-cpu-arguments-slope"], + ), + ), + + bls12_381_g1_neg: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["bls12_381_G1_neg-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["bls12_381_G1_neg-cpu-arguments"]), + ), + + bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_G1_scalarMul-mem-arguments"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["bls12_381_G1_scalarMul-cpu-arguments-intercept"], + cost_map["bls12_381_G1_scalarMul-cpu-arguments-slope"], + ), + ), + + bls12_381_g1_uncompress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost( + cost_map["bls12_381_G1_uncompress-mem-arguments"], + ), + OneArgumentCosting::constant_cost( + cost_map["bls12_381_G1_uncompress-cpu-arguments"], + ), + ), + + bls12_381_g2_add: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G2_add-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G2_add-cpu-arguments"]), + ), + + bls12_381_g2_compress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["bls12_381_G2_compress-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["bls12_381_G2_compress-cpu-arguments"]), + ), + + bls12_381_g2_equal: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G2_equal-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_G2_equal-cpu-arguments"]), + ), + + bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_G2_hashToGroup-mem-arguments"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["bls12_381_G2_hashToGroup-cpu-arguments-intercept"], + cost_map["bls12_381_G2_hashToGroup-cpu-arguments-slope"], + ), + ), + + bls12_381_g2_neg: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["bls12_381_G2_neg-mem-arguments"]), + OneArgumentCosting::constant_cost(cost_map["bls12_381_G2_neg-cpu-arguments"]), + ), + + bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_G2_scalarMul-mem-arguments"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["bls12_381_G2_scalarMul-cpu-arguments-intercept"], + cost_map["bls12_381_G2_scalarMul-cpu-arguments-slope"], + ), + ), + + bls12_381_g2_uncompress: OneArgumentCosting::new( + OneArgumentCosting::constant_cost( + cost_map["bls12_381_G2_uncompress-mem-arguments"], + ), + OneArgumentCosting::constant_cost( + cost_map["bls12_381_G2_uncompress-cpu-arguments"], + ), + ), + + bls12_381_final_verify: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_finalVerify-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_finalVerify-cpu-arguments"]), + ), + + bls12_381_miller_loop: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_millerLoop-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_millerLoop-cpu-arguments"]), + ), + + bls12_381_mul_ml_result: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_mulMlResult-mem-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["bls12_381_mulMlResult-cpu-arguments"]), + ), + + keccak_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["keccak_256-mem-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["keccak_256-cpu-arguments-intercept"], + cost_map["keccak_256-cpu-arguments-slope"], + ), + ), + + blake2b_224: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["blake2b_224-mem-arguments-slope"]), + OneArgumentCosting::linear_cost( + cost_map["blake2b_224-cpu-arguments-intercept"], + cost_map["blake2b_224-cpu-arguments-slope"], + ), + ), + + integer_to_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::literal_in_y_or_linear_in_z( + cost_map["integerToByteString-mem-arguments-intercept"], + cost_map["integerToByteString-mem-arguments-slope"], + ), + ThreeArgumentsCosting::quadratic_in_z( + cost_map["integerToByteString-cpu-arguments-c0"], + cost_map["integerToByteString-cpu-arguments-c1"], + cost_map["integerToByteString-cpu-arguments-c2"], + ), + ), + + byte_string_to_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_y( + cost_map["byteStringToInteger-mem-arguments-intercept"], + cost_map["byteStringToInteger-mem-arguments-slope"], + ), + TwoArgumentsCosting::quadratic_in_y( + cost_map["byteStringToInteger-cpu-arguments-c0"], + cost_map["byteStringToInteger-cpu-arguments-c1"], + cost_map["byteStringToInteger-cpu-arguments-c2"], + ), + ), + + and_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z( + cost_map["andByteString-memory-arguments-intercept"], + cost_map["andByteString-memory-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_y_and_z( + cost_map["andByteString-cpu-arguments-intercept"], + cost_map["andByteString-cpu-arguments-slope1"], + cost_map["andByteString-cpu-arguments-slope2"], + ), + ), + + or_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z( + cost_map["orByteString-memory-arguments-intercept"], + cost_map["orByteString-memory-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_y_and_z( + cost_map["orByteString-cpu-arguments-intercept"], + cost_map["orByteString-cpu-arguments-slope1"], + cost_map["orByteString-cpu-arguments-slope2"], + ), + ), + + xor_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_max_y_z( + cost_map["xorByteString-memory-arguments-intercept"], + cost_map["xorByteString-memory-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_y_and_z( + cost_map["xorByteString-cpu-arguments-intercept"], + cost_map["xorByteString-cpu-arguments-slope1"], + cost_map["xorByteString-cpu-arguments-slope2"], + ), + ), + + complement_byte_string: OneArgumentCosting::new( + OneArgumentCosting::linear_cost( + cost_map["complementByteString-memory-arguments-intercept"], + cost_map["complementByteString-memory-arguments-slope"], + ), + OneArgumentCosting::linear_cost( + cost_map["complementByteString-cpu-arguments-intercept"], + cost_map["complementByteString-cpu-arguments-slope"], + ), + ), + + read_bit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["readBit-memory-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["readBit-cpu-arguments"]), + ), + + write_bits: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_x( + cost_map["writeBits-memory-arguments-intercept"], + cost_map["writeBits-memory-arguments-slope"], + ), + ThreeArgumentsCosting::linear_in_y( + cost_map["writeBits-cpu-arguments-intercept"], + cost_map["writeBits-cpu-arguments-slope"], + ), + ), + + replicate_byte: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x( + cost_map["replicateByte-memory-arguments-intercept"], + cost_map["replicateByte-memory-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["replicateByte-cpu-arguments-intercept"], + cost_map["replicateByte-cpu-arguments-slope"], + ), + ), + + shift_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x( + cost_map["shiftByteString-memory-arguments-intercept"], + cost_map["shiftByteString-memory-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["shiftByteString-cpu-arguments-intercept"], + cost_map["shiftByteString-cpu-arguments-slope"], + ), + ), + + rotate_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x( + cost_map["rotateByteString-memory-arguments-intercept"], + cost_map["rotateByteString-memory-arguments-slope"], + ), + TwoArgumentsCosting::linear_in_x( + cost_map["rotateByteString-cpu-arguments-intercept"], + cost_map["rotateByteString-cpu-arguments-slope"], + ), + ), + + count_set_bits: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["countSetBits-memory-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["countSetBits-cpu-arguments-intercept"], + cost_map["countSetBits-cpu-arguments-slope"], + ), + ), + + find_first_set_bit: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["findFirstSetBit-memory-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["findFirstSetBit-cpu-arguments-intercept"], + cost_map["findFirstSetBit-cpu-arguments-slope"], + ), + ), + + ripemd_160: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(cost_map["ripemd_160-memory-arguments"]), + OneArgumentCosting::linear_cost( + cost_map["ripemd_160-cpu-arguments-intercept"], + cost_map["ripemd_160-cpu-arguments-slope"], + ), + ), + + exp_mod_integer: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(0, 1), + ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), + ), + + drop_list: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::linear_in_x(116711, 1957), + ), + length_of_array: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(198994), + ), + list_to_array: TwoArgumentsCosting::new( + TwoArgumentsCosting::linear_in_x(7, 1), + TwoArgumentsCosting::linear_in_x(307802, 8496), + ), + index_array: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(194922), + ), + } + } + + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { + match builtin { + DefaultFunction::AddInteger => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SubtractInteger => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MultiplyInteger => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::DivideInteger => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::QuotientInteger => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::RemainderInteger => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ModInteger => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsInteger => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanInteger => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsInteger => Some(ExBudget::new( + self.less_than_equals_integer.mem.cost([args[0], args[1]]), + self.less_than_equals_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::AppendByteString => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ConsByteString => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::SliceByteString => Some(ExBudget::new( + self.slice_byte_string.mem.cost([args[0], args[1], args[2]]), + self.slice_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::LengthOfByteString => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + DefaultFunction::IndexByteString => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsByteString => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanByteString => Some(ExBudget::new( + self.less_than_byte_string.mem.cost([args[0], args[1]]), + self.less_than_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( + self.less_than_equals_byte_string + .mem + .cost([args[0], args[1]]), + self.less_than_equals_byte_string + .cpu + .cost([args[0], args[1]]), + )), + DefaultFunction::Sha2_256 => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + DefaultFunction::Sha3_256 => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + DefaultFunction::Blake2b_224 => Some(ExBudget::new( + self.blake2b_224.mem.cost([args[0]]), + self.blake2b_224.cpu.cost([args[0]]), + )), + DefaultFunction::Blake2b_256 => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + DefaultFunction::Keccak_256 => Some(ExBudget::new( + self.keccak_256.mem.cost([args[0]]), + self.keccak_256.cpu.cost([args[0]]), + )), + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( + self.verify_ed25519_signature + .mem + .cost([args[0], args[1], args[2]]), + self.verify_ed25519_signature + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::VerifyEcdsaSecp256k1Signature => Some(ExBudget::new( + self.verify_ecdsa_secp256k1_signature + .mem + .cost([args[0], args[1], args[2]]), + self.verify_ecdsa_secp256k1_signature + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::VerifySchnorrSecp256k1Signature => Some(ExBudget::new( + self.verify_schnorr_secp256k1_signature + .mem + .cost([args[0], args[1], args[2]]), + self.verify_schnorr_secp256k1_signature + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::AppendString => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EqualsString => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + DefaultFunction::IfThenElse => Some(ExBudget::new( + self.if_then_else.mem.cost([args[0], args[1], args[2]]), + self.if_then_else.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ChooseUnit => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Trace => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::FstPair => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + DefaultFunction::SndPair => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseList => Some(ExBudget::new( + self.choose_list.mem.cost([args[0], args[1], args[2]]), + self.choose_list.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::MkCons => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::HeadList => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + DefaultFunction::TailList => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + DefaultFunction::NullList => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + DefaultFunction::ChooseData => Some(ExBudget::new( + self.choose_data + .mem + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + self.choose_data + .cpu + .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), + )), + DefaultFunction::ConstrData => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MapData => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + DefaultFunction::ListData => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + DefaultFunction::IData => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + DefaultFunction::BData => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnConstrData => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnMapData => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnListData => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnIData => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + DefaultFunction::UnBData => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + DefaultFunction::EqualsData => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkPairData => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::MkNilData => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + DefaultFunction::MkNilPairData => Some(ExBudget::new( + self.mk_nil_pair_data.mem.cost([args[0]]), + self.mk_nil_pair_data.cpu.cost([args[0]]), + )), + DefaultFunction::SerialiseData => Some(ExBudget::new( + self.serialise_data.mem.cost([args[0]]), + self.serialise_data.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G1_Add => Some(ExBudget::new( + self.bls12_381_g1_add.mem.cost([args[0], args[1]]), + self.bls12_381_g1_add.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G1_Neg => Some(ExBudget::new( + self.bls12_381_g1_neg.mem.cost([args[0]]), + self.bls12_381_g1_neg.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G1_ScalarMul => Some(ExBudget::new( + self.bls12_381_g1_scalar_mul.mem.cost([args[0], args[1]]), + self.bls12_381_g1_scalar_mul.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G1_Equal => Some(ExBudget::new( + self.bls12_381_g1_equal.mem.cost([args[0], args[1]]), + self.bls12_381_g1_equal.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G1_Compress => Some(ExBudget::new( + self.bls12_381_g1_compress.mem.cost([args[0]]), + self.bls12_381_g1_compress.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G1_Uncompress => Some(ExBudget::new( + self.bls12_381_g1_uncompress.mem.cost([args[0]]), + self.bls12_381_g1_uncompress.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G1_HashToGroup => Some(ExBudget::new( + self.bls12_381_g1_hash_to_group.mem.cost([args[0], args[1]]), + self.bls12_381_g1_hash_to_group.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G2_Add => Some(ExBudget::new( + self.bls12_381_g2_add.mem.cost([args[0], args[1]]), + self.bls12_381_g2_add.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G2_Neg => Some(ExBudget::new( + self.bls12_381_g2_neg.mem.cost([args[0]]), + self.bls12_381_g2_neg.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G2_ScalarMul => Some(ExBudget::new( + self.bls12_381_g2_scalar_mul.mem.cost([args[0], args[1]]), + self.bls12_381_g2_scalar_mul.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G2_Equal => Some(ExBudget::new( + self.bls12_381_g2_equal.mem.cost([args[0], args[1]]), + self.bls12_381_g2_equal.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_G2_Compress => Some(ExBudget::new( + self.bls12_381_g2_compress.mem.cost([args[0]]), + self.bls12_381_g2_compress.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G2_Uncompress => Some(ExBudget::new( + self.bls12_381_g2_uncompress.mem.cost([args[0]]), + self.bls12_381_g2_uncompress.cpu.cost([args[0]]), + )), + DefaultFunction::Bls12_381_G2_HashToGroup => Some(ExBudget::new( + self.bls12_381_g2_hash_to_group.mem.cost([args[0], args[1]]), + self.bls12_381_g2_hash_to_group.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_MillerLoop => Some(ExBudget::new( + self.bls12_381_miller_loop.mem.cost([args[0], args[1]]), + self.bls12_381_miller_loop.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_MulMlResult => Some(ExBudget::new( + self.bls12_381_mul_ml_result.mem.cost([args[0], args[1]]), + self.bls12_381_mul_ml_result.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::Bls12_381_FinalVerify => Some(ExBudget::new( + self.bls12_381_final_verify.mem.cost([args[0], args[1]]), + self.bls12_381_final_verify.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::IntegerToByteString => Some(ExBudget::new( + self.integer_to_byte_string + .mem + .cost([args[0], args[1], args[2]]), + self.integer_to_byte_string + .cpu + .cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ByteStringToInteger => Some(ExBudget::new( + self.byte_string_to_integer.mem.cost([args[0], args[1]]), + self.byte_string_to_integer.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::AndByteString => Some(ExBudget::new( + self.and_byte_string.mem.cost([args[0], args[1], args[2]]), + self.and_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::OrByteString => Some(ExBudget::new( + self.or_byte_string.mem.cost([args[0], args[1], args[2]]), + self.or_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::XorByteString => Some(ExBudget::new( + self.xor_byte_string.mem.cost([args[0], args[1], args[2]]), + self.xor_byte_string.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ComplementByteString => Some(ExBudget::new( + self.complement_byte_string.mem.cost([args[0]]), + self.complement_byte_string.cpu.cost([args[0]]), + )), + DefaultFunction::ReadBit => Some(ExBudget::new( + self.read_bit.mem.cost([args[0], args[1]]), + self.read_bit.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::WriteBits => Some(ExBudget::new( + self.write_bits.mem.cost([args[0], args[1], args[2]]), + self.write_bits.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::ReplicateByte => Some(ExBudget::new( + self.replicate_byte.mem.cost([args[0], args[1]]), + self.replicate_byte.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::ShiftByteString => Some(ExBudget::new( + self.shift_byte_string.mem.cost([args[0], args[1]]), + self.shift_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::RotateByteString => Some(ExBudget::new( + self.rotate_byte_string.mem.cost([args[0], args[1]]), + self.rotate_byte_string.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::CountSetBits => Some(ExBudget::new( + self.count_set_bits.mem.cost([args[0]]), + self.count_set_bits.cpu.cost([args[0]]), + )), + DefaultFunction::FindFirstSetBit => Some(ExBudget::new( + self.find_first_set_bit.mem.cost([args[0]]), + self.find_first_set_bit.cpu.cost([args[0]]), + )), + DefaultFunction::Ripemd_160 => Some(ExBudget::new( + self.ripemd_160.mem.cost([args[0]]), + self.ripemd_160.cpu.cost([args[0]]), + )), + DefaultFunction::ExpModInteger => Some(ExBudget::new( + self.exp_mod_integer.mem.cost([args[0], args[1], args[2]]), + self.exp_mod_integer.cpu.cost([args[0], args[1], args[2]]), + )), + DefaultFunction::DropList => Some(ExBudget::new( + self.drop_list.mem.cost([args[0], args[1]]), + self.drop_list.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::LengthOfArray => Some(ExBudget::new( + self.length_of_array.mem.cost([args[0]]), + self.length_of_array.cpu.cost([args[0]]), + )), + DefaultFunction::ListToArray => Some(ExBudget::new( + self.list_to_array.mem.cost([args[0], args[1]]), + self.list_to_array.cpu.cost([args[0], args[1]]), + )), + DefaultFunction::IndexArray => Some(ExBudget::new( + self.index_array.mem.cost([args[0], args[1]]), + self.index_array.cpu.cost([args[0], args[1]]), + )), + } + } +} diff --git a/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs new file mode 100644 index 000000000..641d6483f --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs @@ -0,0 +1,108 @@ +pub mod builtin_costs_v1; +pub mod builtin_costs_v2; +pub mod builtin_costs_v3; + +use crate::{ + builtin::DefaultFunction, + machine::{cost_model::cost_map::CostMap, ExBudget}, +}; + +pub trait BuiltinCostModel { + fn initialize(cost_map: &CostMap) -> Self; + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option; +} + +#[cfg(test)] +mod tests { + use crate::machine::{ + cost_model::builtin_costs::{ + builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, + builtin_costs_v3::BuiltinCostsV3, + }, + PlutusVersion, + }; + + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn assert_default_cost_model_v1() { + let costs = vec![ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, + 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, + 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, + 4, 2, 85848, 228465, 122, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1, 898148, + 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32, + 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, + 1, 33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 228465, 122, + 0, 1, 1, 90434, 519, 0, 1, 74433, 32, 85848, 228465, 122, 0, 1, 1, 85848, 228465, 122, + 0, 1, 1, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420, + 1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32, + 53384111, 14333, 10, + ]; + + let cost_model = CostMap::new(&PlutusVersion::V1, &costs); + + assert_eq!( + BuiltinCostsV1::default(), + BuiltinCostsV1::initialize(&cost_model) + ); + } + + #[test] + fn assert_default_cost_model_v2() { + let costs = vec![ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, + 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, + 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, + 4, 2, 85848, 228465, 122, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1, 898148, + 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32, + 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, + 1, 33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 228465, 122, + 0, 1, 1, 90434, 519, 0, 1, 74433, 32, 85848, 228465, 122, 0, 1, 1, 85848, 228465, 122, + 0, 1, 1, 955506, 213312, 0, 2, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, + 141992, 32, 100788, 420, 1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, + 25933, 32, 24623, 32, 43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, + ]; + + let cost_model = CostMap::new(&PlutusVersion::V2, &costs); + + assert_eq!( + BuiltinCostsV2::default(), + BuiltinCostsV2::initialize(&cost_model) + ); + } + + #[test] + fn assert_default_cost_model_v3() { + let costs: Vec = vec![ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, + 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, + 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, + 4, 2, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 1000, 42921, 4, 2, + 24548, 29498, 38, 1, 898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, + 32, 83150, 32, 15299, 32, 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, + 43285, 552, 1, 44749, 541, 1, 33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, + 11546, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 90434, 519, 0, 1, + 74433, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 85848, 123203, + 7305, -900, 1716, 549, 57, 85848, 0, 1, 955506, 213312, 0, 2, 270652, 22588, 4, + 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420, 1, 1, 81663, 32, 59498, 32, + 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32, 43053543, 10, 53384111, 14333, + 10, 43574283, 26308, 10, 16000, 100, 16000, 100, 962335, 18, 2780678, 6, 442008, 1, + 52538055, 3756, 18, 267929, 18, 76433006, 8868, 18, 52948122, 18, 1995836, 36, 3227919, + 12, 901022, 1, 166917843, 4307, 36, 284546, 36, 158221314, 26549, 36, 74698472, 36, + 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, 4, 1293828, + 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0, 1, 100181, 726, 719, + 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848, 0, 1, 180194, + 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655, 1, + 1964219, 24520, 3, + ]; + + let cost_model = CostMap::new(&PlutusVersion::V3, &costs); + + assert_eq!( + BuiltinCostsV3::default(), + BuiltinCostsV3::initialize(&cost_model) + ); + } +} diff --git a/crates/uplc/src/machine/cost_model/cost_map.rs b/crates/uplc/src/machine/cost_model/cost_map.rs new file mode 100644 index 000000000..5825e4d15 --- /dev/null +++ b/crates/uplc/src/machine/cost_model/cost_map.rs @@ -0,0 +1,686 @@ +use std::collections::HashMap; +use std::ops::Index; + +use crate::machine::PlutusVersion; + +pub struct CostMap { + map: HashMap, +} + +impl CostMap { + pub fn new(version: &PlutusVersion, values: &[i64]) -> Self { + let keys = match version { + PlutusVersion::V1 => vec![ + "add_integer-cpu-arguments-intercept", + "add_integer-cpu-arguments-slope", + "add_integer-mem-arguments-intercept", + "add_integer-mem-arguments-slope", + "append_byte_string-cpu-arguments-intercept", + "append_byte_string-cpu-arguments-slope", + "append_byte_string-mem-arguments-intercept", + "append_byte_string-mem-arguments-slope", + "append_string-cpu-arguments-intercept", + "append_string-cpu-arguments-slope", + "append_string-mem-arguments-intercept", + "append_string-mem-arguments-slope", + "b_data-cpu-arguments", + "b_data-mem-arguments", + "blake2b_256-cpu-arguments-intercept", + "blake2b_256-cpu-arguments-slope", + "blake2b_256-mem-arguments", + "cek_apply_cost-exBudgetCPU", + "cek_apply_cost-exBudgetmem", + "cek_builtin_cost-exBudgetCPU", + "cek_builtin_cost-exBudgetmem", + "cek_const_cost-exBudgetCPU", + "cek_const_cost-exBudgetmem", + "cek_delay_cost-exBudgetCPU", + "cek_delay_cost-exBudgetmem", + "cek_force_cost-exBudgetCPU", + "cek_force_cost-exBudgetmem", + "cek_lam_cost-exBudgetCPU", + "cek_lam_cost-exBudgetmem", + "cek_startup_cost-exBudgetCPU", + "cek_startup_cost-exBudgetmem", + "cek_var_cost-exBudgetCPU", + "cek_var_cost-exBudgetmem", + "choose_data-cpu-arguments", + "choose_data-mem-arguments", + "choose_list-cpu-arguments", + "choose_list-mem-arguments", + "choose_unit-cpu-arguments", + "choose_unit-mem-arguments", + "cons_byte_string-cpu-arguments-intercept", + "cons_byte_string-cpu-arguments-slope", + "cons_byte_string-mem-arguments-intercept", + "cons_byte_string-mem-arguments-slope", + "constr_data-cpu-arguments", + "constr_data-mem-arguments", + "decode_utf8-cpu-arguments-intercept", + "decode_utf8-cpu-arguments-slope", + "decode_utf8-mem-arguments-intercept", + "decode_utf8-mem-arguments-slope", + "divide_integer-cpu-arguments-constant", + "divide_integer-cpu-arguments-model-arguments-intercept", + "divide_integer-cpu-arguments-model-arguments-slope", + "divide_integer-mem-arguments-intercept", + "divide_integer-mem-arguments-minimum", + "divide_integer-mem-arguments-slope", + "encode_utf8-cpu-arguments-intercept", + "encode_utf8-cpu-arguments-slope", + "encode_utf8-mem-arguments-intercept", + "encode_utf8-mem-arguments-slope", + "equals_byte_string-cpu-arguments-constant", + "equals_byte_string-cpu-arguments-intercept", + "equals_byte_string-cpu-arguments-slope", + "equals_byte_string-mem-arguments", + "equals_data-cpu-arguments-intercept", + "equals_data-cpu-arguments-slope", + "equals_data-mem-arguments", + "equals_integer-cpu-arguments-intercept", + "equals_integer-cpu-arguments-slope", + "equals_integer-mem-arguments", + "equals_string-cpu-arguments-constant", + "equals_string-cpu-arguments-intercept", + "equals_string-cpu-arguments-slope", + "equals_string-mem-arguments", + "fst_pair-cpu-arguments", + "fst_pair-mem-arguments", + "head_list-cpu-arguments", + "head_list-mem-arguments", + "i_data-cpu-arguments", + "i_data-mem-arguments", + "if_then_else-cpu-arguments", + "if_then_else-mem-arguments", + "index_byte_string-cpu-arguments", + "index_byte_string-mem-arguments", + "length_of_byte_string-cpu-arguments", + "length_of_byte_string-mem-arguments", + "less_than_byte_string-cpu-arguments-intercept", + "less_than_byte_string-cpu-arguments-slope", + "less_than_byte_string-mem-arguments", + "less_than_equals_byte_string-cpu-arguments-intercept", + "less_than_equals_byte_string-cpu-arguments-slope", + "less_than_equals_byte_string-mem-arguments", + "less_than_equals_integer-cpu-arguments-intercept", + "less_than_equals_integer-cpu-arguments-slope", + "less_than_equals_integer-mem-arguments", + "less_than_integer-cpu-arguments-intercept", + "less_than_integer-cpu-arguments-slope", + "less_than_integer-mem-arguments", + "list_data-cpu-arguments", + "list_data-mem-arguments", + "map_data-cpu-arguments", + "map_data-mem-arguments", + "mk_cons-cpu-arguments", + "mk_cons-mem-arguments", + "mk_nil_data-cpu-arguments", + "mk_nil_data-mem-arguments", + "mk_nil_pair_data-cpu-arguments", + "mk_nil_pair_data-mem-arguments", + "mk_pair_data-cpu-arguments", + "mk_pair_data-mem-arguments", + "mod_integer-cpu-arguments-constant", + "mod_integer-cpu-arguments-model-arguments-intercept", + "mod_integer-cpu-arguments-model-arguments-slope", + "mod_integer-mem-arguments-intercept", + "mod_integer-mem-arguments-minimum", + "mod_integer-mem-arguments-slope", + "multiply_integer-cpu-arguments-intercept", + "multiply_integer-cpu-arguments-slope", + "multiply_integer-mem-arguments-intercept", + "multiply_integer-mem-arguments-slope", + "null_list-cpu-arguments", + "null_list-mem-arguments", + "quotient_integer-cpu-arguments-constant", + "quotient_integer-cpu-arguments-model-arguments-intercept", + "quotient_integer-cpu-arguments-model-arguments-slope", + "quotient_integer-mem-arguments-intercept", + "quotient_integer-mem-arguments-minimum", + "quotient_integer-mem-arguments-slope", + "remainder_integer-cpu-arguments-constant", + "remainder_integer-cpu-arguments-model-arguments-intercept", + "remainder_integer-cpu-arguments-model-arguments-slope", + "remainder_integer-mem-arguments-intercept", + "remainder_integer-mem-arguments-minimum", + "remainder_integer-mem-arguments-slope", + "sha2_256-cpu-arguments-intercept", + "sha2_256-cpu-arguments-slope", + "sha2_256-mem-arguments", + "sha3_256-cpu-arguments-intercept", + "sha3_256-cpu-arguments-slope", + "sha3_256-mem-arguments", + "slice_byte_string-cpu-arguments-intercept", + "slice_byte_string-cpu-arguments-slope", + "slice_byte_string-mem-arguments-intercept", + "slice_byte_string-mem-arguments-slope", + "snd_pair-cpu-arguments", + "snd_pair-mem-arguments", + "subtract_integer-cpu-arguments-intercept", + "subtract_integer-cpu-arguments-slope", + "subtract_integer-mem-arguments-intercept", + "subtract_integer-mem-arguments-slope", + "tail_list-cpu-arguments", + "tail_list-mem-arguments", + "trace-cpu-arguments", + "trace-mem-arguments", + "un_b_data-cpu-arguments", + "un_b_data-mem-arguments", + "un_constr_data-cpu-arguments", + "un_constr_data-mem-arguments", + "un_i_data-cpu-arguments", + "un_i_data-mem-arguments", + "un_list_data-cpu-arguments", + "un_list_data-mem-arguments", + "un_map_data-cpu-arguments", + "un_map_data-mem-arguments", + "verify_ed25519_signature-cpu-arguments-intercept", + "verify_ed25519_signature-cpu-arguments-slope", + "verify_ed25519_signature-mem-arguments", + ], + PlutusVersion::V2 => vec![ + "add_integer-cpu-arguments-intercept", + "add_integer-cpu-arguments-slope", + "add_integer-mem-arguments-intercept", + "add_integer-mem-arguments-slope", + "append_byte_string-cpu-arguments-intercept", + "append_byte_string-cpu-arguments-slope", + "append_byte_string-mem-arguments-intercept", + "append_byte_string-mem-arguments-slope", + "append_string-cpu-arguments-intercept", + "append_string-cpu-arguments-slope", + "append_string-mem-arguments-intercept", + "append_string-mem-arguments-slope", + "b_data-cpu-arguments", + "b_data-mem-arguments", + "blake2b_256-cpu-arguments-intercept", + "blake2b_256-cpu-arguments-slope", + "blake2b_256-mem-arguments", + "cek_apply_cost-exBudgetCPU", + "cek_apply_cost-exBudgetmem", + "cek_builtin_cost-exBudgetCPU", + "cek_builtin_cost-exBudgetmem", + "cek_const_cost-exBudgetCPU", + "cek_const_cost-exBudgetmem", + "cek_delay_cost-exBudgetCPU", + "cek_delay_cost-exBudgetmem", + "cek_force_cost-exBudgetCPU", + "cek_force_cost-exBudgetmem", + "cek_lam_cost-exBudgetCPU", + "cek_lam_cost-exBudgetmem", + "cek_startup_cost-exBudgetCPU", + "cek_startup_cost-exBudgetmem", + "cek_var_cost-exBudgetCPU", + "cek_var_cost-exBudgetmem", + "choose_data-cpu-arguments", + "choose_data-mem-arguments", + "choose_list-cpu-arguments", + "choose_list-mem-arguments", + "choose_unit-cpu-arguments", + "choose_unit-mem-arguments", + "cons_byte_string-cpu-arguments-intercept", + "cons_byte_string-cpu-arguments-slope", + "cons_byte_string-mem-arguments-intercept", + "cons_byte_string-mem-arguments-slope", + "constr_data-cpu-arguments", + "constr_data-mem-arguments", + "decode_utf8-cpu-arguments-intercept", + "decode_utf8-cpu-arguments-slope", + "decode_utf8-mem-arguments-intercept", + "decode_utf8-mem-arguments-slope", + "divide_integer-cpu-arguments-constant", + "divide_integer-cpu-arguments-model-arguments-intercept", + "divide_integer-cpu-arguments-model-arguments-slope", + "divide_integer-mem-arguments-intercept", + "divide_integer-mem-arguments-minimum", + "divide_integer-mem-arguments-slope", + "encode_utf8-cpu-arguments-intercept", + "encode_utf8-cpu-arguments-slope", + "encode_utf8-mem-arguments-intercept", + "encode_utf8-mem-arguments-slope", + "equals_byte_string-cpu-arguments-constant", + "equals_byte_string-cpu-arguments-intercept", + "equals_byte_string-cpu-arguments-slope", + "equals_byte_string-mem-arguments", + "equals_data-cpu-arguments-intercept", + "equals_data-cpu-arguments-slope", + "equals_data-mem-arguments", + "equals_integer-cpu-arguments-intercept", + "equals_integer-cpu-arguments-slope", + "equals_integer-mem-arguments", + "equals_string-cpu-arguments-constant", + "equals_string-cpu-arguments-intercept", + "equals_string-cpu-arguments-slope", + "equals_string-mem-arguments", + "fst_pair-cpu-arguments", + "fst_pair-mem-arguments", + "head_list-cpu-arguments", + "head_list-mem-arguments", + "i_data-cpu-arguments", + "i_data-mem-arguments", + "if_then_else-cpu-arguments", + "if_then_else-mem-arguments", + "index_byte_string-cpu-arguments", + "index_byte_string-mem-arguments", + "length_of_byte_string-cpu-arguments", + "length_of_byte_string-mem-arguments", + "less_than_byte_string-cpu-arguments-intercept", + "less_than_byte_string-cpu-arguments-slope", + "less_than_byte_string-mem-arguments", + "less_than_equals_byte_string-cpu-arguments-intercept", + "less_than_equals_byte_string-cpu-arguments-slope", + "less_than_equals_byte_string-mem-arguments", + "less_than_equals_integer-cpu-arguments-intercept", + "less_than_equals_integer-cpu-arguments-slope", + "less_than_equals_integer-mem-arguments", + "less_than_integer-cpu-arguments-intercept", + "less_than_integer-cpu-arguments-slope", + "less_than_integer-mem-arguments", + "list_data-cpu-arguments", + "list_data-mem-arguments", + "map_data-cpu-arguments", + "map_data-mem-arguments", + "mk_cons-cpu-arguments", + "mk_cons-mem-arguments", + "mk_nil_data-cpu-arguments", + "mk_nil_data-mem-arguments", + "mk_nil_pair_data-cpu-arguments", + "mk_nil_pair_data-mem-arguments", + "mk_pair_data-cpu-arguments", + "mk_pair_data-mem-arguments", + "mod_integer-cpu-arguments-constant", + "mod_integer-cpu-arguments-model-arguments-intercept", + "mod_integer-cpu-arguments-model-arguments-slope", + "mod_integer-mem-arguments-intercept", + "mod_integer-mem-arguments-minimum", + "mod_integer-mem-arguments-slope", + "multiply_integer-cpu-arguments-intercept", + "multiply_integer-cpu-arguments-slope", + "multiply_integer-mem-arguments-intercept", + "multiply_integer-mem-arguments-slope", + "null_list-cpu-arguments", + "null_list-mem-arguments", + "quotient_integer-cpu-arguments-constant", + "quotient_integer-cpu-arguments-model-arguments-intercept", + "quotient_integer-cpu-arguments-model-arguments-slope", + "quotient_integer-mem-arguments-intercept", + "quotient_integer-mem-arguments-minimum", + "quotient_integer-mem-arguments-slope", + "remainder_integer-cpu-arguments-constant", + "remainder_integer-cpu-arguments-model-arguments-intercept", + "remainder_integer-cpu-arguments-model-arguments-slope", + "remainder_integer-mem-arguments-intercept", + "remainder_integer-mem-arguments-minimum", + "remainder_integer-mem-arguments-slope", + "serialise_data-cpu-arguments-intercept", + "serialise_data-cpu-arguments-slope", + "serialise_data-mem-arguments-intercept", + "serialise_data-mem-arguments-slope", + "sha2_256-cpu-arguments-intercept", + "sha2_256-cpu-arguments-slope", + "sha2_256-mem-arguments", + "sha3_256-cpu-arguments-intercept", + "sha3_256-cpu-arguments-slope", + "sha3_256-mem-arguments", + "slice_byte_string-cpu-arguments-intercept", + "slice_byte_string-cpu-arguments-slope", + "slice_byte_string-mem-arguments-intercept", + "slice_byte_string-mem-arguments-slope", + "snd_pair-cpu-arguments", + "snd_pair-mem-arguments", + "subtract_integer-cpu-arguments-intercept", + "subtract_integer-cpu-arguments-slope", + "subtract_integer-mem-arguments-intercept", + "subtract_integer-mem-arguments-slope", + "tail_list-cpu-arguments", + "tail_list-mem-arguments", + "trace-cpu-arguments", + "trace-mem-arguments", + "un_b_data-cpu-arguments", + "un_b_data-mem-arguments", + "un_constr_data-cpu-arguments", + "un_constr_data-mem-arguments", + "un_i_data-cpu-arguments", + "un_i_data-mem-arguments", + "un_list_data-cpu-arguments", + "un_list_data-mem-arguments", + "un_map_data-cpu-arguments", + "un_map_data-mem-arguments", + "verify_ecdsa_secp256k1_signature-cpu-arguments", + "verify_ecdsa_secp256k1_signature-mem-arguments", + "verify_ed25519_signature-cpu-arguments-intercept", + "verify_ed25519_signature-cpu-arguments-slope", + "verify_ed25519_signature-mem-arguments", + "verify_schnorr_secp256k1_signature-cpu-arguments-intercept", + "verify_schnorr_secp256k1_signature-cpu-arguments-slope", + "verify_schnorr_secp256k1_signature-mem-arguments", + ], + PlutusVersion::V3 => { + let mut base_keys = vec![ + "add_integer-cpu-arguments-intercept", + "add_integer-cpu-arguments-slope", + "add_integer-mem-arguments-intercept", + "add_integer-mem-arguments-slope", + "append_byte_string-cpu-arguments-intercept", + "append_byte_string-cpu-arguments-slope", + "append_byte_string-mem-arguments-intercept", + "append_byte_string-mem-arguments-slope", + "append_string-cpu-arguments-intercept", + "append_string-cpu-arguments-slope", + "append_string-mem-arguments-intercept", + "append_string-mem-arguments-slope", + "b_data-cpu-arguments", + "b_data-mem-arguments", + "blake2b_256-cpu-arguments-intercept", + "blake2b_256-cpu-arguments-slope", + "blake2b_256-mem-arguments", + "cek_apply_cost-exBudgetCPU", + "cek_apply_cost-exBudgetmem", + "cek_builtin_cost-exBudgetCPU", + "cek_builtin_cost-exBudgetmem", + "cek_const_cost-exBudgetCPU", + "cek_const_cost-exBudgetmem", + "cek_delay_cost-exBudgetCPU", + "cek_delay_cost-exBudgetmem", + "cek_force_cost-exBudgetCPU", + "cek_force_cost-exBudgetmem", + "cek_lam_cost-exBudgetCPU", + "cek_lam_cost-exBudgetmem", + "cek_startup_cost-exBudgetCPU", + "cek_startup_cost-exBudgetmem", + "cek_var_cost-exBudgetCPU", + "cek_var_cost-exBudgetmem", + "choose_data-cpu-arguments", + "choose_data-mem-arguments", + "choose_list-cpu-arguments", + "choose_list-mem-arguments", + "choose_unit-cpu-arguments", + "choose_unit-mem-arguments", + "cons_byte_string-cpu-arguments-intercept", + "cons_byte_string-cpu-arguments-slope", + "cons_byte_string-mem-arguments-intercept", + "cons_byte_string-mem-arguments-slope", + "constr_data-cpu-arguments", + "constr_data-mem-arguments", + "decode_utf8-cpu-arguments-intercept", + "decode_utf8-cpu-arguments-slope", + "decode_utf8-mem-arguments-intercept", + "decode_utf8-mem-arguments-slope", + "divide_integer-cpu-arguments-constant", + "divide_integer-cpu-arguments-c00", + "divide_integer-cpu-arguments-c01", + "divide_integer-cpu-arguments-c02", + "divide_integer-cpu-arguments-c10", + "divide_integer-cpu-arguments-c11", + "divide_integer-cpu-arguments-c20", + "divide_integer-cpu-arguments-minimum", + "divide_integer-mem-arguments-intercept", + "divide_integer-mem-arguments-minimum", + "divide_integer-mem-arguments-slope", + "encode_utf8-cpu-arguments-intercept", + "encode_utf8-cpu-arguments-slope", + "encode_utf8-mem-arguments-intercept", + "encode_utf8-mem-arguments-slope", + "equals_byte_string-cpu-arguments-constant", + "equals_byte_string-cpu-arguments-intercept", + "equals_byte_string-cpu-arguments-slope", + "equals_byte_string-mem-arguments", + "equals_data-cpu-arguments-intercept", + "equals_data-cpu-arguments-slope", + "equals_data-mem-arguments", + "equals_integer-cpu-arguments-intercept", + "equals_integer-cpu-arguments-slope", + "equals_integer-mem-arguments", + "equals_string-cpu-arguments-constant", + "equals_string-cpu-arguments-intercept", + "equals_string-cpu-arguments-slope", + "equals_string-mem-arguments", + "fst_pair-cpu-arguments", + "fst_pair-mem-arguments", + "head_list-cpu-arguments", + "head_list-mem-arguments", + "i_data-cpu-arguments", + "i_data-mem-arguments", + "if_then_else-cpu-arguments", + "if_then_else-mem-arguments", + "index_byte_string-cpu-arguments", + "index_byte_string-mem-arguments", + "length_of_byte_string-cpu-arguments", + "length_of_byte_string-mem-arguments", + "less_than_byte_string-cpu-arguments-intercept", + "less_than_byte_string-cpu-arguments-slope", + "less_than_byte_string-mem-arguments", + "less_than_equals_byte_string-cpu-arguments-intercept", + "less_than_equals_byte_string-cpu-arguments-slope", + "less_than_equals_byte_string-mem-arguments", + "less_than_equals_integer-cpu-arguments-intercept", + "less_than_equals_integer-cpu-arguments-slope", + "less_than_equals_integer-mem-arguments", + "less_than_integer-cpu-arguments-intercept", + "less_than_integer-cpu-arguments-slope", + "less_than_integer-mem-arguments", + "list_data-cpu-arguments", + "list_data-mem-arguments", + "map_data-cpu-arguments", + "map_data-mem-arguments", + "mk_cons-cpu-arguments", + "mk_cons-mem-arguments", + "mk_nil_data-cpu-arguments", + "mk_nil_data-mem-arguments", + "mk_nil_pair_data-cpu-arguments", + "mk_nil_pair_data-mem-arguments", + "mk_pair_data-cpu-arguments", + "mk_pair_data-mem-arguments", + "mod_integer-cpu-arguments-constant", + "mod_integer-cpu-arguments-c00", + "mod_integer-cpu-arguments-c01", + "mod_integer-cpu-arguments-c02", + "mod_integer-cpu-arguments-c10", + "mod_integer-cpu-arguments-c11", + "mod_integer-cpu-arguments-c20", + "mod_integer-cpu-arguments-minimum", + "mod_integer-mem-arguments-intercept", + "mod_integer-mem-arguments-slope", + "multiply_integer-cpu-arguments-intercept", + "multiply_integer-cpu-arguments-slope", + "multiply_integer-mem-arguments-intercept", + "multiply_integer-mem-arguments-slope", + "null_list-cpu-arguments", + "null_list-mem-arguments", + "quotient_integer-cpu-arguments-constant", + "quotient_integer-cpu-arguments-c00", + "quotient_integer-cpu-arguments-c01", + "quotient_integer-cpu-arguments-c02", + "quotient_integer-cpu-arguments-c10", + "quotient_integer-cpu-arguments-c11", + "quotient_integer-cpu-arguments-c20", + "quotient_integer-cpu-arguments-minimum", + "quotient_integer-mem-arguments-intercept", + "quotient_integer-mem-arguments-minimum", + "quotient_integer-mem-arguments-slope", + "remainder_integer-cpu-arguments-constant", + "remainder_integer-cpu-arguments-c00", + "remainder_integer-cpu-arguments-c01", + "remainder_integer-cpu-arguments-c02", + "remainder_integer-cpu-arguments-c10", + "remainder_integer-cpu-arguments-c11", + "remainder_integer-cpu-arguments-c20", + "remainder_integer-cpu-arguments-minimum", + "remainder_integer-mem-arguments-intercept", + "remainder_integer-mem-arguments-slope", + "serialise_data-cpu-arguments-intercept", + "serialise_data-cpu-arguments-slope", + "serialise_data-mem-arguments-intercept", + "serialise_data-mem-arguments-slope", + "sha2_256-cpu-arguments-intercept", + "sha2_256-cpu-arguments-slope", + "sha2_256-mem-arguments", + "sha3_256-cpu-arguments-intercept", + "sha3_256-cpu-arguments-slope", + "sha3_256-mem-arguments", + "slice_byte_string-cpu-arguments-intercept", + "slice_byte_string-cpu-arguments-slope", + "slice_byte_string-mem-arguments-intercept", + "slice_byte_string-mem-arguments-slope", + "snd_pair-cpu-arguments", + "snd_pair-mem-arguments", + "subtract_integer-cpu-arguments-intercept", + "subtract_integer-cpu-arguments-slope", + "subtract_integer-mem-arguments-intercept", + "subtract_integer-mem-arguments-slope", + "tail_list-cpu-arguments", + "tail_list-mem-arguments", + "trace-cpu-arguments", + "trace-mem-arguments", + "un_b_data-cpu-arguments", + "un_b_data-mem-arguments", + "un_constr_data-cpu-arguments", + "un_constr_data-mem-arguments", + "un_i_data-cpu-arguments", + "un_i_data-mem-arguments", + "un_list_data-cpu-arguments", + "un_list_data-mem-arguments", + "un_map_data-cpu-arguments", + "un_map_data-mem-arguments", + "verify_ecdsa_secp256k1_signature-cpu-arguments", + "verify_ecdsa_secp256k1_signature-mem-arguments", + "verify_ed25519_signature-cpu-arguments-intercept", + "verify_ed25519_signature-cpu-arguments-slope", + "verify_ed25519_signature-mem-arguments", + "verify_schnorr_secp256k1_signature-cpu-arguments-intercept", + "verify_schnorr_secp256k1_signature-cpu-arguments-slope", + "verify_schnorr_secp256k1_signature-mem-arguments", + "cek_constr_cost-exBudgetCPU", + "cek_constr_cost-exBudgetmem", + "cek_case_cost-exBudgetCPU", + "cek_case_cost-exBudgetmem", + "bls12_381_G1_add-cpu-arguments", + "bls12_381_G1_add-mem-arguments", + "bls12_381_G1_compress-cpu-arguments", + "bls12_381_G1_compress-mem-arguments", + "bls12_381_G1_equal-cpu-arguments", + "bls12_381_G1_equal-mem-arguments", + "bls12_381_G1_hashToGroup-cpu-arguments-intercept", + "bls12_381_G1_hashToGroup-cpu-arguments-slope", + "bls12_381_G1_hashToGroup-mem-arguments", + "bls12_381_G1_neg-cpu-arguments", + "bls12_381_G1_neg-mem-arguments", + "bls12_381_G1_scalarMul-cpu-arguments-intercept", + "bls12_381_G1_scalarMul-cpu-arguments-slope", + "bls12_381_G1_scalarMul-mem-arguments", + "bls12_381_G1_uncompress-cpu-arguments", + "bls12_381_G1_uncompress-mem-arguments", + "bls12_381_G2_add-cpu-arguments", + "bls12_381_G2_add-mem-arguments", + "bls12_381_G2_compress-cpu-arguments", + "bls12_381_G2_compress-mem-arguments", + "bls12_381_G2_equal-cpu-arguments", + "bls12_381_G2_equal-mem-arguments", + "bls12_381_G2_hashToGroup-cpu-arguments-intercept", + "bls12_381_G2_hashToGroup-cpu-arguments-slope", + "bls12_381_G2_hashToGroup-mem-arguments", + "bls12_381_G2_neg-cpu-arguments", + "bls12_381_G2_neg-mem-arguments", + "bls12_381_G2_scalarMul-cpu-arguments-intercept", + "bls12_381_G2_scalarMul-cpu-arguments-slope", + "bls12_381_G2_scalarMul-mem-arguments", + "bls12_381_G2_uncompress-cpu-arguments", + "bls12_381_G2_uncompress-mem-arguments", + "bls12_381_finalVerify-cpu-arguments", + "bls12_381_finalVerify-mem-arguments", + "bls12_381_millerLoop-cpu-arguments", + "bls12_381_millerLoop-mem-arguments", + "bls12_381_mulMlResult-cpu-arguments", + "bls12_381_mulMlResult-mem-arguments", + "keccak_256-cpu-arguments-intercept", + "keccak_256-cpu-arguments-slope", + "keccak_256-mem-arguments", + "blake2b_224-cpu-arguments-intercept", + "blake2b_224-cpu-arguments-slope", + "blake2b_224-mem-arguments-slope", + "integerToByteString-cpu-arguments-c0", + "integerToByteString-cpu-arguments-c1", + "integerToByteString-cpu-arguments-c2", + "integerToByteString-mem-arguments-intercept", + "integerToByteString-mem-arguments-slope", + "byteStringToInteger-cpu-arguments-c0", + "byteStringToInteger-cpu-arguments-c1", + "byteStringToInteger-cpu-arguments-c2", + "byteStringToInteger-mem-arguments-intercept", + "byteStringToInteger-mem-arguments-slope", + ]; + + if values.len() == 297 { + base_keys.extend([ + "andByteString-cpu-arguments-intercept", + "andByteString-cpu-arguments-slope1", + "andByteString-cpu-arguments-slope2", + "andByteString-memory-arguments-intercept", + "andByteString-memory-arguments-slope", + "orByteString-cpu-arguments-intercept", + "orByteString-cpu-arguments-slope1", + "orByteString-cpu-arguments-slope2", + "orByteString-memory-arguments-intercept", + "orByteString-memory-arguments-slope", + "xorByteString-cpu-arguments-intercept", + "xorByteString-cpu-arguments-slope1", + "xorByteString-cpu-arguments-slope2", + "xorByteString-memory-arguments-intercept", + "xorByteString-memory-arguments-slope", + "complementByteString-cpu-arguments-intercept", + "complementByteString-cpu-arguments-slope", + "complementByteString-memory-arguments-intercept", + "complementByteString-memory-arguments-slope", + "readBit-cpu-arguments", + "readBit-memory-arguments", + "writeBits-cpu-arguments-intercept", + "writeBits-cpu-arguments-slope", + "writeBits-memory-arguments-intercept", + "writeBits-memory-arguments-slope", + "replicateByte-cpu-arguments-intercept", + "replicateByte-cpu-arguments-slope", + "replicateByte-memory-arguments-intercept", + "replicateByte-memory-arguments-slope", + "shiftByteString-cpu-arguments-intercept", + "shiftByteString-cpu-arguments-slope", + "shiftByteString-memory-arguments-intercept", + "shiftByteString-memory-arguments-slope", + "rotateByteString-cpu-arguments-intercept", + "rotateByteString-cpu-arguments-slope", + "rotateByteString-memory-arguments-intercept", + "rotateByteString-memory-arguments-slope", + "countSetBits-cpu-arguments-intercept", + "countSetBits-cpu-arguments-slope", + "countSetBits-memory-arguments", + "findFirstSetBit-cpu-arguments-intercept", + "findFirstSetBit-cpu-arguments-slope", + "findFirstSetBit-memory-arguments", + "ripemd_160-cpu-arguments-intercept", + "ripemd_160-cpu-arguments-slope", + "ripemd_160-memory-arguments", + ]); + } + base_keys + } + }; + + let map = cost_map_from_keys_and_values(&keys, values); + + Self { map } + } +} + +fn cost_map_from_keys_and_values(keys: &[&str], values: &[i64]) -> HashMap { + keys.iter() + .cloned() + .map(String::from) + .zip(values.iter().cloned()) + .collect() +} + +impl Index<&str> for CostMap { + type Output = i64; + fn index(&self, key: &str) -> &Self::Output { + self.map.get(key).unwrap_or(&30000000000) + } +} diff --git a/crates/uplc/src/machine/cost_model/costing.rs b/crates/uplc/src/machine/cost_model/costing.rs index 510dcfdca..cc83319e8 100644 --- a/crates/uplc/src/machine/cost_model/costing.rs +++ b/crates/uplc/src/machine/cost_model/costing.rs @@ -60,6 +60,7 @@ pub enum TwoArguments { LinearOnDiagonal(ConstantOrLinear), QuadraticInY(QuadraticFunction), ConstAboveDiagonalIntoQuadraticXAndY(i64, TwoArgumentsQuadraticFunction), + ConstAboveDiagonalIntoMultipliedSizes(i64, MultipliedSizes), } pub type TwoArgumentsCosting = Costing<2, TwoArguments>; @@ -141,6 +142,17 @@ impl TwoArgumentsCosting { coeff_2, }) } + + pub fn const_above_diagonal_into_multiplied_sizes( + constant: i64, + intercept: i64, + slope: i64, + ) -> TwoArguments { + TwoArguments::ConstAboveDiagonalIntoMultipliedSizes( + constant, + MultipliedSizes { intercept, slope }, + ) + } } impl Cost<2> for TwoArguments { @@ -180,6 +192,13 @@ impl Cost<2> for TwoArguments { ) } } + TwoArguments::ConstAboveDiagonalIntoMultipliedSizes(constant, s) => { + if x < y { + *constant + } else { + s.slope * (x * y) + s.intercept + } + } } } } @@ -356,12 +375,6 @@ pub struct ConstantOrLinear { pub slope: i64, } -#[derive(Debug, PartialEq)] -pub struct ConstantOrTwoArguments { - pub constant: i64, - pub model: Box, -} - #[derive(Debug, PartialEq)] pub struct QuadraticFunction { coeff_0: i64, diff --git a/crates/uplc/src/machine/cost_model/machine_costs.rs b/crates/uplc/src/machine/cost_model/machine_costs.rs index 5cbea64aa..c1d696ae9 100644 --- a/crates/uplc/src/machine/cost_model/machine_costs.rs +++ b/crates/uplc/src/machine/cost_model/machine_costs.rs @@ -1,4 +1,4 @@ -use crate::machine::ExBudget; +use crate::machine::{cost_model::cost_map::CostMap, ExBudget}; #[derive(Debug, PartialEq)] pub struct MachineCosts([ExBudget; 9]); @@ -27,4 +27,45 @@ impl MachineCosts { pub fn get(&self, index: usize) -> ExBudget { self.0[index] } + + pub fn initialize_machine_costs(cost_map: &CostMap) -> Self { + MachineCosts([ + ExBudget::new( + cost_map["cek_const_cost-exBudgetmem"], + cost_map["cek_const_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_var_cost-exBudgetmem"], + cost_map["cek_var_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_lam_cost-exBudgetmem"], + cost_map["cek_lam_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_apply_cost-exBudgetmem"], + cost_map["cek_apply_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_delay_cost-exBudgetmem"], + cost_map["cek_delay_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_force_cost-exBudgetmem"], + cost_map["cek_force_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_builtin_cost-exBudgetmem"], + cost_map["cek_builtin_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_constr_cost-exBudgetmem"], + cost_map["cek_constr_cost-exBudgetCPU"], + ), + ExBudget::new( + cost_map["cek_case_cost-exBudgetmem"], + cost_map["cek_case_cost-exBudgetCPU"], + ), + ]) + } } diff --git a/crates/uplc/src/machine/cost_model/mod.rs b/crates/uplc/src/machine/cost_model/mod.rs index 733822987..5cf1482e6 100644 --- a/crates/uplc/src/machine/cost_model/mod.rs +++ b/crates/uplc/src/machine/cost_model/mod.rs @@ -1,4 +1,5 @@ pub mod builtin_costs; +pub(crate) mod cost_map; mod costing; pub mod ex_budget; mod machine_costs; @@ -6,10 +7,40 @@ mod value; pub use value::*; -#[derive(Default, Debug, PartialEq)] -pub struct CostModel { - pub machine_costs: machine_costs::MachineCosts, - pub builtin_costs: builtin_costs::BuiltinCosts, +use crate::machine::{ + cost_model::{builtin_costs::BuiltinCostModel, machine_costs::MachineCosts}, + ExBudget, PlutusVersion, +}; + +#[derive(Debug, PartialEq)] +pub struct CostModel { + pub machine_startup: ExBudget, + pub machine_costs: MachineCosts, + pub builtin_costs: B, +} + +impl CostModel { + pub fn initialize_cost_model(version: &PlutusVersion, cost_model: &[i64]) -> CostModel { + let cost_map = cost_map::CostMap::new(version, cost_model); + Self { + machine_startup: ExBudget { + mem: cost_map["cek_startup_cost-exBudgetmem"], + cpu: cost_map["cek_startup_cost-exBudgetCPU"], + }, + machine_costs: MachineCosts::initialize_machine_costs(&cost_map), + builtin_costs: B::initialize(&cost_map), + } + } +} + +impl Default for CostModel { + fn default() -> Self { + Self { + machine_startup: ExBudget::start_up(), + machine_costs: Default::default(), + builtin_costs: Default::default(), + } + } } #[repr(usize)] diff --git a/crates/uplc/src/machine/error.rs b/crates/uplc/src/machine/error.rs index 0315d0372..81e72729a 100644 --- a/crates/uplc/src/machine/error.rs +++ b/crates/uplc/src/machine/error.rs @@ -40,6 +40,8 @@ where Runtime(RuntimeError<'a>), #[error("Max constr tag exceeded")] MaxConstrTagExceeded(&'a Value<'a, V>), + #[error("Unknown builtin function")] + UnknownBuiltinFunction, } #[derive(thiserror::Error, Debug)] diff --git a/crates/uplc/src/machine/mod.rs b/crates/uplc/src/machine/mod.rs index 65e6f6def..4e079e2ac 100644 --- a/crates/uplc/src/machine/mod.rs +++ b/crates/uplc/src/machine/mod.rs @@ -1,6 +1,6 @@ mod cek; mod context; -mod cost_model; +pub(crate) mod cost_model; mod discharge; mod env; mod error; diff --git a/crates/uplc/src/machine/runtime.rs b/crates/uplc/src/machine/runtime.rs index e2accf829..6a3fa1c4d 100644 --- a/crates/uplc/src/machine/runtime.rs +++ b/crates/uplc/src/machine/runtime.rs @@ -7,6 +7,7 @@ use crate::{ builtin::DefaultFunction, constant::{self, Constant, Integer}, data::PlutusData, + machine::cost_model::builtin_costs::BuiltinCostModel, typ::Type, }; use bumpalo::{ @@ -97,7 +98,7 @@ where } } -impl<'a> Machine<'a> { +impl<'a, B: BuiltinCostModel> Machine<'a, B> { pub fn call( &mut self, runtime: &'a Runtime<'a, V>, @@ -110,10 +111,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.add_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::AddInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -128,10 +136,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.subtract_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::SubtractInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -147,10 +162,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.equals_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::EqualsInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -164,10 +186,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.less_than_equals_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::LessThanEqualsInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -181,10 +210,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.append_byte_string([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::AppendByteString, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -203,10 +239,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.equals_byte_string([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::EqualsByteString, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -220,11 +263,18 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bool()?; let arg2 = runtime.args[1]; let arg3 = runtime.args[2]; - let budget = self.costs.builtin_costs.if_then_else([ - cost_model::BOOL_EX_MEM, - cost_model::value_ex_mem(arg2), - cost_model::value_ex_mem(arg3), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::IfThenElse, + &[ + cost_model::BOOL_EX_MEM, + cost_model::value_ex_mem(arg2), + cost_model::value_ex_mem(arg3), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; if arg1 { @@ -237,10 +287,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.multiply_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::MultiplyInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -256,10 +313,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.divide_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::DivideInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -279,10 +343,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.quotient_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::QuotientInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -299,10 +370,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.remainder_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::RemainderInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -319,10 +397,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.mod_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ModInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -340,10 +425,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.less_than_integer([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::LessThanInteger, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -357,10 +449,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.cons_byte_string([ - cost_model::integer_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ConsByteString, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -396,11 +495,18 @@ impl<'a> Machine<'a> { let arg2 = runtime.args[1].unwrap_integer()?; let arg3 = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.slice_byte_string([ - cost_model::integer_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - cost_model::byte_string_ex_mem(arg3), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::SliceByteString, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + cost_model::byte_string_ex_mem(arg3), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -436,7 +542,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .length_of_byte_string([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::LengthOfByteString, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -451,10 +561,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.index_byte_string([ - cost_model::byte_string_ex_mem(arg1), - cost_model::integer_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::IndexByteString, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -474,10 +591,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.less_than_byte_string([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::LessThanByteString, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -491,10 +615,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.less_than_equals_byte_string([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::LessThanEqualsByteString, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -512,7 +643,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .sha2_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Sha2_256, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -542,7 +677,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .sha3_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Sha3_256, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -572,7 +711,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .blake2b_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Blake2b_256, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -601,7 +744,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .keccak_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Keccak_256, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -631,7 +778,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .blake2b_224([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Blake2b_224, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -659,11 +810,18 @@ impl<'a> Machine<'a> { let message = runtime.args[1].unwrap_byte_string()?; let signature = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.verify_ed25519_signature([ - cost_model::byte_string_ex_mem(public_key), - cost_model::byte_string_ex_mem(message), - cost_model::byte_string_ex_mem(signature), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::VerifyEd25519Signature, + &[ + cost_model::byte_string_ex_mem(public_key), + cost_model::byte_string_ex_mem(message), + cost_model::byte_string_ex_mem(signature), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -690,11 +848,18 @@ impl<'a> Machine<'a> { let message = runtime.args[1].unwrap_byte_string()?; let signature = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.verify_ecdsa_secp256k1_signature([ - cost_model::byte_string_ex_mem(public_key), - cost_model::byte_string_ex_mem(message), - cost_model::byte_string_ex_mem(signature), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::VerifyEcdsaSecp256k1Signature, + &[ + cost_model::byte_string_ex_mem(public_key), + cost_model::byte_string_ex_mem(message), + cost_model::byte_string_ex_mem(signature), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -725,11 +890,15 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .verify_schnorr_secp256k1_signature([ - cost_model::byte_string_ex_mem(public_key), - cost_model::byte_string_ex_mem(message), - cost_model::byte_string_ex_mem(signature), - ]); + .get_cost( + DefaultFunction::VerifySchnorrSecp256k1Signature, + &[ + cost_model::byte_string_ex_mem(public_key), + cost_model::byte_string_ex_mem(message), + cost_model::byte_string_ex_mem(signature), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -751,10 +920,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_string()?; let arg2 = runtime.args[1].unwrap_string()?; - let budget = self.costs.builtin_costs.append_string([ - cost_model::string_ex_mem(arg1), - cost_model::string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::AppendString, + &[ + cost_model::string_ex_mem(arg1), + cost_model::string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -773,10 +949,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_string()?; let arg2 = runtime.args[1].unwrap_string()?; - let budget = self.costs.builtin_costs.equals_string([ - cost_model::string_ex_mem(arg1), - cost_model::string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::EqualsString, + &[ + cost_model::string_ex_mem(arg1), + cost_model::string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -790,7 +973,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .encode_utf8([cost_model::string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::EncodeUtf8, + &[cost_model::string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -812,7 +999,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .decode_utf8([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::DecodeUtf8, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -829,7 +1020,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .choose_unit([cost_model::UNIT_EX_MEM, cost_model::value_ex_mem(arg2)]); + .get_cost( + DefaultFunction::ChooseUnit, + &[cost_model::UNIT_EX_MEM, cost_model::value_ex_mem(arg2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -839,10 +1034,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_string()?; let arg2 = runtime.args[1]; - let budget = self.costs.builtin_costs.trace([ - cost_model::string_ex_mem(arg1), - cost_model::value_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Trace, + &[ + cost_model::string_ex_mem(arg1), + cost_model::value_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -856,7 +1058,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .fst_pair([cost_model::pair_ex_mem(first, second)]); + .get_cost( + DefaultFunction::FstPair, + &[cost_model::pair_ex_mem(first, second)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -870,7 +1076,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .snd_pair([cost_model::pair_ex_mem(first, second)]); + .get_cost( + DefaultFunction::SndPair, + &[cost_model::pair_ex_mem(first, second)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -883,11 +1093,18 @@ impl<'a> Machine<'a> { let arg2 = runtime.args[1]; let arg3 = runtime.args[2]; - let budget = self.costs.builtin_costs.choose_list([ - cost_model::proto_list_ex_mem(list), - cost_model::value_ex_mem(arg2), - cost_model::value_ex_mem(arg3), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ChooseList, + &[ + cost_model::proto_list_ex_mem(list), + cost_model::value_ex_mem(arg2), + cost_model::value_ex_mem(arg3), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -901,10 +1118,17 @@ impl<'a> Machine<'a> { let item = runtime.args[0].unwrap_constant()?; let (typ, list) = runtime.args[1].unwrap_list()?; - let budget = self.costs.builtin_costs.mk_cons([ - cost_model::constant_ex_mem(item), - cost_model::proto_list_ex_mem(list), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::MkCons, + &[ + cost_model::constant_ex_mem(item), + cost_model::proto_list_ex_mem(list), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -932,7 +1156,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .head_list([cost_model::proto_list_ex_mem(list)]); + .get_cost( + DefaultFunction::HeadList, + &[cost_model::proto_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -950,7 +1178,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .tail_list([cost_model::proto_list_ex_mem(list)]); + .get_cost( + DefaultFunction::TailList, + &[cost_model::proto_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -970,7 +1202,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .null_list([cost_model::proto_list_ex_mem(list)]); + .get_cost( + DefaultFunction::NullList, + &[cost_model::proto_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -986,14 +1222,21 @@ impl<'a> Machine<'a> { let arg5 = runtime.args[4]; let arg6 = runtime.args[5]; - let budget = self.costs.builtin_costs.choose_data([ - cost_model::data_ex_mem(arg1), - cost_model::value_ex_mem(arg2), - cost_model::value_ex_mem(arg3), - cost_model::value_ex_mem(arg4), - cost_model::value_ex_mem(arg5), - cost_model::value_ex_mem(arg6), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ChooseData, + &[ + cost_model::data_ex_mem(arg1), + cost_model::value_ex_mem(arg2), + cost_model::value_ex_mem(arg3), + cost_model::value_ex_mem(arg4), + cost_model::value_ex_mem(arg5), + cost_model::value_ex_mem(arg6), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1009,10 +1252,17 @@ impl<'a> Machine<'a> { let tag = runtime.args[0].unwrap_integer()?; let (typ, fields) = runtime.args[1].unwrap_list()?; - let budget = self.costs.builtin_costs.constr_data([ - cost_model::integer_ex_mem(tag), - cost_model::proto_list_ex_mem(fields), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ConstrData, + &[ + cost_model::integer_ex_mem(tag), + cost_model::proto_list_ex_mem(fields), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1058,7 +1308,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .map_data([cost_model::proto_list_ex_mem(list)]); + .get_cost( + DefaultFunction::MapData, + &[cost_model::proto_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1094,7 +1348,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .list_data([cost_model::proto_list_ex_mem(fields)]); + .get_cost( + DefaultFunction::ListData, + &[cost_model::proto_list_ex_mem(fields)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1126,7 +1384,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .i_data([cost_model::integer_ex_mem(i)]); + .get_cost(DefaultFunction::IData, &[cost_model::integer_ex_mem(i)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1142,7 +1401,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .b_data([cost_model::byte_string_ex_mem(b)]); + .get_cost(DefaultFunction::BData, &[cost_model::byte_string_ex_mem(b)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1161,7 +1421,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_constr_data([cost_model::data_list_ex_mem(fields)]); + .get_cost( + DefaultFunction::UnConstrData, + &[cost_model::data_list_ex_mem(fields)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1192,7 +1456,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_map_data([cost_model::data_map_ex_mem(map)]); + .get_cost( + DefaultFunction::UnMapData, + &[cost_model::data_map_ex_mem(map)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1229,7 +1497,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_list_data([cost_model::data_list_ex_mem(list)]); + .get_cost( + DefaultFunction::UnListData, + &[cost_model::data_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1254,7 +1526,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_i_data([cost_model::data_integer_ex_mem(i)]); + .get_cost( + DefaultFunction::UnIData, + &[cost_model::data_integer_ex_mem(i)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1271,7 +1547,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_b_data([cost_model::data_byte_string_ex_mem(bs)]); + .get_cost( + DefaultFunction::UnBData, + &[cost_model::data_byte_string_ex_mem(bs)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1286,7 +1566,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .equals_data([cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)]); + .get_cost( + DefaultFunction::EqualsData, + &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1302,7 +1586,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .mk_pair_data([cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)]); + .get_cost( + DefaultFunction::MkPairData, + &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1324,7 +1612,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .mk_nil_data([cost_model::UNIT_EX_MEM]); + .get_cost(DefaultFunction::MkNilData, &[cost_model::UNIT_EX_MEM]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1343,7 +1632,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .mk_nil_pair_data([cost_model::UNIT_EX_MEM]); + .get_cost(DefaultFunction::MkNilPairData, &[cost_model::UNIT_EX_MEM]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1364,10 +1654,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_g1_element()?; let arg2 = runtime.args[1].unwrap_bls12_381_g1_element()?; - let budget = self.costs.builtin_costs.bls12_381_g1_add([ - cost_model::g1_element_ex_mem(), - cost_model::g1_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G1_Add, + &[ + cost_model::g1_element_ex_mem(), + cost_model::g1_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1389,7 +1686,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_neg([cost_model::g1_element_ex_mem()]); + .get_cost( + DefaultFunction::Bls12_381_G1_Neg, + &[cost_model::g1_element_ex_mem()], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1410,10 +1711,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_bls12_381_g1_element()?; - let budget = self.costs.builtin_costs.bls12_381_g1_scalar_mul([ - cost_model::integer_ex_mem(arg1), - cost_model::g1_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G1_ScalarMul, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::g1_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1456,10 +1764,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_g1_element()?; let arg2 = runtime.args[1].unwrap_bls12_381_g1_element()?; - let budget = self.costs.builtin_costs.bls12_381_g1_equal([ - cost_model::g1_element_ex_mem(), - cost_model::g1_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G1_Equal, + &[ + cost_model::g1_element_ex_mem(), + cost_model::g1_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1475,7 +1790,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_compress([cost_model::g1_element_ex_mem()]); + .get_cost( + DefaultFunction::Bls12_381_G1_Compress, + &[cost_model::g1_element_ex_mem()], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1491,7 +1810,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_uncompress([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Bls12_381_G1_Uncompress, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1507,10 +1830,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.bls12_381_g1_hash_to_group([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G1_HashToGroup, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1543,10 +1873,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_g2_element()?; let arg2 = runtime.args[1].unwrap_bls12_381_g2_element()?; - let budget = self.costs.builtin_costs.bls12_381_g2_add([ - cost_model::g2_element_ex_mem(), - cost_model::g2_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G2_Add, + &[ + cost_model::g2_element_ex_mem(), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1568,7 +1905,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_neg([cost_model::g2_element_ex_mem()]); + .get_cost( + DefaultFunction::Bls12_381_G2_Neg, + &[cost_model::g2_element_ex_mem()], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1589,10 +1930,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_integer()?; let arg2 = runtime.args[1].unwrap_bls12_381_g2_element()?; - let budget = self.costs.builtin_costs.bls12_381_g2_scalar_mul([ - cost_model::integer_ex_mem(arg1), - cost_model::g2_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G2_ScalarMul, + &[ + cost_model::integer_ex_mem(arg1), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1639,10 +1987,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_g2_element()?; let arg2 = runtime.args[1].unwrap_bls12_381_g2_element()?; - let budget = self.costs.builtin_costs.bls12_381_g2_equal([ - cost_model::g2_element_ex_mem(), - cost_model::g2_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G2_Equal, + &[ + cost_model::g2_element_ex_mem(), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1658,7 +2013,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_compress([cost_model::g2_element_ex_mem()]); + .get_cost( + DefaultFunction::Bls12_381_G2_Compress, + &[cost_model::g2_element_ex_mem()], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1674,7 +2033,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_uncompress([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + DefaultFunction::Bls12_381_G2_Uncompress, + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1690,10 +2053,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_byte_string()?; let arg2 = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.bls12_381_g2_hash_to_group([ - cost_model::byte_string_ex_mem(arg1), - cost_model::byte_string_ex_mem(arg2), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_G2_HashToGroup, + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1726,10 +2096,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_g1_element()?; let arg2 = runtime.args[1].unwrap_bls12_381_g2_element()?; - let budget = self.costs.builtin_costs.bls12_381_miller_loop([ - cost_model::g1_element_ex_mem(), - cost_model::g2_element_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_MillerLoop, + &[ + cost_model::g1_element_ex_mem(), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1755,10 +2132,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_ml_result()?; let arg2 = runtime.args[1].unwrap_bls12_381_ml_result()?; - let budget = self.costs.builtin_costs.bls12_381_mul_ml_result([ - cost_model::ml_result_ex_mem(), - cost_model::ml_result_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_MulMlResult, + &[ + cost_model::ml_result_ex_mem(), + cost_model::ml_result_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1778,10 +2162,17 @@ impl<'a> Machine<'a> { let arg1 = runtime.args[0].unwrap_bls12_381_ml_result()?; let arg2 = runtime.args[1].unwrap_bls12_381_ml_result()?; - let budget = self.costs.builtin_costs.bls12_381_final_verify([ - cost_model::ml_result_ex_mem(), - cost_model::ml_result_ex_mem(), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::Bls12_381_FinalVerify, + &[ + cost_model::ml_result_ex_mem(), + cost_model::ml_result_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1811,11 +2202,18 @@ impl<'a> Machine<'a> { let arg1_exmem = if arg1 == 0 { 0 } else { ((arg1 - 1) / 8) + 1 }; - let budget = self.costs.builtin_costs.integer_to_byte_string([ - cost_model::BOOL_EX_MEM, - arg1_exmem, - cost_model::integer_ex_mem(input), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::IntegerToByteString, + &[ + cost_model::BOOL_EX_MEM, + arg1_exmem, + cost_model::integer_ex_mem(input), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1903,10 +2301,17 @@ impl<'a> Machine<'a> { let endianness = runtime.args[0].unwrap_bool()?; let bytes = runtime.args[1].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.byte_string_to_integer([ - cost_model::BOOL_EX_MEM, - cost_model::byte_string_ex_mem(bytes), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ByteStringToInteger, + &[ + cost_model::BOOL_EX_MEM, + cost_model::byte_string_ex_mem(bytes), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1927,11 +2332,18 @@ impl<'a> Machine<'a> { let left_bytes = runtime.args[1].unwrap_byte_string()?; let right_bytes = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.and_byte_string([ - cost_model::BOOL_EX_MEM, - cost_model::byte_string_ex_mem(left_bytes), - cost_model::byte_string_ex_mem(right_bytes), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::AndByteString, + &[ + cost_model::BOOL_EX_MEM, + cost_model::byte_string_ex_mem(left_bytes), + cost_model::byte_string_ex_mem(right_bytes), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1960,11 +2372,18 @@ impl<'a> Machine<'a> { let left_bytes = runtime.args[1].unwrap_byte_string()?; let right_bytes = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.or_byte_string([ - cost_model::BOOL_EX_MEM, - cost_model::byte_string_ex_mem(left_bytes), - cost_model::byte_string_ex_mem(right_bytes), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::OrByteString, + &[ + cost_model::BOOL_EX_MEM, + cost_model::byte_string_ex_mem(left_bytes), + cost_model::byte_string_ex_mem(right_bytes), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1995,11 +2414,18 @@ impl<'a> Machine<'a> { let left_bytes = runtime.args[1].unwrap_byte_string()?; let right_bytes = runtime.args[2].unwrap_byte_string()?; - let budget = self.costs.builtin_costs.or_byte_string([ - cost_model::BOOL_EX_MEM, - cost_model::byte_string_ex_mem(left_bytes), - cost_model::byte_string_ex_mem(right_bytes), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::OrByteString, + &[ + cost_model::BOOL_EX_MEM, + cost_model::byte_string_ex_mem(left_bytes), + cost_model::byte_string_ex_mem(right_bytes), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2031,7 +2457,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .complement_byte_string([cost_model::byte_string_ex_mem(bytes)]); + .get_cost( + DefaultFunction::ComplementByteString, + &[cost_model::byte_string_ex_mem(bytes)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let result = self @@ -2044,10 +2474,17 @@ impl<'a> Machine<'a> { let bytes = runtime.args[0].unwrap_byte_string()?; let bit_index = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.read_bit([ - cost_model::byte_string_ex_mem(bytes), - cost_model::integer_ex_mem(bit_index), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ReadBit, + &[ + cost_model::byte_string_ex_mem(bytes), + cost_model::integer_ex_mem(bit_index), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2077,11 +2514,18 @@ impl<'a> Machine<'a> { let indices = runtime.args[1].unwrap_int_list()?; let set_bit = runtime.args[2].unwrap_bool()?; - let budget = self.costs.builtin_costs.write_bits([ - cost_model::byte_string_ex_mem(bytes.as_slice()), - cost_model::proto_list_ex_mem(indices), - cost_model::BOOL_EX_MEM, - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::WriteBits, + &[ + cost_model::byte_string_ex_mem(bytes.as_slice()), + cost_model::proto_list_ex_mem(indices), + cost_model::BOOL_EX_MEM, + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2135,7 +2579,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .replicate_byte([arg0_ex_mem, cost_model::integer_ex_mem(byte)]); + .get_cost( + DefaultFunction::ReplicateByte, + &[arg0_ex_mem, cost_model::integer_ex_mem(byte)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2181,7 +2629,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .shift_byte_string([cost_model::byte_string_ex_mem(bytes), arg1]); + .get_cost( + DefaultFunction::ShiftByteString, + &[cost_model::byte_string_ex_mem(bytes), arg1], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let length = bytes.len(); @@ -2268,7 +2720,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .rotate_byte_string([cost_model::byte_string_ex_mem(bytes), arg1]); + .get_cost( + DefaultFunction::RotateByteString, + &[cost_model::byte_string_ex_mem(bytes), arg1], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let length = bytes.len(); @@ -2332,7 +2788,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .count_set_bits([cost_model::byte_string_ex_mem(bytes)]); + .get_cost( + DefaultFunction::CountSetBits, + &[cost_model::byte_string_ex_mem(bytes)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let weight: Integer = hamming::weight(bytes).into(); @@ -2345,7 +2805,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .find_first_set_bit([cost_model::byte_string_ex_mem(bytes)]); + .get_cost( + DefaultFunction::FindFirstSetBit, + &[cost_model::byte_string_ex_mem(bytes)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let first_bit = bytes @@ -2372,7 +2836,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .ripemd_160([cost_model::byte_string_ex_mem(input)]); + .get_cost( + DefaultFunction::Ripemd_160, + &[cost_model::byte_string_ex_mem(input)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let mut hasher = Ripemd160::new(); @@ -2387,11 +2855,18 @@ impl<'a> Machine<'a> { let exponent = runtime.args[1].unwrap_integer()?; let modulus = runtime.args[2].unwrap_integer()?; - let budget = self.costs.builtin_costs.exp_mod_integer([ - cost_model::integer_ex_mem(base), - cost_model::integer_ex_mem(exponent), - cost_model::integer_ex_mem(modulus), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ExpModInteger, + &[ + cost_model::integer_ex_mem(base), + cost_model::integer_ex_mem(exponent), + cost_model::integer_ex_mem(modulus), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; if modulus <= &Integer::ZERO { @@ -2422,7 +2897,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .drop_list([arg0, cost_model::proto_list_ex_mem(list)]); + .get_cost( + DefaultFunction::DropList, + &[arg0, cost_model::proto_list_ex_mem(list)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2455,7 +2934,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .length_of_array([cost_model::proto_list_ex_mem(array)]); + .get_cost( + DefaultFunction::LengthOfArray, + &[cost_model::proto_list_ex_mem(array)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2468,10 +2951,17 @@ impl<'a> Machine<'a> { DefaultFunction::ListToArray => { let (list_type, list) = runtime.args[0].unwrap_list()?; - let budget = self.costs.builtin_costs.list_to_array([ - cost_model::proto_list_ex_mem(list), - cost_model::proto_list_ex_mem(list), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::ListToArray, + &[ + cost_model::proto_list_ex_mem(list), + cost_model::proto_list_ex_mem(list), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2485,10 +2975,17 @@ impl<'a> Machine<'a> { let (_, array) = runtime.args[0].unwrap_array()?; let arg1 = runtime.args[1].unwrap_integer()?; - let budget = self.costs.builtin_costs.index_array([ - cost_model::proto_list_ex_mem(array), - cost_model::integer_ex_mem(arg1), - ]); + let budget = self + .costs + .builtin_costs + .get_cost( + DefaultFunction::IndexArray, + &[ + cost_model::proto_list_ex_mem(array), + cost_model::integer_ex_mem(arg1), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let index: i128 = arg1.try_into().unwrap(); diff --git a/crates/uplc/src/program.rs b/crates/uplc/src/program.rs index 74f321dfa..ad961e3ab 100644 --- a/crates/uplc/src/program.rs +++ b/crates/uplc/src/program.rs @@ -2,7 +2,13 @@ use bumpalo::Bump; use crate::{ binder::Eval, - machine::{BuiltinSemantics, CostModel, EvalResult, ExBudget, Machine, PlutusVersion}, + machine::{ + cost_model::builtin_costs::{ + builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, + builtin_costs_v3::BuiltinCostsV3, BuiltinCostModel, + }, + BuiltinSemantics, CostModel, EvalResult, ExBudget, Machine, PlutusVersion, + }, term::Term, }; @@ -39,21 +45,68 @@ where &'a self, arena: &'a Bump, plutus_version: PlutusVersion, + ) -> EvalResult<'a, V> { + match plutus_version { + PlutusVersion::V1 => self.evaluate( + arena, + CostModel::::default(), + plutus_version, + ), + PlutusVersion::V2 => self.evaluate( + arena, + CostModel::::default(), + plutus_version, + ), + PlutusVersion::V3 => self.evaluate( + arena, + CostModel::::default(), + plutus_version, + ), + } + } + + fn evaluate( + &'a self, + arena: &'a Bump, + cost_model: CostModel, + plutus_version: PlutusVersion, ) -> EvalResult<'a, V> { let mut machine = Machine::new( arena, ExBudget::default(), - CostModel::default(), + cost_model, BuiltinSemantics::from(&plutus_version), ); - let term = machine.run(self.term); let mut info = machine.info(); - info.consumed_budget = ExBudget::default() - info.consumed_budget; - EvalResult { term, info } } + + pub fn eval_version_with_model( + &'a self, + arena: &'a Bump, + plutus_version: PlutusVersion, + cost_model: &[i64], + ) -> EvalResult<'a, V> { + match plutus_version { + PlutusVersion::V1 => self.evaluate( + arena, + CostModel::::initialize_cost_model(&plutus_version, cost_model), + plutus_version, + ), + PlutusVersion::V2 => self.evaluate( + arena, + CostModel::::initialize_cost_model(&plutus_version, cost_model), + plutus_version, + ), + PlutusVersion::V3 => self.evaluate( + arena, + CostModel::::initialize_cost_model(&plutus_version, cost_model), + plutus_version, + ), + } + } } #[derive(Debug, Copy, Clone)]