import PlutusTx
import PlutusTx.IsData
import Codec.Serialise
import Data.ByteString.Lazy as BL
import Data.ByteString as BS
import qualified Data.Text.Encoding as Text
import qualified Data.ByteString.Base16 as Base16
import Data.Text (Text)
toHexDigest :: BS.ByteString -> Text
toHexDigest = Text.decodeUtf8 . Base16.encode
toHex = toHexDigest . BL.toStrict . serialise . toData
test = [ toHex 0, toHex 1 ]
> test
["00","01"]
So serialization-lib treats zero very specifically for some reason.
This is the source to the problem that hashing any datum that contains Integer 0 gives a completely wrong result.
We really can't monkey-patch this in CTL, because to_bytes call recurses over WASM data on CSL side. So we really need to update our CSL fork and ask @ngua to upload a new version to NPM.
Quite a while ago I discovered an inconsistency between plutus and cardano-serialization-lib:
Output:
And in Plutus:
So serialization-lib treats zero very specifically for some reason.
This is the source to the problem that hashing any datum that contains
Integer 0
gives a completely wrong result.We really can't monkey-patch this in CTL, because
to_bytes
call recurses over WASM data on CSL side. So we really need to update our CSL fork and ask @ngua to upload a new version to NPM.https://github.com/ngua/cardano-serialization-lib
The ask:
Identify all affected types (CheckInt
,BigInt
,BigNum
in CSL)Fix the CBOR encoder so that it outputs results consistent with Plutus.Upstream the fixActually we just need to update CSL: this has already been fixed: https://github.com/Emurgo/cardano-serialization-lib/pull/332