blockchainkit 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. blockchainkit-0.2.0/CHANGELOG.md +148 -0
  2. blockchainkit-0.2.0/CITATION.cff +20 -0
  3. blockchainkit-0.2.0/CODE_OF_CONDUCT.md +66 -0
  4. blockchainkit-0.2.0/CONTRIBUTING.md +80 -0
  5. blockchainkit-0.2.0/LICENSE +21 -0
  6. blockchainkit-0.2.0/MANIFEST.in +9 -0
  7. blockchainkit-0.2.0/PKG-INFO +195 -0
  8. blockchainkit-0.2.0/README.md +142 -0
  9. blockchainkit-0.2.0/ROADMAP.md +40 -0
  10. blockchainkit-0.2.0/SECURITY.md +36 -0
  11. blockchainkit-0.2.0/blockchainkit/__init__.py +12 -0
  12. blockchainkit-0.2.0/blockchainkit/_validation.py +44 -0
  13. blockchainkit-0.2.0/blockchainkit/consensus/__init__.py +66 -0
  14. blockchainkit-0.2.0/blockchainkit/consensus/core/__init__.py +25 -0
  15. blockchainkit-0.2.0/blockchainkit/consensus/core/base.py +97 -0
  16. blockchainkit-0.2.0/blockchainkit/consensus/systems/__init__.py +46 -0
  17. blockchainkit-0.2.0/blockchainkit/consensus/systems/byzantine.py +91 -0
  18. blockchainkit-0.2.0/blockchainkit/consensus/systems/catch_up.py +60 -0
  19. blockchainkit-0.2.0/blockchainkit/consensus/systems/difficulty.py +74 -0
  20. blockchainkit-0.2.0/blockchainkit/consensus/systems/finality.py +92 -0
  21. blockchainkit-0.2.0/blockchainkit/consensus/systems/fork_choice.py +44 -0
  22. blockchainkit-0.2.0/blockchainkit/consensus/systems/pbft.py +78 -0
  23. blockchainkit-0.2.0/blockchainkit/consensus/systems/pos.py +53 -0
  24. blockchainkit-0.2.0/blockchainkit/consensus/systems/pow.py +58 -0
  25. blockchainkit-0.2.0/blockchainkit/consensus/systems/pricing.py +50 -0
  26. blockchainkit-0.2.0/blockchainkit/consensus/systems/randomized.py +114 -0
  27. blockchainkit-0.2.0/blockchainkit/consensus/systems/selfish.py +81 -0
  28. blockchainkit-0.2.0/blockchainkit/consensus/systems/sortition.py +48 -0
  29. blockchainkit-0.2.0/blockchainkit/consensus/systems/stake_games.py +44 -0
  30. blockchainkit-0.2.0/blockchainkit/consensus/systems/synchrony.py +49 -0
  31. blockchainkit-0.2.0/blockchainkit/consensus/tests/__init__.py +0 -0
  32. blockchainkit-0.2.0/blockchainkit/consensus/tests/test_boundary_cases.py +28 -0
  33. blockchainkit-0.2.0/blockchainkit/consensus/tests/test_breakthrough_apis.py +318 -0
  34. blockchainkit-0.2.0/blockchainkit/consensus/tests/test_consensus.py +61 -0
  35. blockchainkit-0.2.0/blockchainkit/consensus/tests/test_visualizers.py +27 -0
  36. blockchainkit-0.2.0/blockchainkit/consensus/visualizers/__init__.py +9 -0
  37. blockchainkit-0.2.0/blockchainkit/consensus/visualizers/plots.py +80 -0
  38. blockchainkit-0.2.0/blockchainkit/constants.py +66 -0
  39. blockchainkit-0.2.0/blockchainkit/crypto/__init__.py +157 -0
  40. blockchainkit-0.2.0/blockchainkit/crypto/core/__init__.py +21 -0
  41. blockchainkit-0.2.0/blockchainkit/crypto/core/base.py +109 -0
  42. blockchainkit-0.2.0/blockchainkit/crypto/systems/__init__.py +137 -0
  43. blockchainkit-0.2.0/blockchainkit/crypto/systems/asymmetric.py +136 -0
  44. blockchainkit-0.2.0/blockchainkit/crypto/systems/commitments.py +93 -0
  45. blockchainkit-0.2.0/blockchainkit/crypto/systems/curves.py +205 -0
  46. blockchainkit-0.2.0/blockchainkit/crypto/systems/discrete_log.py +156 -0
  47. blockchainkit-0.2.0/blockchainkit/crypto/systems/hashing.py +95 -0
  48. blockchainkit-0.2.0/blockchainkit/crypto/systems/lamport.py +65 -0
  49. blockchainkit-0.2.0/blockchainkit/crypto/systems/mac.py +34 -0
  50. blockchainkit-0.2.0/blockchainkit/crypto/systems/merkle_damgard.py +139 -0
  51. blockchainkit-0.2.0/blockchainkit/crypto/systems/multisig.py +98 -0
  52. blockchainkit-0.2.0/blockchainkit/crypto/systems/one_time_pad.py +42 -0
  53. blockchainkit-0.2.0/blockchainkit/crypto/systems/puzzles.py +96 -0
  54. blockchainkit-0.2.0/blockchainkit/crypto/systems/sharing.py +159 -0
  55. blockchainkit-0.2.0/blockchainkit/crypto/systems/signatures.py +232 -0
  56. blockchainkit-0.2.0/blockchainkit/crypto/tests/__init__.py +0 -0
  57. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_boundary_cases.py +145 -0
  58. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_commitments_and_sharing.py +90 -0
  59. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_crypto.py +203 -0
  60. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_discrete_log.py +76 -0
  61. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_hash_attacks.py +105 -0
  62. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_one_time_pad.py +39 -0
  63. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_puzzles.py +48 -0
  64. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_signature_breakthroughs.py +91 -0
  65. blockchainkit-0.2.0/blockchainkit/crypto/tests/test_visualizers.py +31 -0
  66. blockchainkit-0.2.0/blockchainkit/crypto/utils/__init__.py +5 -0
  67. blockchainkit-0.2.0/blockchainkit/crypto/utils/primes.py +39 -0
  68. blockchainkit-0.2.0/blockchainkit/crypto/visualizers/__init__.py +9 -0
  69. blockchainkit-0.2.0/blockchainkit/crypto/visualizers/plots.py +88 -0
  70. blockchainkit-0.2.0/blockchainkit/network/__init__.py +70 -0
  71. blockchainkit-0.2.0/blockchainkit/network/core/__init__.py +21 -0
  72. blockchainkit-0.2.0/blockchainkit/network/core/base.py +149 -0
  73. blockchainkit-0.2.0/blockchainkit/network/systems/__init__.py +54 -0
  74. blockchainkit-0.2.0/blockchainkit/network/systems/addresses.py +126 -0
  75. blockchainkit-0.2.0/blockchainkit/network/systems/broadcast.py +124 -0
  76. blockchainkit-0.2.0/blockchainkit/network/systems/clocks.py +149 -0
  77. blockchainkit-0.2.0/blockchainkit/network/systems/epidemics.py +111 -0
  78. blockchainkit-0.2.0/blockchainkit/network/systems/gossip.py +201 -0
  79. blockchainkit-0.2.0/blockchainkit/network/systems/kademlia.py +147 -0
  80. blockchainkit-0.2.0/blockchainkit/network/systems/privacy.py +98 -0
  81. blockchainkit-0.2.0/blockchainkit/network/systems/propagation.py +60 -0
  82. blockchainkit-0.2.0/blockchainkit/network/systems/relay.py +123 -0
  83. blockchainkit-0.2.0/blockchainkit/network/systems/replication.py +122 -0
  84. blockchainkit-0.2.0/blockchainkit/network/systems/topology.py +238 -0
  85. blockchainkit-0.2.0/blockchainkit/network/tests/__init__.py +0 -0
  86. blockchainkit-0.2.0/blockchainkit/network/tests/test_boundary_cases.py +161 -0
  87. blockchainkit-0.2.0/blockchainkit/network/tests/test_breakthrough_apis.py +297 -0
  88. blockchainkit-0.2.0/blockchainkit/network/tests/test_network.py +119 -0
  89. blockchainkit-0.2.0/blockchainkit/network/tests/test_visualizers.py +76 -0
  90. blockchainkit-0.2.0/blockchainkit/network/visualizers/__init__.py +14 -0
  91. blockchainkit-0.2.0/blockchainkit/network/visualizers/plots.py +177 -0
  92. blockchainkit-0.2.0/blockchainkit/py.typed +0 -0
  93. blockchainkit-0.2.0/blockchainkit/structures/__init__.py +61 -0
  94. blockchainkit-0.2.0/blockchainkit/structures/core/__init__.py +21 -0
  95. blockchainkit-0.2.0/blockchainkit/structures/core/base.py +100 -0
  96. blockchainkit-0.2.0/blockchainkit/structures/systems/__init__.py +45 -0
  97. blockchainkit-0.2.0/blockchainkit/structures/systems/block.py +144 -0
  98. blockchainkit-0.2.0/blockchainkit/structures/systems/bloom.py +81 -0
  99. blockchainkit-0.2.0/blockchainkit/structures/systems/chain.py +131 -0
  100. blockchainkit-0.2.0/blockchainkit/structures/systems/hash_chain.py +35 -0
  101. blockchainkit-0.2.0/blockchainkit/structures/systems/headers.py +54 -0
  102. blockchainkit-0.2.0/blockchainkit/structures/systems/ledger.py +87 -0
  103. blockchainkit-0.2.0/blockchainkit/structures/systems/merkle.py +273 -0
  104. blockchainkit-0.2.0/blockchainkit/structures/systems/mmr.py +112 -0
  105. blockchainkit-0.2.0/blockchainkit/structures/systems/sparse_merkle.py +139 -0
  106. blockchainkit-0.2.0/blockchainkit/structures/systems/transaction.py +116 -0
  107. blockchainkit-0.2.0/blockchainkit/structures/systems/utxo.py +156 -0
  108. blockchainkit-0.2.0/blockchainkit/structures/tests/__init__.py +0 -0
  109. blockchainkit-0.2.0/blockchainkit/structures/tests/test_boundary_cases.py +132 -0
  110. blockchainkit-0.2.0/blockchainkit/structures/tests/test_breakthrough_apis.py +317 -0
  111. blockchainkit-0.2.0/blockchainkit/structures/tests/test_inspection.py +69 -0
  112. blockchainkit-0.2.0/blockchainkit/structures/tests/test_structures.py +159 -0
  113. blockchainkit-0.2.0/blockchainkit/structures/tests/test_visualizers.py +47 -0
  114. blockchainkit-0.2.0/blockchainkit/structures/utils/__init__.py +6 -0
  115. blockchainkit-0.2.0/blockchainkit/structures/utils/accounts.py +13 -0
  116. blockchainkit-0.2.0/blockchainkit/structures/utils/encoding.py +11 -0
  117. blockchainkit-0.2.0/blockchainkit/structures/visualizers/__init__.py +13 -0
  118. blockchainkit-0.2.0/blockchainkit/structures/visualizers/plots.py +154 -0
  119. blockchainkit-0.2.0/blockchainkit/tests/__init__.py +0 -0
  120. blockchainkit-0.2.0/blockchainkit/tests/test_package.py +60 -0
  121. blockchainkit-0.2.0/blockchainkit/tests/test_visualizers.py +37 -0
  122. blockchainkit-0.2.0/blockchainkit/vm/__init__.py +60 -0
  123. blockchainkit-0.2.0/blockchainkit/vm/core/__init__.py +25 -0
  124. blockchainkit-0.2.0/blockchainkit/vm/core/base.py +171 -0
  125. blockchainkit-0.2.0/blockchainkit/vm/systems/__init__.py +40 -0
  126. blockchainkit-0.2.0/blockchainkit/vm/systems/assembler.py +80 -0
  127. blockchainkit-0.2.0/blockchainkit/vm/systems/expressions.py +91 -0
  128. blockchainkit-0.2.0/blockchainkit/vm/systems/programs.py +143 -0
  129. blockchainkit-0.2.0/blockchainkit/vm/systems/reentrancy.py +70 -0
  130. blockchainkit-0.2.0/blockchainkit/vm/systems/script.py +268 -0
  131. blockchainkit-0.2.0/blockchainkit/vm/systems/stack_machine.py +239 -0
  132. blockchainkit-0.2.0/blockchainkit/vm/systems/turing.py +111 -0
  133. blockchainkit-0.2.0/blockchainkit/vm/systems/verifier.py +81 -0
  134. blockchainkit-0.2.0/blockchainkit/vm/tests/__init__.py +0 -0
  135. blockchainkit-0.2.0/blockchainkit/vm/tests/test_boundary_cases.py +142 -0
  136. blockchainkit-0.2.0/blockchainkit/vm/tests/test_breakthrough_apis.py +217 -0
  137. blockchainkit-0.2.0/blockchainkit/vm/tests/test_trace.py +67 -0
  138. blockchainkit-0.2.0/blockchainkit/vm/tests/test_visualizers.py +43 -0
  139. blockchainkit-0.2.0/blockchainkit/vm/tests/test_vm.py +84 -0
  140. blockchainkit-0.2.0/blockchainkit/vm/visualizers/__init__.py +9 -0
  141. blockchainkit-0.2.0/blockchainkit/vm/visualizers/plots.py +97 -0
  142. blockchainkit-0.2.0/blockchainkit.egg-info/PKG-INFO +195 -0
  143. blockchainkit-0.2.0/blockchainkit.egg-info/SOURCES.txt +277 -0
  144. blockchainkit-0.2.0/blockchainkit.egg-info/dependency_links.txt +1 -0
  145. blockchainkit-0.2.0/blockchainkit.egg-info/requires.txt +24 -0
  146. blockchainkit-0.2.0/blockchainkit.egg-info/top_level.txt +1 -0
  147. blockchainkit-0.2.0/conftest.py +16 -0
  148. blockchainkit-0.2.0/examples/consensus/README.rst +13 -0
  149. blockchainkit-0.2.0/examples/consensus/agreement/README.rst +4 -0
  150. blockchainkit-0.2.0/examples/consensus/agreement/plot_01_byzantine_generals.py +67 -0
  151. blockchainkit-0.2.0/examples/consensus/agreement/plot_02_ben_or.py +59 -0
  152. blockchainkit-0.2.0/examples/consensus/agreement/plot_03_flp_impossibility.py +63 -0
  153. blockchainkit-0.2.0/examples/consensus/agreement/plot_04_partial_synchrony.py +60 -0
  154. blockchainkit-0.2.0/examples/consensus/agreement/plot_05_pbft.py +61 -0
  155. blockchainkit-0.2.0/examples/consensus/attacks/README.rst +4 -0
  156. blockchainkit-0.2.0/examples/consensus/attacks/plot_01_gamblers_ruin.py +64 -0
  157. blockchainkit-0.2.0/examples/consensus/attacks/plot_02_double_spend.py +78 -0
  158. blockchainkit-0.2.0/examples/consensus/attacks/plot_03_selfish_mining.py +60 -0
  159. blockchainkit-0.2.0/examples/consensus/nakamoto/README.rst +4 -0
  160. blockchainkit-0.2.0/examples/consensus/nakamoto/plot_01_longest_chain.py +102 -0
  161. blockchainkit-0.2.0/examples/consensus/nakamoto/plot_02_ghost.py +68 -0
  162. blockchainkit-0.2.0/examples/consensus/pos/README.rst +4 -0
  163. blockchainkit-0.2.0/examples/consensus/pos/plot_01_stake.py +61 -0
  164. blockchainkit-0.2.0/examples/consensus/pos/plot_02_nothing_at_stake.py +61 -0
  165. blockchainkit-0.2.0/examples/consensus/pos/plot_03_sortition.py +78 -0
  166. blockchainkit-0.2.0/examples/consensus/pos/plot_04_casper_ffg.py +70 -0
  167. blockchainkit-0.2.0/examples/consensus/pow/README.rst +4 -0
  168. blockchainkit-0.2.0/examples/consensus/pow/plot_01_pricing_via_processing.py +58 -0
  169. blockchainkit-0.2.0/examples/consensus/pow/plot_02_hashcash.py +78 -0
  170. blockchainkit-0.2.0/examples/consensus/pow/plot_03_difficulty_retargeting.py +55 -0
  171. blockchainkit-0.2.0/examples/crypto/README.rst +14 -0
  172. blockchainkit-0.2.0/examples/crypto/blind_signatures/README.rst +4 -0
  173. blockchainkit-0.2.0/examples/crypto/blind_signatures/plot_01_blind_signatures.py +71 -0
  174. blockchainkit-0.2.0/examples/crypto/commitments/README.rst +4 -0
  175. blockchainkit-0.2.0/examples/crypto/commitments/plot_01_coin_flipping.py +71 -0
  176. blockchainkit-0.2.0/examples/crypto/commitments/plot_02_pedersen.py +69 -0
  177. blockchainkit-0.2.0/examples/crypto/curves/README.rst +4 -0
  178. blockchainkit-0.2.0/examples/crypto/curves/plot_01_elliptic_curves.py +65 -0
  179. blockchainkit-0.2.0/examples/crypto/discrete_log/README.rst +4 -0
  180. blockchainkit-0.2.0/examples/crypto/discrete_log/plot_01_baby_step_giant_step.py +64 -0
  181. blockchainkit-0.2.0/examples/crypto/discrete_log/plot_02_pohlig_hellman.py +76 -0
  182. blockchainkit-0.2.0/examples/crypto/hash_signatures/README.rst +4 -0
  183. blockchainkit-0.2.0/examples/crypto/hash_signatures/plot_01_lamport_signatures.py +79 -0
  184. blockchainkit-0.2.0/examples/crypto/hashing/README.rst +5 -0
  185. blockchainkit-0.2.0/examples/crypto/hashing/plot_01_birthday_attack.py +58 -0
  186. blockchainkit-0.2.0/examples/crypto/hashing/plot_02_merkle_damgard.py +70 -0
  187. blockchainkit-0.2.0/examples/crypto/hashing/plot_03_hmac.py +70 -0
  188. blockchainkit-0.2.0/examples/crypto/hashing/plot_04_sha256_avalanche.py +45 -0
  189. blockchainkit-0.2.0/examples/crypto/one_time_pad/README.rst +4 -0
  190. blockchainkit-0.2.0/examples/crypto/one_time_pad/plot_01_one_time_pad.py +73 -0
  191. blockchainkit-0.2.0/examples/crypto/public_keys/README.rst +4 -0
  192. blockchainkit-0.2.0/examples/crypto/public_keys/plot_01_merkle_puzzles.py +71 -0
  193. blockchainkit-0.2.0/examples/crypto/public_keys/plot_02_diffie_hellman.py +71 -0
  194. blockchainkit-0.2.0/examples/crypto/public_keys/plot_03_rsa.py +60 -0
  195. blockchainkit-0.2.0/examples/crypto/sharing/README.rst +4 -0
  196. blockchainkit-0.2.0/examples/crypto/sharing/plot_01_secret_sharing.py +73 -0
  197. blockchainkit-0.2.0/examples/crypto/sharing/plot_02_feldman_vss.py +70 -0
  198. blockchainkit-0.2.0/examples/crypto/signatures/README.rst +5 -0
  199. blockchainkit-0.2.0/examples/crypto/signatures/plot_01_zero_knowledge.py +70 -0
  200. blockchainkit-0.2.0/examples/crypto/signatures/plot_02_fiat_shamir.py +79 -0
  201. blockchainkit-0.2.0/examples/crypto/signatures/plot_03_schnorr_signatures.py +72 -0
  202. blockchainkit-0.2.0/examples/crypto/signatures/plot_04_nonce_reuse.py +68 -0
  203. blockchainkit-0.2.0/examples/crypto/signatures/plot_05_musig.py +78 -0
  204. blockchainkit-0.2.0/examples/network/README.rst +12 -0
  205. blockchainkit-0.2.0/examples/network/events/README.rst +5 -0
  206. blockchainkit-0.2.0/examples/network/events/plot_01_discrete_event_simulation.py +90 -0
  207. blockchainkit-0.2.0/examples/network/events/plot_02_lamport_clocks.py +86 -0
  208. blockchainkit-0.2.0/examples/network/events/plot_03_vector_clocks.py +75 -0
  209. blockchainkit-0.2.0/examples/network/gossip/README.rst +5 -0
  210. blockchainkit-0.2.0/examples/network/gossip/plot_01_epidemic_algorithms.py +74 -0
  211. blockchainkit-0.2.0/examples/network/gossip/plot_02_rumor_spreading.py +61 -0
  212. blockchainkit-0.2.0/examples/network/gossip/plot_03_reliable_broadcast.py +83 -0
  213. blockchainkit-0.2.0/examples/network/graphs/README.rst +5 -0
  214. blockchainkit-0.2.0/examples/network/graphs/plot_01_random_graphs.py +81 -0
  215. blockchainkit-0.2.0/examples/network/graphs/plot_02_small_world.py +75 -0
  216. blockchainkit-0.2.0/examples/network/graphs/plot_03_scale_free.py +84 -0
  217. blockchainkit-0.2.0/examples/network/overlays/README.rst +4 -0
  218. blockchainkit-0.2.0/examples/network/overlays/plot_01_kademlia.py +74 -0
  219. blockchainkit-0.2.0/examples/network/overlays/plot_02_sybil_attack.py +76 -0
  220. blockchainkit-0.2.0/examples/network/overlays/plot_03_eclipse_attack.py +90 -0
  221. blockchainkit-0.2.0/examples/network/relay/README.rst +5 -0
  222. blockchainkit-0.2.0/examples/network/relay/plot_01_inv_getdata.py +70 -0
  223. blockchainkit-0.2.0/examples/network/relay/plot_02_propagation_and_forks.py +70 -0
  224. blockchainkit-0.2.0/examples/network/relay/plot_03_compact_blocks.py +79 -0
  225. blockchainkit-0.2.0/examples/network/relay/plot_04_dandelion.py +70 -0
  226. blockchainkit-0.2.0/examples/network/replication/README.rst +4 -0
  227. blockchainkit-0.2.0/examples/network/replication/plot_01_cap_theorem.py +96 -0
  228. blockchainkit-0.2.0/examples/structures/README.rst +13 -0
  229. blockchainkit-0.2.0/examples/structures/bloom/README.rst +4 -0
  230. blockchainkit-0.2.0/examples/structures/bloom/plot_01_bloom_filter.py +69 -0
  231. blockchainkit-0.2.0/examples/structures/chain/README.rst +5 -0
  232. blockchainkit-0.2.0/examples/structures/chain/plot_02_payment_lifecycle.py +167 -0
  233. blockchainkit-0.2.0/examples/structures/hash_chains/README.rst +4 -0
  234. blockchainkit-0.2.0/examples/structures/hash_chains/plot_01_lamport_hash_chain.py +62 -0
  235. blockchainkit-0.2.0/examples/structures/ledger/README.rst +4 -0
  236. blockchainkit-0.2.0/examples/structures/ledger/plot_01_double_entry.py +86 -0
  237. blockchainkit-0.2.0/examples/structures/ledger/plot_02_account_nonces.py +80 -0
  238. blockchainkit-0.2.0/examples/structures/merkle/README.rst +4 -0
  239. blockchainkit-0.2.0/examples/structures/merkle/plot_01_merkle_proofs.py +79 -0
  240. blockchainkit-0.2.0/examples/structures/merkle/plot_02_duplicate_leaf.py +62 -0
  241. blockchainkit-0.2.0/examples/structures/merkle/plot_03_consistency_proofs.py +64 -0
  242. blockchainkit-0.2.0/examples/structures/merkle/plot_04_mountain_ranges.py +58 -0
  243. blockchainkit-0.2.0/examples/structures/spv/README.rst +4 -0
  244. blockchainkit-0.2.0/examples/structures/spv/plot_01_light_clients.py +78 -0
  245. blockchainkit-0.2.0/examples/structures/state/README.rst +4 -0
  246. blockchainkit-0.2.0/examples/structures/state/plot_01_sparse_merkle.py +75 -0
  247. blockchainkit-0.2.0/examples/structures/timestamps/README.rst +4 -0
  248. blockchainkit-0.2.0/examples/structures/timestamps/plot_01_linked_timestamps.py +79 -0
  249. blockchainkit-0.2.0/examples/structures/timestamps/plot_02_merkle_batching.py +63 -0
  250. blockchainkit-0.2.0/examples/structures/transactions/README.rst +4 -0
  251. blockchainkit-0.2.0/examples/structures/transactions/plot_01_malleability.py +68 -0
  252. blockchainkit-0.2.0/examples/structures/transactions/plot_02_replay_protection.py +72 -0
  253. blockchainkit-0.2.0/examples/structures/utxo/README.rst +4 -0
  254. blockchainkit-0.2.0/examples/structures/utxo/plot_01_utxo.py +84 -0
  255. blockchainkit-0.2.0/examples/vm/README.rst +13 -0
  256. blockchainkit-0.2.0/examples/vm/contracts/README.rst +4 -0
  257. blockchainkit-0.2.0/examples/vm/contracts/plot_01_vending_machine.py +64 -0
  258. blockchainkit-0.2.0/examples/vm/contracts/plot_02_bytecode_verification.py +76 -0
  259. blockchainkit-0.2.0/examples/vm/ethereum/README.rst +4 -0
  260. blockchainkit-0.2.0/examples/vm/ethereum/plot_01_gas.py +95 -0
  261. blockchainkit-0.2.0/examples/vm/ethereum/plot_02_gas_repricing.py +79 -0
  262. blockchainkit-0.2.0/examples/vm/ethereum/plot_03_reentrancy.py +68 -0
  263. blockchainkit-0.2.0/examples/vm/ethereum/plot_04_integer_overflow.py +66 -0
  264. blockchainkit-0.2.0/examples/vm/foundations/README.rst +5 -0
  265. blockchainkit-0.2.0/examples/vm/foundations/plot_01_reverse_polish.py +57 -0
  266. blockchainkit-0.2.0/examples/vm/foundations/plot_02_halting_problem.py +68 -0
  267. blockchainkit-0.2.0/examples/vm/foundations/plot_03_hardware_stack.py +63 -0
  268. blockchainkit-0.2.0/examples/vm/foundations/plot_04_busy_beaver.py +63 -0
  269. blockchainkit-0.2.0/examples/vm/foundations/plot_05_structured_programming.py +72 -0
  270. blockchainkit-0.2.0/examples/vm/foundations/plot_06_forth.py +69 -0
  271. blockchainkit-0.2.0/examples/vm/replication/README.rst +4 -0
  272. blockchainkit-0.2.0/examples/vm/replication/plot_01_state_machine_replication.py +76 -0
  273. blockchainkit-0.2.0/examples/vm/replication/plot_02_atomic_transactions.py +74 -0
  274. blockchainkit-0.2.0/examples/vm/script/README.rst +5 -0
  275. blockchainkit-0.2.0/examples/vm/script/plot_01_p2pkh.py +65 -0
  276. blockchainkit-0.2.0/examples/vm/script/plot_02_htlc.py +76 -0
  277. blockchainkit-0.2.0/notebooks/quickstart.ipynb +206 -0
  278. blockchainkit-0.2.0/pyproject.toml +126 -0
  279. blockchainkit-0.2.0/setup.cfg +4 -0
@@ -0,0 +1,148 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0] - 2026-10-04
4
+
5
+ The package is aligned with its kit-family siblings, and every subpackage now
6
+ follows its field through at least 15 breakthroughs, each with its own
7
+ experiment.
8
+
9
+ ### Added
10
+
11
+ - Tutorials across subpackages, every line run by the doctest build: *Life of
12
+ a payment*, *Nonces everywhere*, *Hashes everywhere* and *Who do you
13
+ trust?*.
14
+ - Exercise pages, one per subpackage, with 40 worked solutions in collapsed
15
+ boxes, each run by the doctest build. They replace the single solutions page.
16
+ - A "Teaching vs production" note on every history entry that adapts a
17
+ deployed protocol, naming the difference.
18
+ - README figures, regenerated by `docs/make_readme_figure.py` and
19
+ `docs/make_readme_subpackage_figures.py`.
20
+ - Execution history: 16 breakthroughs, each with its own gallery example,
21
+ from reverse Polish notation (1924-1957) to the BeautyChain overflow
22
+ (2018). New APIs: `execute(..., arguments=...)`, the Forth words `OVER` and
23
+ `ROT`, `REVERT`, and the shared `STACK_EFFECTS` table; `validate_program`;
24
+ `assemble` (labels); `to_rpn` and `compile_expression`; `verify_bytecode`
25
+ and `VerificationResult`; `run_turing_machine`, `enumerate_machines` and
26
+ `busy_beaver` (reproducing S(2) = 6); Bitcoin-style Script with
27
+ `verify_script`, `p2pkh_locking`/`p2pkh_unlocking` and `htlc_locking`
28
+ (`OP_CHECKLOCKTIMEVERIFY`); the contracts `vending_machine` and
29
+ `batch_transfer` (BEC overflow, with a SafeMath option); `drain_bank`
30
+ (DAO reentrancy); and the plot `plot_stack_height`.
31
+ - Network history: 17 breakthroughs, each with its own gallery example, from
32
+ Erdős-Rényi random graphs (1959) to Dandelion (2017). New APIs: `Graph`,
33
+ `erdos_renyi`, `ring_lattice`, `watts_strogatz`, `barabasi_albert` and
34
+ `complete_graph`; `lamport_timestamps`, `vector_timestamps`,
35
+ `happened_before` and `concurrent`; `spread_rumor` (push, pull, push-pull)
36
+ and `pittel_rounds`; `reliable_broadcast` (Bracha); `ReplicatedRegister`
37
+ (CAP); `KademliaNetwork`, `xor_distance` and `node_id`; `AddressManager`
38
+ and `eclipse_probability`; `relay_cost`, `compact_block_relay` and
39
+ `short_id`; `fork_rate` and `simulate_fork_rate`; `first_spy_precision`;
40
+ `SimulatedNetwork.from_graph` and `SimulatedNetwork.messages_sent`; the
41
+ plots `plot_graph`, `plot_space_time` and `plot_rumor_spread`; and the
42
+ `COMPACT_BLOCK_DOMAIN` constant.
43
+ - Consensus history: 17 breakthroughs, each with its own gallery example,
44
+ from the gambler's ruin (1656) to Casper FFG (2017). New APIs:
45
+ `oral_messages` (Byzantine generals); `ben_or` (randomized consensus, also
46
+ used to show the FLP adversary); `view_changes` (partial synchrony);
47
+ `modular_square_root` (Dwork-Naor pricing); `pbft_round` and
48
+ `quorum_size`; `attacker_success_probability` (whitepaper section 11, checked
49
+ against its table); `retarget` and `simulate_difficulty`; `ghost_tip` and
50
+ `subtree_work`; `selfish_mining_revenue`, `selfish_mining_threshold` and
51
+ `simulate_selfish_mining`; `fork_voting_payoffs` (nothing at stake);
52
+ `sortition`; and `FinalityGadget` (Casper FFG with slashing detection).
53
+ - Structures history: 15 breakthroughs, each with its own gallery example,
54
+ from double-entry bookkeeping (1494) to Merkle mountain ranges (2016). New
55
+ APIs: `Ledger.total_supply`; `BloomFilter`; `hash_chain` and
56
+ `verify_one_time_password`; `BlockHeader`, `Block.to_header()` and
57
+ `verify_header_chain` for light clients; `bitcoin_merkle_root` (Bitcoin's
58
+ duplicated-leaf convention, for CVE-2012-2459); `MerkleTree.consistency_proof`
59
+ and `verify_consistency` (RFC 6962/9162); `UTXOSet`, `UTXOTransaction`,
60
+ `OutPoint` and `Coin`; `Transaction.unsigned_id` (SegWit-style);
61
+ `SparseMerkleTree` with membership and non-membership proofs; and
62
+ `MerkleMountainRange`.
63
+ - Cryptography history: 22 breakthroughs, each with its own gallery example,
64
+ from the one-time pad (1917-1949) to MuSig (2018). New APIs behind them:
65
+ `one_time_pad`/`xor_bytes`; `baby_step_giant_step` and `pohlig_hellman`;
66
+ `merkle_puzzles`/`solve_puzzle`; `lamport_keypair`/`lamport_sign`/
67
+ `lamport_verify`; `find_collision`/`truncated_hash`; a readable
68
+ Merkle-Damgard SHA-256 (`merkle_damgard_sha256`, `sha256_compress`,
69
+ `sha256_padding`) with `length_extension`; `naive_mac` and `hmac_sha256`;
70
+ `pedersen_commit`/`pedersen_generators`; `feldman_split`/`feldman_verify`;
71
+ `TEACHING_GROUP`, a 62-bit safe-prime group; `simulate_transcript`;
72
+ `deterministic_nonce` (RFC 6979, checked against the RFC's vectors); and
73
+ `musig_coefficients`/`aggregate_public_keys`/`musig_sign`.
74
+ - `visualizers/` in every subpackage (Matplotlib, imported explicitly; plain
75
+ `import blockchainkit` still loads only the standard library):
76
+ `plot_curve_points`, `plot_hamming_distances`, `plot_merkle_tree`,
77
+ `plot_proof_trace`, `plot_block_tree`, `plot_mining_trials`,
78
+ `plot_stake_shares`, `plot_gossip_timeline`, `plot_execution_trace`.
79
+ Matplotlib and NumPy are now runtime dependencies; the `examples` extra is
80
+ gone.
81
+ - `execute(..., trace=True)` records a `TraceStep` after every instruction,
82
+ following jumps; a failed run carries its partial trace in `VMError.trace`.
83
+ `execute(..., gas_costs=...)` prices opcodes individually (each at least 1).
84
+ - `MerkleTree.levels`, `MerkleTree.leaf_count`, and `trace_proof`, which
85
+ returns a `MerkleTrace` of `ProofStep`s, even for a proof that fails.
86
+ - `Blockchain.blocks`, `tips()`, `work_at()` and `state_at()` to inspect
87
+ side forks.
88
+ - `enumerate_points` lists every point of a small curve.
89
+
90
+ ### Changed
91
+
92
+ - The documentation follows the kit-family structure: generated hub pages per
93
+ subpackage, per-subpackage API pages, a `history/` directory with one
94
+ breakthroughs page per subpackage (each entry with its own *References:*
95
+ line and `minigallery`), an examples index, tutorials (the guided course and
96
+ solutions), and JupyterLite launch buttons. Examples moved to
97
+ `examples/<subpackage>/<topic>/`. The committed per-example notebooks and
98
+ their sync scripts are replaced by sphinx-gallery downloads and a single
99
+ `notebooks/quickstart.ipynb`.
100
+ - The package uses the kit-family layout: one subpackage per domain with
101
+ `core/`, `systems/`, `utils/` and `tests/`, shared validation in
102
+ `_validation.py`, and every consensus-relevant constant in `constants.py`.
103
+ Public `bk.<subpackage>.<name>` imports are unchanged.
104
+ - A wrong argument *type* (bool, float, string) now raises `TypeError`; an
105
+ out-of-range integer still raises `ValueError`. `multiply` reports the two
106
+ cases separately.
107
+ - Mining varies only the header nonce: `Block.merkle_root` and `Block.hash`
108
+ are cached, and `Block.header(nonce=...)` builds a candidate header without
109
+ rebuilding the Merkle tree. Mining a 20-transaction block is about 59 times
110
+ faster per attempt (2 µs instead of 118 µs).
111
+ - `verify` skips the subgroup-membership multiplications when Hasse's bound
112
+ proves the cofactor is 1 (new `Curve.cofactor_is_one`), halving the cost of
113
+ verification on secp256k1.
114
+ - `Ledger`, `Blockchain`, `MerkleTree` and `SimulatedNetwork` have readable
115
+ `repr`s.
116
+
117
+ ### Fixed
118
+
119
+ - `Transaction` rejects a `signature` that is not a `SchnorrSignature`;
120
+ before, the block hash raised `AttributeError` later.
121
+ - `execute` raises `VMError`, not `TypeError`, for a non-string opcode.
122
+ - `Curve` accepts secp256k1's field prime and group order only in their own
123
+ roles; swapping them no longer skips the primality check.
124
+ - A receive callback that raises no longer leaves the payload marked seen.
125
+ - `eventual_catch_up` rejects non-numeric fractions, and `StakeSampler` and
126
+ `SimulatedNetwork` reject non-integer seeds.
127
+
128
+ ## [0.1.0] - 2026-10-04
129
+
130
+ Initial local release, never published.
131
+
132
+ - Five typed subpackages for cryptography, authenticated structures, consensus
133
+ experiments, peer simulation, and bounded execution.
134
+ - Sphinx history chapter covering 15 milestones with primary references.
135
+ - Twelve executable gallery experiments and matching generated notebooks.
136
+ - Signed account transfers, replay checks, atomic ledger updates, and fork
137
+ state restoration through cumulative-work chain selection.
138
+ - Explicit teaching scope and package-specific serialization conventions.
139
+
140
+ - Full statement and branch coverage, with 112 tests and a 100% coverage gate.
141
+ - Stake sampling uses cumulative integer weights and binary search; Merkle proof
142
+ validation removes a redundant guard already implied by the checked path length.
143
+
144
+ - Guided seven-lesson course with learning objectives, prerequisites, checkpoints,
145
+ and executable worked answers for all thirteen experiments.
146
+ - Payment-lifecycle capstone with local pending queues, partitioned mining,
147
+ synchronization, reorganization, reinclusion, and replay rejection.
148
+ - Merkle-proof and VM stack trace figures; historical overview and dependency map.
@@ -0,0 +1,20 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use blockchainkit in your research or teaching, please cite it as below."
3
+ title: "blockchainkit: cryptography and blockchain breakthroughs, explained through reproducible Python experiments"
4
+ type: software
5
+ version: 0.2.0
6
+ # Add `doi:` with this release's own Zenodo version DOI (not the concept DOI)
7
+ # once the first release is archived.
8
+ license: MIT
9
+ repository-code: "https://github.com/cpoli/blockchainkit"
10
+ url: "https://cpoli.github.io/blockchainkit/"
11
+ authors:
12
+ - given-names: "Charles"
13
+ family-names: "Poli"
14
+ email: "cpoli374@gmail.com"
15
+ keywords:
16
+ - blockchain
17
+ - cryptography
18
+ - education
19
+ - simulation
20
+ - consensus
@@ -0,0 +1,66 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in
6
+ our community a harassment-free experience for everyone, regardless of
7
+ age, body size, visible or invisible disability, ethnicity, sex
8
+ characteristics, gender identity and expression, level of experience,
9
+ education, socio-economic status, nationality, personal appearance, race,
10
+ caste, color, religion, or sexual identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open,
13
+ welcoming, diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment:
18
+
19
+ - Demonstrating empathy and kindness toward other people
20
+ - Being respectful of differing opinions, viewpoints, and experiences
21
+ - Giving and gracefully accepting constructive feedback
22
+ - Accepting responsibility and apologizing to those affected by our
23
+ mistakes, and learning from the experience
24
+ - Focusing on what is best not just for us as individuals, but for the
25
+ overall community
26
+
27
+ Examples of unacceptable behavior:
28
+
29
+ - The use of sexualized language or imagery, and sexual attention or
30
+ advances of any kind
31
+ - Trolling, insulting or derogatory comments, and personal or political
32
+ attacks
33
+ - Public or private harassment
34
+ - Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ - Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Project maintainers are responsible for clarifying and enforcing our
42
+ standards of acceptable behavior and will take appropriate and fair
43
+ corrective action in response to any behavior that they deem
44
+ inappropriate, threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all community spaces (issues, pull
49
+ requests, discussions), and also applies when an individual is officially
50
+ representing the community in public spaces.
51
+
52
+ ## Enforcement
53
+
54
+ Instances of abusive, harassing, or otherwise unacceptable behavior may
55
+ be reported to the project maintainers by opening a confidential report
56
+ via GitHub (see [SECURITY.md](SECURITY.md) for the equivalent private
57
+ reporting channel). All complaints will be reviewed and investigated
58
+ promptly and fairly.
59
+
60
+ ## Attribution
61
+
62
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
63
+ version 2.1, available at
64
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
65
+
66
+ [homepage]: https://www.contributor-covenant.org
@@ -0,0 +1,80 @@
1
+ # Contributing
2
+
3
+ Keep the teaching chain intact: historical motivation, mathematical mechanism,
4
+ typed public API, checked example, and explicit model assumptions.
5
+
6
+ blockchainkit is organized as one subpackage per domain
7
+ (`blockchainkit/<name>/`), each with its own `core/` (shared types and result
8
+ dataclasses), `systems/` (concrete constructions and protocols, one module per
9
+ family), `utils/` (supporting helpers that are not a model themselves), and
10
+ `tests/` directory. Code shared by every subpackage lives at the top level:
11
+ argument validation in `_validation.py` and every consensus-relevant constant
12
+ (hash domain tags, encoding bounds, the default chain ID) in `constants.py`.
13
+ New material belongs in the subpackage it fits best, re-exported from that
14
+ subpackage's `__init__.py`.
15
+
16
+ ## Setup
17
+
18
+ ```bash
19
+ python -m venv .venv
20
+ source .venv/bin/activate
21
+ python -m pip install -e ".[dev]"
22
+ pre-commit install
23
+ ```
24
+
25
+ ## Required checks
26
+
27
+ ```bash
28
+ ruff check .
29
+ ruff format --check .
30
+ mypy
31
+ pytest --cov=blockchainkit --cov-branch --cov-report=term-missing
32
+ pytest --doctest-modules blockchainkit --ignore-glob="*/tests/*"
33
+ cd docs && MPLBACKEND=Agg make html && MPLBACKEND=Agg make doctest && cd ..
34
+ python -m build
35
+ ```
36
+
37
+ Coverage runs must reach 100% for statements and branches across all package
38
+ modules. `pyproject.toml` enforces this threshold for the CI coverage command.
39
+ Add meaningful boundary and failure tests; do not exclude code to meet the target.
40
+
41
+ The tests check independent vectors (SHA-256 test vectors, hand-computed curve
42
+ points), algebraic identities (Diffie-Hellman agreement, RSA and blinding
43
+ round-trips, Shamir reconstruction from every threshold subset), and failure
44
+ behavior (signature tampering, nonce reuse, malformed Merkle proofs, replayed
45
+ or overdrawn transfers, fork state restoration, VM resource limits). Passing
46
+ them shows the teaching models behave as documented; it is not a
47
+ cryptographic security audit.
48
+
49
+ ## History is part of the implementation
50
+
51
+ `docs/source/history/` is a first-class deliverable: one page per subpackage,
52
+ `<subpackage>_breakthroughs.rst`. A new entry must cite a primary source in a
53
+ *References:* line, explain the original problem, give the key equation or
54
+ mechanism, link to a concrete public API, and link its own gallery example(s)
55
+ with `.. minigallery::`. No example is shared between two breakthroughs, and
56
+ each example's title names its breakthrough. Distinguish original protocols
57
+ from teaching adaptations. Do not describe a proposed future feature as an
58
+ implemented breakthrough.
59
+
60
+ Every public algorithm should have a clear docstring and type annotations.
61
+ Use NumPy-style parameter/return sections where they clarify the interface.
62
+ Tests should compare independent vectors, algebraic properties, conservation
63
+ laws, or failure behavior rather than merely asserting the function returns.
64
+
65
+ ## Examples
66
+
67
+ Examples live in `examples/<subpackage>/<topic>/plot_NN_<name>.py`, and each
68
+ topic folder has a `README.rst` header. Sphinx-Gallery runs every script during
69
+ the docs build and offers each one as a downloadable notebook and a JupyterLite
70
+ launch, so the script is the single source of truth. Separate explanation and
71
+ code with `# %%` cells. Use fixed simulation seeds, small bounded searches,
72
+ assertions of the expected result, a "What to look for" section, and an
73
+ exercise. Plot with the subpackage's `visualizers` where one fits.
74
+
75
+ ## Protocol changes
76
+
77
+ Changing hash domains, serialization, validation, or tie-breaking can change
78
+ consensus behavior. Update `docs/source/protocol.rst`, the relevant tests,
79
+ examples, and changelog together. Reproducibility is scoped to recorded inputs
80
+ and runtime versions; it is not a substitute for cryptographic randomness.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Charles Poli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # The sdist carries the full test suite (each subpackage's tests/) for
2
+ # downstream packagers; the wheel does not, via exclude-package-data in
3
+ # pyproject.toml.
4
+ graft blockchainkit
5
+ include conftest.py
6
+ include LICENSE README.md CONTRIBUTING.md CHANGELOG.md CITATION.cff CODE_OF_CONDUCT.md SECURITY.md ROADMAP.md
7
+ recursive-include examples *.py *.rst
8
+ include notebooks/quickstart.ipynb
9
+ global-exclude __pycache__ *.py[cod] .DS_Store
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: blockchainkit
3
+ Version: 0.2.0
4
+ Summary: Cryptography and blockchain breakthroughs, explained through reproducible Python experiments.
5
+ Author-email: Charles Poli <cpoli374@gmail.com>
6
+ Maintainer-email: Charles Poli <cpoli374@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/cpoli/blockchainkit
9
+ Project-URL: Issues, https://github.com/cpoli/blockchainkit/issues
10
+ Project-URL: Changelog, https://github.com/cpoli/blockchainkit/blob/main/CHANGELOG.md
11
+ Project-URL: Documentation, https://cpoli.github.io/blockchainkit/
12
+ Keywords: blockchain,cryptography,education,simulation,consensus,merkle-tree,proof-of-work,proof-of-stake,elliptic-curves,digital-signatures,gossip-protocol
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Typing :: Typed
25
+ Classifier: Topic :: Education
26
+ Classifier: Topic :: Security :: Cryptography
27
+ Classifier: Topic :: Scientific/Engineering
28
+ Requires-Python: >=3.10
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: matplotlib>=3.6
32
+ Requires-Dist: numpy>=1.24
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest>=7; extra == "test"
35
+ Requires-Dist: pytest-cov>=4; extra == "test"
36
+ Requires-Dist: hypothesis>=6; extra == "test"
37
+ Provides-Extra: docs
38
+ Requires-Dist: sphinx>=7; extra == "docs"
39
+ Requires-Dist: pydata-sphinx-theme>=0.15; extra == "docs"
40
+ Requires-Dist: sphinx-gallery>=0.17; extra == "docs"
41
+ Requires-Dist: sphinx-design>=0.6; extra == "docs"
42
+ Requires-Dist: myst-parser>=2; extra == "docs"
43
+ Requires-Dist: jupyterlite-sphinx>=0.17; extra == "docs"
44
+ Requires-Dist: jupyterlite-pyodide-kernel>=0.4; extra == "docs"
45
+ Requires-Dist: pillow>=9; extra == "docs"
46
+ Provides-Extra: dev
47
+ Requires-Dist: blockchainkit[docs,test]; extra == "dev"
48
+ Requires-Dist: ruff==0.16.6; extra == "dev"
49
+ Requires-Dist: mypy>=1.10; extra == "dev"
50
+ Requires-Dist: pre-commit>=3.7; extra == "dev"
51
+ Requires-Dist: build>=1; extra == "dev"
52
+ Dynamic: license-file
53
+
54
+ # blockchainkit
55
+
56
+ | | |
57
+ |:--|:-:|
58
+ | Quality | [![License](https://img.shields.io/github/license/cpoli/blockchainkit)](https://github.com/cpoli/blockchainkit/blob/main/LICENSE) [![CI](https://github.com/cpoli/blockchainkit/actions/workflows/ci.yml/badge.svg)](https://github.com/cpoli/blockchainkit/actions/workflows/ci.yml) [![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](#development) |
59
+ | Documentation | [![Docs](https://img.shields.io/badge/docs-cpoli.github.io%2Fblockchainkit-blue)](https://cpoli.github.io/blockchainkit/) |
60
+ | Code style | [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) |
61
+ | Try it online | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/cpoli/blockchainkit/blob/main/notebooks/quickstart.ipynb) [![JupyterLite](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://cpoli.github.io/blockchainkit/lite/lab/) |
62
+
63
+ **Cryptography and blockchains, understood through experiments.**
64
+ blockchainkit is a Python toolkit for learning and teaching how blockchains
65
+ work, from the one-time pad to Ethereum's gas. Each idea is followed from its
66
+ history and mathematics to a small, typed, inspectable implementation, a
67
+ figure, and an experiment you can change. Every subpackage's documentation
68
+ walks through the field's breakthroughs in historical order, 87 of them in
69
+ all, each linked to the code and the gallery example that reproduce it.
70
+
71
+ ![A Merkle proof, Nakamoto's double-spend probabilities, and a Lamport space-time diagram, all drawn with blockchainkit](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_hero.png)
72
+
73
+ - **For students:** recover a private key from a reused signing nonce, find
74
+ hash collisions at the birthday bound, watch a fork undo a payment, mine
75
+ selfishly, eclipse a node, and drain a DAO-style contract, in a few lines
76
+ each.
77
+ - **For instructors:** five subpackages, one consistent API, 88 gallery
78
+ examples (each downloadable as a notebook or runnable in the browser),
79
+ exercise pages with worked solutions, and cross-cutting tutorials.
80
+ - **Honest about its limits:** tiny keys, variable-time arithmetic and
81
+ simplified formats keep the mathematics visible. Every adaptation is marked
82
+ on its history entry and specified in the
83
+ [model boundaries](https://cpoli.github.io/blockchainkit/protocol.html).
84
+ This is teaching software, not a wallet or a node.
85
+
86
+ `import blockchainkit` loads only the standard library. Matplotlib and NumPy
87
+ are used only by each subpackage's `visualizers`.
88
+
89
+ ```bash
90
+ pip install blockchainkit # Python 3.10+
91
+ ```
92
+
93
+ Conventionally imported as `bk`:
94
+
95
+ ```python
96
+ import blockchainkit as bk
97
+
98
+ alice_key = 7 # A fixed teaching key: never use such a key for real money.
99
+ alice = bk.structures.address(bk.crypto.public_key(alice_key))
100
+ bob = bk.structures.address(bk.crypto.public_key(11))
101
+
102
+ payment = bk.structures.Transaction(bk.crypto.public_key(alice_key), bob, 25, 0)
103
+ payment = payment.signed(alice_key, signing_nonce=17) # Never reuse a signing nonce.
104
+
105
+ genesis = bk.consensus.mine(bk.structures.Block(difficulty=5)).block
106
+ chain = bk.structures.Blockchain(genesis, bk.structures.Ledger({alice: 100}))
107
+ block = bk.structures.Block(genesis.hash, (payment,), height=1, timestamp=1, difficulty=5)
108
+ chain.add(bk.consensus.mine(block).block)
109
+ assert chain.state.balances[bob] == 25
110
+ ```
111
+
112
+ The [quickstart notebook](https://github.com/cpoli/blockchainkit/blob/main/notebooks/quickstart.ipynb)
113
+ takes one payment from a signature to a mined block in about ten minutes.
114
+ Open it in Colab using the badge above.
115
+
116
+ ## Subpackages
117
+
118
+ - [`blockchainkit.crypto`](https://cpoli.github.io/blockchainkit/api/gallery/crypto/) -- the one-time pad,
119
+ baby-step giant-step and Pohlig-Hellman, Merkle's puzzles, Diffie-Hellman and RSA, Shamir and Feldman
120
+ secret sharing, Lamport signatures, birthday attacks, commitments (hash and Pedersen), blind signatures,
121
+ elliptic curves, zero knowledge and Fiat-Shamir, Merkle-Damgård and length extension, HMAC, Schnorr
122
+ signatures, RFC 6979 nonces, and MuSig. 22 breakthroughs.
123
+
124
+ ![Scalar multiples on an elliptic curve, the SHA-256 avalanche, and the birthday bound](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_crypto.png)
125
+
126
+ - [`blockchainkit.structures`](https://cpoli.github.io/blockchainkit/api/gallery/structures/) -- double-entry
127
+ ledgers, Bloom filters, Merkle trees and proofs, hash chains, linked and batched timestamps, the UTXO and
128
+ account models, light clients, Bitcoin's duplicated-leaf bug, Certificate Transparency consistency proofs,
129
+ transaction malleability, Merkle mountain ranges, replay protection, sparse Merkle trees, and blocks with
130
+ cumulative-work fork choice. 15 breakthroughs.
131
+
132
+ ![A Merkle proof, a fork in a block tree, and Bloom-filter false-positive rates](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_structures.png)
133
+
134
+ - [`blockchainkit.consensus`](https://cpoli.github.io/blockchainkit/api/gallery/consensus/) -- the gambler's
135
+ ruin, Byzantine generals, Ben-Or and FLP, partial synchrony, PBFT, pricing functions and Hashcash, Nakamoto
136
+ consensus and its double-spend calculation, difficulty retargeting, GHOST, selfish mining, proof of stake,
137
+ nothing at stake, Casper FFG, and cryptographic sortition. 17 breakthroughs.
138
+
139
+ ![Double-spend probabilities, selfish-mining revenue, and difficulty retargeting](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_consensus.png)
140
+
141
+ - [`blockchainkit.network`](https://cpoli.github.io/blockchainkit/api/gallery/network/) -- discrete-event
142
+ gossip, random, small-world and scale-free graphs, Lamport and vector clocks, epidemic rumor spreading,
143
+ Bracha's reliable broadcast, CAP, Kademlia, Sybil and eclipse attacks, inv/getdata relay, propagation and
144
+ forks, compact blocks, and Dandelion. 17 breakthroughs.
145
+
146
+ ![A small-world graph, push and pull gossip, and Kademlia lookup hops](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_network.png)
147
+
148
+ - [`blockchainkit.vm`](https://cpoli.github.io/blockchainkit/api/gallery/vm/) -- a deterministic 256-bit
149
+ stack machine with gas and atomic failure, reverse Polish notation, Turing machines and the busy beaver,
150
+ structured programming, Forth, state-machine replication, smart contracts, bytecode verification, Bitcoin
151
+ Script with P2PKH and hash time-locked contracts, gas repricing, the DAO's reentrancy, and integer
152
+ overflow. 16 breakthroughs.
153
+
154
+ ![Stack height of two expressions, halting times of two-state Turing machines, and a reentrancy attack](https://raw.githubusercontent.com/cpoli/blockchainkit/main/docs/source/_static/images/readme_vm.png)
155
+
156
+ ## Learn
157
+
158
+ - [Start here](https://cpoli.github.io/blockchainkit/start_here.html): the ideas, with one imaginary
159
+ payment and no prerequisites.
160
+ - [Guided course](https://cpoli.github.io/blockchainkit/tutorials/course.html): seven lessons in
161
+ prerequisite order.
162
+ - Tutorials across subpackages: [life of a payment](https://cpoli.github.io/blockchainkit/tutorials/life_of_a_payment.html),
163
+ [nonces everywhere](https://cpoli.github.io/blockchainkit/tutorials/nonces_everywhere.html),
164
+ [hashes everywhere](https://cpoli.github.io/blockchainkit/tutorials/hashes_everywhere.html), and
165
+ [who do you trust?](https://cpoli.github.io/blockchainkit/tutorials/who_do_you_trust.html)
166
+ - [Exercises](https://cpoli.github.io/blockchainkit/exercises/index.html): worked solutions, checked by
167
+ every documentation build.
168
+ - [History](https://cpoli.github.io/blockchainkit/history/index.html): the breakthroughs, each with
169
+ plain-language explanation, mathematics, primary references, and its own experiment.
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ python -m venv .venv && source .venv/bin/activate
175
+ pip install -e ".[dev]"
176
+ pytest --cov=blockchainkit --cov-branch # 100% statement and branch coverage, enforced
177
+ pytest --doctest-modules blockchainkit --ignore-glob="*/tests/*"
178
+ ruff check . && ruff format --check .
179
+ mypy # strict
180
+ cd docs && MPLBACKEND=Agg make html && MPLBACKEND=Agg make doctest
181
+ ```
182
+
183
+ The documentation build runs every gallery example and every code line in
184
+ the tutorials and exercise solutions, and treats warnings as errors. The README
185
+ figures are regenerated with `python docs/make_readme_figure.py` and
186
+ `python docs/make_readme_subpackage_figures.py`. See
187
+ [CONTRIBUTING.md](CONTRIBUTING.md).
188
+
189
+ blockchainkit belongs to a family of teaching toolkits with the same
190
+ architecture: [mathematicskit](https://github.com/cpoli/mathematicskit),
191
+ [physicskit](https://github.com/cpoli/physicskit) and
192
+ [chemistrykit](https://github.com/cpoli/chemistrykit).
193
+
194
+ MIT license; see [LICENSE](LICENSE). To cite blockchainkit, see
195
+ [CITATION.cff](CITATION.cff).