<p>In one of your previous classes you said that some teams are optimising their contracts with this type of validator <code>BuiltinData -&gt; BuiltinData -&gt; BuiltinData -&gt; ()</code>  and I'll refer to those contracts as &quot;optimised&quot; (logic inside is the same, other than resolving types from BuiltinData). I've tried doing that even with custom context <code>ctx = PlutusTx.unsafeFromBuiltinData @CustomScriptContext rawContext</code> and when I build scripts and calculate expected memory and CPU budget with this command</p>
<pre><code>writePlutusScript filename scriptSerial scriptSBS =
  do
    case Plutus.defaultCostModelParams of
      Just m -&gt;
        let (logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose m scriptSBS []
         in do
              print (&quot;Log output&quot; :: String) &gt;&gt; print logout
              case e of
                Left evalErr -&gt; print (&quot;Eval Error&quot; :: String) &gt;&gt; print evalErr
                Right exbudget -&gt; print (&quot;Ex Budget&quot; :: String) &gt;&gt; print exbudget
</code></pre>
<p>and I get info that budget is decreased a lot for &quot;optimised&quot; validators</p>
<pre><code>Non optimised: ExBudget {exBudgetCPU = ExCPU 15184330, exBudgetMemory = ExMemory 51100}
Optimised: ExBudget {exBudgetCPU = ExCPU 8306767, exBudgetMemory = ExMemory 28000}
</code></pre>
<p>But when I try to build and submit a batch (via <code>cardano-cli transaction build</code> and <code>cardano-cli submit</code>) with couple of different contacts  utxos and 1  &quot;optimised&quot; contracts utxos I get <code>ExUnitsTooBigUTxO</code> error (on submit) and it says that it exceedes memory by a lot (4000000+)</p>
<pre><code>{unWrapExUnits = ExUnits' {exUnitsMem' = 16000000, exUnitsSteps' = 10000000000}}) (WrapExUnits {unWrapExUnits = ExUnits' {exUnitsMem' = 20120006, exUnitsSteps' = 8471969427}}
</code></pre>
<p>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 <code>cardano-cli submit</code> 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 <code>build-raw</code> and add custom  (ones I've received from the plutus code) exUnits, and would that help?</p>

CC BY-SA 4.0
2022-07-15T10:32:21.033Z
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?
Sebastian Nagel
CC BY-SA 4.0
2022-07-21T15:09:31.927Z
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
<plutus-pioneer-program><cardano-cli><validator>
Optimising validators with `BuiltinData -> BuiltinData -> BuiltinData -> ()` and building tx with cardano-cli
# Optimising validators with `BuiltinData -> BuiltinData -> BuiltinData -> ()` and building tx with cardano-cli

(Asked by: username_0 on 2022-02-08)

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?

**Tags:** plutus-pioneer-program, cardano-cli, validator
> **Comments:**
> **username_1**: 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?  
> **username_0**: 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  

---

## 0 answers

