Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
92 stars 50 forks source link

`SubCoin` aliased over wrong type #1397

Open jy14898 opened 1 year ago

jy14898 commented 1 year ago

https://github.com/input-output-hk/cardano-ledger/blob/bb0b5a2c4218a7704c45e2066a2de31fe2683b8f/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L377

sub_coin = positive_interval

https://github.com/Plutonomicon/cardano-transaction-lib/blob/7f2532c824dfc516c3851d90df575586059603ad/src/Internal/Cardano/Types/Transaction.purs#L413

I don't think it'll ever be relevant, maybe a comment will suffice. Even then, UnitInterval doesn't even check it lies between 0 and 1...

klntsky commented 1 year ago

UnitInterval consists of BigNums that are always positive. Where is positive_interval defined in CDDL? In CSL, there are no checks for the value to be in range (the type is UnitInterval there)

jy14898 commented 1 year ago

Well, the formal definitions are unit interval = 0.0 to 1.0, positive internal = 0.0 to infinity

This lines up with what the ledger PDF says

image

Note that for prices (which uses subcoin, and therefore positive_interval), they just use a rational in the spec...

image

Pool influence (according to the PDF) shouldn't be a unit interval either image

https://github.com/Plutonomicon/cardano-transaction-lib/blob/7f2532c824dfc516c3851d90df575586059603ad/src/Internal/Cardano/Types/Transaction.purs#L388-L390

I think CSL is wrong too, but it's just a matter of naming, the underlying representation for all is the same:

image