Skip to content

Conversation

@sae3023
Copy link

@sae3023 sae3023 commented Dec 22, 2025

There's a FIXME in NewmChainService about using something that would allow you to omit Ogmois.

Scalus contains an offline Plutus script evaluator, and this commit in my fork adds a tiny integration of the evaluator to newm-server.

Glad to ask any questions or to help with further integration.

.from(scalaSeq)
}

private fun hexToByteArray(hex: String): ByteArray = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove helper function in favor of String.hexToByteArray() extension function in io.newm.chain.util.CardanoKtx

* @param utxos All UTxOs needed for evaluation (source + reference inputs)
* @param config The configuration object containing network information
*/
fun evaluateTx(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do the plutus cost models come into play here? Are they hardcoded somewhere in CardanoInfo? If so, this seems brittle and we should get the plutus cost model from the blockchain instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the CostModels are in ProtocolParameters, which are in CardanoInfo.

The evaluator itself needs only the slot config, the major protocol version and the cost models, so if the following signature is fine:

fun evaluateTx(
        cborBytes: ByteArray,
        utxos: Set<Utxo>,
        slotConfig: SlotConfig,
        costModels: CostModels
    )

Both of these types seem to be very straightforward to map to Scalus ledger types

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this looks fine, I'd appreciate a hint of where these types are described in newm, and I'll ping you when I fix the function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sae3023 In TransactionBuilder.kt, it is constructed with a protocolParametersResult. Inside this structure is the plutusCostModels. All of this data currently comes from Ogmios through Kogmios which is our Ogmios gRPC wrapper in Kotlin. We're not trying to entirely eliminate Ogmios with this fix, just utilize Scalus where it makes sense for efficiency.

@sae3023
Copy link
Author

sae3023 commented Dec 22, 2025

@AndrewWestberg PTAL

I did the cost models, but I'm not entirely sure about the casts, doesn't look like it's the best way to do it, but I've sort of threw it together quickly.

I'll take another look in the morning too.

RedeemerTag.valueOf("Cert") -> "certificate"
RedeemerTag.valueOf("Reward") -> "withdrawal"
RedeemerTag.valueOf("Voting") -> "vote"
RedeemerTag.valueOf("Proposing") -> "propose"
Copy link
Collaborator

@wlara wlara Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is RedeemerTag an enum and RedeemerTag.valueOf() returns the value? If so, we should use the enum values directly here in the left side. Example:

 RedeemerTag.Spend -> "spend"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants