2

In one of your previous classes you said that some teams are optimising their contracts with this type of validator BuiltinData -> BuiltinData -> BuiltinData -> () and I'll refer to those contracts as "optimised" (logic inside is the same, other than resolving types from BuiltinData). I've tried doing that even with custom context ctx = PlutusTx.unsafeFromBuiltinData @CustomScriptContext rawContext and when I build scripts and calculate expected memory and CPU budget with this command

writePlutusScript filename scriptSerial scriptSBS =
  do
    case Plutus.defaultCostModelParams of
      Just m ->
        let (logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose m scriptSBS []
         in do
              print ("Log output" :: String) >> print logout
              case e of
                Left evalErr -> print ("Eval Error" :: String) >> print evalErr
                Right exbudget -> print ("Ex Budget" :: String) >> print exbudget

and I get info that budget is decreased a lot for "optimised" validators

Non optimised: ExBudget {exBudgetCPU = ExCPU 15184330, exBudgetMemory = ExMemory 51100}
Optimised: ExBudget {exBudgetCPU = ExCPU 8306767, exBudgetMemory = ExMemory 28000}

But when I try to build and submit a batch (via cardano-cli transaction build and cardano-cli submit) with couple of different contacts utxos and 1 "optimised" contracts utxos I get ExUnitsTooBigUTxO error (on submit) and it says that it exceedes memory by a lot (4000000+)

{unWrapExUnits = ExUnits' {exUnitsMem' = 16000000, exUnitsSteps' = 10000000000}}) (WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 20120006, exUnitsSteps' = 8471969427}}

and when i use non optimised contract utxo in the same batch (only difference is that one utxo) my transaction goes through. How could that be? Does cardano-cli submit uses same logic for calculation of units as I've posted above (and as transaction build), Why did transaction build go trough if it has memory issues (when I'm over limit transaction build usually informs me)? And could there be a reason to use build-raw and add custom (ones I've received from the plutus code) exUnits, and would that help?

2
  • The last paragraph is not clear to me. Are you creating a transaction which does evaluate multiple scripts or is it only the one script for which you also calculated the budget? Commented Jul 15, 2022 at 10:32
  • It's 2 different scripts/validators in one "batch", first one is "LP" script/validator that is used in both cases (optimised and non optimised) and second is "Order" script, which is in the failing case optimised and in successful case non optimised
    – Kaliman
    Commented Jul 21, 2022 at 15:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.