From 8dbdd6b8ad602c1a0fc3ef74affe5e885bd211f2 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Fri, 3 Oct 2025 11:30:16 -0500 Subject: [PATCH 1/9] feat: added builtin cost model A Signed-off-by: Jonathan Lim --- .../src/machine/cost_model/builtin_costs.rs | 381 ++++++++++++++++++ crates/uplc/src/machine/cost_model/costing.rs | 19 + 2 files changed, 400 insertions(+) diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs.rs index c42cbdc30..e3f625203 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs.rs @@ -706,6 +706,387 @@ impl BuiltinCosts { ) } + pub fn v1() -> Self { + Self { + add_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(205665, 812), + ), + subtract_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::max_size(1, 1), + TwoArgumentsCosting::max_size(205665, 812), + ), + multiply_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::added_sizes(69522, 11687), + ), + divide_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + 196500, 453240, 220, + ), + ), + quotient_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + 196500, 453240, 220, + ), + ), + remainder_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + 196500, 453240, 220, + ), + ), + mod_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::subtracted_sizes(0, 1, 1), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( + 196500, 453240, 220, + ), + ), + equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(208512, 421), + ), + less_than_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(208896, 511), + ), + less_than_equals_integer: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(204924, 473), + ), + append_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::added_sizes(1000, 571), + ), + cons_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(0, 1), + TwoArgumentsCosting::linear_in_y(221973, 511), + ), + slice_byte_string: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::linear_in_z(4, 0), + ThreeArgumentsCosting::linear_in_z(265318, 0), + ), + length_of_byte_string: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(10), + OneArgumentCosting::constant_cost(1000), + ), + index_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(57667), + ), + equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(245000, 216773, 62), + ), + less_than_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(197145, 156), + ), + less_than_equals_byte_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(197145, 156), + ), + sha2_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(806990, 30482), + ), + sha3_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(1927926, 82523), + ), + blake2b_256: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(117366, 10475), + ), + verify_ed25519_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_z(57996947, 18975), + ), + verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::constant_cost(35190005), + ), + verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(10), + ThreeArgumentsCosting::linear_in_y(39121781, 32260), + ), + append_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::added_sizes(4, 1), + TwoArgumentsCosting::added_sizes(1000, 24177), + ), + equals_string: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::linear_on_diagonal(187000, 1000, 52998), + ), + encode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(1000, 28662), + ), + decode_utf8: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(4, 2), + OneArgumentCosting::linear_cost(497525, 14068), + ), + if_then_else: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(1), + ThreeArgumentsCosting::constant_cost(80556), + ), + choose_unit: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(4), + TwoArgumentsCosting::constant_cost(46417), + ), + trace: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(212342), + ), + fst_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(80436), + ), + snd_pair: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(85931), + ), + choose_list: ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(32), + ThreeArgumentsCosting::constant_cost(175354), + ), + mk_cons: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(65493), + ), + head_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(43249), + ), + tail_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(41182), + ), + null_list: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(60091), + ), + choose_data: SixArgumentsCosting::new( + SixArgumentsCosting::constant_cost(32), + SixArgumentsCosting::constant_cost(19537), + ), + constr_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(89141), + ), + map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(64832), + ), + list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(52467), + ), + i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(1000), + ), + b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(1000), + ), + un_constr_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(32696), + ), + un_map_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(38314), + ), + un_list_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(32247), + ), + un_i_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(43357), + ), + un_b_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(31220), + ), + equals_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(1), + TwoArgumentsCosting::min_size(1060367, 12586), + ), + mk_pair_data: TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(32), + TwoArgumentsCosting::constant_cost(76511), + ), + mk_nil_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(22558), + ), + mk_nil_pair_data: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(32), + OneArgumentCosting::constant_cost(16563), + ), + serialise_data: OneArgumentCosting::new( + OneArgumentCosting::linear_cost(0, 2), + OneArgumentCosting::linear_cost(1159724, 392670), + ), + blake2b_224: OneArgumentCosting::new( + OneArgumentCosting::constant_cost(4), + OneArgumentCosting::linear_cost(117366, 10475), + ), + 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), + ), + } + } + pub fn v3() -> Self { Self { add_integer: TwoArgumentsCosting::new( diff --git a/crates/uplc/src/machine/cost_model/costing.rs b/crates/uplc/src/machine/cost_model/costing.rs index 510dcfdca..e44ba2459 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 + } + } } } } From cd906e5043306c0da126a378334bcffce3e8525e Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Fri, 3 Oct 2025 11:46:34 -0500 Subject: [PATCH 2/9] feat: add builtin cost model B Signed-off-by: Jonathan Lim --- .../src/machine/cost_model/builtin_costs.rs | 378 ++++++++++++++++++ 1 file changed, 378 insertions(+) diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs.rs index e3f625203..9f3bc7f41 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs.rs @@ -1087,6 +1087,384 @@ impl BuiltinCosts { } } + pub fn v2() -> 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), + ), + 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), + ), + } + } + pub fn v3() -> Self { Self { add_integer: TwoArgumentsCosting::new( From 0c16e841eac86943fb721bb4fd4ee442ae2e88e0 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Wed, 8 Oct 2025 10:50:19 -0500 Subject: [PATCH 3/9] feat: choose cost model based on plutus version Signed-off-by: Jonathan Lim --- crates/uplc/src/machine/cost_model/mod.rs | 16 ++++++++++++++++ crates/uplc/src/program.rs | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/uplc/src/machine/cost_model/mod.rs b/crates/uplc/src/machine/cost_model/mod.rs index 733822987..8e51e388d 100644 --- a/crates/uplc/src/machine/cost_model/mod.rs +++ b/crates/uplc/src/machine/cost_model/mod.rs @@ -6,12 +6,28 @@ mod value; pub use value::*; +use crate::machine::PlutusVersion; + #[derive(Default, Debug, PartialEq)] pub struct CostModel { pub machine_costs: machine_costs::MachineCosts, pub builtin_costs: builtin_costs::BuiltinCosts, } +impl From<&PlutusVersion> for CostModel { + fn from(version: &PlutusVersion) -> Self { + let builtin_costs = match version { + crate::machine::PlutusVersion::V1 => builtin_costs::BuiltinCosts::v1(), + crate::machine::PlutusVersion::V2 => builtin_costs::BuiltinCosts::v2(), + crate::machine::PlutusVersion::V3 => builtin_costs::BuiltinCosts::v3(), + }; + Self { + machine_costs: Default::default(), + builtin_costs, + } + } +} + #[repr(usize)] pub enum StepKind { Constant = 0, diff --git a/crates/uplc/src/program.rs b/crates/uplc/src/program.rs index 74f321dfa..c510e5def 100644 --- a/crates/uplc/src/program.rs +++ b/crates/uplc/src/program.rs @@ -43,7 +43,7 @@ where let mut machine = Machine::new( arena, ExBudget::default(), - CostModel::default(), + CostModel::from(&plutus_version), BuiltinSemantics::from(&plutus_version), ); From 3fa2a1198b16411447855ae28ce7b8ec60f92eb3 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Wed, 8 Oct 2025 10:53:49 -0500 Subject: [PATCH 4/9] style: formatting Signed-off-by: Jonathan Lim --- crates/uplc/src/machine/cost_model/builtin_costs.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs.rs index 9f3bc7f41..98f5eac48 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs.rs @@ -1107,15 +1107,11 @@ impl BuiltinCosts { ), quotient_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::subtracted_sizes(0, 1, 1), - TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( - 85848, 228465, 122 - ), + 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, - ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), ), mod_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::subtracted_sizes(0, 1, 1), From d4b44447e291185bea812d3460801a66fbf86b7d Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Wed, 8 Oct 2025 11:02:25 -0500 Subject: [PATCH 5/9] style: removed unused argument for clippy Signed-off-by: Jonathan Lim --- crates/uplc/src/machine/cost_model/costing.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/uplc/src/machine/cost_model/costing.rs b/crates/uplc/src/machine/cost_model/costing.rs index e44ba2459..cc83319e8 100644 --- a/crates/uplc/src/machine/cost_model/costing.rs +++ b/crates/uplc/src/machine/cost_model/costing.rs @@ -375,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, From 26998d01a1f823386445b4daabdc3147386ef4ad Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Mon, 20 Oct 2025 08:07:16 -0500 Subject: [PATCH 6/9] feat: added cost model from params Signed-off-by: Jonathan Lim --- crates/uplc/src/machine/cek.rs | 2 +- .../src/machine/cost_model/builtin_costs.rs | 1440 ++++++++++++++--- .../uplc/src/machine/cost_model/cost_map.rs | 686 ++++++++ .../src/machine/cost_model/machine_costs.rs | 43 +- crates/uplc/src/machine/cost_model/mod.rs | 26 +- crates/uplc/src/machine/mod.rs | 2 +- crates/uplc/src/program.rs | 21 + 7 files changed, 2011 insertions(+), 209 deletions(-) create mode 100644 crates/uplc/src/machine/cost_model/cost_map.rs diff --git a/crates/uplc/src/machine/cek.rs b/crates/uplc/src/machine/cek.rs index 1905a4e08..c52ddebc9 100644 --- a/crates/uplc/src/machine/cek.rs +++ b/crates/uplc/src/machine/cek.rs @@ -54,7 +54,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 index 98f5eac48..e45922191 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs.rs @@ -1,4 +1,4 @@ -use crate::machine::ExBudget; +use crate::machine::{cost_model::cost_map::CostMap, ExBudget, PlutusVersion}; use super::costing::{ Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, TwoArgumentsCosting, @@ -710,363 +710,355 @@ impl BuiltinCosts { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size(1, 1), - TwoArgumentsCosting::max_size(205665, 812), + TwoArgumentsCosting::max_size(100788, 420), ), subtract_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size(1, 1), - TwoArgumentsCosting::max_size(205665, 812), + TwoArgumentsCosting::max_size(100788, 420), ), multiply_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::added_sizes(69522, 11687), + TwoArgumentsCosting::multiplied_sizes(90434, 519), ), divide_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::subtracted_sizes(0, 1, 1), - TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes( - 196500, 453240, 220, - ), + 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( - 196500, 453240, 220, - ), + 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( - 196500, 453240, 220, - ), + 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( - 196500, 453240, 220, - ), + TwoArgumentsCosting::const_above_diagonal_into_multiplied_sizes(85848, 228465, 122), ), equals_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(208512, 421), + TwoArgumentsCosting::min_size(51775, 558), ), less_than_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(208896, 511), + TwoArgumentsCosting::min_size(44749, 541), ), less_than_equals_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(204924, 473), + TwoArgumentsCosting::min_size(43285, 552), ), append_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::added_sizes(1000, 571), + TwoArgumentsCosting::added_sizes(1000, 173), ), cons_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::added_sizes(0, 1), - TwoArgumentsCosting::linear_in_y(221973, 511), + TwoArgumentsCosting::linear_in_y(72010, 178), ), slice_byte_string: ThreeArgumentsCosting::new( ThreeArgumentsCosting::linear_in_z(4, 0), - ThreeArgumentsCosting::linear_in_z(265318, 0), + ThreeArgumentsCosting::linear_in_z(20467, 1), ), length_of_byte_string: OneArgumentCosting::new( OneArgumentCosting::constant_cost(10), - OneArgumentCosting::constant_cost(1000), + OneArgumentCosting::constant_cost(22100), ), index_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(4), - TwoArgumentsCosting::constant_cost(57667), + TwoArgumentsCosting::constant_cost(13169), ), equals_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::linear_on_diagonal(245000, 216773, 62), + TwoArgumentsCosting::linear_on_diagonal(24548, 29498, 38), ), less_than_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(197145, 156), + TwoArgumentsCosting::min_size(28999, 74), ), less_than_equals_byte_string: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(197145, 156), + TwoArgumentsCosting::min_size(28999, 74), ), sha2_256: OneArgumentCosting::new( OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(806990, 30482), + OneArgumentCosting::linear_cost(270652, 22588), ), sha3_256: OneArgumentCosting::new( OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(1927926, 82523), + OneArgumentCosting::linear_cost(1457325, 64566), ), blake2b_256: OneArgumentCosting::new( OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(117366, 10475), + OneArgumentCosting::linear_cost(201305, 8356), ), verify_ed25519_signature: ThreeArgumentsCosting::new( ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::linear_in_z(57996947, 18975), + ThreeArgumentsCosting::linear_in_y(53384111, 14333), ), verify_ecdsa_secp256k1_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::constant_cost(35190005), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(10), - ThreeArgumentsCosting::linear_in_y(39121781, 32260), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), append_string: TwoArgumentsCosting::new( TwoArgumentsCosting::added_sizes(4, 1), - TwoArgumentsCosting::added_sizes(1000, 24177), + TwoArgumentsCosting::added_sizes(1000, 59957), ), equals_string: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::linear_on_diagonal(187000, 1000, 52998), + TwoArgumentsCosting::linear_on_diagonal(39184, 1000, 60594), ), encode_utf8: OneArgumentCosting::new( OneArgumentCosting::linear_cost(4, 2), - OneArgumentCosting::linear_cost(1000, 28662), + OneArgumentCosting::linear_cost(1000, 42921), ), decode_utf8: OneArgumentCosting::new( OneArgumentCosting::linear_cost(4, 2), - OneArgumentCosting::linear_cost(497525, 14068), + OneArgumentCosting::linear_cost(91189, 769), ), if_then_else: ThreeArgumentsCosting::new( ThreeArgumentsCosting::constant_cost(1), - ThreeArgumentsCosting::constant_cost(80556), + ThreeArgumentsCosting::constant_cost(76049), ), choose_unit: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(4), - TwoArgumentsCosting::constant_cost(46417), + TwoArgumentsCosting::constant_cost(61462), ), trace: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(212342), + TwoArgumentsCosting::constant_cost(59498), ), fst_pair: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(80436), + OneArgumentCosting::constant_cost(141895), ), snd_pair: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(85931), + OneArgumentCosting::constant_cost(141992), ), choose_list: ThreeArgumentsCosting::new( ThreeArgumentsCosting::constant_cost(32), - ThreeArgumentsCosting::constant_cost(175354), + ThreeArgumentsCosting::constant_cost(132994), ), mk_cons: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(65493), + TwoArgumentsCosting::constant_cost(72362), ), head_list: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(43249), + OneArgumentCosting::constant_cost(83150), ), tail_list: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(41182), + OneArgumentCosting::constant_cost(81663), ), null_list: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(60091), + OneArgumentCosting::constant_cost(74433), ), choose_data: SixArgumentsCosting::new( SixArgumentsCosting::constant_cost(32), - SixArgumentsCosting::constant_cost(19537), + SixArgumentsCosting::constant_cost(94375), ), constr_data: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(89141), + TwoArgumentsCosting::constant_cost(22151), ), map_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(64832), + OneArgumentCosting::constant_cost(68246), ), list_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(52467), + OneArgumentCosting::constant_cost(33852), ), i_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(1000), + OneArgumentCosting::constant_cost(15299), ), b_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(1000), + OneArgumentCosting::constant_cost(11183), ), un_constr_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(32696), + OneArgumentCosting::constant_cost(24588), ), un_map_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(38314), + OneArgumentCosting::constant_cost(24623), ), un_list_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(32247), + OneArgumentCosting::constant_cost(25933), ), un_i_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(43357), + OneArgumentCosting::constant_cost(20744), ), un_b_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(31220), + OneArgumentCosting::constant_cost(20142), ), equals_data: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::min_size(1060367, 12586), + TwoArgumentsCosting::min_size(898148, 27279), ), mk_pair_data: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(32), - TwoArgumentsCosting::constant_cost(76511), + TwoArgumentsCosting::constant_cost(11546), ), mk_nil_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(22558), + OneArgumentCosting::constant_cost(7243), ), mk_nil_pair_data: OneArgumentCosting::new( OneArgumentCosting::constant_cost(32), - OneArgumentCosting::constant_cost(16563), + OneArgumentCosting::constant_cost(7391), ), serialise_data: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(0, 2), - OneArgumentCosting::linear_cost(1159724, 392670), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), blake2b_224: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(117366, 10475), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), keccak_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(2261318, 64571), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::constant_cost(962335), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(267929), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(76433006, 8868), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(442008), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(6), - OneArgumentCosting::constant_cost(2780678), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(52948122), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(52538055, 3756), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::constant_cost(1995836), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(284546), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(158_221_314, 26_549), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(901_022), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(12), - OneArgumentCosting::constant_cost(3_227_919), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(74_698_472), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(166_917_843, 4_307), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_miller_loop: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(254006273), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_mul_ml_result: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(2174038), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_final_verify: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(333849714), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), integer_to_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::literal_in_y_or_linear_in_z(0, 1), - ThreeArgumentsCosting::quadratic_in_z(1293828, 28716, 63), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), byte_string_to_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_y(0, 1), - TwoArgumentsCosting::quadratic_in_y(1006041, 43623, 251), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), and_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), or_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), xor_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), complement_byte_string: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(0, 1), - OneArgumentCosting::linear_cost(107878, 680), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), read_bit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(95336), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), write_bits: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_x(0, 1), - ThreeArgumentsCosting::linear_in_y(281145, 18848), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), replicate_byte: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(1, 1), - TwoArgumentsCosting::linear_in_x(180194, 159), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), shift_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(158519, 8942), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), rotate_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(159378, 8813), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), count_set_bits: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(107490, 3298), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), find_first_set_bit: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(106057, 655), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), ripemd_160: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(3), - OneArgumentCosting::linear_cost(1964219, 24520), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), exp_mod_integer: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_z(0, 1), - ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), drop_list: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(4), @@ -1301,146 +1293,145 @@ impl BuiltinCosts { 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), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), keccak_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(4), - OneArgumentCosting::linear_cost(2261318, 64571), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::constant_cost(962335), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(267929), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(76433006, 8868), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(442008), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g1_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(6), - OneArgumentCosting::constant_cost(2780678), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(18), - OneArgumentCosting::constant_cost(52948122), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(18), - TwoArgumentsCosting::linear_in_x(52538055, 3756), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::constant_cost(1995836), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(284546), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(158_221_314, 26_549), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(901_022), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_g2_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(12), - OneArgumentCosting::constant_cost(3_227_919), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(36), - OneArgumentCosting::constant_cost(74_698_472), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(36), - TwoArgumentsCosting::linear_in_x(166_917_843, 4_307), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_miller_loop: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(254006273), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_mul_ml_result: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(72), - TwoArgumentsCosting::constant_cost(2174038), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), bls12_381_final_verify: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(333849714), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), integer_to_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::literal_in_y_or_linear_in_z(0, 1), - ThreeArgumentsCosting::quadratic_in_z(1293828, 28716, 63), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), byte_string_to_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_y(0, 1), - TwoArgumentsCosting::quadratic_in_y(1006041, 43623, 251), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), and_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), or_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), xor_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_max_y_z(0, 1), - ThreeArgumentsCosting::linear_in_y_and_z(100181, 726, 719), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), complement_byte_string: OneArgumentCosting::new( - OneArgumentCosting::linear_cost(0, 1), - OneArgumentCosting::linear_cost(107878, 680), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), read_bit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(1), - TwoArgumentsCosting::constant_cost(95336), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), write_bits: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_x(0, 1), - ThreeArgumentsCosting::linear_in_y(281145, 18848), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), replicate_byte: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(1, 1), - TwoArgumentsCosting::linear_in_x(180194, 159), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), shift_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(158519, 8942), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), rotate_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::linear_in_x(0, 1), - TwoArgumentsCosting::linear_in_x(159378, 8813), + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), ), count_set_bits: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(107490, 3298), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), find_first_set_bit: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(1), - OneArgumentCosting::linear_cost(106057, 655), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), ripemd_160: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(3), - OneArgumentCosting::linear_cost(1964219, 24520), + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), ), exp_mod_integer: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_z(0, 1), - ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), ), drop_list: TwoArgumentsCosting::new( TwoArgumentsCosting::constant_cost(4), @@ -1843,4 +1834,1047 @@ impl BuiltinCosts { ), } } + + pub fn initialize_builtin_costs(version: &PlutusVersion, 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"], + ), + match version { + PlutusVersion::V1 | PlutusVersion::V2 => { + 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"], + ) + } + PlutusVersion::V3 => { + 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( + match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::subtracted_sizes( + cost_map["mod_integer-mem-arguments-intercept"], + cost_map["mod_integer-mem-arguments-slope"], + cost_map["mod_integer-mem-arguments-minimum"], + ), + PlutusVersion::V3 => TwoArgumentsCosting::linear_in_y( + cost_map["mod_integer-mem-arguments-intercept"], + cost_map["mod_integer-mem-arguments-slope"], + ), + }, + match version { + PlutusVersion::V1 | PlutusVersion::V2 => { + 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"], + ) + } + PlutusVersion::V3 => { + 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"], + ), + match version { + PlutusVersion::V1 | PlutusVersion::V2 => { + 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"], + ) + } + PlutusVersion::V3 => { + 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( + match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::subtracted_sizes( + cost_map["remainder_integer-mem-arguments-intercept"], + cost_map["remainder_integer-mem-arguments-slope"], + cost_map["remainder_integer-mem-arguments-minimum"], + ), + PlutusVersion::V3 => TwoArgumentsCosting::linear_in_y( + cost_map["remainder_integer-mem-arguments-intercept"], + cost_map["remainder_integer-mem-arguments-slope"], + ), + }, + match version { + PlutusVersion::V1 | PlutusVersion::V2 => { + 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"], + ) + } + PlutusVersion::V3 => { + 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: match version { + PlutusVersion::V1 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_mulMlResult-mem-arguments"], + ), + TwoArgumentsCosting::constant_cost( + cost_map["bls12_381_mulMlResult-cpu-arguments"], + ), + ), + }, + keccak_256: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(cost_map["readBit-memory-arguments"]), + TwoArgumentsCosting::constant_cost(cost_map["readBit-cpu-arguments"]), + ), + }, + write_bits: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( + TwoArgumentsCosting::constant_cost(30000000000), + TwoArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( + OneArgumentCosting::constant_cost(30000000000), + OneArgumentCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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: match version { + PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( + ThreeArgumentsCosting::constant_cost(30000000000), + ThreeArgumentsCosting::constant_cost(30000000000), + ), + PlutusVersion::V3 => 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), + ), + } + } +} + +#[cfg(test)] +mod tests { + 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!( + BuiltinCosts::v1(), + BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V1, &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!( + BuiltinCosts::v2(), + BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V2, &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!( + BuiltinCosts::v3(), + BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V3, &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/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 8e51e388d..67234d80f 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,12 +7,30 @@ mod value; pub use value::*; -use crate::machine::PlutusVersion; +use crate::machine::{ + cost_model::{builtin_costs::BuiltinCosts, machine_costs::MachineCosts}, + ExBudget, PlutusVersion, +}; #[derive(Default, Debug, PartialEq)] pub struct CostModel { - pub machine_costs: machine_costs::MachineCosts, - pub builtin_costs: builtin_costs::BuiltinCosts, + pub machine_startup: ExBudget, + pub machine_costs: MachineCosts, + pub builtin_costs: BuiltinCosts, +} + +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: BuiltinCosts::initialize_builtin_costs(version, &cost_map), + } + } } impl From<&PlutusVersion> for CostModel { @@ -22,6 +41,7 @@ impl From<&PlutusVersion> for CostModel { crate::machine::PlutusVersion::V3 => builtin_costs::BuiltinCosts::v3(), }; Self { + machine_startup: ExBudget::start_up(), machine_costs: Default::default(), builtin_costs, } 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/program.rs b/crates/uplc/src/program.rs index c510e5def..31d2dbf69 100644 --- a/crates/uplc/src/program.rs +++ b/crates/uplc/src/program.rs @@ -54,6 +54,27 @@ where EvalResult { term, info } } + + pub fn eval_version_with_model( + &'a self, + arena: &'a Bump, + plutus_version: PlutusVersion, + cost_model: &[i64], + ) -> EvalResult<'a, V> { + let mut machine = Machine::new( + arena, + ExBudget::default(), + CostModel::initialize_cost_model(&plutus_version, 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 } + } } #[derive(Debug, Copy, Clone)] From fc5f18bcf0c4d2578905989e44f22429a32e569d Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Wed, 5 Nov 2025 09:09:34 -0600 Subject: [PATCH 7/9] feat: semantically scoped cost model Signed-off-by: Jonathan Lim --- .../src/machine/cost_model/builtin_costs.rs | 2829 +---------------- .../builtin_costs/builtin_costs_v1.rs | 852 +++++ .../builtin_costs/builtin_costs_v2.rs | 900 ++++++ .../builtin_costs/builtin_costs_v3.rs | 1589 +++++++++ crates/uplc/src/machine/cost_model/mod.rs | 6 +- crates/uplc/src/machine/error.rs | 2 + crates/uplc/src/machine/runtime.rs | 923 ++++-- 7 files changed, 4078 insertions(+), 3023 deletions(-) create mode 100644 crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v1.rs create mode 100644 crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v2.rs create mode 100644 crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs.rs index e45922191..a74aab0ea 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs.rs @@ -1,2793 +1,82 @@ -use crate::machine::{cost_model::cost_map::CostMap, ExBudget, PlutusVersion}; - -use super::costing::{ - Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, TwoArgumentsCosting, +mod builtin_costs_v1; +mod builtin_costs_v2; +mod builtin_costs_v3; + +use crate::machine::{ + cost_model::{ + builtin_costs::{ + builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, + builtin_costs_v3::BuiltinCostsV3, + }, + cost_map::CostMap, + }, + ExBudget, PlutusVersion, }; #[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, +pub enum BuiltinCostsVersion { + BuiltinCostsV1(BuiltinCostsV1), + BuiltinCostsV2(BuiltinCostsV2), + BuiltinCostsV3(Box), +} - exp_mod_integer: ThreeArgumentsCosting, - drop_list: TwoArgumentsCosting, - length_of_array: OneArgumentCosting, - list_to_array: TwoArgumentsCosting, - index_array: TwoArgumentsCosting, +#[derive(Debug, PartialEq)] +pub struct BuiltinCosts { + builtin_costs: BuiltinCostsVersion, } impl Default for BuiltinCosts { fn default() -> Self { - BuiltinCosts::v3() + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new(BuiltinCostsV3::default())), + } } } 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 v1() -> 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(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - verify_schnorr_secp256k1_signature: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - 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::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - blake2b_224: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - keccak_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_miller_loop: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_mul_ml_result: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_final_verify: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - integer_to_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - byte_string_to_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - and_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - or_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - xor_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - complement_byte_string: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - read_bit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - write_bits: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - replicate_byte: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - shift_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - rotate_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - count_set_bits: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - find_first_set_bit: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - ripemd_160: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - exp_mod_integer: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - 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), - ), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV1(BuiltinCostsV1::default()), } } - pub fn v2() -> 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), - ), - blake2b_224: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - keccak_256: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g1_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g1_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_add: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_neg: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_scalar_mul: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_equal: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_g2_compress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_uncompress: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - bls12_381_g2_hash_to_group: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_miller_loop: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_mul_ml_result: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - bls12_381_final_verify: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - integer_to_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - byte_string_to_integer: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - and_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - or_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - xor_byte_string: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - complement_byte_string: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - read_bit: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - write_bits: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - replicate_byte: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - shift_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - rotate_byte_string: TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - count_set_bits: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - find_first_set_bit: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - ripemd_160: OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - exp_mod_integer: ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - 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), - ), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV2(BuiltinCostsV2::default()), } } - 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), - ), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new(BuiltinCostsV3::default())), } } pub fn initialize_builtin_costs(version: &PlutusVersion, 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"], - ), - match version { - PlutusVersion::V1 | PlutusVersion::V2 => { - 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"], - ) - } - PlutusVersion::V3 => { - 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( - match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::subtracted_sizes( - cost_map["mod_integer-mem-arguments-intercept"], - cost_map["mod_integer-mem-arguments-slope"], - cost_map["mod_integer-mem-arguments-minimum"], - ), - PlutusVersion::V3 => TwoArgumentsCosting::linear_in_y( - cost_map["mod_integer-mem-arguments-intercept"], - cost_map["mod_integer-mem-arguments-slope"], - ), - }, - match version { - PlutusVersion::V1 | PlutusVersion::V2 => { - 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"], - ) - } - PlutusVersion::V3 => { - 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"], - ), - match version { - PlutusVersion::V1 | PlutusVersion::V2 => { - 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"], - ) - } - PlutusVersion::V3 => { - 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( - match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::subtracted_sizes( - cost_map["remainder_integer-mem-arguments-intercept"], - cost_map["remainder_integer-mem-arguments-slope"], - cost_map["remainder_integer-mem-arguments-minimum"], - ), - PlutusVersion::V3 => TwoArgumentsCosting::linear_in_y( - cost_map["remainder_integer-mem-arguments-intercept"], - cost_map["remainder_integer-mem-arguments-slope"], - ), - }, - match version { - PlutusVersion::V1 | PlutusVersion::V2 => { - 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"], - ) - } - PlutusVersion::V3 => { - 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: match version { - PlutusVersion::V1 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V2 | PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost( - cost_map["bls12_381_mulMlResult-mem-arguments"], - ), - TwoArgumentsCosting::constant_cost( - cost_map["bls12_381_mulMlResult-cpu-arguments"], - ), - ), - }, - keccak_256: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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"], - ), + builtin_costs: match version { + PlutusVersion::V1 => BuiltinCostsVersion::BuiltinCostsV1( + BuiltinCostsV1::initialize_builtin_costs(cost_map), ), - }, - and_byte_string: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(cost_map["readBit-memory-arguments"]), - TwoArgumentsCosting::constant_cost(cost_map["readBit-cpu-arguments"]), - ), - }, - write_bits: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => TwoArgumentsCosting::new( - TwoArgumentsCosting::constant_cost(30000000000), - TwoArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => OneArgumentCosting::new( - OneArgumentCosting::constant_cost(30000000000), - OneArgumentCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => 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: match version { - PlutusVersion::V1 | PlutusVersion::V2 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::constant_cost(30000000000), - ThreeArgumentsCosting::constant_cost(30000000000), - ), - PlutusVersion::V3 => ThreeArgumentsCosting::new( - ThreeArgumentsCosting::linear_in_z(0, 1), - ThreeArgumentsCosting::exp_mod_cost(607153, 231697, 53144), + PlutusVersion::V2 => BuiltinCostsVersion::BuiltinCostsV2( + BuiltinCostsV2::initialize_builtin_costs(cost_map), ), + PlutusVersion::V3 => BuiltinCostsVersion::BuiltinCostsV3(Box::new( + BuiltinCostsV3::initialize_builtin_costs(cost_map), + )), }, - 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), - ), + } + } + + pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + match &self.builtin_costs { + BuiltinCostsVersion::BuiltinCostsV1(builtin_costs) => { + builtin_costs.get_cost(builtin, args) + } + BuiltinCostsVersion::BuiltinCostsV2(builtin_costs) => { + builtin_costs.get_cost(builtin, args) + } + BuiltinCostsVersion::BuiltinCostsV3(builtin_costs) => { + builtin_costs.get_cost(builtin, args) + } } } } @@ -2816,7 +105,9 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V1, &costs); assert_eq!( - BuiltinCosts::v1(), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV1(BuiltinCostsV1::default()) + }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V1, &cost_model) ); } @@ -2840,7 +131,9 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V2, &costs); assert_eq!( - BuiltinCosts::v2(), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV2(BuiltinCostsV2::default()) + }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V2, &cost_model) ); } @@ -2873,7 +166,11 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V3, &costs); assert_eq!( - BuiltinCosts::v3(), + BuiltinCosts { + builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new( + BuiltinCostsV3::default() + )) + }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V3, &cost_model) ); } 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..7fd128128 --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v1.rs @@ -0,0 +1,852 @@ +use crate::machine::{ + cost_model::{ + 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 BuiltinCostsV1 { + pub 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), + ), + } + } + pub fn initialize_builtin_costs(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"], + ), + ), + } + } +} + +impl BuiltinCostsV1 { + pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + match builtin { + "add_integer" => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + "subtract_integer" => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + "multiply_integer" => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + "divide_integer" => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + "quotient_integer" => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + "remainder_integer" => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + "mod_integer" => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + "equals_integer" => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_integer" => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_equals_integer" => 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]]), + )), + "append_byte_string" => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + "cons_byte_string" => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + "slice_byte_string" => 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]]), + )), + "length_of_byte_string" => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + "index_byte_string" => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + "equals_byte_string" => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + "less_than_byte_string" => 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]]), + )), + "less_than_equals_byte_string" => 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]]), + )), + "sha2_256" => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + "sha3_256" => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + "blake2b_256" => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + "verify_ed25519_signature" => 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]]), + )), + "append_string" => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + "equals_string" => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + "encode_utf8" => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + "decode_utf8" => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + "if_then_else" => 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]]), + )), + "choose_unit" => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + "trace" => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + "fst_pair" => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + "snd_pair" => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + "choose_list" => 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]]), + )), + "mk_cons" => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + "head_list" => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + "tail_list" => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + "null_list" => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + "choose_data" => 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]]), + )), + "constr_data" => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + "map_data" => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + "list_data" => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + "i_data" => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + "b_data" => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + "un_constr_data" => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + "un_map_data" => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + "un_list_data" => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + "un_i_data" => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + "un_b_data" => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + "equals_data" => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + "mk_pair_data" => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + "mk_nil_data" => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + "mk_nil_pair_data" => 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..3e3d68d2d --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v2.rs @@ -0,0 +1,900 @@ +use crate::machine::{ + cost_model::{ + 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 BuiltinCostsV2 { + pub 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), + ), + } + } + + pub fn initialize_builtin_costs(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"], + ), + ), + } + } +} + +impl BuiltinCostsV2 { + pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + match builtin { + "add_integer" => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + "subtract_integer" => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + "multiply_integer" => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + "divide_integer" => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + "quotient_integer" => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + "remainder_integer" => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + "mod_integer" => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + "equals_integer" => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_integer" => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_equals_integer" => 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]]), + )), + "append_byte_string" => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + "cons_byte_string" => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + "slice_byte_string" => 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]]), + )), + "length_of_byte_string" => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + "index_byte_string" => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + "equals_byte_string" => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + "less_than_byte_string" => 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]]), + )), + "less_than_equals_byte_string" => 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]]), + )), + "sha2_256" => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + "sha3_256" => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + "blake2b_256" => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + "verify_ed25519_signature" => 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]]), + )), + "append_string" => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + "equals_string" => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + "encode_utf8" => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + "decode_utf8" => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + "if_then_else" => 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]]), + )), + "choose_unit" => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + "trace" => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + "fst_pair" => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + "snd_pair" => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + "choose_list" => 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]]), + )), + "mk_cons" => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + "head_list" => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + "tail_list" => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + "null_list" => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + "choose_data" => 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]]), + )), + "constr_data" => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + "map_data" => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + "list_data" => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + "i_data" => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + "b_data" => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + "un_constr_data" => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + "un_map_data" => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + "un_list_data" => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + "un_i_data" => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + "un_b_data" => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + "equals_data" => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + "mk_pair_data" => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + "mk_nil_data" => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + "mk_nil_pair_data" => Some(ExBudget::new( + self.mk_nil_pair_data.mem.cost([args[0]]), + self.mk_nil_pair_data.cpu.cost([args[0]]), + )), + "serialise_data" => 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..9044aa81a --- /dev/null +++ b/crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs @@ -0,0 +1,1589 @@ +use crate::machine::{ + cost_model::{ + 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 BuiltinCostsV3 { + pub 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), + ), + } + } + + pub fn initialize_builtin_costs(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), + ), + } + } +} + +impl BuiltinCostsV3 { + pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + match builtin { + "add_integer" => Some(ExBudget::new( + self.add_integer.mem.cost([args[0], args[1]]), + self.add_integer.cpu.cost([args[0], args[1]]), + )), + "subtract_integer" => Some(ExBudget::new( + self.subtract_integer.mem.cost([args[0], args[1]]), + self.subtract_integer.cpu.cost([args[0], args[1]]), + )), + "multiply_integer" => Some(ExBudget::new( + self.multiply_integer.mem.cost([args[0], args[1]]), + self.multiply_integer.cpu.cost([args[0], args[1]]), + )), + "divide_integer" => Some(ExBudget::new( + self.divide_integer.mem.cost([args[0], args[1]]), + self.divide_integer.cpu.cost([args[0], args[1]]), + )), + "quotient_integer" => Some(ExBudget::new( + self.quotient_integer.mem.cost([args[0], args[1]]), + self.quotient_integer.cpu.cost([args[0], args[1]]), + )), + "remainder_integer" => Some(ExBudget::new( + self.remainder_integer.mem.cost([args[0], args[1]]), + self.remainder_integer.cpu.cost([args[0], args[1]]), + )), + "mod_integer" => Some(ExBudget::new( + self.mod_integer.mem.cost([args[0], args[1]]), + self.mod_integer.cpu.cost([args[0], args[1]]), + )), + "equals_integer" => Some(ExBudget::new( + self.equals_integer.mem.cost([args[0], args[1]]), + self.equals_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_integer" => Some(ExBudget::new( + self.less_than_integer.mem.cost([args[0], args[1]]), + self.less_than_integer.cpu.cost([args[0], args[1]]), + )), + "less_than_equals_integer" => 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]]), + )), + "append_byte_string" => Some(ExBudget::new( + self.append_byte_string.mem.cost([args[0], args[1]]), + self.append_byte_string.cpu.cost([args[0], args[1]]), + )), + "cons_byte_string" => Some(ExBudget::new( + self.cons_byte_string.mem.cost([args[0], args[1]]), + self.cons_byte_string.cpu.cost([args[0], args[1]]), + )), + "slice_byte_string" => 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]]), + )), + "length_of_byte_string" => Some(ExBudget::new( + self.length_of_byte_string.mem.cost([args[0]]), + self.length_of_byte_string.cpu.cost([args[0]]), + )), + "index_byte_string" => Some(ExBudget::new( + self.index_byte_string.mem.cost([args[0], args[1]]), + self.index_byte_string.cpu.cost([args[0], args[1]]), + )), + "equals_byte_string" => Some(ExBudget::new( + self.equals_byte_string.mem.cost([args[0], args[1]]), + self.equals_byte_string.cpu.cost([args[0], args[1]]), + )), + "less_than_byte_string" => 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]]), + )), + "less_than_equals_byte_string" => 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]]), + )), + "sha2_256" => Some(ExBudget::new( + self.sha2_256.mem.cost([args[0]]), + self.sha2_256.cpu.cost([args[0]]), + )), + "sha3_256" => Some(ExBudget::new( + self.sha3_256.mem.cost([args[0]]), + self.sha3_256.cpu.cost([args[0]]), + )), + "blake2b_224" => Some(ExBudget::new( + self.blake2b_224.mem.cost([args[0]]), + self.blake2b_224.cpu.cost([args[0]]), + )), + "blake2b_256" => Some(ExBudget::new( + self.blake2b_256.mem.cost([args[0]]), + self.blake2b_256.cpu.cost([args[0]]), + )), + "keccak_256" => Some(ExBudget::new( + self.keccak_256.mem.cost([args[0]]), + self.keccak_256.cpu.cost([args[0]]), + )), + "verify_ed25519_signature" => 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]]), + )), + "verify_ecdsa_secp256k1_signature" => 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]]), + )), + "verify_schnorr_secp256k1_signature" => 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]]), + )), + + "append_string" => Some(ExBudget::new( + self.append_string.mem.cost([args[0], args[1]]), + self.append_string.cpu.cost([args[0], args[1]]), + )), + "equals_string" => Some(ExBudget::new( + self.equals_string.mem.cost([args[0], args[1]]), + self.equals_string.cpu.cost([args[0], args[1]]), + )), + "encode_utf8" => Some(ExBudget::new( + self.encode_utf8.mem.cost([args[0]]), + self.encode_utf8.cpu.cost([args[0]]), + )), + "decode_utf8" => Some(ExBudget::new( + self.decode_utf8.mem.cost([args[0]]), + self.decode_utf8.cpu.cost([args[0]]), + )), + "if_then_else" => 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]]), + )), + "choose_unit" => Some(ExBudget::new( + self.choose_unit.mem.cost([args[0], args[1]]), + self.choose_unit.cpu.cost([args[0], args[1]]), + )), + "trace" => Some(ExBudget::new( + self.trace.mem.cost([args[0], args[1]]), + self.trace.cpu.cost([args[0], args[1]]), + )), + "fst_pair" => Some(ExBudget::new( + self.fst_pair.mem.cost([args[0]]), + self.fst_pair.cpu.cost([args[0]]), + )), + "snd_pair" => Some(ExBudget::new( + self.snd_pair.mem.cost([args[0]]), + self.snd_pair.cpu.cost([args[0]]), + )), + "choose_list" => 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]]), + )), + "mk_cons" => Some(ExBudget::new( + self.mk_cons.mem.cost([args[0], args[1]]), + self.mk_cons.cpu.cost([args[0], args[1]]), + )), + "head_list" => Some(ExBudget::new( + self.head_list.mem.cost([args[0]]), + self.head_list.cpu.cost([args[0]]), + )), + "tail_list" => Some(ExBudget::new( + self.tail_list.mem.cost([args[0]]), + self.tail_list.cpu.cost([args[0]]), + )), + "null_list" => Some(ExBudget::new( + self.null_list.mem.cost([args[0]]), + self.null_list.cpu.cost([args[0]]), + )), + "choose_data" => 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]]), + )), + "constr_data" => Some(ExBudget::new( + self.constr_data.mem.cost([args[0], args[1]]), + self.constr_data.cpu.cost([args[0], args[1]]), + )), + "map_data" => Some(ExBudget::new( + self.map_data.mem.cost([args[0]]), + self.map_data.cpu.cost([args[0]]), + )), + "list_data" => Some(ExBudget::new( + self.list_data.mem.cost([args[0]]), + self.list_data.cpu.cost([args[0]]), + )), + "i_data" => Some(ExBudget::new( + self.i_data.mem.cost([args[0]]), + self.i_data.cpu.cost([args[0]]), + )), + "b_data" => Some(ExBudget::new( + self.b_data.mem.cost([args[0]]), + self.b_data.cpu.cost([args[0]]), + )), + "un_constr_data" => Some(ExBudget::new( + self.un_constr_data.mem.cost([args[0]]), + self.un_constr_data.cpu.cost([args[0]]), + )), + "un_map_data" => Some(ExBudget::new( + self.un_map_data.mem.cost([args[0]]), + self.un_map_data.cpu.cost([args[0]]), + )), + "un_list_data" => Some(ExBudget::new( + self.un_list_data.mem.cost([args[0]]), + self.un_list_data.cpu.cost([args[0]]), + )), + "un_i_data" => Some(ExBudget::new( + self.un_i_data.mem.cost([args[0]]), + self.un_i_data.cpu.cost([args[0]]), + )), + "un_b_data" => Some(ExBudget::new( + self.un_b_data.mem.cost([args[0]]), + self.un_b_data.cpu.cost([args[0]]), + )), + "equals_data" => Some(ExBudget::new( + self.equals_data.mem.cost([args[0], args[1]]), + self.equals_data.cpu.cost([args[0], args[1]]), + )), + "mk_pair_data" => Some(ExBudget::new( + self.mk_pair_data.mem.cost([args[0], args[1]]), + self.mk_pair_data.cpu.cost([args[0], args[1]]), + )), + "mk_nil_data" => Some(ExBudget::new( + self.mk_nil_data.mem.cost([args[0]]), + self.mk_nil_data.cpu.cost([args[0]]), + )), + "mk_nil_pair_data" => Some(ExBudget::new( + self.mk_nil_pair_data.mem.cost([args[0]]), + self.mk_nil_pair_data.cpu.cost([args[0]]), + )), + "serialise_data" => Some(ExBudget::new( + self.serialise_data.mem.cost([args[0]]), + self.serialise_data.cpu.cost([args[0]]), + )), + "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]]), + )), + "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]]), + )), + "bls12_381_g1_scalar_mul" => 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]]), + )), + "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]]), + )), + "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]]), + )), + "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]]), + )), + "bls12_381_g1_hash_to_group" => 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]]), + )), + "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]]), + )), + "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]]), + )), + "bls12_381_g2_scalar_mul" => 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]]), + )), + "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]]), + )), + "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]]), + )), + "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]]), + )), + "bls12_381_g2_hash_to_group" => 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]]), + )), + "bls12_381_miller_loop" => 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]]), + )), + "bls12_381_mul_ml_result" => 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]]), + )), + "bls12_381_final_verify" => 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]]), + )), + "integer_to_byte_string" => 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]]), + )), + "byte_string_to_integer" => 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]]), + )), + "and_byte_string" => 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]]), + )), + "or_byte_string" => 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]]), + )), + "xor_byte_string" => 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]]), + )), + "complement_byte_string" => Some(ExBudget::new( + self.complement_byte_string.mem.cost([args[0]]), + self.complement_byte_string.cpu.cost([args[0]]), + )), + "read_bit" => Some(ExBudget::new( + self.read_bit.mem.cost([args[0], args[1]]), + self.read_bit.cpu.cost([args[0], args[1]]), + )), + "write_bits" => 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]]), + )), + "replicate_byte" => Some(ExBudget::new( + self.replicate_byte.mem.cost([args[0], args[1]]), + self.replicate_byte.cpu.cost([args[0], args[1]]), + )), + "shift_byte_string" => Some(ExBudget::new( + self.shift_byte_string.mem.cost([args[0], args[1]]), + self.shift_byte_string.cpu.cost([args[0], args[1]]), + )), + "rotate_byte_string" => Some(ExBudget::new( + self.rotate_byte_string.mem.cost([args[0], args[1]]), + self.rotate_byte_string.cpu.cost([args[0], args[1]]), + )), + "count_set_bits" => Some(ExBudget::new( + self.count_set_bits.mem.cost([args[0]]), + self.count_set_bits.cpu.cost([args[0]]), + )), + "find_first_set_bit" => Some(ExBudget::new( + self.find_first_set_bit.mem.cost([args[0]]), + self.find_first_set_bit.cpu.cost([args[0]]), + )), + "ripemd_160" => Some(ExBudget::new( + self.ripemd_160.mem.cost([args[0]]), + self.ripemd_160.cpu.cost([args[0]]), + )), + "exp_mod_integer" => 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]]), + )), + "drop_list" => Some(ExBudget::new( + self.drop_list.mem.cost([args[0], args[1]]), + self.drop_list.cpu.cost([args[0], args[1]]), + )), + "length_of_array" => Some(ExBudget::new( + self.length_of_array.mem.cost([args[0]]), + self.length_of_array.cpu.cost([args[0]]), + )), + "list_to_array" => Some(ExBudget::new( + self.list_to_array.mem.cost([args[0], args[1]]), + self.list_to_array.cpu.cost([args[0], args[1]]), + )), + "index_array" => Some(ExBudget::new( + self.index_array.mem.cost([args[0], args[1]]), + self.index_array.cpu.cost([args[0], args[1]]), + )), + _ => None, + } + } +} diff --git a/crates/uplc/src/machine/cost_model/mod.rs b/crates/uplc/src/machine/cost_model/mod.rs index 67234d80f..dad161dcb 100644 --- a/crates/uplc/src/machine/cost_model/mod.rs +++ b/crates/uplc/src/machine/cost_model/mod.rs @@ -36,9 +36,9 @@ impl CostModel { impl From<&PlutusVersion> for CostModel { fn from(version: &PlutusVersion) -> Self { let builtin_costs = match version { - crate::machine::PlutusVersion::V1 => builtin_costs::BuiltinCosts::v1(), - crate::machine::PlutusVersion::V2 => builtin_costs::BuiltinCosts::v2(), - crate::machine::PlutusVersion::V3 => builtin_costs::BuiltinCosts::v3(), + crate::machine::PlutusVersion::V1 => BuiltinCosts::v1(), + crate::machine::PlutusVersion::V2 => BuiltinCosts::v2(), + crate::machine::PlutusVersion::V3 => BuiltinCosts::v3(), }; Self { machine_startup: ExBudget::start_up(), 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/runtime.rs b/crates/uplc/src/machine/runtime.rs index e2accf829..9e5bea204 100644 --- a/crates/uplc/src/machine/runtime.rs +++ b/crates/uplc/src/machine/runtime.rs @@ -110,10 +110,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( + "add_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -128,10 +135,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( + "subtract_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -147,10 +161,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( + "equals_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -164,10 +185,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( + "less_than_equals_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -181,10 +209,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( + "append_byte_string", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -203,10 +238,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( + "equals_byte_string", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -220,11 +262,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( + "if_then_else", + &[ + 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 +286,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( + "multiply_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -256,10 +312,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( + "divide_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -279,10 +342,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( + "quotient_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -299,10 +369,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( + "remainder_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -319,10 +396,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( + "mod_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -340,10 +424,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( + "less_than_integer", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -357,10 +448,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( + "cons_byte_string", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -396,11 +494,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( + "slice_byte_string", + &[ + 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 +541,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .length_of_byte_string([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + "length_of_byte_string", + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -451,10 +560,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( + "index_byte_string", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::integer_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -474,10 +590,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( + "less_than_byte_string", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -491,10 +614,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( + "less_than_equals_byte_string", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -512,7 +642,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .sha2_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("sha2_256", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -542,7 +673,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .sha3_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("sha3_256", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -572,7 +704,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .blake2b_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("blake2b_256", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -601,7 +734,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .keccak_256([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("keccak_256", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -631,7 +765,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .blake2b_224([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("blake2b_224", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -659,11 +794,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( + "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), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -690,11 +832,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( + "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), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -725,11 +874,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( + "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), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -751,10 +904,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( + "append_string", + &[ + cost_model::string_ex_mem(arg1), + cost_model::string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -773,10 +933,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( + "equals_string", + &[ + cost_model::string_ex_mem(arg1), + cost_model::string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -790,7 +957,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .encode_utf8([cost_model::string_ex_mem(arg1)]); + .get_cost("encode_utf8", &[cost_model::string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -812,7 +980,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .decode_utf8([cost_model::byte_string_ex_mem(arg1)]); + .get_cost("decode_utf8", &[cost_model::byte_string_ex_mem(arg1)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -829,7 +998,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( + "choose_unit", + &[cost_model::UNIT_EX_MEM, cost_model::value_ex_mem(arg2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -839,10 +1012,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( + "trace", + &[ + cost_model::string_ex_mem(arg1), + cost_model::value_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -856,7 +1036,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .fst_pair([cost_model::pair_ex_mem(first, second)]); + .get_cost("fst_pair", &[cost_model::pair_ex_mem(first, second)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -870,7 +1051,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .snd_pair([cost_model::pair_ex_mem(first, second)]); + .get_cost("snd_pair", &[cost_model::pair_ex_mem(first, second)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -883,11 +1065,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( + "choose_list", + &[ + 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 +1090,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( + "mk_cons", + &[ + cost_model::constant_ex_mem(item), + cost_model::proto_list_ex_mem(list), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -932,7 +1128,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .head_list([cost_model::proto_list_ex_mem(list)]); + .get_cost("head_list", &[cost_model::proto_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -950,7 +1147,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .tail_list([cost_model::proto_list_ex_mem(list)]); + .get_cost("tail_list", &[cost_model::proto_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -970,7 +1168,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .null_list([cost_model::proto_list_ex_mem(list)]); + .get_cost("null_list", &[cost_model::proto_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -986,14 +1185,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( + "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), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1009,10 +1215,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( + "constr_data", + &[ + cost_model::integer_ex_mem(tag), + cost_model::proto_list_ex_mem(fields), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1058,7 +1271,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .map_data([cost_model::proto_list_ex_mem(list)]); + .get_cost("map_data", &[cost_model::proto_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1094,7 +1308,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .list_data([cost_model::proto_list_ex_mem(fields)]); + .get_cost("list_data", &[cost_model::proto_list_ex_mem(fields)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1126,7 +1341,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .i_data([cost_model::integer_ex_mem(i)]); + .get_cost("i_data", &[cost_model::integer_ex_mem(i)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1142,7 +1358,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .b_data([cost_model::byte_string_ex_mem(b)]); + .get_cost("b_data", &[cost_model::byte_string_ex_mem(b)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1161,7 +1378,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_constr_data([cost_model::data_list_ex_mem(fields)]); + .get_cost("un_constr_data", &[cost_model::data_list_ex_mem(fields)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1192,7 +1410,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_map_data([cost_model::data_map_ex_mem(map)]); + .get_cost("un_map_data", &[cost_model::data_map_ex_mem(map)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1229,7 +1448,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_list_data([cost_model::data_list_ex_mem(list)]); + .get_cost("un_list_data", &[cost_model::data_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1254,7 +1474,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_i_data([cost_model::data_integer_ex_mem(i)]); + .get_cost("un_i_data", &[cost_model::data_integer_ex_mem(i)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1271,7 +1492,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .un_b_data([cost_model::data_byte_string_ex_mem(bs)]); + .get_cost("un_b_data", &[cost_model::data_byte_string_ex_mem(bs)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1286,7 +1508,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( + "equals_data", + &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1302,7 +1528,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( + "mk_pair_data", + &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1324,7 +1554,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .mk_nil_data([cost_model::UNIT_EX_MEM]); + .get_cost("mk_nil_data", &[cost_model::UNIT_EX_MEM]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1343,7 +1574,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .mk_nil_pair_data([cost_model::UNIT_EX_MEM]); + .get_cost("mk_nil_pair_data", &[cost_model::UNIT_EX_MEM]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1364,10 +1596,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( + "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 +1628,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_neg([cost_model::g1_element_ex_mem()]); + .get_cost("bls12_381_g1_neg", &[cost_model::g1_element_ex_mem()]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1410,10 +1650,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( + "bls12_381_g1_scalar_mul", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::g1_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1456,10 +1703,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( + "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 +1729,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_compress([cost_model::g1_element_ex_mem()]); + .get_cost("bls12_381_g1_compress", &[cost_model::g1_element_ex_mem()]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1491,7 +1746,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g1_uncompress([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + "bls12_381_g1_uncompress", + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1507,10 +1766,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( + "bls12_381_g1_hash_to_group", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1543,10 +1809,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( + "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 +1841,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_neg([cost_model::g2_element_ex_mem()]); + .get_cost("bls12_381_g2_neg", &[cost_model::g2_element_ex_mem()]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1589,10 +1863,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( + "bls12_381_g2_scalar_mul", + &[ + cost_model::integer_ex_mem(arg1), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1639,10 +1920,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( + "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 +1946,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_compress([cost_model::g2_element_ex_mem()]); + .get_cost("bls12_381_g2_compress", &[cost_model::g2_element_ex_mem()]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1674,7 +1963,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .bls12_381_g2_uncompress([cost_model::byte_string_ex_mem(arg1)]); + .get_cost( + "bls12_381_g2_uncompress", + &[cost_model::byte_string_ex_mem(arg1)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1690,10 +1983,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( + "bls12_381_g2_hash_to_group", + &[ + cost_model::byte_string_ex_mem(arg1), + cost_model::byte_string_ex_mem(arg2), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1726,10 +2026,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( + "bls12_381_miller_loop", + &[ + cost_model::g1_element_ex_mem(), + cost_model::g2_element_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1755,10 +2062,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( + "bls12_381_mul_ml_result", + &[ + cost_model::ml_result_ex_mem(), + cost_model::ml_result_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1778,10 +2092,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( + "bls12_381_final_verify", + &[ + cost_model::ml_result_ex_mem(), + cost_model::ml_result_ex_mem(), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1811,11 +2132,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( + "integer_to_byte_string", + &[ + cost_model::BOOL_EX_MEM, + arg1_exmem, + cost_model::integer_ex_mem(input), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1903,10 +2231,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( + "byte_string_to_integer", + &[ + cost_model::BOOL_EX_MEM, + cost_model::byte_string_ex_mem(bytes), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -1927,11 +2262,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( + "and_byte_string", + &[ + 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 +2302,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( + "or_byte_string", + &[ + 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 +2344,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( + "or_byte_string", + &[ + 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 +2387,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .complement_byte_string([cost_model::byte_string_ex_mem(bytes)]); + .get_cost( + "complement_byte_string", + &[cost_model::byte_string_ex_mem(bytes)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let result = self @@ -2044,10 +2404,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( + "read_bit", + &[ + cost_model::byte_string_ex_mem(bytes), + cost_model::integer_ex_mem(bit_index), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2077,11 +2444,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( + "write_bits", + &[ + 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 +2509,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .replicate_byte([arg0_ex_mem, cost_model::integer_ex_mem(byte)]); + .get_cost( + "replicate_byte", + &[arg0_ex_mem, cost_model::integer_ex_mem(byte)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2181,7 +2559,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .shift_byte_string([cost_model::byte_string_ex_mem(bytes), arg1]); + .get_cost( + "shift_byte_string", + &[cost_model::byte_string_ex_mem(bytes), arg1], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let length = bytes.len(); @@ -2268,7 +2650,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .rotate_byte_string([cost_model::byte_string_ex_mem(bytes), arg1]); + .get_cost( + "rotate_byte_string", + &[cost_model::byte_string_ex_mem(bytes), arg1], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let length = bytes.len(); @@ -2332,7 +2718,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .count_set_bits([cost_model::byte_string_ex_mem(bytes)]); + .get_cost("count_set_bits", &[cost_model::byte_string_ex_mem(bytes)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let weight: Integer = hamming::weight(bytes).into(); @@ -2345,7 +2732,11 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .find_first_set_bit([cost_model::byte_string_ex_mem(bytes)]); + .get_cost( + "find_first_set_bit", + &[cost_model::byte_string_ex_mem(bytes)], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let first_bit = bytes @@ -2372,7 +2763,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .ripemd_160([cost_model::byte_string_ex_mem(input)]); + .get_cost("ripemd_160", &[cost_model::byte_string_ex_mem(input)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; let mut hasher = Ripemd160::new(); @@ -2387,11 +2779,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( + "exp_mod_integer", + &[ + 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 +2821,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .drop_list([arg0, cost_model::proto_list_ex_mem(list)]); + .get_cost("drop_list", &[arg0, cost_model::proto_list_ex_mem(list)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2455,7 +2855,8 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .length_of_array([cost_model::proto_list_ex_mem(array)]); + .get_cost("length_of_array", &[cost_model::proto_list_ex_mem(array)]) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2468,10 +2869,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( + "list_to_array", + &[ + cost_model::proto_list_ex_mem(list), + cost_model::proto_list_ex_mem(list), + ], + ) + .ok_or(MachineError::UnknownBuiltinFunction)?; self.spend_budget(budget)?; @@ -2485,10 +2893,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( + "index_array", + &[ + 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(); From ab4d625fca4f85ba3abc4691212c4f454b0bf3c0 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Fri, 7 Nov 2025 11:34:09 -0600 Subject: [PATCH 8/9] style: refactored names, layout, and function matching Signed-off-by: Jonathan Lim --- .../builtin_costs/builtin_costs_v1.rs | 130 ++++----- .../builtin_costs/builtin_costs_v2.rs | 132 ++++----- .../builtin_costs/builtin_costs_v3.rs | 214 +++++++------- .../mod.rs} | 83 +++--- crates/uplc/src/machine/runtime.rs | 263 ++++++++++++------ 5 files changed, 451 insertions(+), 371 deletions(-) rename crates/uplc/src/machine/cost_model/{builtin_costs.rs => builtin_costs/mod.rs} (71%) 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 index 7fd128128..c384838bb 100644 --- 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 @@ -1,12 +1,16 @@ -use crate::machine::{ - cost_model::{ - cost_map::CostMap, - costing::{ - Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, - TwoArgumentsCosting, +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, }, + ExBudget, }, - ExBudget, }; #[derive(Debug, PartialEq)] @@ -74,8 +78,8 @@ pub struct BuiltinCostsV1 { mk_nil_pair_data: OneArgumentCosting, } -impl BuiltinCostsV1 { - pub fn default() -> Self { +impl BuiltinCostModel for BuiltinCostsV1 { + fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size(1, 1), @@ -283,7 +287,7 @@ impl BuiltinCostsV1 { ), } } - pub fn initialize_builtin_costs(cost_map: &CostMap) -> Self { + fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size( @@ -625,80 +629,78 @@ impl BuiltinCostsV1 { ), } } -} -impl BuiltinCostsV1 { - pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { match builtin { - "add_integer" => Some(ExBudget::new( + DefaultFunction::AddInteger => Some(ExBudget::new( self.add_integer.mem.cost([args[0], args[1]]), self.add_integer.cpu.cost([args[0], args[1]]), )), - "subtract_integer" => Some(ExBudget::new( + DefaultFunction::SubtractInteger => Some(ExBudget::new( self.subtract_integer.mem.cost([args[0], args[1]]), self.subtract_integer.cpu.cost([args[0], args[1]]), )), - "multiply_integer" => Some(ExBudget::new( + DefaultFunction::MultiplyInteger => Some(ExBudget::new( self.multiply_integer.mem.cost([args[0], args[1]]), self.multiply_integer.cpu.cost([args[0], args[1]]), )), - "divide_integer" => Some(ExBudget::new( + DefaultFunction::DivideInteger => Some(ExBudget::new( self.divide_integer.mem.cost([args[0], args[1]]), self.divide_integer.cpu.cost([args[0], args[1]]), )), - "quotient_integer" => Some(ExBudget::new( + DefaultFunction::QuotientInteger => Some(ExBudget::new( self.quotient_integer.mem.cost([args[0], args[1]]), self.quotient_integer.cpu.cost([args[0], args[1]]), )), - "remainder_integer" => Some(ExBudget::new( + DefaultFunction::RemainderInteger => Some(ExBudget::new( self.remainder_integer.mem.cost([args[0], args[1]]), self.remainder_integer.cpu.cost([args[0], args[1]]), )), - "mod_integer" => Some(ExBudget::new( + DefaultFunction::ModInteger => Some(ExBudget::new( self.mod_integer.mem.cost([args[0], args[1]]), self.mod_integer.cpu.cost([args[0], args[1]]), )), - "equals_integer" => Some(ExBudget::new( + DefaultFunction::EqualsInteger => Some(ExBudget::new( self.equals_integer.mem.cost([args[0], args[1]]), self.equals_integer.cpu.cost([args[0], args[1]]), )), - "less_than_integer" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_integer" => Some(ExBudget::new( + 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]]), )), - "append_byte_string" => Some(ExBudget::new( + 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]]), )), - "cons_byte_string" => Some(ExBudget::new( + 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]]), )), - "slice_byte_string" => Some(ExBudget::new( + 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]]), )), - "length_of_byte_string" => Some(ExBudget::new( + DefaultFunction::LengthOfByteString => Some(ExBudget::new( self.length_of_byte_string.mem.cost([args[0]]), self.length_of_byte_string.cpu.cost([args[0]]), )), - "index_byte_string" => Some(ExBudget::new( + 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]]), )), - "equals_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_byte_string" => Some(ExBudget::new( + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( self.less_than_equals_byte_string .mem .cost([args[0], args[1]]), @@ -706,19 +708,19 @@ impl BuiltinCostsV1 { .cpu .cost([args[0], args[1]]), )), - "sha2_256" => Some(ExBudget::new( + DefaultFunction::Sha2_256 => Some(ExBudget::new( self.sha2_256.mem.cost([args[0]]), self.sha2_256.cpu.cost([args[0]]), )), - "sha3_256" => Some(ExBudget::new( + DefaultFunction::Sha3_256 => Some(ExBudget::new( self.sha3_256.mem.cost([args[0]]), self.sha3_256.cpu.cost([args[0]]), )), - "blake2b_256" => Some(ExBudget::new( + DefaultFunction::Blake2b_256 => Some(ExBudget::new( self.blake2b_256.mem.cost([args[0]]), self.blake2b_256.cpu.cost([args[0]]), )), - "verify_ed25519_signature" => Some(ExBudget::new( + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( self.verify_ed25519_signature .mem .cost([args[0], args[1], args[2]]), @@ -726,63 +728,63 @@ impl BuiltinCostsV1 { .cpu .cost([args[0], args[1], args[2]]), )), - "append_string" => Some(ExBudget::new( + DefaultFunction::AppendString => Some(ExBudget::new( self.append_string.mem.cost([args[0], args[1]]), self.append_string.cpu.cost([args[0], args[1]]), )), - "equals_string" => Some(ExBudget::new( + DefaultFunction::EqualsString => Some(ExBudget::new( self.equals_string.mem.cost([args[0], args[1]]), self.equals_string.cpu.cost([args[0], args[1]]), )), - "encode_utf8" => Some(ExBudget::new( + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( self.encode_utf8.mem.cost([args[0]]), self.encode_utf8.cpu.cost([args[0]]), )), - "decode_utf8" => Some(ExBudget::new( + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( self.decode_utf8.mem.cost([args[0]]), self.decode_utf8.cpu.cost([args[0]]), )), - "if_then_else" => Some(ExBudget::new( + 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]]), )), - "choose_unit" => Some(ExBudget::new( + DefaultFunction::ChooseUnit => Some(ExBudget::new( self.choose_unit.mem.cost([args[0], args[1]]), self.choose_unit.cpu.cost([args[0], args[1]]), )), - "trace" => Some(ExBudget::new( + DefaultFunction::Trace => Some(ExBudget::new( self.trace.mem.cost([args[0], args[1]]), self.trace.cpu.cost([args[0], args[1]]), )), - "fst_pair" => Some(ExBudget::new( + DefaultFunction::FstPair => Some(ExBudget::new( self.fst_pair.mem.cost([args[0]]), self.fst_pair.cpu.cost([args[0]]), )), - "snd_pair" => Some(ExBudget::new( + DefaultFunction::SndPair => Some(ExBudget::new( self.snd_pair.mem.cost([args[0]]), self.snd_pair.cpu.cost([args[0]]), )), - "choose_list" => Some(ExBudget::new( + 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]]), )), - "mk_cons" => Some(ExBudget::new( + DefaultFunction::MkCons => Some(ExBudget::new( self.mk_cons.mem.cost([args[0], args[1]]), self.mk_cons.cpu.cost([args[0], args[1]]), )), - "head_list" => Some(ExBudget::new( + DefaultFunction::HeadList => Some(ExBudget::new( self.head_list.mem.cost([args[0]]), self.head_list.cpu.cost([args[0]]), )), - "tail_list" => Some(ExBudget::new( + DefaultFunction::TailList => Some(ExBudget::new( self.tail_list.mem.cost([args[0]]), self.tail_list.cpu.cost([args[0]]), )), - "null_list" => Some(ExBudget::new( + DefaultFunction::NullList => Some(ExBudget::new( self.null_list.mem.cost([args[0]]), self.null_list.cpu.cost([args[0]]), )), - "choose_data" => Some(ExBudget::new( + DefaultFunction::ChooseData => Some(ExBudget::new( self.choose_data .mem .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), @@ -790,59 +792,59 @@ impl BuiltinCostsV1 { .cpu .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), )), - "constr_data" => Some(ExBudget::new( + DefaultFunction::ConstrData => Some(ExBudget::new( self.constr_data.mem.cost([args[0], args[1]]), self.constr_data.cpu.cost([args[0], args[1]]), )), - "map_data" => Some(ExBudget::new( + DefaultFunction::MapData => Some(ExBudget::new( self.map_data.mem.cost([args[0]]), self.map_data.cpu.cost([args[0]]), )), - "list_data" => Some(ExBudget::new( + DefaultFunction::ListData => Some(ExBudget::new( self.list_data.mem.cost([args[0]]), self.list_data.cpu.cost([args[0]]), )), - "i_data" => Some(ExBudget::new( + DefaultFunction::IData => Some(ExBudget::new( self.i_data.mem.cost([args[0]]), self.i_data.cpu.cost([args[0]]), )), - "b_data" => Some(ExBudget::new( + DefaultFunction::BData => Some(ExBudget::new( self.b_data.mem.cost([args[0]]), self.b_data.cpu.cost([args[0]]), )), - "un_constr_data" => Some(ExBudget::new( + DefaultFunction::UnConstrData => Some(ExBudget::new( self.un_constr_data.mem.cost([args[0]]), self.un_constr_data.cpu.cost([args[0]]), )), - "un_map_data" => Some(ExBudget::new( + DefaultFunction::UnMapData => Some(ExBudget::new( self.un_map_data.mem.cost([args[0]]), self.un_map_data.cpu.cost([args[0]]), )), - "un_list_data" => Some(ExBudget::new( + DefaultFunction::UnListData => Some(ExBudget::new( self.un_list_data.mem.cost([args[0]]), self.un_list_data.cpu.cost([args[0]]), )), - "un_i_data" => Some(ExBudget::new( + DefaultFunction::UnIData => Some(ExBudget::new( self.un_i_data.mem.cost([args[0]]), self.un_i_data.cpu.cost([args[0]]), )), - "un_b_data" => Some(ExBudget::new( + DefaultFunction::UnBData => Some(ExBudget::new( self.un_b_data.mem.cost([args[0]]), self.un_b_data.cpu.cost([args[0]]), )), - "equals_data" => Some(ExBudget::new( + DefaultFunction::EqualsData => Some(ExBudget::new( self.equals_data.mem.cost([args[0], args[1]]), self.equals_data.cpu.cost([args[0], args[1]]), )), - "mk_pair_data" => Some(ExBudget::new( + 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]]), )), - "mk_nil_data" => Some(ExBudget::new( + DefaultFunction::MkNilData => Some(ExBudget::new( self.mk_nil_data.mem.cost([args[0]]), self.mk_nil_data.cpu.cost([args[0]]), )), - "mk_nil_pair_data" => Some(ExBudget::new( + DefaultFunction::MkNilPairData => Some(ExBudget::new( self.mk_nil_pair_data.mem.cost([args[0]]), self.mk_nil_pair_data.cpu.cost([args[0]]), )), 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 index 3e3d68d2d..4a148ebfc 100644 --- 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 @@ -1,12 +1,16 @@ -use crate::machine::{ - cost_model::{ - cost_map::CostMap, - costing::{ - Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, - TwoArgumentsCosting, +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, }, + ExBudget, }, - ExBudget, }; #[derive(Debug, PartialEq)] @@ -77,8 +81,8 @@ pub struct BuiltinCostsV2 { serialise_data: OneArgumentCosting, } -impl BuiltinCostsV2 { - pub fn default() -> Self { +impl BuiltinCostModel for BuiltinCostsV2 { + fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size(1, 1), @@ -299,7 +303,7 @@ impl BuiltinCostsV2 { } } - pub fn initialize_builtin_costs(cost_map: &CostMap) -> Self { + fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size( @@ -669,80 +673,78 @@ impl BuiltinCostsV2 { ), } } -} -impl BuiltinCostsV2 { - pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { match builtin { - "add_integer" => Some(ExBudget::new( + DefaultFunction::AddInteger => Some(ExBudget::new( self.add_integer.mem.cost([args[0], args[1]]), self.add_integer.cpu.cost([args[0], args[1]]), )), - "subtract_integer" => Some(ExBudget::new( + DefaultFunction::SubtractInteger => Some(ExBudget::new( self.subtract_integer.mem.cost([args[0], args[1]]), self.subtract_integer.cpu.cost([args[0], args[1]]), )), - "multiply_integer" => Some(ExBudget::new( + DefaultFunction::MultiplyInteger => Some(ExBudget::new( self.multiply_integer.mem.cost([args[0], args[1]]), self.multiply_integer.cpu.cost([args[0], args[1]]), )), - "divide_integer" => Some(ExBudget::new( + DefaultFunction::DivideInteger => Some(ExBudget::new( self.divide_integer.mem.cost([args[0], args[1]]), self.divide_integer.cpu.cost([args[0], args[1]]), )), - "quotient_integer" => Some(ExBudget::new( + DefaultFunction::QuotientInteger => Some(ExBudget::new( self.quotient_integer.mem.cost([args[0], args[1]]), self.quotient_integer.cpu.cost([args[0], args[1]]), )), - "remainder_integer" => Some(ExBudget::new( + DefaultFunction::RemainderInteger => Some(ExBudget::new( self.remainder_integer.mem.cost([args[0], args[1]]), self.remainder_integer.cpu.cost([args[0], args[1]]), )), - "mod_integer" => Some(ExBudget::new( + DefaultFunction::ModInteger => Some(ExBudget::new( self.mod_integer.mem.cost([args[0], args[1]]), self.mod_integer.cpu.cost([args[0], args[1]]), )), - "equals_integer" => Some(ExBudget::new( + DefaultFunction::EqualsInteger => Some(ExBudget::new( self.equals_integer.mem.cost([args[0], args[1]]), self.equals_integer.cpu.cost([args[0], args[1]]), )), - "less_than_integer" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_integer" => Some(ExBudget::new( + 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]]), )), - "append_byte_string" => Some(ExBudget::new( + 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]]), )), - "cons_byte_string" => Some(ExBudget::new( + 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]]), )), - "slice_byte_string" => Some(ExBudget::new( + 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]]), )), - "length_of_byte_string" => Some(ExBudget::new( + DefaultFunction::LengthOfByteString => Some(ExBudget::new( self.length_of_byte_string.mem.cost([args[0]]), self.length_of_byte_string.cpu.cost([args[0]]), )), - "index_byte_string" => Some(ExBudget::new( + 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]]), )), - "equals_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_byte_string" => Some(ExBudget::new( + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( self.less_than_equals_byte_string .mem .cost([args[0], args[1]]), @@ -750,19 +752,19 @@ impl BuiltinCostsV2 { .cpu .cost([args[0], args[1]]), )), - "sha2_256" => Some(ExBudget::new( + DefaultFunction::Sha2_256 => Some(ExBudget::new( self.sha2_256.mem.cost([args[0]]), self.sha2_256.cpu.cost([args[0]]), )), - "sha3_256" => Some(ExBudget::new( + DefaultFunction::Sha3_256 => Some(ExBudget::new( self.sha3_256.mem.cost([args[0]]), self.sha3_256.cpu.cost([args[0]]), )), - "blake2b_256" => Some(ExBudget::new( + DefaultFunction::Blake2b_256 => Some(ExBudget::new( self.blake2b_256.mem.cost([args[0]]), self.blake2b_256.cpu.cost([args[0]]), )), - "verify_ed25519_signature" => Some(ExBudget::new( + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( self.verify_ed25519_signature .mem .cost([args[0], args[1], args[2]]), @@ -770,63 +772,63 @@ impl BuiltinCostsV2 { .cpu .cost([args[0], args[1], args[2]]), )), - "append_string" => Some(ExBudget::new( + DefaultFunction::AppendString => Some(ExBudget::new( self.append_string.mem.cost([args[0], args[1]]), self.append_string.cpu.cost([args[0], args[1]]), )), - "equals_string" => Some(ExBudget::new( + DefaultFunction::EqualsString => Some(ExBudget::new( self.equals_string.mem.cost([args[0], args[1]]), self.equals_string.cpu.cost([args[0], args[1]]), )), - "encode_utf8" => Some(ExBudget::new( + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( self.encode_utf8.mem.cost([args[0]]), self.encode_utf8.cpu.cost([args[0]]), )), - "decode_utf8" => Some(ExBudget::new( + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( self.decode_utf8.mem.cost([args[0]]), self.decode_utf8.cpu.cost([args[0]]), )), - "if_then_else" => Some(ExBudget::new( + 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]]), )), - "choose_unit" => Some(ExBudget::new( + DefaultFunction::ChooseUnit => Some(ExBudget::new( self.choose_unit.mem.cost([args[0], args[1]]), self.choose_unit.cpu.cost([args[0], args[1]]), )), - "trace" => Some(ExBudget::new( + DefaultFunction::Trace => Some(ExBudget::new( self.trace.mem.cost([args[0], args[1]]), self.trace.cpu.cost([args[0], args[1]]), )), - "fst_pair" => Some(ExBudget::new( + DefaultFunction::FstPair => Some(ExBudget::new( self.fst_pair.mem.cost([args[0]]), self.fst_pair.cpu.cost([args[0]]), )), - "snd_pair" => Some(ExBudget::new( + DefaultFunction::SndPair => Some(ExBudget::new( self.snd_pair.mem.cost([args[0]]), self.snd_pair.cpu.cost([args[0]]), )), - "choose_list" => Some(ExBudget::new( + 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]]), )), - "mk_cons" => Some(ExBudget::new( + DefaultFunction::MkCons => Some(ExBudget::new( self.mk_cons.mem.cost([args[0], args[1]]), self.mk_cons.cpu.cost([args[0], args[1]]), )), - "head_list" => Some(ExBudget::new( + DefaultFunction::HeadList => Some(ExBudget::new( self.head_list.mem.cost([args[0]]), self.head_list.cpu.cost([args[0]]), )), - "tail_list" => Some(ExBudget::new( + DefaultFunction::TailList => Some(ExBudget::new( self.tail_list.mem.cost([args[0]]), self.tail_list.cpu.cost([args[0]]), )), - "null_list" => Some(ExBudget::new( + DefaultFunction::NullList => Some(ExBudget::new( self.null_list.mem.cost([args[0]]), self.null_list.cpu.cost([args[0]]), )), - "choose_data" => Some(ExBudget::new( + DefaultFunction::ChooseData => Some(ExBudget::new( self.choose_data .mem .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), @@ -834,63 +836,63 @@ impl BuiltinCostsV2 { .cpu .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), )), - "constr_data" => Some(ExBudget::new( + DefaultFunction::ConstrData => Some(ExBudget::new( self.constr_data.mem.cost([args[0], args[1]]), self.constr_data.cpu.cost([args[0], args[1]]), )), - "map_data" => Some(ExBudget::new( + DefaultFunction::MapData => Some(ExBudget::new( self.map_data.mem.cost([args[0]]), self.map_data.cpu.cost([args[0]]), )), - "list_data" => Some(ExBudget::new( + DefaultFunction::ListData => Some(ExBudget::new( self.list_data.mem.cost([args[0]]), self.list_data.cpu.cost([args[0]]), )), - "i_data" => Some(ExBudget::new( + DefaultFunction::IData => Some(ExBudget::new( self.i_data.mem.cost([args[0]]), self.i_data.cpu.cost([args[0]]), )), - "b_data" => Some(ExBudget::new( + DefaultFunction::BData => Some(ExBudget::new( self.b_data.mem.cost([args[0]]), self.b_data.cpu.cost([args[0]]), )), - "un_constr_data" => Some(ExBudget::new( + DefaultFunction::UnConstrData => Some(ExBudget::new( self.un_constr_data.mem.cost([args[0]]), self.un_constr_data.cpu.cost([args[0]]), )), - "un_map_data" => Some(ExBudget::new( + DefaultFunction::UnMapData => Some(ExBudget::new( self.un_map_data.mem.cost([args[0]]), self.un_map_data.cpu.cost([args[0]]), )), - "un_list_data" => Some(ExBudget::new( + DefaultFunction::UnListData => Some(ExBudget::new( self.un_list_data.mem.cost([args[0]]), self.un_list_data.cpu.cost([args[0]]), )), - "un_i_data" => Some(ExBudget::new( + DefaultFunction::UnIData => Some(ExBudget::new( self.un_i_data.mem.cost([args[0]]), self.un_i_data.cpu.cost([args[0]]), )), - "un_b_data" => Some(ExBudget::new( + DefaultFunction::UnBData => Some(ExBudget::new( self.un_b_data.mem.cost([args[0]]), self.un_b_data.cpu.cost([args[0]]), )), - "equals_data" => Some(ExBudget::new( + DefaultFunction::EqualsData => Some(ExBudget::new( self.equals_data.mem.cost([args[0], args[1]]), self.equals_data.cpu.cost([args[0], args[1]]), )), - "mk_pair_data" => Some(ExBudget::new( + 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]]), )), - "mk_nil_data" => Some(ExBudget::new( + DefaultFunction::MkNilData => Some(ExBudget::new( self.mk_nil_data.mem.cost([args[0]]), self.mk_nil_data.cpu.cost([args[0]]), )), - "mk_nil_pair_data" => Some(ExBudget::new( + DefaultFunction::MkNilPairData => Some(ExBudget::new( self.mk_nil_pair_data.mem.cost([args[0]]), self.mk_nil_pair_data.cpu.cost([args[0]]), )), - "serialise_data" => Some(ExBudget::new( + DefaultFunction::SerialiseData => Some(ExBudget::new( self.serialise_data.mem.cost([args[0]]), self.serialise_data.cpu.cost([args[0]]), )), 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 index 9044aa81a..ac08c825b 100644 --- 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 @@ -1,12 +1,16 @@ -use crate::machine::{ - cost_model::{ - cost_map::CostMap, - costing::{ - Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, - TwoArgumentsCosting, +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::BuiltinCostModel, + cost_map::CostMap, + costing::{ + Cost, OneArgumentCosting, SixArgumentsCosting, ThreeArgumentsCosting, + TwoArgumentsCosting, + }, }, + ExBudget, }, - ExBudget, }; #[derive(Debug, PartialEq)] @@ -118,8 +122,8 @@ pub struct BuiltinCostsV3 { index_array: TwoArgumentsCosting, } -impl BuiltinCostsV3 { - pub fn default() -> Self { +impl BuiltinCostModel for BuiltinCostsV3 { + fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size(1, 1), @@ -502,7 +506,7 @@ impl BuiltinCostsV3 { } } - pub fn initialize_builtin_costs(cost_map: &CostMap) -> Self { + fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( TwoArgumentsCosting::max_size( @@ -1185,80 +1189,78 @@ impl BuiltinCostsV3 { ), } } -} -impl BuiltinCostsV3 { - pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { match builtin { - "add_integer" => Some(ExBudget::new( + DefaultFunction::AddInteger => Some(ExBudget::new( self.add_integer.mem.cost([args[0], args[1]]), self.add_integer.cpu.cost([args[0], args[1]]), )), - "subtract_integer" => Some(ExBudget::new( + DefaultFunction::SubtractInteger => Some(ExBudget::new( self.subtract_integer.mem.cost([args[0], args[1]]), self.subtract_integer.cpu.cost([args[0], args[1]]), )), - "multiply_integer" => Some(ExBudget::new( + DefaultFunction::MultiplyInteger => Some(ExBudget::new( self.multiply_integer.mem.cost([args[0], args[1]]), self.multiply_integer.cpu.cost([args[0], args[1]]), )), - "divide_integer" => Some(ExBudget::new( + DefaultFunction::DivideInteger => Some(ExBudget::new( self.divide_integer.mem.cost([args[0], args[1]]), self.divide_integer.cpu.cost([args[0], args[1]]), )), - "quotient_integer" => Some(ExBudget::new( + DefaultFunction::QuotientInteger => Some(ExBudget::new( self.quotient_integer.mem.cost([args[0], args[1]]), self.quotient_integer.cpu.cost([args[0], args[1]]), )), - "remainder_integer" => Some(ExBudget::new( + DefaultFunction::RemainderInteger => Some(ExBudget::new( self.remainder_integer.mem.cost([args[0], args[1]]), self.remainder_integer.cpu.cost([args[0], args[1]]), )), - "mod_integer" => Some(ExBudget::new( + DefaultFunction::ModInteger => Some(ExBudget::new( self.mod_integer.mem.cost([args[0], args[1]]), self.mod_integer.cpu.cost([args[0], args[1]]), )), - "equals_integer" => Some(ExBudget::new( + DefaultFunction::EqualsInteger => Some(ExBudget::new( self.equals_integer.mem.cost([args[0], args[1]]), self.equals_integer.cpu.cost([args[0], args[1]]), )), - "less_than_integer" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_integer" => Some(ExBudget::new( + 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]]), )), - "append_byte_string" => Some(ExBudget::new( + 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]]), )), - "cons_byte_string" => Some(ExBudget::new( + 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]]), )), - "slice_byte_string" => Some(ExBudget::new( + 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]]), )), - "length_of_byte_string" => Some(ExBudget::new( + DefaultFunction::LengthOfByteString => Some(ExBudget::new( self.length_of_byte_string.mem.cost([args[0]]), self.length_of_byte_string.cpu.cost([args[0]]), )), - "index_byte_string" => Some(ExBudget::new( + 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]]), )), - "equals_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_byte_string" => Some(ExBudget::new( + 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]]), )), - "less_than_equals_byte_string" => Some(ExBudget::new( + DefaultFunction::LessThanEqualsByteString => Some(ExBudget::new( self.less_than_equals_byte_string .mem .cost([args[0], args[1]]), @@ -1266,27 +1268,27 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1]]), )), - "sha2_256" => Some(ExBudget::new( + DefaultFunction::Sha2_256 => Some(ExBudget::new( self.sha2_256.mem.cost([args[0]]), self.sha2_256.cpu.cost([args[0]]), )), - "sha3_256" => Some(ExBudget::new( + DefaultFunction::Sha3_256 => Some(ExBudget::new( self.sha3_256.mem.cost([args[0]]), self.sha3_256.cpu.cost([args[0]]), )), - "blake2b_224" => Some(ExBudget::new( + DefaultFunction::Blake2b_224 => Some(ExBudget::new( self.blake2b_224.mem.cost([args[0]]), self.blake2b_224.cpu.cost([args[0]]), )), - "blake2b_256" => Some(ExBudget::new( + DefaultFunction::Blake2b_256 => Some(ExBudget::new( self.blake2b_256.mem.cost([args[0]]), self.blake2b_256.cpu.cost([args[0]]), )), - "keccak_256" => Some(ExBudget::new( + DefaultFunction::Keccak_256 => Some(ExBudget::new( self.keccak_256.mem.cost([args[0]]), self.keccak_256.cpu.cost([args[0]]), )), - "verify_ed25519_signature" => Some(ExBudget::new( + DefaultFunction::VerifyEd25519Signature => Some(ExBudget::new( self.verify_ed25519_signature .mem .cost([args[0], args[1], args[2]]), @@ -1294,7 +1296,7 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1], args[2]]), )), - "verify_ecdsa_secp256k1_signature" => Some(ExBudget::new( + DefaultFunction::VerifyEcdsaSecp256k1Signature => Some(ExBudget::new( self.verify_ecdsa_secp256k1_signature .mem .cost([args[0], args[1], args[2]]), @@ -1302,7 +1304,7 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1], args[2]]), )), - "verify_schnorr_secp256k1_signature" => Some(ExBudget::new( + DefaultFunction::VerifySchnorrSecp256k1Signature => Some(ExBudget::new( self.verify_schnorr_secp256k1_signature .mem .cost([args[0], args[1], args[2]]), @@ -1310,64 +1312,63 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1], args[2]]), )), - - "append_string" => Some(ExBudget::new( + DefaultFunction::AppendString => Some(ExBudget::new( self.append_string.mem.cost([args[0], args[1]]), self.append_string.cpu.cost([args[0], args[1]]), )), - "equals_string" => Some(ExBudget::new( + DefaultFunction::EqualsString => Some(ExBudget::new( self.equals_string.mem.cost([args[0], args[1]]), self.equals_string.cpu.cost([args[0], args[1]]), )), - "encode_utf8" => Some(ExBudget::new( + DefaultFunction::EncodeUtf8 => Some(ExBudget::new( self.encode_utf8.mem.cost([args[0]]), self.encode_utf8.cpu.cost([args[0]]), )), - "decode_utf8" => Some(ExBudget::new( + DefaultFunction::DecodeUtf8 => Some(ExBudget::new( self.decode_utf8.mem.cost([args[0]]), self.decode_utf8.cpu.cost([args[0]]), )), - "if_then_else" => Some(ExBudget::new( + 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]]), )), - "choose_unit" => Some(ExBudget::new( + DefaultFunction::ChooseUnit => Some(ExBudget::new( self.choose_unit.mem.cost([args[0], args[1]]), self.choose_unit.cpu.cost([args[0], args[1]]), )), - "trace" => Some(ExBudget::new( + DefaultFunction::Trace => Some(ExBudget::new( self.trace.mem.cost([args[0], args[1]]), self.trace.cpu.cost([args[0], args[1]]), )), - "fst_pair" => Some(ExBudget::new( + DefaultFunction::FstPair => Some(ExBudget::new( self.fst_pair.mem.cost([args[0]]), self.fst_pair.cpu.cost([args[0]]), )), - "snd_pair" => Some(ExBudget::new( + DefaultFunction::SndPair => Some(ExBudget::new( self.snd_pair.mem.cost([args[0]]), self.snd_pair.cpu.cost([args[0]]), )), - "choose_list" => Some(ExBudget::new( + 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]]), )), - "mk_cons" => Some(ExBudget::new( + DefaultFunction::MkCons => Some(ExBudget::new( self.mk_cons.mem.cost([args[0], args[1]]), self.mk_cons.cpu.cost([args[0], args[1]]), )), - "head_list" => Some(ExBudget::new( + DefaultFunction::HeadList => Some(ExBudget::new( self.head_list.mem.cost([args[0]]), self.head_list.cpu.cost([args[0]]), )), - "tail_list" => Some(ExBudget::new( + DefaultFunction::TailList => Some(ExBudget::new( self.tail_list.mem.cost([args[0]]), self.tail_list.cpu.cost([args[0]]), )), - "null_list" => Some(ExBudget::new( + DefaultFunction::NullList => Some(ExBudget::new( self.null_list.mem.cost([args[0]]), self.null_list.cpu.cost([args[0]]), )), - "choose_data" => Some(ExBudget::new( + DefaultFunction::ChooseData => Some(ExBudget::new( self.choose_data .mem .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), @@ -1375,135 +1376,135 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1], args[2], args[3], args[4], args[5]]), )), - "constr_data" => Some(ExBudget::new( + DefaultFunction::ConstrData => Some(ExBudget::new( self.constr_data.mem.cost([args[0], args[1]]), self.constr_data.cpu.cost([args[0], args[1]]), )), - "map_data" => Some(ExBudget::new( + DefaultFunction::MapData => Some(ExBudget::new( self.map_data.mem.cost([args[0]]), self.map_data.cpu.cost([args[0]]), )), - "list_data" => Some(ExBudget::new( + DefaultFunction::ListData => Some(ExBudget::new( self.list_data.mem.cost([args[0]]), self.list_data.cpu.cost([args[0]]), )), - "i_data" => Some(ExBudget::new( + DefaultFunction::IData => Some(ExBudget::new( self.i_data.mem.cost([args[0]]), self.i_data.cpu.cost([args[0]]), )), - "b_data" => Some(ExBudget::new( + DefaultFunction::BData => Some(ExBudget::new( self.b_data.mem.cost([args[0]]), self.b_data.cpu.cost([args[0]]), )), - "un_constr_data" => Some(ExBudget::new( + DefaultFunction::UnConstrData => Some(ExBudget::new( self.un_constr_data.mem.cost([args[0]]), self.un_constr_data.cpu.cost([args[0]]), )), - "un_map_data" => Some(ExBudget::new( + DefaultFunction::UnMapData => Some(ExBudget::new( self.un_map_data.mem.cost([args[0]]), self.un_map_data.cpu.cost([args[0]]), )), - "un_list_data" => Some(ExBudget::new( + DefaultFunction::UnListData => Some(ExBudget::new( self.un_list_data.mem.cost([args[0]]), self.un_list_data.cpu.cost([args[0]]), )), - "un_i_data" => Some(ExBudget::new( + DefaultFunction::UnIData => Some(ExBudget::new( self.un_i_data.mem.cost([args[0]]), self.un_i_data.cpu.cost([args[0]]), )), - "un_b_data" => Some(ExBudget::new( + DefaultFunction::UnBData => Some(ExBudget::new( self.un_b_data.mem.cost([args[0]]), self.un_b_data.cpu.cost([args[0]]), )), - "equals_data" => Some(ExBudget::new( + DefaultFunction::EqualsData => Some(ExBudget::new( self.equals_data.mem.cost([args[0], args[1]]), self.equals_data.cpu.cost([args[0], args[1]]), )), - "mk_pair_data" => Some(ExBudget::new( + 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]]), )), - "mk_nil_data" => Some(ExBudget::new( + DefaultFunction::MkNilData => Some(ExBudget::new( self.mk_nil_data.mem.cost([args[0]]), self.mk_nil_data.cpu.cost([args[0]]), )), - "mk_nil_pair_data" => Some(ExBudget::new( + DefaultFunction::MkNilPairData => Some(ExBudget::new( self.mk_nil_pair_data.mem.cost([args[0]]), self.mk_nil_pair_data.cpu.cost([args[0]]), )), - "serialise_data" => Some(ExBudget::new( + DefaultFunction::SerialiseData => Some(ExBudget::new( self.serialise_data.mem.cost([args[0]]), self.serialise_data.cpu.cost([args[0]]), )), - "bls12_381_g1_add" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_neg" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_scalar_mul" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_equal" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_compress" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_uncompress" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g1_hash_to_group" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_add" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_neg" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_scalar_mul" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_equal" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_compress" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_uncompress" => Some(ExBudget::new( + 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]]), )), - "bls12_381_g2_hash_to_group" => Some(ExBudget::new( + 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]]), )), - "bls12_381_miller_loop" => Some(ExBudget::new( + 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]]), )), - "bls12_381_mul_ml_result" => Some(ExBudget::new( + 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]]), )), - "bls12_381_final_verify" => Some(ExBudget::new( + 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]]), )), - "integer_to_byte_string" => Some(ExBudget::new( + DefaultFunction::IntegerToByteString => Some(ExBudget::new( self.integer_to_byte_string .mem .cost([args[0], args[1], args[2]]), @@ -1511,79 +1512,78 @@ impl BuiltinCostsV3 { .cpu .cost([args[0], args[1], args[2]]), )), - "byte_string_to_integer" => Some(ExBudget::new( + 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]]), )), - "and_byte_string" => Some(ExBudget::new( + 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]]), )), - "or_byte_string" => Some(ExBudget::new( + 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]]), )), - "xor_byte_string" => Some(ExBudget::new( + 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]]), )), - "complement_byte_string" => Some(ExBudget::new( + DefaultFunction::ComplementByteString => Some(ExBudget::new( self.complement_byte_string.mem.cost([args[0]]), self.complement_byte_string.cpu.cost([args[0]]), )), - "read_bit" => Some(ExBudget::new( + DefaultFunction::ReadBit => Some(ExBudget::new( self.read_bit.mem.cost([args[0], args[1]]), self.read_bit.cpu.cost([args[0], args[1]]), )), - "write_bits" => Some(ExBudget::new( + 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]]), )), - "replicate_byte" => Some(ExBudget::new( + DefaultFunction::ReplicateByte => Some(ExBudget::new( self.replicate_byte.mem.cost([args[0], args[1]]), self.replicate_byte.cpu.cost([args[0], args[1]]), )), - "shift_byte_string" => Some(ExBudget::new( + 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]]), )), - "rotate_byte_string" => Some(ExBudget::new( + 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]]), )), - "count_set_bits" => Some(ExBudget::new( + DefaultFunction::CountSetBits => Some(ExBudget::new( self.count_set_bits.mem.cost([args[0]]), self.count_set_bits.cpu.cost([args[0]]), )), - "find_first_set_bit" => Some(ExBudget::new( + DefaultFunction::FindFirstSetBit => Some(ExBudget::new( self.find_first_set_bit.mem.cost([args[0]]), self.find_first_set_bit.cpu.cost([args[0]]), )), - "ripemd_160" => Some(ExBudget::new( + DefaultFunction::Ripemd_160 => Some(ExBudget::new( self.ripemd_160.mem.cost([args[0]]), self.ripemd_160.cpu.cost([args[0]]), )), - "exp_mod_integer" => Some(ExBudget::new( + 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]]), )), - "drop_list" => Some(ExBudget::new( + DefaultFunction::DropList => Some(ExBudget::new( self.drop_list.mem.cost([args[0], args[1]]), self.drop_list.cpu.cost([args[0], args[1]]), )), - "length_of_array" => Some(ExBudget::new( + DefaultFunction::LengthOfArray => Some(ExBudget::new( self.length_of_array.mem.cost([args[0]]), self.length_of_array.cpu.cost([args[0]]), )), - "list_to_array" => Some(ExBudget::new( + 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]]), )), - "index_array" => Some(ExBudget::new( + DefaultFunction::IndexArray => Some(ExBudget::new( self.index_array.mem.cost([args[0], args[1]]), self.index_array.cpu.cost([args[0], args[1]]), )), - _ => None, } } } diff --git a/crates/uplc/src/machine/cost_model/builtin_costs.rs b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs similarity index 71% rename from crates/uplc/src/machine/cost_model/builtin_costs.rs rename to crates/uplc/src/machine/cost_model/builtin_costs/mod.rs index a74aab0ea..b5f89e3a2 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs @@ -2,81 +2,78 @@ mod builtin_costs_v1; mod builtin_costs_v2; mod builtin_costs_v3; -use crate::machine::{ - cost_model::{ - builtin_costs::{ - builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, - builtin_costs_v3::BuiltinCostsV3, +use crate::{ + builtin::DefaultFunction, + machine::{ + cost_model::{ + builtin_costs::{ + builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, + builtin_costs_v3::BuiltinCostsV3, + }, + cost_map::CostMap, }, - cost_map::CostMap, + ExBudget, PlutusVersion, }, - ExBudget, PlutusVersion, }; +pub trait BuiltinCostModel { + fn default() -> Self; + fn initialize(cost_map: &CostMap) -> Self; + fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option; +} + #[derive(Debug, PartialEq)] -pub enum BuiltinCostsVersion { - BuiltinCostsV1(BuiltinCostsV1), - BuiltinCostsV2(BuiltinCostsV2), - BuiltinCostsV3(Box), +pub enum CostsVersion { + V1(BuiltinCostsV1), + V2(BuiltinCostsV2), + V3(Box), } #[derive(Debug, PartialEq)] pub struct BuiltinCosts { - builtin_costs: BuiltinCostsVersion, + version: CostsVersion, } impl Default for BuiltinCosts { fn default() -> Self { - BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new(BuiltinCostsV3::default())), - } + Self::v3() } } impl BuiltinCosts { pub fn v1() -> Self { BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV1(BuiltinCostsV1::default()), + version: CostsVersion::V1(BuiltinCostsV1::default()), } } pub fn v2() -> Self { BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV2(BuiltinCostsV2::default()), + version: CostsVersion::V2(BuiltinCostsV2::default()), } } pub fn v3() -> Self { BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new(BuiltinCostsV3::default())), + version: CostsVersion::V3(Box::new(BuiltinCostsV3::default())), } } pub fn initialize_builtin_costs(version: &PlutusVersion, cost_map: &CostMap) -> Self { Self { - builtin_costs: match version { - PlutusVersion::V1 => BuiltinCostsVersion::BuiltinCostsV1( - BuiltinCostsV1::initialize_builtin_costs(cost_map), - ), - PlutusVersion::V2 => BuiltinCostsVersion::BuiltinCostsV2( - BuiltinCostsV2::initialize_builtin_costs(cost_map), - ), - PlutusVersion::V3 => BuiltinCostsVersion::BuiltinCostsV3(Box::new( - BuiltinCostsV3::initialize_builtin_costs(cost_map), - )), + version: match version { + PlutusVersion::V1 => CostsVersion::V1(BuiltinCostsV1::initialize(cost_map)), + PlutusVersion::V2 => CostsVersion::V2(BuiltinCostsV2::initialize(cost_map)), + PlutusVersion::V3 => { + CostsVersion::V3(Box::new(BuiltinCostsV3::initialize(cost_map))) + } }, } } - pub fn get_cost(&self, builtin: &str, args: &[i64]) -> Option { - match &self.builtin_costs { - BuiltinCostsVersion::BuiltinCostsV1(builtin_costs) => { - builtin_costs.get_cost(builtin, args) - } - BuiltinCostsVersion::BuiltinCostsV2(builtin_costs) => { - builtin_costs.get_cost(builtin, args) - } - BuiltinCostsVersion::BuiltinCostsV3(builtin_costs) => { - builtin_costs.get_cost(builtin, args) - } + pub fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { + match &self.version { + CostsVersion::V1(costs) => costs.get_cost(builtin, args), + CostsVersion::V2(costs) => costs.get_cost(builtin, args), + CostsVersion::V3(costs) => costs.get_cost(builtin, args), } } } @@ -106,7 +103,7 @@ mod tests { assert_eq!( BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV1(BuiltinCostsV1::default()) + version: CostsVersion::V1(BuiltinCostsV1::default()) }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V1, &cost_model) ); @@ -132,7 +129,7 @@ mod tests { assert_eq!( BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV2(BuiltinCostsV2::default()) + version: CostsVersion::V2(BuiltinCostsV2::default()) }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V2, &cost_model) ); @@ -167,9 +164,7 @@ mod tests { assert_eq!( BuiltinCosts { - builtin_costs: BuiltinCostsVersion::BuiltinCostsV3(Box::new( - BuiltinCostsV3::default() - )) + version: CostsVersion::V3(Box::new(BuiltinCostsV3::default())) }, BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V3, &cost_model) ); diff --git a/crates/uplc/src/machine/runtime.rs b/crates/uplc/src/machine/runtime.rs index 9e5bea204..edb63cde1 100644 --- a/crates/uplc/src/machine/runtime.rs +++ b/crates/uplc/src/machine/runtime.rs @@ -114,7 +114,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "add_integer", + DefaultFunction::AddInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -139,7 +139,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "subtract_integer", + DefaultFunction::SubtractInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -165,7 +165,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "equals_integer", + DefaultFunction::EqualsInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -189,7 +189,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "less_than_equals_integer", + DefaultFunction::LessThanEqualsInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -213,7 +213,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "append_byte_string", + DefaultFunction::AppendByteString, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -242,7 +242,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "equals_byte_string", + DefaultFunction::EqualsByteString, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -266,7 +266,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "if_then_else", + DefaultFunction::IfThenElse, &[ cost_model::BOOL_EX_MEM, cost_model::value_ex_mem(arg2), @@ -290,7 +290,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "multiply_integer", + DefaultFunction::MultiplyInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -316,7 +316,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "divide_integer", + DefaultFunction::DivideInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -346,7 +346,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "quotient_integer", + DefaultFunction::QuotientInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -373,7 +373,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "remainder_integer", + DefaultFunction::RemainderInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -400,7 +400,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "mod_integer", + DefaultFunction::ModInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -428,7 +428,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "less_than_integer", + DefaultFunction::LessThanInteger, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -452,7 +452,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "cons_byte_string", + DefaultFunction::ConsByteString, &[ cost_model::integer_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -498,7 +498,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "slice_byte_string", + DefaultFunction::SliceByteString, &[ cost_model::integer_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -542,7 +542,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "length_of_byte_string", + DefaultFunction::LengthOfByteString, &[cost_model::byte_string_ex_mem(arg1)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -564,7 +564,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "index_byte_string", + DefaultFunction::IndexByteString, &[ cost_model::byte_string_ex_mem(arg1), cost_model::integer_ex_mem(arg2), @@ -594,7 +594,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "less_than_byte_string", + DefaultFunction::LessThanByteString, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -618,7 +618,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "less_than_equals_byte_string", + DefaultFunction::LessThanEqualsByteString, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -642,7 +642,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -673,7 +676,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -704,7 +710,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -734,7 +743,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -765,7 +777,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -798,7 +813,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "verify_ed25519_signature", + DefaultFunction::VerifyEd25519Signature, &[ cost_model::byte_string_ex_mem(public_key), cost_model::byte_string_ex_mem(message), @@ -836,7 +851,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "verify_ecdsa_secp256k1_signature", + DefaultFunction::VerifyEcdsaSecp256k1Signature, &[ cost_model::byte_string_ex_mem(public_key), cost_model::byte_string_ex_mem(message), @@ -875,7 +890,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "verify_schnorr_secp256k1_signature", + DefaultFunction::VerifySchnorrSecp256k1Signature, &[ cost_model::byte_string_ex_mem(public_key), cost_model::byte_string_ex_mem(message), @@ -908,7 +923,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "append_string", + DefaultFunction::AppendString, &[ cost_model::string_ex_mem(arg1), cost_model::string_ex_mem(arg2), @@ -937,7 +952,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "equals_string", + DefaultFunction::EqualsString, &[ cost_model::string_ex_mem(arg1), cost_model::string_ex_mem(arg2), @@ -957,7 +972,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -980,7 +998,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -999,7 +1020,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "choose_unit", + DefaultFunction::ChooseUnit, &[cost_model::UNIT_EX_MEM, cost_model::value_ex_mem(arg2)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -1016,7 +1037,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "trace", + DefaultFunction::Trace, &[ cost_model::string_ex_mem(arg1), cost_model::value_ex_mem(arg2), @@ -1036,7 +1057,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1051,7 +1075,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1069,7 +1096,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "choose_list", + DefaultFunction::ChooseList, &[ cost_model::proto_list_ex_mem(list), cost_model::value_ex_mem(arg2), @@ -1094,7 +1121,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "mk_cons", + DefaultFunction::MkCons, &[ cost_model::constant_ex_mem(item), cost_model::proto_list_ex_mem(list), @@ -1128,7 +1155,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1147,7 +1177,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1168,7 +1201,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1189,7 +1225,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "choose_data", + DefaultFunction::ChooseData, &[ cost_model::data_ex_mem(arg1), cost_model::value_ex_mem(arg2), @@ -1219,7 +1255,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "constr_data", + DefaultFunction::ConstrData, &[ cost_model::integer_ex_mem(tag), cost_model::proto_list_ex_mem(fields), @@ -1271,7 +1307,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1308,7 +1347,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1341,7 +1383,7 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1358,7 +1400,7 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1378,7 +1420,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1410,7 +1455,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1448,7 +1496,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1474,7 +1525,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1492,7 +1546,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1509,7 +1566,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "equals_data", + DefaultFunction::EqualsData, &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -1529,7 +1586,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "mk_pair_data", + DefaultFunction::MkPairData, &[cost_model::data_ex_mem(d1), cost_model::data_ex_mem(d2)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -1554,7 +1611,7 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1574,7 +1631,7 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1600,7 +1657,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g1_add", + DefaultFunction::Bls12_381_G1_Add, &[ cost_model::g1_element_ex_mem(), cost_model::g1_element_ex_mem(), @@ -1628,7 +1685,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1654,7 +1714,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g1_scalar_mul", + DefaultFunction::Bls12_381_G1_ScalarMul, &[ cost_model::integer_ex_mem(arg1), cost_model::g1_element_ex_mem(), @@ -1707,7 +1767,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g1_equal", + DefaultFunction::Bls12_381_G1_Equal, &[ cost_model::g1_element_ex_mem(), cost_model::g1_element_ex_mem(), @@ -1729,7 +1789,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1747,7 +1810,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g1_uncompress", + DefaultFunction::Bls12_381_G1_Uncompress, &[cost_model::byte_string_ex_mem(arg1)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -1770,7 +1833,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g1_hash_to_group", + DefaultFunction::Bls12_381_G1_HashToGroup, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -1813,7 +1876,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g2_add", + DefaultFunction::Bls12_381_G2_Add, &[ cost_model::g2_element_ex_mem(), cost_model::g2_element_ex_mem(), @@ -1841,7 +1904,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1867,7 +1933,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g2_scalar_mul", + DefaultFunction::Bls12_381_G2_ScalarMul, &[ cost_model::integer_ex_mem(arg1), cost_model::g2_element_ex_mem(), @@ -1924,7 +1990,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g2_equal", + DefaultFunction::Bls12_381_G2_Equal, &[ cost_model::g2_element_ex_mem(), cost_model::g2_element_ex_mem(), @@ -1946,7 +2012,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -1964,7 +2033,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g2_uncompress", + DefaultFunction::Bls12_381_G2_Uncompress, &[cost_model::byte_string_ex_mem(arg1)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -1987,7 +2056,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_g2_hash_to_group", + DefaultFunction::Bls12_381_G2_HashToGroup, &[ cost_model::byte_string_ex_mem(arg1), cost_model::byte_string_ex_mem(arg2), @@ -2030,7 +2099,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_miller_loop", + DefaultFunction::Bls12_381_MillerLoop, &[ cost_model::g1_element_ex_mem(), cost_model::g2_element_ex_mem(), @@ -2066,7 +2135,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_mul_ml_result", + DefaultFunction::Bls12_381_MulMlResult, &[ cost_model::ml_result_ex_mem(), cost_model::ml_result_ex_mem(), @@ -2096,7 +2165,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "bls12_381_final_verify", + DefaultFunction::Bls12_381_FinalVerify, &[ cost_model::ml_result_ex_mem(), cost_model::ml_result_ex_mem(), @@ -2136,7 +2205,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "integer_to_byte_string", + DefaultFunction::IntegerToByteString, &[ cost_model::BOOL_EX_MEM, arg1_exmem, @@ -2235,7 +2304,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "byte_string_to_integer", + DefaultFunction::ByteStringToInteger, &[ cost_model::BOOL_EX_MEM, cost_model::byte_string_ex_mem(bytes), @@ -2266,7 +2335,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "and_byte_string", + DefaultFunction::AndByteString, &[ cost_model::BOOL_EX_MEM, cost_model::byte_string_ex_mem(left_bytes), @@ -2306,7 +2375,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "or_byte_string", + DefaultFunction::OrByteString, &[ cost_model::BOOL_EX_MEM, cost_model::byte_string_ex_mem(left_bytes), @@ -2348,7 +2417,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "or_byte_string", + DefaultFunction::OrByteString, &[ cost_model::BOOL_EX_MEM, cost_model::byte_string_ex_mem(left_bytes), @@ -2388,7 +2457,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "complement_byte_string", + DefaultFunction::ComplementByteString, &[cost_model::byte_string_ex_mem(bytes)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -2408,7 +2477,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "read_bit", + DefaultFunction::ReadBit, &[ cost_model::byte_string_ex_mem(bytes), cost_model::integer_ex_mem(bit_index), @@ -2448,7 +2517,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "write_bits", + DefaultFunction::WriteBits, &[ cost_model::byte_string_ex_mem(bytes.as_slice()), cost_model::proto_list_ex_mem(indices), @@ -2510,7 +2579,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "replicate_byte", + DefaultFunction::ReplicateByte, &[arg0_ex_mem, cost_model::integer_ex_mem(byte)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -2560,7 +2629,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "shift_byte_string", + DefaultFunction::ShiftByteString, &[cost_model::byte_string_ex_mem(bytes), arg1], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -2651,7 +2720,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "rotate_byte_string", + DefaultFunction::RotateByteString, &[cost_model::byte_string_ex_mem(bytes), arg1], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -2718,7 +2787,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -2733,7 +2805,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "find_first_set_bit", + DefaultFunction::FindFirstSetBit, &[cost_model::byte_string_ex_mem(bytes)], ) .ok_or(MachineError::UnknownBuiltinFunction)?; @@ -2763,7 +2835,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -2783,7 +2858,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "exp_mod_integer", + DefaultFunction::ExpModInteger, &[ cost_model::integer_ex_mem(base), cost_model::integer_ex_mem(exponent), @@ -2821,7 +2896,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -2855,7 +2933,10 @@ impl<'a> Machine<'a> { let budget = self .costs .builtin_costs - .get_cost("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)?; @@ -2873,7 +2954,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "list_to_array", + DefaultFunction::ListToArray, &[ cost_model::proto_list_ex_mem(list), cost_model::proto_list_ex_mem(list), @@ -2897,7 +2978,7 @@ impl<'a> Machine<'a> { .costs .builtin_costs .get_cost( - "index_array", + DefaultFunction::IndexArray, &[ cost_model::proto_list_ex_mem(array), cost_model::integer_ex_mem(arg1), From 48bdd7b09ff41989268a883218e4f834f83b39f1 Mon Sep 17 00:00:00 2001 From: yHSJ Date: Mon, 10 Nov 2025 19:17:22 -0600 Subject: [PATCH 9/9] chore: use generics to remove simplify builtin costs usage Signed-off-by: yHSJ --- crates/uplc/src/flat/data.rs | 13 +-- crates/uplc/src/flat/decode/mod.rs | 2 +- crates/uplc/src/flat/encode/mod.rs | 6 +- crates/uplc/src/machine/cek.rs | 13 ++- .../builtin_costs/builtin_costs_v1.rs | 5 +- .../builtin_costs/builtin_costs_v2.rs | 5 +- .../builtin_costs/builtin_costs_v3.rs | 4 +- .../machine/cost_model/builtin_costs/mod.rs | 100 ++++-------------- crates/uplc/src/machine/cost_model/mod.rs | 25 ++--- crates/uplc/src/machine/runtime.rs | 3 +- crates/uplc/src/program.rs | 68 ++++++++---- 11 files changed, 106 insertions(+), 138 deletions(-) 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 c52ddebc9..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 { 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 index c384838bb..e8bd83d44 100644 --- 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 @@ -78,7 +78,7 @@ pub struct BuiltinCostsV1 { mk_nil_pair_data: OneArgumentCosting, } -impl BuiltinCostModel for BuiltinCostsV1 { +impl Default for BuiltinCostsV1 { fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( @@ -287,6 +287,9 @@ impl BuiltinCostModel for BuiltinCostsV1 { ), } } +} + +impl BuiltinCostModel for BuiltinCostsV1 { fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( 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 index 4a148ebfc..cea2eb324 100644 --- 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 @@ -81,7 +81,7 @@ pub struct BuiltinCostsV2 { serialise_data: OneArgumentCosting, } -impl BuiltinCostModel for BuiltinCostsV2 { +impl Default for BuiltinCostsV2 { fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( @@ -302,7 +302,8 @@ impl BuiltinCostModel for BuiltinCostsV2 { ), } } - +} +impl BuiltinCostModel for BuiltinCostsV2 { fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( 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 index ac08c825b..284892e65 100644 --- 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 @@ -122,7 +122,7 @@ pub struct BuiltinCostsV3 { index_array: TwoArgumentsCosting, } -impl BuiltinCostModel for BuiltinCostsV3 { +impl Default for BuiltinCostsV3 { fn default() -> Self { Self { add_integer: TwoArgumentsCosting::new( @@ -505,7 +505,9 @@ impl BuiltinCostModel for BuiltinCostsV3 { ), } } +} +impl BuiltinCostModel for BuiltinCostsV3 { fn initialize(cost_map: &CostMap) -> Self { Self { add_integer: TwoArgumentsCosting::new( diff --git a/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs index b5f89e3a2..641d6483f 100644 --- a/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs +++ b/crates/uplc/src/machine/cost_model/builtin_costs/mod.rs @@ -1,85 +1,27 @@ -mod builtin_costs_v1; -mod builtin_costs_v2; -mod builtin_costs_v3; +pub mod builtin_costs_v1; +pub mod builtin_costs_v2; +pub mod builtin_costs_v3; use crate::{ builtin::DefaultFunction, - machine::{ - cost_model::{ - builtin_costs::{ - builtin_costs_v1::BuiltinCostsV1, builtin_costs_v2::BuiltinCostsV2, - builtin_costs_v3::BuiltinCostsV3, - }, - cost_map::CostMap, - }, - ExBudget, PlutusVersion, - }, + machine::{cost_model::cost_map::CostMap, ExBudget}, }; pub trait BuiltinCostModel { - fn default() -> Self; fn initialize(cost_map: &CostMap) -> Self; fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option; } -#[derive(Debug, PartialEq)] -pub enum CostsVersion { - V1(BuiltinCostsV1), - V2(BuiltinCostsV2), - V3(Box), -} - -#[derive(Debug, PartialEq)] -pub struct BuiltinCosts { - version: CostsVersion, -} - -impl Default for BuiltinCosts { - fn default() -> Self { - Self::v3() - } -} - -impl BuiltinCosts { - pub fn v1() -> Self { - BuiltinCosts { - version: CostsVersion::V1(BuiltinCostsV1::default()), - } - } - pub fn v2() -> Self { - BuiltinCosts { - version: CostsVersion::V2(BuiltinCostsV2::default()), - } - } - pub fn v3() -> Self { - BuiltinCosts { - version: CostsVersion::V3(Box::new(BuiltinCostsV3::default())), - } - } - - pub fn initialize_builtin_costs(version: &PlutusVersion, cost_map: &CostMap) -> Self { - Self { - version: match version { - PlutusVersion::V1 => CostsVersion::V1(BuiltinCostsV1::initialize(cost_map)), - PlutusVersion::V2 => CostsVersion::V2(BuiltinCostsV2::initialize(cost_map)), - PlutusVersion::V3 => { - CostsVersion::V3(Box::new(BuiltinCostsV3::initialize(cost_map))) - } - }, - } - } - - pub fn get_cost(&self, builtin: DefaultFunction, args: &[i64]) -> Option { - match &self.version { - CostsVersion::V1(costs) => costs.get_cost(builtin, args), - CostsVersion::V2(costs) => costs.get_cost(builtin, args), - CostsVersion::V3(costs) => costs.get_cost(builtin, args), - } - } -} - #[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; @@ -102,10 +44,8 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V1, &costs); assert_eq!( - BuiltinCosts { - version: CostsVersion::V1(BuiltinCostsV1::default()) - }, - BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V1, &cost_model) + BuiltinCostsV1::default(), + BuiltinCostsV1::initialize(&cost_model) ); } @@ -128,10 +68,8 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V2, &costs); assert_eq!( - BuiltinCosts { - version: CostsVersion::V2(BuiltinCostsV2::default()) - }, - BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V2, &cost_model) + BuiltinCostsV2::default(), + BuiltinCostsV2::initialize(&cost_model) ); } @@ -163,10 +101,8 @@ mod tests { let cost_model = CostMap::new(&PlutusVersion::V3, &costs); assert_eq!( - BuiltinCosts { - version: CostsVersion::V3(Box::new(BuiltinCostsV3::default())) - }, - BuiltinCosts::initialize_builtin_costs(&PlutusVersion::V3, &cost_model) + BuiltinCostsV3::default(), + BuiltinCostsV3::initialize(&cost_model) ); } } diff --git a/crates/uplc/src/machine/cost_model/mod.rs b/crates/uplc/src/machine/cost_model/mod.rs index dad161dcb..5cf1482e6 100644 --- a/crates/uplc/src/machine/cost_model/mod.rs +++ b/crates/uplc/src/machine/cost_model/mod.rs @@ -8,19 +8,19 @@ mod value; pub use value::*; use crate::machine::{ - cost_model::{builtin_costs::BuiltinCosts, machine_costs::MachineCosts}, + cost_model::{builtin_costs::BuiltinCostModel, machine_costs::MachineCosts}, ExBudget, PlutusVersion, }; -#[derive(Default, Debug, PartialEq)] -pub struct CostModel { +#[derive(Debug, PartialEq)] +pub struct CostModel { pub machine_startup: ExBudget, pub machine_costs: MachineCosts, - pub builtin_costs: BuiltinCosts, + pub builtin_costs: B, } -impl CostModel { - pub fn initialize_cost_model(version: &PlutusVersion, cost_model: &[i64]) -> CostModel { +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 { @@ -28,22 +28,17 @@ impl CostModel { cpu: cost_map["cek_startup_cost-exBudgetCPU"], }, machine_costs: MachineCosts::initialize_machine_costs(&cost_map), - builtin_costs: BuiltinCosts::initialize_builtin_costs(version, &cost_map), + builtin_costs: B::initialize(&cost_map), } } } -impl From<&PlutusVersion> for CostModel { - fn from(version: &PlutusVersion) -> Self { - let builtin_costs = match version { - crate::machine::PlutusVersion::V1 => BuiltinCosts::v1(), - crate::machine::PlutusVersion::V2 => BuiltinCosts::v2(), - crate::machine::PlutusVersion::V3 => BuiltinCosts::v3(), - }; +impl Default for CostModel { + fn default() -> Self { Self { machine_startup: ExBudget::start_up(), machine_costs: Default::default(), - builtin_costs, + builtin_costs: Default::default(), } } } diff --git a/crates/uplc/src/machine/runtime.rs b/crates/uplc/src/machine/runtime.rs index edb63cde1..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>, diff --git a/crates/uplc/src/program.rs b/crates/uplc/src/program.rs index 31d2dbf69..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,19 +45,41 @@ 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::from(&plutus_version), + 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 } } @@ -61,19 +89,23 @@ where plutus_version: PlutusVersion, cost_model: &[i64], ) -> EvalResult<'a, V> { - let mut machine = Machine::new( - arena, - ExBudget::default(), - CostModel::initialize_cost_model(&plutus_version, 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 } + 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, + ), + } } }