Skip to content

blockchainkit 0.2.0

Choose a tag to compare

@github-actions github-actions released this 04 Oct 09:59
· 16 commits to main since this release

The package is aligned with its kit-family siblings, and every subpackage now
follows its field through at least 15 breakthroughs, each with its own
experiment.

Added

  • Tutorials across subpackages, every line run by the doctest build: Life of
    a payment
    , Nonces everywhere, Hashes everywhere and Who do you
    trust?
    .
  • Exercise pages, one per subpackage, with 40 worked solutions in collapsed
    boxes, each run by the doctest build. They replace the single solutions page.
  • A "Teaching vs production" note on every history entry that adapts a
    deployed protocol, naming the difference.
  • README figures, regenerated by docs/make_readme_figure.py and
    docs/make_readme_subpackage_figures.py.
  • Execution history: 16 breakthroughs, each with its own gallery example,
    from reverse Polish notation (1924-1957) to the BeautyChain overflow
    (2018). New APIs: execute(..., arguments=...), the Forth words OVER and
    ROT, REVERT, and the shared STACK_EFFECTS table; validate_program;
    assemble (labels); to_rpn and compile_expression; verify_bytecode
    and VerificationResult; run_turing_machine, enumerate_machines and
    busy_beaver (reproducing S(2) = 6); Bitcoin-style Script with
    verify_script, p2pkh_locking/p2pkh_unlocking and htlc_locking
    (OP_CHECKLOCKTIMEVERIFY); the contracts vending_machine and
    batch_transfer (BEC overflow, with a SafeMath option); drain_bank
    (DAO reentrancy); and the plot plot_stack_height.
  • Network history: 17 breakthroughs, each with its own gallery example, from
    Erdős-Rényi random graphs (1959) to Dandelion (2017). New APIs: Graph,
    erdos_renyi, ring_lattice, watts_strogatz, barabasi_albert and
    complete_graph; lamport_timestamps, vector_timestamps,
    happened_before and concurrent; spread_rumor (push, pull, push-pull)
    and pittel_rounds; reliable_broadcast (Bracha); ReplicatedRegister
    (CAP); KademliaNetwork, xor_distance and node_id; AddressManager
    and eclipse_probability; relay_cost, compact_block_relay and
    short_id; fork_rate and simulate_fork_rate; first_spy_precision;
    SimulatedNetwork.from_graph and SimulatedNetwork.messages_sent; the
    plots plot_graph, plot_space_time and plot_rumor_spread; and the
    COMPACT_BLOCK_DOMAIN constant.
  • Consensus history: 17 breakthroughs, each with its own gallery example,
    from the gambler's ruin (1656) to Casper FFG (2017). New APIs:
    oral_messages (Byzantine generals); ben_or (randomized consensus, also
    used to show the FLP adversary); view_changes (partial synchrony);
    modular_square_root (Dwork-Naor pricing); pbft_round and
    quorum_size; attacker_success_probability (whitepaper section 11, checked
    against its table); retarget and simulate_difficulty; ghost_tip and
    subtree_work; selfish_mining_revenue, selfish_mining_threshold and
    simulate_selfish_mining; fork_voting_payoffs (nothing at stake);
    sortition; and FinalityGadget (Casper FFG with slashing detection).
  • Structures history: 15 breakthroughs, each with its own gallery example,
    from double-entry bookkeeping (1494) to Merkle mountain ranges (2016). New
    APIs: Ledger.total_supply; BloomFilter; hash_chain and
    verify_one_time_password; BlockHeader, Block.to_header() and
    verify_header_chain for light clients; bitcoin_merkle_root (Bitcoin's
    duplicated-leaf convention, for CVE-2012-2459); MerkleTree.consistency_proof
    and verify_consistency (RFC 6962/9162); UTXOSet, UTXOTransaction,
    OutPoint and Coin; Transaction.unsigned_id (SegWit-style);
    SparseMerkleTree with membership and non-membership proofs; and
    MerkleMountainRange.
  • Cryptography history: 22 breakthroughs, each with its own gallery example,
    from the one-time pad (1917-1949) to MuSig (2018). New APIs behind them:
    one_time_pad/xor_bytes; baby_step_giant_step and pohlig_hellman;
    merkle_puzzles/solve_puzzle; lamport_keypair/lamport_sign/
    lamport_verify; find_collision/truncated_hash; a readable
    Merkle-Damgard SHA-256 (merkle_damgard_sha256, sha256_compress,
    sha256_padding) with length_extension; naive_mac and hmac_sha256;
    pedersen_commit/pedersen_generators; feldman_split/feldman_verify;
    TEACHING_GROUP, a 62-bit safe-prime group; simulate_transcript;
    deterministic_nonce (RFC 6979, checked against the RFC's vectors); and
    musig_coefficients/aggregate_public_keys/musig_sign.
  • visualizers/ in every subpackage (Matplotlib, imported explicitly; plain
    import blockchainkit still loads only the standard library):
    plot_curve_points, plot_hamming_distances, plot_merkle_tree,
    plot_proof_trace, plot_block_tree, plot_mining_trials,
    plot_stake_shares, plot_gossip_timeline, plot_execution_trace.
    Matplotlib and NumPy are now runtime dependencies; the examples extra is
    gone.
  • execute(..., trace=True) records a TraceStep after every instruction,
    following jumps; a failed run carries its partial trace in VMError.trace.
    execute(..., gas_costs=...) prices opcodes individually (each at least 1).
  • MerkleTree.levels, MerkleTree.leaf_count, and trace_proof, which
    returns a MerkleTrace of ProofSteps, even for a proof that fails.
  • Blockchain.blocks, tips(), work_at() and state_at() to inspect
    side forks.
  • enumerate_points lists every point of a small curve.

Changed

  • The documentation follows the kit-family structure: generated hub pages per
    subpackage, per-subpackage API pages, a history/ directory with one
    breakthroughs page per subpackage (each entry with its own References:
    line and minigallery), an examples index, tutorials (the guided course and
    solutions), and JupyterLite launch buttons. Examples moved to
    examples/<subpackage>/<topic>/. The committed per-example notebooks and
    their sync scripts are replaced by sphinx-gallery downloads and a single
    notebooks/quickstart.ipynb.
  • The package uses the kit-family layout: one subpackage per domain with
    core/, systems/, utils/ and tests/, shared validation in
    _validation.py, and every consensus-relevant constant in constants.py.
    Public bk.<subpackage>.<name> imports are unchanged.
  • A wrong argument type (bool, float, string) now raises TypeError; an
    out-of-range integer still raises ValueError. multiply reports the two
    cases separately.
  • Mining varies only the header nonce: Block.merkle_root and Block.hash
    are cached, and Block.header(nonce=...) builds a candidate header without
    rebuilding the Merkle tree. Mining a 20-transaction block is about 59 times
    faster per attempt (2 µs instead of 118 µs).
  • verify skips the subgroup-membership multiplications when Hasse's bound
    proves the cofactor is 1 (new Curve.cofactor_is_one), halving the cost of
    verification on secp256k1.
  • Ledger, Blockchain, MerkleTree and SimulatedNetwork have readable
    reprs.

Fixed

  • Transaction rejects a signature that is not a SchnorrSignature;
    before, the block hash raised AttributeError later.
  • execute raises VMError, not TypeError, for a non-string opcode.
  • Curve accepts secp256k1's field prime and group order only in their own
    roles; swapping them no longer skips the primality check.
  • A receive callback that raises no longer leaves the payload marked seen.
  • eventual_catch_up rejects non-numeric fractions, and StakeSampler and
    SimulatedNetwork reject non-integer seeds.