Skip to content

fix: build script_data_hash from network cost models; connector-go v0.4.0 compat#1

Open
mgpai22 wants to merge 2 commits into
pv3from
pv3-connector-v0.4
Open

fix: build script_data_hash from network cost models; connector-go v0.4.0 compat#1
mgpai22 wants to merge 2 commits into
pv3from
pv3-connector-v0.4

Conversation

@mgpai22

@mgpai22 mgpai22 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

Make this fork usable by callers built against upstream apollo v1.7.0+ (cardano-connector-go v0.4.0) and fix a stale cost-model bug that caused mainnet tx rejections.

Based on the pv3 commit the downstream executor already pins (d169a80) to keep the change minimal and avoid pulling in unrelated newer pv3 behaviour (the EvaluateTx signature change).

Changes

  • ProtocolParameters compat: fee fields MinFeeConstant/MinFeeCoefficient int to int64, and CostModels renamed to CostModelsRaw (keeps json tag cost_models). Internal consumers updated (Base.Fee, ToBaseParams, Utils.Fee, Maestro and Ogmios contexts).
  • script_data_hash: ApolloBuilder.scriptDataHash() now sources cost models from the chain context ProtocolParameters.CostModelsRaw with hardcoded fallback. The hardcoded PlutusV1/V2/V3 constants go stale on protocol updates (mainnet PlutusV3 grew from 297 to 350 params), producing a script_data_hash the node rejects with ConwayUtxowFailure PPViewHashesDontMatch. V2/V3 use a plain definite array (NewCostModelArray); V1 keeps the bytestring-wrapped encoding (CostModelV1Raw).

Tests

  • scriptdatahash_repro_test.go with testdata/sdh_repro.json reproduce a real rejected mainnet tx fully offline: the hardcoded path yields the rejected hash, and the CostModelsRaw path yields the node expected hash.

Verification

  • Confirmed end to end on mainnet via the downstream executor: tx c673e6fa1052de882ceb6ba5be3ab693c3f7d1a81832c90266c250d05de521ad, valid_contract true.

mgpai22 added 2 commits June 22, 2026 16:36
Minimal API-compat changes on top of the pv3 commit the executor already
pins (d169a80), so callers built against upstream apollo v1.7.0+ (e.g.
cardano-connector-go v0.4.0) compile and run against this fork without
adopting newer pv3 changes or a full upstream rebase:

- ProtocolParameters.MinFeeConstant / MinFeeCoefficient: int -> int64
- ProtocolParameters.CostModels (map[string][]int64) renamed to
  CostModelsRaw, keeping json tag "cost_models" (connector-go v0.4.0
  writes the raw cost-model map into CostModelsRaw)

Internal consumers updated for the int64 fee fields (Base.Fee,
ToBaseParams, Utils.Fee, Maestro/Ogmios contexts) and the rename (Ogmios).
script_data_hash still uses the hardcoded PLUTUSV1/V2/V3 cost-model
constants exactly as before, so tx-building behaviour is unchanged.
…ants

ApolloBuilder.scriptDataHash() hardcoded PLUTUSV1/V2/V3COSTMODEL when
assembling the Conway language views. When the protocol updates its cost
models (e.g. mainnet PlutusV3 grew from 297 to 350 params), the hardcoded
values go stale and the resulting script_data_hash no longer matches what
the node computes -> ConwayUtxowFailure PPViewHashesDontMatch, tx rejected.

Now prefer the cost models from the chain context's
ProtocolParameters.CostModelsRaw (already canonical-ordered), falling back
to the hardcoded constants only when the context can't supply them. V2/V3
use a plain definite array (NewCostModelArray); V1 keeps the special
bytestring-wrapped indefinite-array encoding (CostModelV1Raw).

Verified offline against a real mainnet tx the node rejected
(scriptdatahash_repro_test.go + testdata/sdh_repro.json): the hardcoded
path reproduces the rejected hash, and the CostModelsRaw path reproduces
the node-expected hash. Confirmed end-to-end on mainnet (tx
c673e6fa1052de882ceb6ba5be3ab693c3f7d1a81832c90266c250d05de521ad,
valid_contract=True).
@mgpai22 mgpai22 force-pushed the pv3-connector-v0.4 branch from 7c94a37 to fe41a22 Compare June 22, 2026 17:41
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.

1 participant