Native Transaction Evaluator

A transaction evaluator backed by the in-process Untyped Plutus Core virtual machine. It resolves each redeemer’s script and datum, builds the version-appropriate Plutus script context, evaluates the program on the CEK machine against the supplied cost model, and writes the consumed execution units back into the redeemer. It implements the standard transaction evaluator interface, so it is used exactly like the provider-backed evaluator and requires no network access.

cardano_error_t cardano_tx_evaluator_new_native(const cardano_slot_config_t *slot_config, cardano_costmdls_t *cost_models, uint64_t protocol_major, cardano_tx_evaluator_t **tx_evaluator)

Creates a native phase-2 transaction evaluator backed by the in-process UPLC VM.

The native evaluator is the phase-2 driver: for every redeemer in a transaction it resolves the script and (for spends) the datum, builds the version-appropriate Plutus ScriptContext, applies the arguments, evaluates the program on the CEK machine, and writes the consumed execution units back into the redeemer it returns. It plugs into the existing cardano_tx_evaluator_t interface through a cardano_tx_evaluator_impl_t, so callers use it exactly as they would the provider-backed evaluator.

The cardano_tx_evaluator_evaluate signature carries no slot config, cost models or protocol version, so this constructor binds them once: the slot config converts validity slots to POSIX time for the ScriptContext, the cost models and protocol major version select the builtin semantics variant per script. The evaluator copies slot_config and takes a reference on cost_models; both stay owned by the evaluator for its lifetime.

Usage Example:

cardano_tx_evaluator_t* evaluator = NULL;
cardano_error_t         result    = cardano_tx_evaluator_new_native(
  &CARDANO_MAINNET_SLOT_CONFIG, cost_models, 10U, &evaluator);

if (result == CARDANO_SUCCESS)
{
  cardano_redeemer_list_t* redeemers = NULL;
  result = cardano_tx_evaluator_evaluate(evaluator, tx, additional_utxos, &redeemers);
  // ... inspect redeemers' ex-units ...
  cardano_redeemer_list_unref(&redeemers);
  cardano_tx_evaluator_unref(&evaluator);
}

Remark

For each script the driver builds the structured cost model from the cost_models entry matching the script’s language version and threads it, together with the selected builtin semantics variant, into the CEK machine’s budget accounting. The returned execution units therefore reflect the supplied ledger cost model exactly: the machine charges every step and builtin against those coefficients. When cost_models carries no entry for a version, the per-version default coefficients for the protocol version are used instead.

Parameters:
const cardano_slot_config_t *slot_config

[in] The slot/time parameters used to convert the transaction validity interval to POSIX time. Must not be NULL.

cardano_costmdls_t *cost_models

[in] The ledger cost models keyed by Plutus language version. May be NULL, in which case the evaluator uses the per-version default semantics for the protocol version.

uint64_t protocol_major

[in] The protocol major version selecting the builtin semantics variant at the Chang and Van-Rossem boundaries.

cardano_tx_evaluator_t **tx_evaluator

[out] On success, set to the newly created evaluator. The caller owns it and releases it with cardano_tx_evaluator_unref. Left untouched on failure.

Returns:

CARDANO_SUCCESS on success, CARDANO_ERROR_POINTER_IS_NULL if slot_config or tx_evaluator is NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if the evaluator context cannot be allocated.