merkle-log 0.1.1 → 0.2.0
raw patch · 4 files changed
+60/−41 lines, 4 filesdep +cryptondep ~cryptonitePVP ok
version bump matches the API change (PVP)
Dependencies added: crypton
Dependency ranges changed: cryptonite
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- bench/Main.hs +22/−18
- merkle-log.cabal +11/−8
- test/Main.hs +23/−15
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for merkle-log +## 0.2.0 -- 2023-06-08++* Switch from cryptonite to crypton package.+ ## 0.1.1 -- 2021-06-24 * Build with GHC-9
bench/Main.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}@@ -29,7 +30,8 @@ import Criterion import Criterion.Main -import Crypto.Hash+import "crypton" Crypto.Hash+import qualified "cryptonite" Crypto.Hash as CR import qualified Data.ByteArray as BA import qualified Data.ByteString as B@@ -57,15 +59,15 @@ [ bgroup "create tree" [ bgroup "SHA512t_256" [ createBench @(ML SHA512t_256) e- , createBench @(HT SHA512t_256) e+ , createBench @(HT CR.SHA512t_256) e ] , bgroup "SHA256" [ createBench @(ML SHA256) e- , createBench @(HT SHA256) e+ , createBench @(HT CR.SHA256) e ] , bgroup "SHA3_256" [ createBench @(ML SHA3_256) e- , createBench @(HT SHA3_256) e+ , createBench @(HT CR.SHA3_256) e ] , bgroup "BLAKE2b_256" [ createBench @(ML Blake2b_256) e@@ -74,15 +76,15 @@ , bgroup "create inclusion proof" [ bgroup "SHA512t_256" [ proofBench @(ML SHA512t_256) e- , proofBench @(HT SHA512t_256) e+ , proofBench @(HT CR.SHA512t_256) e ] , bgroup "SHA256" [ proofBench @(ML SHA256) e- , proofBench @(HT SHA256) e+ , proofBench @(HT CR.SHA256) e ] , bgroup "SHA3_256" [ proofBench @(ML SHA3_256) e- , proofBench @(HT SHA3_256) e+ , proofBench @(HT CR.SHA3_256) e ] , bgroup "BLAKE2b_256" [ proofBench @(ML Blake2b_256) e@@ -91,15 +93,15 @@ , bgroup "verify inclusion proof" [ bgroup "SHA512t_256" [ verifyBench @(ML SHA512t_256) e- , verifyBench @(HT SHA512t_256) e+ , verifyBench @(HT CR.SHA512t_256) e ] , bgroup "SHA256" [ verifyBench @(ML SHA256) e- , verifyBench @(HT SHA256) e+ , verifyBench @(HT CR.SHA256) e ] , bgroup "SHA3_256" [ verifyBench @(ML SHA3_256) e- , verifyBench @(HT SHA3_256) e+ , verifyBench @(HT CR.SHA3_256) e ] , bgroup "BLAKE2b_256" [ verifyBench @(ML Blake2b_256) e@@ -216,7 +218,9 @@ tree = ML.merkleTree @a . fmap ML.InputNode root = ML.merkleRoot proof t ix i =- let Right p = ML.merkleProof (ML.InputNode ix) i t+ let p = case ML.merkleProof (ML.InputNode ix) i t of+ Right x -> x+ Left e -> error $ "proof creation failed in benchmark: " <> show e in MLProof p (ML.merkleRoot t) verify (MLProof p r) = ML.runMerkleProof p == r @@ -233,7 +237,7 @@ {-# UNPACK #-} !(HT.InclusionProof a) {-# UNPACK #-} !B.ByteString -- ^ Proof subject (leaf)- {-# UNPACK #-} !(Digest a)+ {-# UNPACK #-} !(CR.Digest a) -- ^ Root of the Tree deriving (Generic) @@ -251,17 +255,17 @@ data HT a -htSettings :: forall a . HashAlgorithm a => HT.Settings B.ByteString a+htSettings :: forall a . CR.HashAlgorithm a => HT.Settings B.ByteString a htSettings = HT.defaultSettings- { HT.hash0 = hash @B.ByteString @a mempty- , HT.hash1 = \x -> hash @_ @a (B.singleton 0x00 `B.append` x)- , HT.hash2 = \x y -> hash @_ @a $ B.concat [B.singleton 0x01, BA.convert x, BA.convert y]+ { HT.hash0 = CR.hash @B.ByteString @a mempty+ , HT.hash1 = \x -> CR.hash @_ @a (B.singleton 0x00 `B.append` x)+ , HT.hash2 = \x y -> CR.hash @_ @a $ B.concat [B.singleton 0x01, BA.convert x, BA.convert y] } -instance HashAlgorithm a => Impl (HT a) where+instance (CR.HashAlgorithm a) => Impl (HT a) where type Tree (HT a) = HT.MerkleHashTrees B.ByteString a type Proof (HT a) = HTProof a- type Root (HT a) = Digest a+ type Root (HT a) = CR.Digest a label = "hash-tree" tree = HT.fromList htSettings
merkle-log.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: merkle-log-version: 0.1.1+version: 0.2.0 synopsis: Merkle Tree Logs description: Binary Merkle Trees homepage: https://github.com/kadena-io/merkle-log@@ -9,12 +9,14 @@ license-file: LICENSE author: Lars Kuhtz maintainer: Lars Kuhtz <lars@kadena.io>-copyright: Copyright (c) 2019, Kadena LLC+copyright: Copyright (c) 2019-2023, Kadena LLC category: Data tested-with:- GHC==9.0.1- GHC==8.10.5- GHC==8.8.4+ GHC==9.6+ GHC==9.4+ GHC==9.2+ GHC==9.0+ GHC==8.10 extra-source-files: README.md CHANGELOG.md@@ -33,7 +35,7 @@ build-depends: , base >=4.11 && <5 , bytestring >=0.10- , cryptonite >=0.25+ , crypton >=0.31 , deepseq >=1.4 , exceptions >=0.10 , memory >=0.14@@ -56,7 +58,7 @@ , QuickCheck >=2.11 , base >=4.11 && <5 , bytestring >=0.10- , cryptonite >=0.25+ , crypton >=0.31 , deepseq >=1.4 , exceptions >=0.10 , memory >=0.14@@ -79,7 +81,8 @@ , base >=4.11 && <5 , bytestring >=0.10 , criterion >=1.5- , cryptonite >=0.25+ , crypton >=0.31+ , cryptonite >=0.30 , deepseq >=1.4 , hash-tree >=0.0 , memory >=0.14
test/Main.hs view
@@ -107,27 +107,31 @@ -- is empty (singleton tree). -- changeProofPath :: HashAlgorithm a => MerkleProof a -> MerkleProof a-changeProofPath p = p { _merkleProofObject = o }+changeProofPath p = p { _merkleProofObject = obj } where- Right o = decodeMerkleProofObject . BA.pack @BA.Bytes- $ case splitAt 12 (BA.unpack (_merkleProofObject p)) of- (h, 0x00 : t) -> h <> (0x01 : t)- (h, 0x01 : t) -> h <> (0x00 : t)- (_, _ : _) -> error "invalid proof object"- (_, []) -> error "unexpected empty proof object"+ obj = case decodeMerkleProofObject (BA.pack @BA.Bytes o) of+ Right x -> x+ Left e -> error $ "test/Main.chainProofPath: failed to decode proof object: " <> show e+ o = case splitAt 12 (BA.unpack (_merkleProofObject p)) of+ (h, 0x00 : t) -> h <> (0x01 : t)+ (h, 0x01 : t) -> h <> (0x00 : t)+ (_, _ : _) -> error "invalid proof object"+ (_, []) -> error "unexpected empty proof object" -- | Change hash of first proof step. Throws error is the proof -- is empty (singleton tree). -- changeProofHash :: HashAlgorithm a => MerkleProof a -> MerkleProof a-changeProofHash p = p { _merkleProofObject = o }+changeProofHash p = p { _merkleProofObject = obj } where- Right o = decodeMerkleProofObject . BA.pack @BA.Bytes- $ case splitAt 12 (BA.unpack (_merkleProofObject p)) of- (h, h1 : h2 : t) -> h <> (h1 : 1 + h2 : t)- (_, []) -> error "unexpected empty proof object"- _ -> error "invalid proof object"+ obj = case decodeMerkleProofObject (BA.pack @BA.Bytes o) of+ Right x -> x+ Left e -> error $ "test/Main.chainProofHash: failed to decode proof object: " <> show e+ o = case splitAt 12 (BA.unpack (_merkleProofObject p)) of+ (h, h1 : h2 : t) -> h <> (h1 : 1 + h2 : t)+ (_, []) -> error "unexpected empty proof object"+ _ -> error "invalid proof object" -- | Changes the proof step count and verifies that decoding of the modified proof object fails. -- Throws error is the proof is empty (singleton tree).@@ -261,7 +265,9 @@ p = case merkleProof (l !! i) i t of Left e -> error (displayException e) Right x -> x- p' = p { _merkleProofSubject = MerkleProofSubject (InputNode "a") }+ p' = p { _merkleProofSubject = changeSubject (_merkleProofSubject p) }+ changeSubject (MerkleProofSubject (InputNode "a")) = MerkleProofSubject (InputNode "b")+ changeSubject _ = MerkleProofSubject (InputNode "b") prop_proofInvalidObjectPath :: UniqueInputs SHA512t_256@@ -305,7 +311,9 @@ prop_chainProof (MerkleTreeChain l) = runMerkleProof @SHA512t_256 p === merkleRoot (snd $ NE.last l) where- Right p = merkleProof_ (InputNode "a") l+ p = case merkleProof_ (InputNode "a") l of+ Right x -> x+ Left e -> error $ "test/Main.prop_chainProof: merkleProof failed: " <> show e prop_encodeProofObject :: MerkleProof SHA512t_256 -> Property prop_encodeProofObject p