packages feed

haskoin-core 3.0.0 → 3.0.1

raw patch · 5 files changed

+84/−56 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -7,6 +7,23 @@  ## [Unreleased] +## [3.0.1] - 2026-11-30++### Fixed++- **The tests with a time limit on a large transaction no longer fail on a+  slow or busy computer.** Sixteen tests check that `signTx`, `verifyStdTx`,+  `judgeInputs`, `signPsbt`, `finalizePsbt` and `mergeTxs` hash a transaction+  once and not once for each input, by a limit on their time. With 5000+  inputs and a limit of three seconds, the slowest of them took over a+  second built with optimisation, and one went over the limit on the+  builder of Stackage, which is twice as slow. The transaction now has 1000+  inputs and 200,000 outputs, and the limit is eight seconds: the code takes+  0.4 seconds at most, and code that hashes for each input takes 35 or+  more. The old sizes left little room on that side too: built with+  optimisation, code that hashes for each input took 3.3 to 3.8 seconds+  for 5000 inputs, just over the limit. Only the tests changed.+ ## [3.0.0] - 2026-11-25  This release breaks backwards compatibility in three places:
README.md view
@@ -116,7 +116,7 @@ ```yaml resolver: nightly-2026-10-28 extra-deps:-  - haskoin-core-3.0.0+  - haskoin-core-3.0.1   - base16-2.0   - secp256k1-haskell-3.0.0 ```
haskoin-core.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           haskoin-core-version:        3.0.0+version:        3.0.1 synopsis:       Bitcoin & Bitcoin Cash library for Haskell description:    Please see the README on GitHub at <https://github.com/jprupp/haskoin-core#readme> category:       Bitcoin, Finance, Network
test/Haskoin/Transaction/TaprootSpec.hs view
@@ -742,25 +742,37 @@ -- | BIP 341 has the digest of every input of a transaction commit to four -- hashes over all its inputs and one over all its outputs, which "may be -- cached across signatures of the same transaction". Each test fails by its--- time when a function computes them again for each input: 5000 times the--- hashes of 5000 inputs. The seconds in the comments are those of such--- code built without optimisation, on the computer where the tests were--- written. The code that computes the hashes once takes under a second--- there.+-- time when a function computes them again for each input: 1000 times the+-- hashes of 200,000 outputs.+--+-- The limit is a time on the clock, so a slow or busy computer can fail a+-- test of code that is right. The builder of Stackage did, at twice the+-- time of the computer where the tests were written, when the transaction+-- had 5000 inputs and one output and the limit was three seconds. The many+-- outputs are what keeps the two kinds of code apart: they cost the code+-- that hashes once next to nothing, and they are most of what the other+-- code hashes for each input. On that computer a test takes 0.4 seconds+-- at most with the code that hashes once, built with optimisation or+-- without: a twentieth of the limit. With code that hashes for each input+-- it takes 37 seconds built with optimisation and 100 without, over four+-- times the limit. sharedHashesCostSpec :: Spec sharedHashesCostSpec =   describe-    "A transaction of 5000 Taproot inputs takes time by its size, \-    \and not by the square of its size: in under three seconds"+    "A transaction of 1000 Taproot inputs and 200,000 outputs takes time by its size, \+    \and not by the number of its inputs times its size: in under eight seconds"     $ do-      let count = 5000+      let count = 1000+          payments = 200000+          limit = 8000000           secret = (fst bip86Key).key           internal = derivePubKey secret           coinScript = either error id (taprootScriptOutput (TaprootOutput internal Nothing))           coin = TxOut 100000 (encodeSerial coinScript)           funding = "1111111111111111111111111111111111111111111111111111111111111111"-          outpoints = [OutPoint funding i | i <- [1 .. 5000]]-          unsigned = buildTx outpoints [(coinScript, 99000)]+          outpoints = [OutPoint funding i | i <- [1 .. fromIntegral count]]+          -- 1000 coins of 100,000 satoshi pay 200,000 outputs of 400+          unsigned = buildTx outpoints (replicate payments (coinScript, 400))           sigInputs = [SigInput coinScript 100000 outpoint sigHashDefault Nothing | outpoint <- outpoints]           signed = either error id (signTx btc unsigned sigInputs [secret])           -- The PSBT of the transaction: each input has its coin and the@@ -770,51 +782,45 @@                 input = insertInputTapInternalKey internal (insertWitnessUtxo coin Map.empty)              in Psbt empty.version empty.unsignedTx empty.globals (replicate count input) empty.outputs           signedPsbt = either error id (signPsbt btc (keySigner secret) psbt)-          -- Whether the work gives the answer, when it does within three-          -- seconds. What the work starts from is built before the time+          -- Whether the work gives the answer, when it does within the+          -- limit. What the work starts from is built before the time           -- starts.           answers :: (Eq a) => Int -> a -> a -> IO (Maybe Bool)           answers built work answer = do             _ <- evaluate built-            timeout 3000000 (evaluate (work == answer))+            timeout limit (evaluate (work == answer))           sizeOf = BS.length . encodeSerial -      -- 15 seconds       it "taprootSigHashWith gives a digest of its own to each input, from the hashes that they share" $ do         let digests = do               hashes <- taprootTxHashes unsigned (replicate count coin)               mapM (\i -> taprootSigHashWith hashes i sigHashDefault Nothing Nothing) [0 .. count - 1]-        answers (sizeOf unsigned) (Set.size . Set.fromList <$> digests) (Right 5000) `shouldReturn` Just True+        answers (sizeOf unsigned) (Set.size . Set.fromList <$> digests) (Right count) `shouldReturn` Just True -      -- 16 seconds       it "signTx signs every input with a signature of 64 bytes" $ do         let signatureSizes = map (map BS.length) . (.witness)             signatures = signatureSizes <$> signTx btc unsigned sigInputs [secret]-        answers (sizeOf unsigned) signatures (Right (replicate 5000 [64]))+        answers (sizeOf unsigned) signatures (Right (replicate count [64]))           `shouldReturn` Just True -      -- 16 seconds       it "verifyStdTx verifies the signed transaction" $         answers (sizeOf signed) (verifyStdTx btc signed [(coinScript, 100000, outpoint) | outpoint <- outpoints]) True           `shouldReturn` Just True -      -- 16 seconds       it "judgeInputs says of every input of the signed transaction that it is verified" $-        answers (sizeOf signed) (judgeInputs btc signed (replicate count (Just coin))) (replicate 5000 InputVerified)+        answers (sizeOf signed) (judgeInputs btc signed (replicate count (Just coin))) (replicate count InputVerified)           `shouldReturn` Just True -      -- 16 seconds       it "signPsbt adds a key path signature of 64 bytes to every input" $ do         let signatureSizes = map (fmap (fmap (BS.length . encodeTaprootSig)) . tapKeySig) . (.inputs)             signedInputs = signatureSizes <$> signPsbt btc (keySigner secret) psbt-        answers (BS.length (encodePsbt psbt)) signedInputs (Right (replicate 5000 (Right (Just 64))))+        answers (BS.length (encodePsbt psbt)) signedInputs (Right (replicate count (Right (Just 64))))           `shouldReturn` Just True -      -- 16 seconds       it "finalizePsbt gives every input a final witness of one signature of 64 bytes" $ do         let witnessSizes = map (fmap (fmap (map BS.length)) . finalScriptWitness) . (.inputs)             finalInputs = witnessSizes <$> finalizePsbt btc signedPsbt-        answers (BS.length (encodePsbt signedPsbt)) finalInputs (Right (replicate 5000 (Right (Just [64]))))+        answers (BS.length (encodePsbt signedPsbt)) finalInputs (Right (replicate count (Right (Just [64]))))           `shouldReturn` Just True  digestHex :: Digest SHA256 -> Text
test/Haskoin/TransactionSpec.hs view
@@ -1233,22 +1233,35 @@ -- output of the transaction. It is the digest of a SegWit version 0 input -- on Bitcoin and of every input on Bitcoin Cash. When each input computes -- the three hashes again, the time grows with the number of inputs times--- the size of the transaction. The comment of a test is the time that it--- took before the hashes were computed once.+-- the size of the transaction. Each test fails by its time then: 1000+-- times the hashes of 200,000 outputs.+--+-- The limit is a time on the clock, so a slow or busy computer can fail a+-- test of code that is right, as the builder of Stackage did when the+-- transaction had 5000 inputs and 8000 outputs and the limit was three+-- seconds. The many outputs are what keeps the two kinds of code apart:+-- they cost the code that hashes once next to nothing, and they are most+-- of what the other code hashes for each input. On the computer where+-- the tests were written, a test takes 0.3 seconds at most with the code+-- that hashes once, built with optimisation or without: a twentieth of+-- the limit. With code that hashes for each input it takes 35 seconds+-- built with optimisation, over four times the limit. sharedHashesCostSpec :: Spec sharedHashesCostSpec =   describe-    "A transaction of 5000 inputs and 8000 outputs takes time by its size, \-    \and not by the square of its size: in under three seconds"+    "A transaction of 1000 inputs and 200,000 outputs takes time by its size, \+    \and not by the number of its inputs times its size: in under eight seconds"     $ do-      let (key, public) = fixedKey 1+      let count = 1000+          limit = 8000000+          (key, public) = fixedKey 1           h = keyHash public-          outpoints = map coinAt [1 .. 5000]-          -- 5000 coins of 100,000 satoshi pay 8000 outputs of 50,000-          unsigned = buildTx outpoints (replicate 8000 (PayPKHash h, 50000))+          outpoints = map coinAt [1 .. fromIntegral count]+          -- 1000 coins of 100,000 satoshi pay 200,000 outputs of 400+          unsigned = buildTx outpoints (replicate 200000 (PayPKHash h, 400))           sigInputs coin = [SigInput coin 100000 outpoint sigHashAll Nothing | outpoint <- outpoints]           coins coin = [(coin, 100000, outpoint) | outpoint <- outpoints]-          spent coin = replicate 5000 (Just (TxOut 100000 (encodeSerial coin)))+          spent coin = replicate count (Just (TxOut 100000 (encodeSerial coin)))           signedOn net coin = either error id (signTx net unsigned (sigInputs coin) [key.key])           -- On Bitcoin the coins are P2WPKH, on Bitcoin Cash P2PKH           witnessCoin = PayWitnessPKHash h@@ -1265,69 +1278,61 @@           psbt =             let empty = psbtOf unsigned                 input = insertWitnessUtxo (TxOut 100000 (encodeSerial witnessCoin)) Map.empty-             in Psbt empty.version empty.unsignedTx empty.globals (replicate 5000 input) empty.outputs+             in Psbt empty.version empty.unsignedTx empty.globals (replicate count input) empty.outputs           signer = (keySigner key.key) {requirePreviousTx = False}           signedPsbt = either error id (signPsbt btc signer psbt)-          -- Whether the work gives the answer, when it does within three-          -- seconds. What the work starts from is built before the time+          -- Whether the work gives the answer, when it does within the+          -- limit. What the work starts from is built before the time           -- starts.           answers :: (Eq a) => Int -> a -> a -> IO (Maybe Bool)           answers built work answer = do             _ <- evaluate built-            timeout 3000000 (evaluate (work == answer))+            timeout limit (evaluate (work == answer))           sizeOf = B.length . encodeSerial        it "txSigHashForkIdWith gives a digest of its own to each input, from the hashes that they share" $ do         let hashes = txSigHashes unsigned             digests = do               code <- encodeOutput cashCoin-              mapM (\i -> txSigHashForkIdWith btc hashes code 100000 i sigHashAll) [0 .. 4999]-        answers (sizeOf unsigned) (Set.size . Set.fromList <$> digests) (Right 5000) `shouldReturn` Just True+              mapM (\i -> txSigHashForkIdWith btc hashes code 100000 i sigHashAll) [0 .. count - 1]+        answers (sizeOf unsigned) (Set.size . Set.fromList <$> digests) (Right count) `shouldReturn` Just True -      -- 18 seconds       it "signTx gives every SegWit input a signature that ends with the hash type 0x01, and the key of 33 bytes" $ do         let shape stack = (B.last <$> take 1 stack, B.length <$> drop 1 stack)             witnesses = map shape . (.witness) <$> signTx btc unsigned (sigInputs witnessCoin) [key.key]-        answers (sizeOf unsigned) witnesses (Right (replicate 5000 ([0x01], [33]))) `shouldReturn` Just True+        answers (sizeOf unsigned) witnesses (Right (replicate count ([0x01], [33]))) `shouldReturn` Just True -      -- 17 seconds       it "verifyStdTx verifies the signed SegWit transaction" $         answers (sizeOf signed) (verifyStdTx btc signed (coins witnessCoin)) True `shouldReturn` Just True -      -- 17 seconds       it "judgeInputs says of every input of the signed SegWit transaction that it is verified" $-        answers (sizeOf signed) (judgeInputs btc signed (spent witnessCoin)) (replicate 5000 InputVerified)+        answers (sizeOf signed) (judgeInputs btc signed (spent witnessCoin)) (replicate count InputVerified)           `shouldReturn` Just True -      -- 17 seconds       it "signPsbt adds one partial signature to every SegWit input" $ do         let signatureCounts = map (fmap length . partialSignatures) . (.inputs)             signedInputs = signatureCounts <$> signPsbt btc signer psbt-        answers (B.length (encodePsbt psbt)) signedInputs (Right (replicate 5000 (Right 1)))+        answers (B.length (encodePsbt psbt)) signedInputs (Right (replicate count (Right 1)))           `shouldReturn` Just True -      -- 17 seconds       it "finalizePsbt gives every SegWit input a final witness of two items" $ do         let witnessSizes = map (fmap (fmap length) . finalScriptWitness) . (.inputs)             finalInputs = witnessSizes <$> finalizePsbt btc signedPsbt-        answers (B.length (encodePsbt signedPsbt)) finalInputs (Right (replicate 5000 (Right (Just 2))))+        answers (B.length (encodePsbt signedPsbt)) finalInputs (Right (replicate count (Right (Just 2))))           `shouldReturn` Just True -      -- 17 seconds       it "signTx signs every input of Bitcoin Cash with the hash type 0x41" $ do         let hashType input = case unmarshal bch input.script of               Right (RegularInput (SpendPKHash (TxSignature _ sh) _)) -> Just sh               _ -> Nothing             hashTypes = map hashType . (.inputs) <$> signTx bch unsigned (sigInputs cashCoin) [key.key]-        answers (sizeOf unsigned) hashTypes (Right (replicate 5000 (Just 0x41))) `shouldReturn` Just True+        answers (sizeOf unsigned) hashTypes (Right (replicate count (Just 0x41))) `shouldReturn` Just True -      -- 17 seconds       it "verifyStdTx verifies the signed transaction of Bitcoin Cash" $         answers (sizeOf cashSigned) (verifyStdTx bch cashSigned (coins cashCoin)) True `shouldReturn` Just True -      -- 17 seconds       it "judgeInputs says of every input of the signed transaction of Bitcoin Cash that it is verified" $-        answers (sizeOf cashSigned) (judgeInputs bch cashSigned (spent cashCoin)) (replicate 5000 InputVerified)+        answers (sizeOf cashSigned) (judgeInputs bch cashSigned (spent cashCoin)) (replicate count InputVerified)           `shouldReturn` Just True        it "mergeTxs gives every multisig input of Bitcoin Cash the signatures of its two cosigners" $ do@@ -1335,7 +1340,7 @@               Right (RegularInput (SpendMulSig sigs)) -> Just (length sigs)               _ -> Nothing             counts = map signatureCount . (.inputs) <$> mergeTxs bch cosigned (coins multisigCoin)-        answers (sum (map sizeOf cosigned)) counts (Right (replicate 5000 (Just 2))) `shouldReturn` Just True+        answers (sum (map sizeOf cosigned)) counts (Right (replicate count (Just 2))) `shouldReturn` Just True  genesisSpec :: Spec genesisSpec =