-
Notifications
You must be signed in to change notification settings - Fork 158
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 ValueNotConservedUTxO serialization #1955
Conversation
!(Core.Value era) -- the Coin consumed by this transaction | ||
!(Core.Value era) -- the Coin produced by this transaction | ||
!(Delta (Core.Value era)) -- the Coin consumed by this transaction | ||
!(Delta (Core.Value era)) -- the Coin produced by this transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrBliss - is it okay that I have changed the serialization for this predicate failure? I do not know who all uses the failure serializations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect forall (x :: Word64). toCBOR (word64ToCoin x) == toCBOR (toDelta (word64ToCoin x)
to be true, in which case this change is fine.
UPDATE: QuickCheck doesn't find a counterexample on my machine:
prop_DeltaCoin_binary_compat :: Word64 -> Property
prop_DeltaCoin_binary_compat x =
serialize' (word64ToCoin x) === serialize' (toDelta (word64ToCoin x))
> quickCheckWith prop_DeltaCoin_binary_compat
+++ OK, passed 100 tests.
So I believe this change is safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, great! thank you for (quick) checking!
tx = Tx @C txbody wits SNothing | ||
st = runShelleyBase $ applySTSTest @(LEDGER C) (TRC (ledgerEnv, (utxoState, dpState), tx)) | ||
-- We test that the serialization of the predicate failure does not return bottom | ||
in serialize' st @?= serialize' st |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a less silly way to enforce that the serialization does not return bottom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use rnf
, deepseq
, or force
on serialize' st
. What you have works too.
(there are two spaces before the second st
)
@@ -40,6 +41,10 @@ type ShelleyBased era = | |||
ChainData (Value era), | |||
SerialisableData (Value era), | |||
SerialisableData (CompactForm (Value era)), | |||
ChainData (Delta (Value era)), | |||
SerialisableData (Delta (Value era)), | |||
Eq (Delta (Value era)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChainData
includes Eq
already.
!(Core.Value era) -- the Coin consumed by this transaction | ||
!(Core.Value era) -- the Coin produced by this transaction | ||
!(Delta (Core.Value era)) -- the Coin consumed by this transaction | ||
!(Delta (Core.Value era)) -- the Coin produced by this transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect forall (x :: Word64). toCBOR (word64ToCoin x) == toCBOR (toDelta (word64ToCoin x)
to be true, in which case this change is fine.
UPDATE: QuickCheck doesn't find a counterexample on my machine:
prop_DeltaCoin_binary_compat :: Word64 -> Property
prop_DeltaCoin_binary_compat x =
serialize' (word64ToCoin x) === serialize' (toDelta (word64ToCoin x))
> quickCheckWith prop_DeltaCoin_binary_compat
+++ OK, passed 100 tests.
So I believe this change is safe.
instance Torsor.Torsor Coin where | ||
type Delta Coin = DeltaCoin | ||
addDelta = addDelta | ||
toDelta = toDelta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a danger of the following happening in modules that import both:
Ambiguous occurrence ‘toDelta’
It could refer to
either ‘Cardano.Ledger.Torsor.toDelta’,
imported from ‘Cardano.Ledger.Torsor’
or ‘Shelley.Spec.Ledger.Coin.toDelta’,
imported from ‘Shelley.Spec.Ledger.Coin’
toDelta :: Coin -> DeltaCoin
could be renamed to toDeltaCoin
?
The ValueNotConservedUTxO predicate failure contains two values of type Coin (in the Shelley era, but Core.Value in general). Though the Coin values in the ledger state are always within the proper bounds (ie Word64), the failure could produce values outside of this range. This caused a serialization error for ValueNotConservedUTxO, since we do not allow the serialization of coins out of the Word64 range. For the Coin type, we already had a wrapper DeltaCoin which can be used when we want to intentionally serialize any Coin. This is now generalized to a Torsor type class, which ValueNotConservedUTxO now uses. Resolves: CAD-2168
70339b9
to
b57ab4e
Compare
bors merge |
1955: fix ValueNotConservedUTxO serialization r=mrBliss a=JaredCorduan The `ValueNotConservedUTxO` predicate failure contains two values of type `Coin` (in the Shelley era, but `Core.Value` in general). Though the `Coin` values in the ledger state are always within the proper bounds (ie `Word64`), the failure could produce values outside of this range. This caused a serialization error for `ValueNotConservedUTxO`, since we do not allow the serialization of coins out of the `Word64` range. For the `Coin` type, we already had a wrapper `DeltaCoin` which can be used when we want to intentionally serialize any `Coin`. This is now generalized to a `Torsor` type class, which `ValueNotConservedUTxO` now uses (I'm happy to have help with the name...). Co-authored-by: Jared Corduan <jared.corduan@iohk.io>
Sorry bors, too slow |
bors cancel |
2719: Update dependency on cardano-ledger-specs r=mrBliss a=mrBliss Reason: IntersectMBO/cardano-ledger#1955 Co-authored-by: Thomas Winant <thomas@well-typed.com>
This updates the dependencies on `cardano-ledger-specs` and `ouroboros-network` to bring in IntersectMBO/cardano-ledger#1955 Other visible change: IntersectMBO/ouroboros-network#2714
This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried. |
bors cancel |
This updates the dependencies on `cardano-ledger-specs` and `ouroboros-network` to bring in IntersectMBO/cardano-ledger#1955 Other visible change: IntersectMBO/ouroboros-network#2714
2039: Update: fix ValueNotConservedUTxO serialization r=mrBliss a=mrBliss This updates the dependencies on `cardano-ledger-specs` and `ouroboros-network` to bring in IntersectMBO/cardano-ledger#1955 Other visible change: IntersectMBO/ouroboros-network#2714 Co-authored-by: Thomas Winant <thomas@well-typed.com>
This updates the dependencies on `cardano-ledger-specs` and `ouroboros-network` to bring in IntersectMBO/cardano-ledger#1955 Other visible change: IntersectMBO/ouroboros-network#2714
The
ValueNotConservedUTxO
predicate failure contains two values of typeCoin
(in the Shelley era, butCore.Value
in general). Though theCoin
values in the ledger state are always within the proper bounds (ieWord64
), the failure could produce values outside of this range. This caused a serialization error forValueNotConservedUTxO
, since we do not allow the serialization of coins out of theWord64
range.For the
Coin
type, we already had a wrapperDeltaCoin
which can be used when we want to intentionally serialize anyCoin
. This is now generalized to aTorsor
type class, whichValueNotConservedUTxO
now uses (I'm happy to have help with the name...).