Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Babbage era evaluateMinLovelaceOutput function #2814

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ where
import Cardano.Ledger.Alonzo.Data (AuxiliaryData (..), binaryDataToData)
import Cardano.Ledger.Alonzo.Language (Language (..))
import qualified Cardano.Ledger.Alonzo.Rules.Bbody as Alonzo (AlonzoBBODY)
import Cardano.Ledger.Alonzo.Rules.Utxo (utxoEntrySize)
import Cardano.Ledger.Alonzo.Scripts (Script (..), isPlutusScript)
import Cardano.Ledger.Alonzo.TxInfo (ExtendedUTxO (..), validScript)
import qualified Cardano.Ledger.Alonzo.TxSeq as Alonzo (TxSeq (..), hashTxSeq)
Expand All @@ -35,7 +34,7 @@ import Cardano.Ledger.Babbage.PParams
updatePParams,
)
import Cardano.Ledger.Babbage.Rules.Ledger (BabbageLEDGER)
import Cardano.Ledger.Babbage.Rules.Utxo (BabbageUTXO)
import Cardano.Ledger.Babbage.Rules.Utxo (BabbageUTXO, babbageMinUTxOSize)
import Cardano.Ledger.Babbage.Rules.Utxos (BabbageUTXOS)
import Cardano.Ledger.Babbage.Rules.Utxow (BabbageUTXOW)
import Cardano.Ledger.Babbage.Scripts (babbageInputDataHashes, babbageTxScripts)
Expand Down Expand Up @@ -192,8 +191,7 @@ instance CC.Crypto c => API.CLI (BabbageEra c) where
where
ws' = ws {txwitsVKey = Set.union newWits (txwitsVKey ws)}

evaluateMinLovelaceOutput pp out =
Coin $ utxoEntrySize out * unCoin (_coinsPerUTxOByte pp)
evaluateMinLovelaceOutput = babbageMinUTxOSize

type instance Core.Tx (BabbageEra c) = ValidatedTx (BabbageEra c)

Expand Down
17 changes: 13 additions & 4 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ validateCollateralEqBalance bal txcoll =
SNothing -> pure ()
SJust tc -> failureUnless (bal == tc) (UnequalCollateralReturn bal tc)

babbageMinUTxOSize ::
( ToCBOR (Core.TxOut era),
HasField "_coinsPerUTxOByte" (Core.PParams era) Coin
) =>
Core.PParams era ->
Core.TxOut era ->
Coin
babbageMinUTxOSize pp out =
Coin $
(fromIntegral . BSL.length . serialize $ out) * (unCoin $ getField @"_coinsPerUTxOByte" pp)

-- > getValue txout ≥ inject ( serSize txout ∗ coinsPerUTxOByte pp )
validateOutputTooSmallUTxO ::
( Era era,
Expand All @@ -262,9 +273,7 @@ validateOutputTooSmallUTxO ::
Test (BabbageUtxoPred era)
validateOutputTooSmallUTxO pp outs = failureUnless (null outputsTooSmall) $ BabbageOutputTooSmallUTxO outputsTooSmall
where
Coin coinsPerUTxOByte = getField @"_coinsPerUTxOByte" pp
serSize = fromIntegral . BSL.length . serialize
outs' = map (\out -> (out, serSize out * coinsPerUTxOByte)) outs
outs' = map (\out -> (out, unCoin $ babbageMinUTxOSize pp out)) outs
outputsTooSmall =
filter
( \(out, minSize) ->
Expand Down Expand Up @@ -370,7 +379,7 @@ utxoTransition = do
ShelleyMA.validateTriesToForgeADA txb

let outs = allOuts txb
{- ∀ txout ∈ allOuts txb, getValue txout ≥ inject (uxoEntrySize txout ∗ coinsPerUTxOByte pp) -}
{- ∀ txout ∈ allOuts txb, getValue txout ≥ inject (serSize txout ∗ coinsPerUTxOByte pp) -}
runTest $ validateOutputTooSmallUTxO pp outs

{- ∀ txout ∈ allOuts txb, serSize (getValue txout) ≤ maxValSize pp -}
Expand Down