From 472cea6c41463b4ce872dd6845590257f9664353 Mon Sep 17 00:00:00 2001 From: Kasey White Date: Sat, 17 Sep 2022 21:12:48 -0400 Subject: [PATCH] parameratize cost model --- crates/cli/src/main.rs | 2 +- crates/uplc/src/ast.rs | 32 +- crates/uplc/src/machine.rs | 17 +- crates/uplc/src/machine/cost_model.rs | 1650 +++++++++++++++++++++- crates/uplc/src/machine/runtime.rs | 8 +- crates/uplc/src/transaction_eval.rs | 475 ++++++- crates/uplc/src/transaction_eval/eval.rs | 10 +- 7 files changed, 2143 insertions(+), 51 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 54d4cb3c..63c0c6c3 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -52,7 +52,7 @@ fn main() -> anyhow::Result<()> { slot_length, }; - eval_tx(tx_babbage, &resolved_inputs, &slot_config)?; + // eval_tx(tx_babbage, &resolved_inputs, &slot_config)?; } } }, diff --git a/crates/uplc/src/ast.rs b/crates/uplc/src/ast.rs index 55a38ae6..b8fb7ab3 100644 --- a/crates/uplc/src/ast.rs +++ b/crates/uplc/src/ast.rs @@ -1,13 +1,13 @@ use std::{fmt::Display, rc::Rc}; -use pallas_primitives::alonzo::PlutusData; +use pallas_primitives::{alonzo::PlutusData, babbage::Language}; use crate::{ builtins::DefaultFunction, debruijn::{self, Converter}, flat::Binder, machine::{ - cost_model::{CostModel, ExBudget}, + cost_model::{initialize_cost_model, CostModel, ExBudget}, Machine, }, }; @@ -488,7 +488,33 @@ impl Program { ExBudget, Vec, ) { - let mut machine = Machine::new(CostModel::default(), ExBudget::default(), 200); + let mut machine = Machine::new( + Language::PlutusV2, + CostModel::default(), + ExBudget::default(), + 200, + ); + + let term = machine.run(&self.term); + + (term, machine.ex_budget, machine.logs) + } + + pub fn eval_with_params( + &self, + version: &Language, + costs: &[i64], + ) -> ( + Result, crate::machine::Error>, + ExBudget, + Vec, + ) { + let mut machine = Machine::new( + version.clone(), + initialize_cost_model(version, costs), + ExBudget::default(), + 200, //slippage + ); let term = machine.run(&self.term); diff --git a/crates/uplc/src/machine.rs b/crates/uplc/src/machine.rs index 07f5c346..e03e12e1 100644 --- a/crates/uplc/src/machine.rs +++ b/crates/uplc/src/machine.rs @@ -11,7 +11,7 @@ mod runtime; use cost_model::{ExBudget, StepKind}; pub use error::Error; -use pallas_primitives::babbage::{BigInt, PlutusData}; +use pallas_primitives::babbage::{BigInt, Language, PlutusData}; use self::{cost_model::CostModel, runtime::BuiltinRuntime}; @@ -39,10 +39,16 @@ pub struct Machine { unbudgeted_steps: [u32; 8], pub logs: Vec, stack: Vec, + version: Language, } impl Machine { - pub fn new(costs: CostModel, initial_budget: ExBudget, slippage: u32) -> Machine { + pub fn new( + version: Language, + costs: CostModel, + initial_budget: ExBudget, + slippage: u32, + ) -> Machine { Machine { costs, ex_budget: initial_budget, @@ -50,6 +56,7 @@ impl Machine { unbudgeted_steps: [0; 8], logs: vec![], stack: vec![], + version, } } @@ -347,8 +354,10 @@ impl Machine { runtime: BuiltinRuntime, ) -> Result { if runtime.is_ready() { - let cost = runtime.to_ex_budget(&self.costs.builtin_costs); - + let cost = match self.version { + Language::PlutusV1 => runtime.to_ex_budget_v1(&self.costs.builtin_costs), + Language::PlutusV2 => runtime.to_ex_budget_v2(&self.costs.builtin_costs), + }; self.spend_budget(cost)?; runtime.call(&mut self.logs) diff --git a/crates/uplc/src/machine/cost_model.rs b/crates/uplc/src/machine/cost_model.rs index 78ddcf42..1aa095d9 100644 --- a/crates/uplc/src/machine/cost_model.rs +++ b/crates/uplc/src/machine/cost_model.rs @@ -1,7 +1,22 @@ +use std::collections::HashMap; + +use pallas_primitives::babbage::Language; + use crate::builtins::DefaultFunction; use super::Value; +macro_rules! hashmap { + // map-like + ($($k:expr => $v:expr),* $(,)?) => {{ + core::convert::From::from([$(($k, $v),)*]) + }}; + // set-like + ($($v:expr),* $(,)?) => {{ + core::convert::From::from([$($v,)*]) + }}; +} + /// Can be negative #[derive(Debug, Clone, PartialEq, Eq, Copy)] pub struct ExBudget { @@ -364,14 +379,14 @@ impl Default for BuiltinCosts { }), }, verify_ecdsa_secp256k1_signature: CostingFun { - mem: ThreeArguments::ConstantCost(10), - cpu: ThreeArguments::ConstantCost(35190005), + mem: ThreeArguments::ConstantCost(20000000000), + cpu: ThreeArguments::ConstantCost(20000000000), }, verify_schnorr_secp256k1_signature: CostingFun { - mem: ThreeArguments::ConstantCost(10), + mem: ThreeArguments::ConstantCost(20000000000), cpu: ThreeArguments::LinearInY(LinearSize { - intercept: 39121781, - slope: 32260, + intercept: 20000000000, + slope: 0, }), }, append_string: CostingFun { @@ -530,7 +545,7 @@ impl Default for BuiltinCosts { } impl BuiltinCosts { - pub fn to_ex_budget(&self, fun: DefaultFunction, args: &[Value]) -> ExBudget { + pub fn to_ex_budget_v2(&self, fun: DefaultFunction, args: &[Value]) -> ExBudget { match fun { DefaultFunction::AddInteger => ExBudget { mem: self @@ -934,6 +949,1629 @@ impl BuiltinCosts { }, } } + + pub fn to_ex_budget_v1(&self, fun: DefaultFunction, args: &[Value]) -> ExBudget { + match fun { + DefaultFunction::AddInteger => ExBudget { + mem: self + .add_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .add_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::SubtractInteger => ExBudget { + mem: self + .subtract_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .subtract_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::MultiplyInteger => ExBudget { + mem: self + .multiply_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .multiply_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::DivideInteger => ExBudget { + mem: self + .divide_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .divide_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::QuotientInteger => ExBudget { + mem: self + .quotient_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .quotient_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::RemainderInteger => ExBudget { + mem: self + .remainder_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .remainder_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::ModInteger => ExBudget { + mem: self + .mod_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .mod_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::EqualsInteger => ExBudget { + mem: self + .equals_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .equals_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::LessThanInteger => ExBudget { + mem: self + .less_than_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .less_than_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::LessThanEqualsInteger => ExBudget { + mem: self + .less_than_equals_integer + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .less_than_equals_integer + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::AppendByteString => ExBudget { + mem: self + .append_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .append_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::ConsByteString => ExBudget { + mem: self + .cons_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .cons_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::SliceByteString => ExBudget { + mem: self.slice_byte_string.mem.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + cpu: self.slice_byte_string.cpu.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + }, + DefaultFunction::LengthOfByteString => ExBudget { + mem: self.length_of_byte_string.mem.cost(args[0].to_ex_mem()), + cpu: self.length_of_byte_string.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::IndexByteString => ExBudget { + mem: self + .index_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .index_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::EqualsByteString => ExBudget { + mem: self + .equals_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .equals_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::LessThanByteString => ExBudget { + mem: self + .less_than_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .less_than_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::LessThanEqualsByteString => ExBudget { + mem: self + .less_than_equals_byte_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .less_than_equals_byte_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::Sha2_256 => ExBudget { + mem: self.sha2_256.mem.cost(args[0].to_ex_mem()), + cpu: self.sha2_256.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::Sha3_256 => ExBudget { + mem: self.sha3_256.mem.cost(args[0].to_ex_mem()), + cpu: self.sha3_256.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::Blake2b_256 => ExBudget { + mem: self.blake2b_256.mem.cost(args[0].to_ex_mem()), + cpu: self.blake2b_256.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::VerifyEd25519Signature => ExBudget { + mem: self.verify_ed25519_signature.mem.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + cpu: self.verify_ed25519_signature.cpu.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + }, + DefaultFunction::VerifyEcdsaSecp256k1Signature => unreachable!(), + DefaultFunction::VerifySchnorrSecp256k1Signature => unreachable!(), + DefaultFunction::AppendString => ExBudget { + mem: self + .append_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .append_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::EqualsString => ExBudget { + mem: self + .equals_string + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .equals_string + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::EncodeUtf8 => ExBudget { + mem: self.encode_utf8.mem.cost(args[0].to_ex_mem()), + cpu: self.encode_utf8.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::DecodeUtf8 => ExBudget { + mem: self.decode_utf8.mem.cost(args[0].to_ex_mem()), + cpu: self.decode_utf8.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::IfThenElse => ExBudget { + mem: self.if_then_else.mem.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + cpu: self.if_then_else.cpu.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + }, + DefaultFunction::ChooseUnit => ExBudget { + mem: self + .choose_unit + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .choose_unit + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::Trace => ExBudget { + mem: self + .trace + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .trace + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::FstPair => ExBudget { + mem: self.fst_pair.mem.cost(args[0].to_ex_mem()), + cpu: self.fst_pair.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::SndPair => ExBudget { + mem: self.snd_pair.mem.cost(args[0].to_ex_mem()), + cpu: self.snd_pair.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::ChooseList => ExBudget { + mem: self.choose_list.mem.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + cpu: self.choose_list.cpu.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + ), + }, + DefaultFunction::MkCons => ExBudget { + mem: self + .mk_cons + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .mk_cons + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::HeadList => ExBudget { + mem: self.head_list.mem.cost(args[0].to_ex_mem()), + cpu: self.head_list.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::TailList => ExBudget { + mem: self.tail_list.mem.cost(args[0].to_ex_mem()), + cpu: self.tail_list.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::NullList => ExBudget { + mem: self.null_list.mem.cost(args[0].to_ex_mem()), + cpu: self.null_list.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::ChooseData => ExBudget { + mem: self.choose_data.mem.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + args[3].to_ex_mem(), + args[4].to_ex_mem(), + args[5].to_ex_mem(), + ), + cpu: self.choose_data.cpu.cost( + args[0].to_ex_mem(), + args[1].to_ex_mem(), + args[2].to_ex_mem(), + args[3].to_ex_mem(), + args[4].to_ex_mem(), + args[5].to_ex_mem(), + ), + }, + DefaultFunction::ConstrData => ExBudget { + mem: self + .constr_data + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .constr_data + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::MapData => ExBudget { + mem: self.map_data.mem.cost(args[0].to_ex_mem()), + cpu: self.map_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::ListData => ExBudget { + mem: self.list_data.mem.cost(args[0].to_ex_mem()), + cpu: self.list_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::IData => ExBudget { + mem: self.i_data.mem.cost(args[0].to_ex_mem()), + cpu: self.i_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::BData => ExBudget { + mem: self.b_data.mem.cost(args[0].to_ex_mem()), + cpu: self.b_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::UnConstrData => ExBudget { + mem: self.un_constr_data.mem.cost(args[0].to_ex_mem()), + cpu: self.un_constr_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::UnMapData => ExBudget { + mem: self.un_map_data.mem.cost(args[0].to_ex_mem()), + cpu: self.un_map_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::UnListData => ExBudget { + mem: self.un_list_data.mem.cost(args[0].to_ex_mem()), + cpu: self.un_list_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::UnIData => ExBudget { + mem: self.un_i_data.mem.cost(args[0].to_ex_mem()), + cpu: self.un_i_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::UnBData => ExBudget { + mem: self.un_b_data.mem.cost(args[0].to_ex_mem()), + cpu: self.un_b_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::EqualsData => ExBudget { + mem: self + .equals_data + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .equals_data + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::SerialiseData => unreachable!(), + DefaultFunction::MkPairData => ExBudget { + mem: self + .mk_pair_data + .mem + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + cpu: self + .mk_pair_data + .cpu + .cost(args[0].to_ex_mem(), args[1].to_ex_mem()), + }, + DefaultFunction::MkNilData => ExBudget { + mem: self.mk_nil_data.mem.cost(args[0].to_ex_mem()), + cpu: self.mk_nil_data.cpu.cost(args[0].to_ex_mem()), + }, + DefaultFunction::MkNilPairData => ExBudget { + mem: self.mk_nil_pair_data.mem.cost(args[0].to_ex_mem()), + cpu: self.mk_nil_pair_data.cpu.cost(args[0].to_ex_mem()), + }, + } + } +} + +pub fn initialize_cost_model(version: &Language, costs: &[i64]) -> CostModel { + let cost_map: HashMap<&str, i64> = match version { + Language::PlutusV1 => { + hashmap! { + "add_integer-cpu-arguments-intercept" => costs[0], + "add_integer-cpu-arguments-slope" => costs[1], + "add_integer-mem-arguments-intercept" => costs[2], + "add_integer-mem-arguments-slope" => costs[3], + "append_byte_string-cpu-arguments-intercept" => costs[4], + "append_byte_string-cpu-arguments-slope" => costs[5], + "append_byte_string-mem-arguments-intercept" => costs[6], + "append_byte_string-mem-arguments-slope" => costs[7], + "append_string-cpu-arguments-intercept" => costs[8], + "append_string-cpu-arguments-slope" => costs[9], + "append_string-mem-arguments-intercept" => costs[10], + "append_string-mem-arguments-slope" => costs[11], + "b_data-cpu-arguments" => costs[12], + "b_data-mem-arguments" => costs[13], + "blake2b_256-cpu-arguments-intercept" => costs[14], + "blake2b_256-cpu-arguments-slope" => costs[15], + "blake2b_256-mem-arguments" => costs[16], + "cek_apply_cost-exBudgetCPU" => costs[17], + "cek_apply_cost-exBudgetmem" => costs[18], + "cek_builtin_cost-exBudgetCPU" => costs[19], + "cek_builtin_cost-exBudgetmem" => costs[20], + "cek_const_cost-exBudgetCPU" => costs[21], + "cek_const_cost-exBudgetmem" => costs[22], + "cek_delay_cost-exBudgetCPU" => costs[23], + "cek_delay_cost-exBudgetmem" => costs[24], + "cek_force_cost-exBudgetCPU" => costs[25], + "cek_force_cost-exBudgetmem" => costs[26], + "cek_lam_cost-exBudgetCPU" => costs[27], + "cek_lam_cost-exBudgetmem" => costs[28], + "cek_startup_cost-exBudgetCPU" => costs[29], + "cek_startup_cost-exBudgetmem" => costs[30], + "cek_var_cost-exBudgetCPU" => costs[31], + "cek_var_cost-exBudgetmem" => costs[32], + "choose_data-cpu-arguments" => costs[33], + "choose_data-mem-arguments" => costs[34], + "choose_list-cpu-arguments" => costs[35], + "choose_list-mem-arguments" => costs[36], + "choose_unit-cpu-arguments" => costs[37], + "choose_unit-mem-arguments" => costs[38], + "cons_byte_string-cpu-arguments-intercept" => costs[39], + "cons_byte_string-cpu-arguments-slope" => costs[40], + "cons_byte_string-mem-arguments-intercept" => costs[41], + "cons_byte_string-mem-arguments-slope" => costs[42], + "constr_data-cpu-arguments" => costs[43], + "constr_data-mem-arguments" => costs[44], + "decode_utf8-cpu-arguments-intercept" => costs[45], + "decode_utf8-cpu-arguments-slope" => costs[46], + "decode_utf8-mem-arguments-intercept" => costs[47], + "decode_utf8-mem-arguments-slope" => costs[48], + "divide_integer-cpu-arguments-constant" => costs[49], + "divide_integer-cpu-arguments-model-arguments-intercept" => costs[50], + "divide_integer-cpu-arguments-model-arguments-slope" => costs[51], + "divide_integer-mem-arguments-intercept" => costs[52], + "divide_integer-mem-arguments-minimum" => costs[53], + "divide_integer-mem-arguments-slope" => costs[54], + "encode_utf8-cpu-arguments-intercept" => costs[55], + "encode_utf8-cpu-arguments-slope" => costs[56], + "encode_utf8-mem-arguments-intercept" => costs[57], + "encode_utf8-mem-arguments-slope" => costs[58], + "equals_byte_string-cpu-arguments-constant" => costs[59], + "equals_byte_string-cpu-arguments-intercept" => costs[60], + "equals_byte_string-cpu-arguments-slope" => costs[61], + "equals_byte_string-mem-arguments" => costs[62], + "equals_data-cpu-arguments-intercept" => costs[63], + "equals_data-cpu-arguments-slope" => costs[64], + "equals_data-mem-arguments" => costs[65], + "equals_integer-cpu-arguments-intercept" => costs[66], + "equals_integer-cpu-arguments-slope" => costs[67], + "equals_integer-mem-arguments" => costs[68], + "equals_string-cpu-arguments-constant" => costs[69], + "equals_string-cpu-arguments-intercept" => costs[70], + "equals_string-cpu-arguments-slope" => costs[71], + "equals_string-mem-arguments" => costs[72], + "fst_pair-cpu-arguments" => costs[73], + "fst_pair-mem-arguments" => costs[74], + "head_list-cpu-arguments" => costs[75], + "head_list-mem-arguments" => costs[76], + "i_data-cpu-arguments" => costs[77], + "i_data-mem-arguments" => costs[78], + "if_then_else-cpu-arguments" => costs[79], + "if_then_else-mem-arguments" => costs[80], + "index_byte_string-cpu-arguments" => costs[81], + "index_byte_string-mem-arguments" => costs[82], + "length_of_byte_string-cpu-arguments" => costs[83], + "length_of_byte_string-mem-arguments" => costs[84], + "less_than_byte_string-cpu-arguments-intercept" => costs[85], + "less_than_byte_string-cpu-arguments-slope" => costs[86], + "less_than_byte_string-mem-arguments" => costs[87], + "less_than_equals_byte_string-cpu-arguments-intercept" => costs[88], + "less_than_equals_byte_string-cpu-arguments-slope" => costs[89], + "less_than_equals_byte_string-mem-arguments" => costs[90], + "less_than_equals_integer-cpu-arguments-intercept" => costs[91], + "less_than_equals_integer-cpu-arguments-slope" => costs[92], + "less_than_equals_integer-mem-arguments" => costs[93], + "less_than_integer-cpu-arguments-intercept" => costs[94], + "less_than_integer-cpu-arguments-slope" => costs[95], + "less_than_integer-mem-arguments" => costs[96], + "list_data-cpu-arguments" => costs[97], + "list_data-mem-arguments" => costs[98], + "map_data-cpu-arguments" => costs[99], + "map_data-mem-arguments" => costs[100], + "mk_cons-cpu-arguments" => costs[101], + "mk_cons-mem-arguments" => costs[102], + "mk_nil_data-cpu-arguments" => costs[103], + "mk_nil_data-mem-arguments" => costs[104], + "mk_nil_pair_data-cpu-arguments" => costs[105], + "mk_nil_pair_data-mem-arguments" => costs[106], + "mk_pair_data-cpu-arguments" => costs[107], + "mk_pair_data-mem-arguments" => costs[108], + "mod_integer-cpu-arguments-constant" => costs[109], + "mod_integer-cpu-arguments-model-arguments-intercept" => costs[110], + "mod_integer-cpu-arguments-model-arguments-slope" => costs[111], + "mod_integer-mem-arguments-intercept" => costs[112], + "mod_integer-mem-arguments-minimum" => costs[113], + "mod_integer-mem-arguments-slope" => costs[114], + "multiply_integer-cpu-arguments-intercept" => costs[115], + "multiply_integer-cpu-arguments-slope" => costs[116], + "multiply_integer-mem-arguments-intercept" => costs[117], + "multiply_integer-mem-arguments-slope" => costs[118], + "null_list-cpu-arguments" => costs[119], + "null_list-mem-arguments" => costs[120], + "quotient_integer-cpu-arguments-constant" => costs[121], + "quotient_integer-cpu-arguments-model-arguments-intercept" => costs[122], + "quotient_integer-cpu-arguments-model-arguments-slope" => costs[123], + "quotient_integer-mem-arguments-intercept" => costs[124], + "quotient_integer-mem-arguments-minimum" => costs[125], + "quotient_integer-mem-arguments-slope" => costs[126], + "remainder_integer-cpu-arguments-constant" => costs[127], + "remainder_integer-cpu-arguments-model-arguments-intercept" => costs[128], + "remainder_integer-cpu-arguments-model-arguments-slope" => costs[129], + "remainder_integer-mem-arguments-intercept" => costs[130], + "remainder_integer-mem-arguments-minimum" => costs[131], + "remainder_integer-mem-arguments-slope" => costs[132], + "sha2_256-cpu-arguments-intercept" => costs[133], + "sha2_256-cpu-arguments-slope" => costs[134], + "sha2_256-mem-arguments" => costs[135], + "sha3_256-cpu-arguments-intercept" => costs[136], + "sha3_256-cpu-arguments-slope" => costs[137], + "sha3_256-mem-arguments" => costs[138], + "slice_byte_string-cpu-arguments-intercept" => costs[139], + "slice_byte_string-cpu-arguments-slope" => costs[140], + "slice_byte_string-mem-arguments-intercept" => costs[141], + "slice_byte_string-mem-arguments-slope" => costs[142], + "snd_pair-cpu-arguments" => costs[143], + "snd_pair-mem-arguments" => costs[144], + "subtract_integer-cpu-arguments-intercept" => costs[145], + "subtract_integer-cpu-arguments-slope" => costs[146], + "subtract_integer-mem-arguments-intercept" => costs[147], + "subtract_integer-mem-arguments-slope" => costs[148], + "tail_list-cpu-arguments" => costs[149], + "tail_list-mem-arguments" => costs[150], + "trace-cpu-arguments" => costs[151], + "trace-mem-arguments" => costs[152], + "un_b_data-cpu-arguments" => costs[153], + "un_b_data-mem-arguments" => costs[154], + "un_constr_data-cpu-arguments" => costs[155], + "un_constr_data-mem-arguments" => costs[156], + "un_i_data-cpu-arguments" => costs[157], + "un_i_data-mem-arguments" => costs[158], + "un_list_data-cpu-arguments" => costs[159], + "un_list_data-mem-arguments" => costs[160], + "un_map_data-cpu-arguments" => costs[161], + "un_map_data-mem-arguments" => costs[162], + "verify_ed25519_signature-cpu-arguments-intercept" => costs[163], + "verify_ed25519_signature-cpu-arguments-slope" => costs[164], + "verify_ed25519_signature-mem-arguments" => costs[165] + } + } + Language::PlutusV2 => { + hashmap! { + "add_integer-cpu-arguments-intercept"=> costs[0], + "add_integer-cpu-arguments-slope"=> costs[1], + "add_integer-mem-arguments-intercept"=> costs[2], + "add_integer-mem-arguments-slope"=> costs[3], + "append_byte_string-cpu-arguments-intercept"=> costs[4], + "append_byte_string-cpu-arguments-slope"=> costs[5], + "append_byte_string-mem-arguments-intercept"=> costs[6], + "append_byte_string-mem-arguments-slope"=> costs[7], + "append_string-cpu-arguments-intercept"=> costs[8], + "append_string-cpu-arguments-slope"=> costs[9], + "append_string-mem-arguments-intercept"=> costs[10], + "append_string-mem-arguments-slope"=> costs[11], + "b_data-cpu-arguments"=> costs[12], + "b_data-mem-arguments"=> costs[13], + "blake2b_256-cpu-arguments-intercept"=> costs[14], + "blake2b_256-cpu-arguments-slope"=> costs[15], + "blake2b_256-mem-arguments"=> costs[16], + "cek_apply_cost-exBudgetCPU"=> costs[17], + "cek_apply_cost-exBudgetmem"=> costs[18], + "cek_builtin_cost-exBudgetCPU"=> costs[19], + "cek_builtin_cost-exBudgetmem"=> costs[20], + "cek_const_cost-exBudgetCPU"=> costs[21], + "cek_const_cost-exBudgetmem"=> costs[22], + "cek_delay_cost-exBudgetCPU"=> costs[23], + "cek_delay_cost-exBudgetmem"=> costs[24], + "cek_force_cost-exBudgetCPU"=> costs[25], + "cek_force_cost-exBudgetmem"=> costs[26], + "cek_lam_cost-exBudgetCPU"=> costs[27], + "cek_lam_cost-exBudgetmem"=> costs[28], + "cek_startup_cost-exBudgetCPU"=> costs[29], + "cek_startup_cost-exBudgetmem"=> costs[30], + "cek_var_cost-exBudgetCPU"=> costs[31], + "cek_var_cost-exBudgetmem"=> costs[32], + "choose_data-cpu-arguments"=> costs[33], + "choose_data-mem-arguments"=> costs[34], + "choose_list-cpu-arguments"=> costs[35], + "choose_list-mem-arguments"=> costs[36], + "choose_unit-cpu-arguments"=> costs[37], + "choose_unit-mem-arguments"=> costs[38], + "cons_byte_string-cpu-arguments-intercept"=> costs[39], + "cons_byte_string-cpu-arguments-slope"=> costs[40], + "cons_byte_string-mem-arguments-intercept"=> costs[41], + "cons_byte_string-mem-arguments-slope"=> costs[42], + "constr_data-cpu-arguments"=> costs[43], + "constr_data-mem-arguments"=> costs[44], + "decode_utf8-cpu-arguments-intercept"=> costs[45], + "decode_utf8-cpu-arguments-slope"=> costs[46], + "decode_utf8-mem-arguments-intercept"=> costs[47], + "decode_utf8-mem-arguments-slope"=> costs[48], + "divide_integer-cpu-arguments-constant"=> costs[49], + "divide_integer-cpu-arguments-model-arguments-intercept"=> costs[50], + "divide_integer-cpu-arguments-model-arguments-slope"=> costs[51], + "divide_integer-mem-arguments-intercept"=> costs[52], + "divide_integer-mem-arguments-minimum"=> costs[53], + "divide_integer-mem-arguments-slope"=> costs[54], + "encode_utf8-cpu-arguments-intercept"=> costs[55], + "encode_utf8-cpu-arguments-slope"=> costs[56], + "encode_utf8-mem-arguments-intercept"=> costs[57], + "encode_utf8-mem-arguments-slope"=> costs[58], + "equals_byte_string-cpu-arguments-constant"=> costs[59], + "equals_byte_string-cpu-arguments-intercept"=> costs[60], + "equals_byte_string-cpu-arguments-slope"=> costs[61], + "equals_byte_string-mem-arguments"=> costs[62], + "equals_data-cpu-arguments-intercept"=> costs[63], + "equals_data-cpu-arguments-slope"=> costs[64], + "equals_data-mem-arguments"=> costs[65], + "equals_integer-cpu-arguments-intercept"=> costs[66], + "equals_integer-cpu-arguments-slope"=> costs[67], + "equals_integer-mem-arguments"=> costs[68], + "equals_string-cpu-arguments-constant"=> costs[69], + "equals_string-cpu-arguments-intercept"=> costs[70], + "equals_string-cpu-arguments-slope"=> costs[71], + "equals_string-mem-arguments"=> costs[72], + "fst_pair-cpu-arguments"=> costs[73], + "fst_pair-mem-arguments"=> costs[74], + "head_list-cpu-arguments"=> costs[75], + "head_list-mem-arguments"=> costs[76], + "i_data-cpu-arguments"=> costs[77], + "i_data-mem-arguments"=> costs[78], + "if_then_else-cpu-arguments"=> costs[79], + "if_then_else-mem-arguments"=> costs[80], + "index_byte_string-cpu-arguments"=> costs[81], + "index_byte_string-mem-arguments"=> costs[82], + "length_of_byte_string-cpu-arguments"=> costs[83], + "length_of_byte_string-mem-arguments"=> costs[84], + "less_than_byte_string-cpu-arguments-intercept"=> costs[85], + "less_than_byte_string-cpu-arguments-slope"=> costs[86], + "less_than_byte_string-mem-arguments"=> costs[87], + "less_than_equals_byte_string-cpu-arguments-intercept"=> costs[88], + "less_than_equals_byte_string-cpu-arguments-slope"=> costs[89], + "less_than_equals_byte_string-mem-arguments"=> costs[90], + "less_than_equals_integer-cpu-arguments-intercept"=> costs[91], + "less_than_equals_integer-cpu-arguments-slope"=> costs[92], + "less_than_equals_integer-mem-arguments"=> costs[93], + "less_than_integer-cpu-arguments-intercept"=> costs[94], + "less_than_integer-cpu-arguments-slope"=> costs[95], + "less_than_integer-mem-arguments"=> costs[96], + "list_data-cpu-arguments"=> costs[97], + "list_data-mem-arguments"=> costs[98], + "map_data-cpu-arguments"=> costs[99], + "map_data-mem-arguments"=> costs[100], + "mk_cons-cpu-arguments"=> costs[101], + "mk_cons-mem-arguments"=> costs[102], + "mk_nil_data-cpu-arguments"=> costs[103], + "mk_nil_data-mem-arguments"=> costs[104], + "mk_nil_pair_data-cpu-arguments"=> costs[105], + "mk_nil_pair_data-mem-arguments"=> costs[106], + "mk_pair_data-cpu-arguments"=> costs[107], + "mk_pair_data-mem-arguments"=> costs[108], + "mod_integer-cpu-arguments-constant"=> costs[109], + "mod_integer-cpu-arguments-model-arguments-intercept"=> costs[110], + "mod_integer-cpu-arguments-model-arguments-slope"=> costs[111], + "mod_integer-mem-arguments-intercept"=> costs[112], + "mod_integer-mem-arguments-minimum"=> costs[113], + "mod_integer-mem-arguments-slope"=> costs[114], + "multiply_integer-cpu-arguments-intercept"=> costs[115], + "multiply_integer-cpu-arguments-slope"=> costs[116], + "multiply_integer-mem-arguments-intercept"=> costs[117], + "multiply_integer-mem-arguments-slope"=> costs[118], + "null_list-cpu-arguments"=> costs[119], + "null_list-mem-arguments"=> costs[120], + "quotient_integer-cpu-arguments-constant"=> costs[121], + "quotient_integer-cpu-arguments-model-arguments-intercept"=> costs[122], + "quotient_integer-cpu-arguments-model-arguments-slope"=> costs[123], + "quotient_integer-mem-arguments-intercept"=> costs[124], + "quotient_integer-mem-arguments-minimum"=> costs[125], + "quotient_integer-mem-arguments-slope"=> costs[126], + "remainder_integer-cpu-arguments-constant"=> costs[127], + "remainder_integer-cpu-arguments-model-arguments-intercept"=> costs[128], + "remainder_integer-cpu-arguments-model-arguments-slope"=> costs[129], + "remainder_integer-mem-arguments-intercept"=> costs[130], + "remainder_integer-mem-arguments-minimum"=> costs[131], + "remainder_integer-mem-arguments-slope"=> costs[132], + "serialise_data-cpu-arguments-intercept"=> costs[133], + "serialise_data-cpu-arguments-slope"=> costs[134], + "serialise_data-mem-arguments-intercept"=> costs[135], + "serialise_data-mem-arguments-slope"=> costs[136], + "sha2_256-cpu-arguments-intercept"=> costs[137], + "sha2_256-cpu-arguments-slope"=> costs[138], + "sha2_256-mem-arguments"=> costs[139], + "sha3_256-cpu-arguments-intercept"=> costs[140], + "sha3_256-cpu-arguments-slope"=> costs[141], + "sha3_256-mem-arguments"=> costs[142], + "slice_byte_string-cpu-arguments-intercept"=> costs[143], + "slice_byte_string-cpu-arguments-slope"=> costs[144], + "slice_byte_string-mem-arguments-intercept"=> costs[145], + "slice_byte_string-mem-arguments-slope"=> costs[146], + "snd_pair-cpu-arguments"=> costs[147], + "snd_pair-mem-arguments"=> costs[148], + "subtract_integer-cpu-arguments-intercept"=> costs[149], + "subtract_integer-cpu-arguments-slope"=> costs[150], + "subtract_integer-mem-arguments-intercept"=> costs[151], + "subtract_integer-mem-arguments-slope"=> costs[152], + "tail_list-cpu-arguments"=> costs[153], + "tail_list-mem-arguments"=> costs[154], + "trace-cpu-arguments"=> costs[155], + "trace-mem-arguments"=> costs[156], + "un_b_data-cpu-arguments"=> costs[157], + "un_b_data-mem-arguments"=> costs[158], + "un_constr_data-cpu-arguments"=> costs[159], + "un_constr_data-mem-arguments"=> costs[160], + "un_i_data-cpu-arguments"=> costs[161], + "un_i_data-mem-arguments"=> costs[162], + "un_list_data-cpu-arguments"=> costs[163], + "un_list_data-mem-arguments"=> costs[164], + "un_map_data-cpu-arguments"=> costs[165], + "un_map_data-mem-arguments"=> costs[166], + "verify_ecdsa_secp256k1_signature-cpu-arguments"=> costs[167], + "verify_ecdsa_secp256k1_signature-mem-arguments"=> costs[168], + "verify_ed25519_signature-cpu-arguments-intercept"=> costs[169], + "verify_ed25519_signature-cpu-arguments-slope"=> costs[170], + "verify_ed25519_signature-mem-arguments"=> costs[171], + "verify_schnorr_secp256k1_signature-cpu-arguments-intercept"=> costs[172], + "verify_schnorr_secp256k1_signature-cpu-arguments-slope"=> costs[173], + "verify_schnorr_secp256k1_signature-mem-arguments"=> costs[174] + } + } + }; + CostModel { + machine_costs: MachineCosts { + startup: ExBudget { + mem: *cost_map + .get("cek_startup_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_startup_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + var: ExBudget { + mem: *cost_map + .get("cek_var_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_var_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + constant: ExBudget { + mem: *cost_map + .get("cek_const_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_const_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + lambda: ExBudget { + mem: *cost_map + .get("cek_lam_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_lam_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + delay: ExBudget { + mem: *cost_map + .get("cek_delay_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_delay_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + force: ExBudget { + mem: *cost_map + .get("cek_force_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_force_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + apply: ExBudget { + mem: *cost_map + .get("cek_apply_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_apply_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + builtin: ExBudget { + mem: *cost_map + .get("cek_builtin_cost-exBudgetCPU") + .unwrap_or(&30000000000), + cpu: *cost_map + .get("cek_builtin_cost-exBudgetmem") + .unwrap_or(&30000000000), + }, + }, + builtin_costs: BuiltinCosts { + add_integer: CostingFun { + mem: TwoArguments::MaxSize(MaxSize { + intercept: *cost_map + .get("add_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("add_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::MaxSize(MaxSize { + intercept: *cost_map + .get("add_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("add_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + subtract_integer: CostingFun { + mem: TwoArguments::MaxSize(MaxSize { + intercept: *cost_map + .get("subtract_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("subtract_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::MaxSize(MaxSize { + intercept: *cost_map + .get("subtract_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("subtract_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + multiply_integer: CostingFun { + mem: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("multiply_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("multiply_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("multiply_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("multiply_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + divide_integer: CostingFun { + mem: TwoArguments::SubtractedSizes(SubtractedSizes { + intercept: *cost_map + .get("divide_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("divide_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + minimum: *cost_map + .get("divide_integer-mem-arguments-minimum") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments { + constant: *cost_map + .get("divide_integer-cpu-arguments-constant") + .unwrap_or(&30000000000), + model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes { + intercept: *cost_map + .get("divide_integer-cpu-arguments-model-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("divide_integer-cpu-arguments-model-arguments-slope") + .unwrap_or(&30000000000), + })), + }), + }, + quotient_integer: CostingFun { + mem: TwoArguments::SubtractedSizes(SubtractedSizes { + intercept: *cost_map + .get("quotient_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("quotient_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + minimum: *cost_map + .get("quotient_integer-mem-arguments-minimum") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments { + constant: *cost_map + .get("quotient_integer-cpu-arguments-constant") + .unwrap_or(&30000000000), + model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes { + intercept: *cost_map + .get("quotient_integer-cpu-arguments-model-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("quotient_integer-cpu-arguments-model-arguments-slope") + .unwrap_or(&30000000000), + })), + }), + }, + remainder_integer: CostingFun { + mem: TwoArguments::SubtractedSizes(SubtractedSizes { + intercept: *cost_map + .get("remainder_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("remainder_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + minimum: *cost_map + .get("remainder_integer-mem-arguments-minimum") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments { + constant: *cost_map + .get("remainder_integer-cpu-arguments-constant") + .unwrap_or(&30000000000), + model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes { + intercept: *cost_map + .get("remainder_integer-cpu-arguments-model-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("remainder_integer-cpu-arguments-model-arguments-slope") + .unwrap_or(&30000000000), + })), + }), + }, + mod_integer: CostingFun { + mem: TwoArguments::SubtractedSizes(SubtractedSizes { + intercept: *cost_map + .get("mod_integer-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("mod_integer-mem-arguments-slope") + .unwrap_or(&30000000000), + minimum: *cost_map + .get("mod_integer-mem-arguments-minimum") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments { + constant: *cost_map + .get("mod_integer-cpu-arguments-constant") + .unwrap_or(&30000000000), + model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes { + intercept: *cost_map + .get("mod_integer-cpu-arguments-model-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("mod_integer-cpu-arguments-model-arguments-slope") + .unwrap_or(&30000000000), + })), + }), + }, + equals_integer: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("equals_integer-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("equals_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("equals_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + less_than_integer: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("less_than_integer-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("less_than_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("less_than_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + less_than_equals_integer: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("less_than_equals_integer-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("less_than_equals_integer-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("less_than_equals_integer-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + append_byte_string: CostingFun { + mem: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("append_byte_string-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("append_byte_string-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("append_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("append_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + cons_byte_string: CostingFun { + mem: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("cons_byte_string-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("cons_byte_string-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::LinearInY(LinearSize { + intercept: *cost_map + .get("cons_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("cons_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + slice_byte_string: CostingFun { + mem: ThreeArguments::LinearInZ(LinearSize { + intercept: *cost_map + .get("slice_byte_string-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("slice_byte_string-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: ThreeArguments::LinearInZ(LinearSize { + intercept: *cost_map + .get("slice_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("slice_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + length_of_byte_string: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("length_of_byte_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("length_of_byte_string-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + index_byte_string: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("index_byte_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map + .get("index_byte_string-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + equals_byte_string: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("equals_byte_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::LinearOnDiagonal(ConstantOrLinear { + constant: *cost_map + .get("equals_byte_string-cpu-arguments-constant") + .unwrap_or(&30000000000), + intercept: *cost_map + .get("equals_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("equals_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + less_than_byte_string: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("less_than_byte_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("less_than_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("less_than_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + less_than_equals_byte_string: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("less_than_equals_byte_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("less_than_equals_byte_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("less_than_equals_byte_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + sha2_256: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("sha2_256-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("sha2_256-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("sha2_256-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + sha3_256: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("sha3_256-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("sha3_256-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("sha3_256-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + blake2b_256: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("blake2b_256-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("blake2b_256-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("blake2b_256-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + verify_ed25519_signature: CostingFun { + mem: ThreeArguments::ConstantCost( + *cost_map + .get("verify_ed25519_signature-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: ThreeArguments::LinearInZ(LinearSize { + intercept: *cost_map + .get("verify_ed25519_signature-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("verify_ed25519_signature-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + verify_ecdsa_secp256k1_signature: CostingFun { + mem: ThreeArguments::ConstantCost( + *cost_map + .get("verify_ecdsa_secp256k1_signature-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: ThreeArguments::ConstantCost( + *cost_map + .get("verify_ecdsa_secp256k1_signature-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + verify_schnorr_secp256k1_signature: CostingFun { + mem: ThreeArguments::ConstantCost( + *cost_map + .get("verify_schnorr_secp256k1_signature-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: ThreeArguments::LinearInY(LinearSize { + intercept: *cost_map + .get("verify_schnorr_secp256k1_signature-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("verify_schnorr_secp256k1_signature-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + append_string: CostingFun { + mem: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("append_string-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("append_string-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: TwoArguments::AddedSizes(AddedSizes { + intercept: *cost_map + .get("append_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("append_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + equals_string: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("equals_string-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::LinearOnDiagonal(ConstantOrLinear { + constant: *cost_map + .get("equals_string-cpu-arguments-constant") + .unwrap_or(&30000000000), + intercept: *cost_map + .get("equals_string-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("equals_string-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + encode_utf8: CostingFun { + mem: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("encode_utf8-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("encode_utf8-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("encode_utf8-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("encode_utf8-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + decode_utf8: CostingFun { + mem: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("decode_utf8-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("decode_utf8-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("decode_utf8-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("decode_utf8-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + if_then_else: CostingFun { + mem: ThreeArguments::ConstantCost( + *cost_map + .get("if_then_else-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: ThreeArguments::ConstantCost( + *cost_map + .get("if_then_else-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + choose_unit: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("choose_unit-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map + .get("choose_unit-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + trace: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map.get("trace-mem-arguments").unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map.get("trace-cpu-arguments").unwrap_or(&30000000000), + ), + }, + fst_pair: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("fst_pair-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("fst_pair-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + snd_pair: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("snd_pair-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("snd_pair-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + choose_list: CostingFun { + mem: ThreeArguments::ConstantCost( + *cost_map + .get("choose_list-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: ThreeArguments::ConstantCost( + *cost_map + .get("choose_list-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + mk_cons: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("mk_cons-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map + .get("mk_cons-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + head_list: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("head_list-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("head_list-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + tail_list: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("tail_list-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("tail_list-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + null_list: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("null_list-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("null_list-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + choose_data: CostingFun { + mem: SixArguments::ConstantCost( + *cost_map + .get("choose_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: SixArguments::ConstantCost( + *cost_map + .get("choose_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + constr_data: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("constr_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map + .get("constr_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + map_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("map_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("map_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + list_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("list_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("list_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + i_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map.get("i_data-mem-arguments").unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map.get("i_data-cpu-arguments").unwrap_or(&30000000000), + ), + }, + b_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map.get("b_data-mem-arguments").unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map.get("b_data-cpu-arguments").unwrap_or(&30000000000), + ), + }, + un_constr_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("un_constr_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("un_constr_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + un_map_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("un_map_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("un_map_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + un_list_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("un_list_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("un_list_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + un_i_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("un_i_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("un_i_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + un_b_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("un_b_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("un_b_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + equals_data: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("equals_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::MinSize(MinSize { + intercept: *cost_map + .get("equals_data-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("equals_data-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + mk_pair_data: CostingFun { + mem: TwoArguments::ConstantCost( + *cost_map + .get("mk_pair_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: TwoArguments::ConstantCost( + *cost_map + .get("mk_pair_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + mk_nil_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("mk_nil_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("mk_nil_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + mk_nil_pair_data: CostingFun { + mem: OneArgument::ConstantCost( + *cost_map + .get("mk_nil_pair_data-mem-arguments") + .unwrap_or(&30000000000), + ), + cpu: OneArgument::ConstantCost( + *cost_map + .get("mk_nil_pair_data-cpu-arguments") + .unwrap_or(&30000000000), + ), + }, + serialise_data: CostingFun { + mem: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("serialise_data-mem-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("serialise_data-mem-arguments-slope") + .unwrap_or(&30000000000), + }), + cpu: OneArgument::LinearCost(LinearSize { + intercept: *cost_map + .get("serialise_data-cpu-arguments-intercept") + .unwrap_or(&30000000000), + slope: *cost_map + .get("serialise_data-cpu-arguments-slope") + .unwrap_or(&30000000000), + }), + }, + }, + } } pub struct CostingFun { diff --git a/crates/uplc/src/machine/runtime.rs b/crates/uplc/src/machine/runtime.rs index c722dc9d..fa1614b2 100644 --- a/crates/uplc/src/machine/runtime.rs +++ b/crates/uplc/src/machine/runtime.rs @@ -63,8 +63,12 @@ impl BuiltinRuntime { Ok(()) } - pub fn to_ex_budget(&self, costs: &BuiltinCosts) -> ExBudget { - costs.to_ex_budget(self.fun, &self.args) + pub fn to_ex_budget_v2(&self, costs: &BuiltinCosts) -> ExBudget { + costs.to_ex_budget_v2(self.fun, &self.args) + } + + pub fn to_ex_budget_v1(&self, costs: &BuiltinCosts) -> ExBudget { + costs.to_ex_budget_v1(self.fun, &self.args) } } diff --git a/crates/uplc/src/transaction_eval.rs b/crates/uplc/src/transaction_eval.rs index 6ea0d6b2..33fc9e11 100644 --- a/crates/uplc/src/transaction_eval.rs +++ b/crates/uplc/src/transaction_eval.rs @@ -1,9 +1,11 @@ use pallas_primitives::{ - babbage::{CostMdls, MintedTx, Redeemer, TransactionInput, TransactionOutput}, + babbage::{CostMdls, Language, MintedTx, Redeemer, TransactionInput, TransactionOutput}, Fragment, }; use pallas_traverse::{Era, MultiEraTx}; +use crate::Error; + use self::script_context::{ResolvedInput, SlotConfig}; mod eval; @@ -13,46 +15,63 @@ mod to_plutus_data; pub fn eval_tx( tx: &MintedTx, utxos: &[ResolvedInput], - //TODO: costMdls + cost_mdls: &CostMdls, + version: &Language, slot_config: &SlotConfig, ) -> anyhow::Result> { let redeemers = tx.transaction_witness_set.redeemer.as_ref(); let lookup_table = eval::get_script_and_datum_lookup_table(tx, utxos); - match redeemers { - Some(rs) => { - let mut collected_redeemers = vec![]; - for redeemer in rs.iter() { - collected_redeemers.push(eval::eval_redeemer( - tx, - utxos, - slot_config, - redeemer, - &lookup_table, - )?) + let costs_maybe = match version { + Language::PlutusV1 => cost_mdls.plutus_v1.as_ref(), + Language::PlutusV2 => cost_mdls.plutus_v2.as_ref(), + }; + + if let Some(costs) = costs_maybe { + match redeemers { + Some(rs) => { + let mut collected_redeemers = vec![]; + for redeemer in rs.iter() { + collected_redeemers.push(eval::eval_redeemer( + tx, + utxos, + slot_config, + redeemer, + &lookup_table, + version, + costs, + )?) + } + Ok(collected_redeemers) } - Ok(collected_redeemers) + None => Ok(vec![]), } - None => Ok(vec![]), + } else { + Err(anyhow::Error::msg(format!( + "Missing cost model for version: {:?}", + version + ))) } } pub fn eval_tx_raw( - tx_bytes: &Vec, - utxos_bytes: &Vec<(Vec, Vec)>, - cost_mdls_bytes: &Vec, + tx_bytes: &[u8], + utxos_bytes: &[(Vec, Vec)], + cost_mdls_bytes: &[u8], + version_bytes: u32, slot_config: (u64, u64), -) -> Result>, ()> { - let multi_era_tx = MultiEraTx::decode(Era::Babbage, &tx_bytes) - .or_else(|_| MultiEraTx::decode(Era::Alonzo, &tx_bytes)) - .or_else(|_| Err(()))?; // TODO: proper error message +) -> Result>, Error> { + let multi_era_tx = MultiEraTx::decode(Era::Babbage, tx_bytes) + .or_else(|_| MultiEraTx::decode(Era::Alonzo, tx_bytes)) + .map_err(|_| Error::from("Wrong era. Please use Babbage or Alonzo"))?; // TODO: proper error message - let cost_mdls = CostMdls::decode_fragment(&cost_mdls_bytes).or_else(|_| Err(()))?; // TODO: proper error message + let cost_mdls = CostMdls::decode_fragment(cost_mdls_bytes) + .map_err(|_| Error::from("Unable to decode cost models"))?; // TODO: proper error message let utxos: Vec = utxos_bytes .iter() - .map(|(input, output)| ResolvedInput { + .map(|(input, _output)| ResolvedInput { input: TransactionInput::decode_fragment(input).unwrap(), output: TransactionOutput::decode_fragment(input).unwrap(), }) @@ -63,13 +82,19 @@ pub fn eval_tx_raw( slot_length: slot_config.1, }; + let version = match version_bytes { + 1 => Language::PlutusV1, + 2 => Language::PlutusV2, + _ => unreachable!(), + }; + match multi_era_tx { - MultiEraTx::Babbage(tx) => match eval_tx(&tx, &utxos, &sc) { + MultiEraTx::Babbage(tx) => match eval_tx(&tx, &utxos, &cost_mdls, &version, &sc) { Ok(redeemers) => Ok(redeemers .iter() .map(|r| r.encode_fragment().unwrap()) .collect()), - Err(_) => Err(()), + Err(_) => Err(Error::from("Can't eval without redeemers")), }, // MultiEraTx::AlonzoCompatible(tx, _) => match eval_tx(&tx, &utxos, &sc) { // Ok(redeemers) => Ok(redeemers @@ -79,7 +104,7 @@ pub fn eval_tx_raw( // Err(_) => Err(()), // }, // TODO: I probably did a mistake here with using MintedTx which is only compatible with Babbage tx. - _ => Err(()), + _ => Err(Error::from("Wrong era. Please use babbage")), } } @@ -87,7 +112,7 @@ pub fn eval_tx_raw( mod tests { use pallas_codec::utils::MaybeIndefArray; use pallas_primitives::{ - babbage::{TransactionInput, TransactionOutput}, + babbage::{CostMdls, Language, TransactionInput, TransactionOutput}, Fragment, }; use pallas_traverse::{Era, MultiEraTx}; @@ -130,12 +155,196 @@ mod tests { slot_length: 1000, }; + let costs: Vec = vec![ + 205665, + 812, + 1, + 1, + 1000, + 571, + 0, + 1, + 1000, + 24177, + 4, + 1, + 1000, + 32, + 117366, + 10475, + 4, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 100, + 100, + 23000, + 100, + 19537, + 32, + 175354, + 32, + 46417, + 4, + 221973, + 511, + 0, + 1, + 89141, + 32, + 497525, + 14068, + 4, + 2, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1000, + 28662, + 4, + 2, + 245000, + 216773, + 62, + 1, + 1060367, + 12586, + 1, + 208512, + 421, + 1, + 187000, + 1000, + 52998, + 1, + 80436, + 32, + 43249, + 32, + 1000, + 32, + 80556, + 1, + 57667, + 4, + 1000, + 10, + 197145, + 156, + 1, + 197145, + 156, + 1, + 204924, + 473, + 1, + 208896, + 511, + 1, + 52467, + 32, + 64832, + 32, + 65493, + 32, + 22558, + 32, + 16563, + 32, + 76511, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 69522, + 11687, + 0, + 1, + 60091, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1159724, + 392670, + 0, + 2, + 806990, + 30482, + 4, + 1927926, + 82523, + 4, + 265318, + 0, + 4, + 0, + 85931, + 32, + 205665, + 812, + 1, + 1, + 41182, + 32, + 212342, + 32, + 31220, + 32, + 32696, + 32, + 43357, + 32, + 32247, + 32, + 38314, + 32, + 20000000000, + 20000000000, + 9462713, + 1021, + 10, + 20000000000, + 0, + 20000000000, + ]; + + let cost_mdl = CostMdls { + plutus_v1: None, + plutus_v2: Some(costs), + }; + let multi_era_tx = MultiEraTx::decode(Era::Babbage, &tx_bytes) .or_else(|_| MultiEraTx::decode(Era::Alonzo, &tx_bytes)) .unwrap(); match multi_era_tx { MultiEraTx::Babbage(tx) => { - let redeemers = eval_tx(&tx, &utxos, &slot_config).unwrap(); + let redeemers = + eval_tx(&tx, &utxos, &cost_mdl, &Language::PlutusV2, &slot_config).unwrap(); assert_eq!(redeemers.len(), 1) } @@ -181,12 +390,196 @@ mod tests { slot_length: 1000, }; + let costs: Vec = vec![ + 205665, + 812, + 1, + 1, + 1000, + 571, + 0, + 1, + 1000, + 24177, + 4, + 1, + 1000, + 32, + 117366, + 10475, + 4, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 100, + 100, + 23000, + 100, + 19537, + 32, + 175354, + 32, + 46417, + 4, + 221973, + 511, + 0, + 1, + 89141, + 32, + 497525, + 14068, + 4, + 2, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1000, + 28662, + 4, + 2, + 245000, + 216773, + 62, + 1, + 1060367, + 12586, + 1, + 208512, + 421, + 1, + 187000, + 1000, + 52998, + 1, + 80436, + 32, + 43249, + 32, + 1000, + 32, + 80556, + 1, + 57667, + 4, + 1000, + 10, + 197145, + 156, + 1, + 197145, + 156, + 1, + 204924, + 473, + 1, + 208896, + 511, + 1, + 52467, + 32, + 64832, + 32, + 65493, + 32, + 22558, + 32, + 16563, + 32, + 76511, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 69522, + 11687, + 0, + 1, + 60091, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1159724, + 392670, + 0, + 2, + 806990, + 30482, + 4, + 1927926, + 82523, + 4, + 265318, + 0, + 4, + 0, + 85931, + 32, + 205665, + 812, + 1, + 1, + 41182, + 32, + 212342, + 32, + 31220, + 32, + 32696, + 32, + 43357, + 32, + 32247, + 32, + 38314, + 32, + 20000000000, + 20000000000, + 9462713, + 1021, + 10, + 20000000000, + 0, + 20000000000, + ]; + + let cost_mdl = CostMdls { + plutus_v1: None, + plutus_v2: Some(costs), + }; + let multi_era_tx = MultiEraTx::decode(Era::Babbage, &tx_bytes) .or_else(|_| MultiEraTx::decode(Era::Alonzo, &tx_bytes)) .unwrap(); match multi_era_tx { MultiEraTx::Babbage(tx) => { - let redeemers = eval_tx(&tx, &utxos, &slot_config).unwrap(); + let redeemers = + eval_tx(&tx, &utxos, &cost_mdl, &Language::PlutusV2, &slot_config).unwrap(); println!("{:?}", redeemers.len()); } @@ -232,12 +625,32 @@ mod tests { slot_length: 1000, }; + let costs: Vec = vec![ + 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4, + 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 100, 100, + 23000, 100, 19537, 32, 175354, 32, 46417, 4, 221973, 511, 0, 1, 89141, 32, 497525, + 14068, 4, 2, 196500, 453240, 220, 0, 1, 1, 1000, 28662, 4, 2, 245000, 216773, 62, 1, + 1060367, 12586, 1, 208512, 421, 1, 187000, 1000, 52998, 1, 80436, 32, 43249, 32, 1000, + 32, 80556, 1, 57667, 4, 1000, 10, 197145, 156, 1, 197145, 156, 1, 204924, 473, 1, + 208896, 511, 1, 52467, 32, 64832, 32, 65493, 32, 22558, 32, 16563, 32, 76511, 32, + 196500, 453240, 220, 0, 1, 1, 69522, 11687, 0, 1, 60091, 32, 196500, 453240, 220, 0, 1, + 1, 196500, 453240, 220, 0, 1, 1, 806990, 30482, 4, 1927926, 82523, 4, 265318, 0, 4, 0, + 85931, 32, 205665, 812, 1, 1, 41182, 32, 212342, 32, 31220, 32, 32696, 32, 43357, 32, + 32247, 32, 38314, 32, 9462713, 1021, 10, + ]; + + let cost_mdl = CostMdls { + plutus_v1: Some(costs), + plutus_v2: None, + }; + let multi_era_tx = MultiEraTx::decode(Era::Babbage, &tx_bytes) .or_else(|_| MultiEraTx::decode(Era::Alonzo, &tx_bytes)) .unwrap(); match multi_era_tx { MultiEraTx::Babbage(tx) => { - let redeemers = eval_tx(&tx, &utxos, &slot_config).unwrap(); + let redeemers = + eval_tx(&tx, &utxos, &cost_mdl, &Language::PlutusV1, &slot_config).unwrap(); println!("{:?}", redeemers.len()); } diff --git a/crates/uplc/src/transaction_eval/eval.rs b/crates/uplc/src/transaction_eval/eval.rs index 7fc37e73..867db658 100644 --- a/crates/uplc/src/transaction_eval/eval.rs +++ b/crates/uplc/src/transaction_eval/eval.rs @@ -7,9 +7,9 @@ use pallas_addresses::{Address, ScriptHash, StakePayload}; use pallas_codec::utils::{KeyValuePairs, MaybeIndefArray}; use pallas_crypto::hash::Hash; use pallas_primitives::babbage::{ - Certificate, DatumHash, DatumOption, ExUnits, Mint, MintedTx, PlutusV1Script, PlutusV2Script, - PolicyId, Redeemer, RedeemerTag, RewardAccount, Script, StakeCredential, TransactionInput, - TransactionOutput, Value, Withdrawals, + Certificate, DatumHash, DatumOption, ExUnits, Language, Mint, MintedTx, PlutusV1Script, + PlutusV2Script, PolicyId, Redeemer, RedeemerTag, RewardAccount, Script, StakeCredential, + TransactionInput, TransactionOutput, Value, Withdrawals, }; use pallas_traverse::{ComputeHash, OriginalHash}; use std::{collections::HashMap, convert::TryInto, ops::Deref, vec}; @@ -556,6 +556,8 @@ pub fn eval_redeemer( slot_config: &SlotConfig, redeemer: &Redeemer, lookup_table: &DataLookupTable, + version: &Language, + costs: &[i64], ) -> anyhow::Result { let purpose = get_script_purpose( redeemer, @@ -585,7 +587,7 @@ pub fn eval_redeemer( .apply_data(datum) .apply_data(redeemer.data.clone()) .apply_data(script_context.to_plutus_data()) - .eval(); + .eval_with_params(version, costs); match result.0 { Ok(_) => {}