[BUG] - `fromLedgerUTxO` drops native reference scripts' original bytes, so `query ref-script-size` and `transaction build` undercount them
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 53/100
Direzione di ricerca
Start with fromLedgerUTxO and toLedgerUTxO in Cardano/Api/Query/Internal/Type/QueryInMode.hs, then follow the native script conversions in Cardano/Api/Plutus/Internal/Script.hs. Compare how original bytes are preserved for Plutus scripts with the native script path; the expected result is that native reference scripts retain their on-chain bytes through the round trip. Check that query ref-script-size and transaction fee sizing count those bytes as the ledger does.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Internal/External: External
Area: Other: the size and fee of native reference scripts.
Summary
fromLedgerUTxO turns a native reference script into a SimpleScript, which keeps no bytes, and toLedgerUTxO rebuilds it in canonical CBOR (Diagnosis, below). When the script was written on chain in a non-canonical encoding, cardano-cli's counts then fall short of the ledger's:
cardano-cli query ref-script-sizereports fewer bytes than the ledger counts;transaction buildsets its fee from the same short count, and the ledger refuses the transaction;- a transaction sized from
query ref-script-sizecan exceed the reference-script size limit.
Anyone can create such an output. The ledger refuses the affected transactions, so no funds are at risk.
Steps to reproduce
The refusals below are from local devnets at protocol version 12.0 (Dijkstra). We created the script outputs with a tool that writes the script bytes as given.
transaction build
-
Create 13 outputs, each with a different native reference script that is 15,702 bytes as written on chain, with every CBOR head (integers, array lengths, and byte-string lengths) in its 8-byte form. Each script's canonical encoding is 9,124 bytes, and
query ref-script-sizereports 9,124 for each output. -
Build a transaction that references all 13 outputs:
cardano-cli dijkstra transaction build --testnet-magic 42 --socket-path <socket> --tx-in <input> --read-only-tx-in-reference <output-1> ... --read-only-tx-in-reference <output-13> --change-address <address> --out-file tx.bodyIt sets a fee of 2,754,831 lovelace, 4,444 above the minimum fee at the CLI's count of 13 × 9,124 = 118,612 bytes.
-
Sign it with
transaction signand submit it withtransaction submit. The ledger refuses it:
ShelleyTxValidationError ShelleyBasedEraDijkstra (DijkstraApplyTxError (LedgerFailure (DijkstraUtxowFailure (UtxoFailure (FeeTooSmallUTxO Mismatch (RelGTEQ) {supplied: Coin 2754831, expected: Coin 6484239}))) :| []))
The expected 6,484,239 is the minimum fee with the scripts counted as written, 13 × 15,702 = 204,126 bytes. The same transaction with that fee, and its change lowered to match, is accepted.
The reference-script size limit
-
Create 13 outputs, each with a different native reference script that is 15,871 bytes as written on chain. The scripts write some of their CBOR heads in their 8-byte form: the first writes 16 of its heads that way, and its canonical encoding is 15,748 bytes.
-
cardano-cli dijkstra query ref-script-size --tx-in <output> --testnet-magic 42 --output-jsonreports 15,748 for each output, and{"refInputScriptSize": 204724}for all 13 together. -
Submit a transaction that references all 13 outputs. The ledger counts 13 × 15,871 = 206,323 bytes, over the 204,800 limit, although the CLI's count of 204,724 is under it:
ShelleyTxValidationError ShelleyBasedEraDijkstra (DijkstraApplyTxError (LedgerFailure (DijkstraTxRefScriptsSizeTooBig Mismatch (RelLTEQ) {supplied: 206323, expected: 204800}) :| []))
The same transaction with 12 reference inputs (190,452 bytes by the ledger's count, 188,976 by the CLI's) is accepted.
A minimal script for a test
82 1b 00 00 00 00 00 00 00 00 58 1c <28-byte key hash> is a RequireSignature script with its leading 0, the constructor index, written in the 8-byte form: 40 bytes as written. Its canonical encoding, 82 00 58 1c <28-byte key hash>, is 32 bytes.
Expected behavior
A round trip through fromLedgerUTxO and toLedgerUTxO keeps each native reference script's original bytes, as it already keeps a Plutus script's. query ref-script-size and the fee from transaction build then count a reference script as the ledger does: as the creating transaction wrote it.
#1238 kept original bytes the same way in inline datums' JSON round trip, and IntersectMBO/cardano-ledger#6296 in Dijkstra's era translation of native scripts.
Diagnosis
From reading the source at master, in the order the data flows:
-
A UTxO query's result goes through
fromLedgerUTxO(call site), which converts each native script to aSimpleScript(Conway, Dijkstra).SimpleScriptholds no bytes. -
toLedgerUTxOrebuilds the script throughtoShelleyScript, which callstoAllegraTimelockin Conway ortoDijkstraNativeScriptin Dijkstra. The ledger constructors they call memoize a fresh canonical encoding. -
Two functions then sum
originalBytesSizeover the rebuilt scripts:getReferenceInputsSizeForTxIds, and the ledger'scalcMinFeeTx, whichmakeTransactionBodyAutoBalancereaches throughcalculateMinTxFee. -
In cardano-cli,
runQueryRefScriptSizeCmdsums overtoLedgerUTxOofqueryUtxo's result.transaction buildtakes its UTxO fromqueryStateForBalancedTxand passestoLedgerUTxOof it tomakeTransactionBodyAutoBalance.
The rebuilt script also hashes differently. On chain, the first script of the size-limit run hashes to 0988d691c3b026f1960b7c691024e05a073d1f1b5f9a1ecf534b86a9; its canonical encoding hashes to 6e614b818d262427d1006ca86576f8cc99b2573cdfc19dd5c2bcc0e1.
We observed these refusals only in Dijkstra, and haven't tried Conway, where cardano-api takes the same path through toAllegraTimelock. We found this while pricing reference-script fees on a devnet from query ref-script-size.
System info
- OS: Linux, x86_64.
- Local builds of these releases, against cardano-ledger
07d904eb2and, separately,37975bb0a:- cardano-cli 11.7.0.0 (
24c05829e8); - cardano-api 11.12.0.0 (
c727cd63bd); - cardano-node 11.2.1 (
90bc1cd938); - ouroboros-consensus 5.4.0.0 (
808e400545).
- cardano-cli 11.7.0.0 (
- Their only patches let them build against those ledger commits (version bounds, and adaptations to changed ledger functions), and touch nothing on the code path above. The ledger is unpatched.
- Both builds give the size-limit result. The
transaction buildresult is from the37975bb0abuild. - The code path above is the same on cardano-api master (
7a1705780f) and cardano-cli master (dabfa5aed6).
- Lingua principale
- Haskell
- Stelle
- 41
- Fork
- 33
- Merge medio
- 3g 3h
- PR unite (30g)
- 15
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di IntersectMBO/cardano-api
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
IntersectMBO/cardano-api#1434 ·
I maintainer di solito rispondono entro 2 giorni
-
`Prelude.maximum: empty list` crash in fee estimation for empty `RequireAnyOf` (`{"type": "any", "scripts": []}`) scriptsForse già presa @Jimbo4350 l’ha presa 8 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
IntersectMBO/cardano-api#1424 ·
I maintainer di solito rispondono entro 2 giorni
-
type: enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
IntersectMBO/cardano-api#1423 ·
I maintainer di solito rispondono entro 2 giorni
-
Add a dedicated transaction viewing type to the experimental APIForse già presa @palas l’ha presa 21 giorni fa. Apertatype: enhancement
IntersectMBO/cardano-api#1416 · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
Dijkstra era type: enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
IntersectMBO/cardano-api#1386 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di IntersectMBO/cardano-api
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
haskell/bytestring#730 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
seal-harness/seal-harness#399 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
fmidue/codeworld-tasks#124 ·
-
allow haskell-src-exts-1.24Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
reflex-frp/reflex#563 ·
-
The codecov job never gets a runner on macos-26 and is cancelledForse già presa @yegor256 l’ha presa 1 giorno fa. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
objectionary/phino#2524 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno