
Web3 Foundation
https://web3.foundation
Tessera: Python JAM Client
Case Study: Implementing the Join-Accumulate Machine Protocol in Python

Project Timeline
Ongoing Development(Apr 2025 - Ongoing)
Deep dive into the JAM Graypaper, defining core data structures, network protocols, cryptographic primitives, and the overall client architecture in Python.
Building the peer-to-peer networking stack based on anticipated JAM requirements and implementing client-side logic for interacting with Safrole and Grandpa consensus mechanisms (verification, message handling).
Implementing state trie interactions, block processing logic, state transition verification, and integrating with a PVM (PolkaVM/RISC-V) execution environment or verifier.
Implementing service account handling, refinement/accumulation verification, testing against simulated networks and potentially testnets.
Project Team
Exceptional talent working together to deliver this project.
ChainScore Labs
Design, Development, Implementation
Key Metrics
The impact and scale of this project.
JAM Graypaper v0.6.4+
Target Specification
The protocol specification Tessera aims to implement.
Python 3.10+
Implementation Language
Core language for the client.
Full/Light Node (TBD)
Client Type Goal
Initial focus likely on full node logic, potential for light client adaptation.
Network Sync & Validation
Performance Goal
Targeting efficient synchronization and validation within Python's performance constraints.

A technical case study documenting the design and development considerations for Tessera, a Python-based client implementation for the JAM (Join-Accumulate Machine) protocol. This study explores how Tessera aims to interpret and implement the JAM specification outlined in the Graypaper, focusing on core protocol mechanics, state management, PVM interaction, consensus participation (client-side), networking, and cryptographic requirements necessary for a functional JAM node.
Web3 Foundation
Visit websiteTessera: A Python Implementation of the JAM Protocol
Core JAM Concepts in Tessera
- Hybrid Architecture: Modeling the distinction between on-chain (Accumulation) and in-core (Refinement) computation logic and their interaction.
- Service-Oriented Model: Implementing data structures and logic for service accounts, including state (storage, preimages), code (refine/accumulate entry points), balance, and gas limits.
- Coretime Concept: Handling core assignment, authorization checks (verifying authorizer logic outputs), and coretime accounting from a client perspective.
- Block & State Structure: Defining Python classes/objects for blocks, headers, extrinsics (tickets, preimages, reports, etc.), and the partitioned state tuple (α, β, γ...).
- State Transition Function (Y): Implementing the block-level state transition logic, ensuring deterministic updates based on prior state and block contents.
Peer-to-Peer Networking Layer
Connecting to the JAM Network
- Peer Discovery: Implementing mechanisms like Discv5 or Kademlia DHT for finding other JAM nodes.
- Message Serialization: Defining and implementing serialization/deserialization formats (e.g., SSZ, RLPx, or a JAM-specific format) for network messages.
- Gossip Protocols: Implementing gossip logic for propagating new blocks, transactions (if applicable directly), and consensus messages efficiently.
- Request/Response Protocols: Defining protocols for requesting specific blocks, state parts, or historical data from peers during synchronization.
- Transport Layer: Utilizing secure and reliable transport protocols (e.g., TCP with TLS/Noise).
Consensus Mechanism Interaction (Client-Side)
- Safrole Verification: Validating block author eligibility based on sealing keys derived from tickets/VRFs. Implementing the fork-choice rule based on Safrole's criteria (e.g., highest valid ticket score, chain length).
- Grandpa Verification: Processing Grandpa votes (prevotes, precommits) gossiped on the network. Verifying vote signatures against the known validator set. Identifying finalized blocks based on supermajority agreement (2/3+).
- Validator Set Management: Tracking the current and upcoming validator sets (κ, λ, γκ) based on state transitions and epoch changes defined in Safrole.
- Epoch Processing: Handling epoch transitions, including validator set rotation and Safrole state updates (roots, sealers).
Block Processing and State Transition
Applying the JAM State Machine
- Block Validation: Verifying header fields (parent hash, state root, extrinsic root), seal signature (Hs), VRF output (Hu), consensus markers (He, Hw, Ho).
- Extrinsic Processing: Handling different extrinsic types (Tickets ET, Preimages EP, Reports EG, Assurances EA, Disputes ED) according to their specific validation rules and state effects.
- State Transition (Y): Implementing the logic for updating each state component (α, β, γ...) based on the prior state and the processed block B, as defined in Graypaper section 4.2.1 and subsequent sections.
- Accumulation Logic Verification: Executing or verifying the results of the 'Accumulate' entry point for relevant service accounts affected by the block's work reports (W*).
- State Root Calculation: Calculating the posterior state root (H'r) after applying state changes, using the specified Merkle Trie structure, and comparing it to the expected root.
PVM (PolkaVM/RISC-V) Integration
Executing and Verifying Service Code
- Execution Environment: Integrating a RISC-V (RV64EM compatible) interpreter, JIT, or external process interface.
- Gas Metering: Implementing instruction-level gas counting according to PVM specifications to enforce computational limits.
- Host Function Interface (Ω): Providing implementations for all host functions callable from within the PVM (e.g., state access, historical lookups, cryptographic operations, logging).
- State Interaction: Allowing the PVM to securely read relevant parts of the JAM state and propose state modifications (primarily for Accumulate).
- Refinement Verification: Potentially re-executing or verifying proofs of refinement computation performed in-core by guarantors.
- Accumulation Execution/Verification: Executing the 'Accumulate' entry point for services based on work reports within the defined gas limits.
State Management and Storage
- Data Store: Utilizing a performant key-value database (e.g., LMDB, RocksDB) suitable for large datasets and frequent updates.
- Merkle Trie Implementation: Implementing or using a library for the specific binary Patricia Merkle Trie structure defined in the JAM Graypaper (Appendix D), optimized for Python.
- Atomic Updates: Ensuring state changes from a block are applied atomically; either all succeed or none do, maintaining state consistency.
- State Root Calculation: Efficiently calculating the state root after each block application.
- State Pruning: Implementing strategies to prune old state data that is no longer needed (beyond finality + archival requirements) to manage storage growth.
- Preimage/Lookup Handling: Storing and managing preimage data (components p and l of service accounts) and implementing the historical lookup logic (Λ).
Cryptographic Primitives
Implementing JAM's Security Foundations
- Hashing: Blake2b-256 (H) and Keccak-256 (Hk) for various commitments and identifiers.
- Signatures (Ed25519): Used for assurances (EA) and potentially other validator messages. Requires key generation, signing, and verification.
- Signatures (BLS12-381): Used for Grandpa finality votes and BEEFY commitments. Requires key generation, signing, verification, and aggregation.
- Signatures (Bandersnatch Schnorr-like): Used for block seals (Hs). Requires specific curve operations.
- VRFs (Bandersnatch RingVRF): Used for ticket generation (ET) and potentially Safrole leader selection. Requires proof generation and verification, and output derivation (Y).
- Serialization/Merklization: Implementing the specific encoding (Appendix C) and Merklization (Appendix D/E) rules for state and block components.
Statistics
Challenges and Considerations for Python
- Performance Bottlenecks: Python's Global Interpreter Lock (GIL) can limit CPU-bound parallelism. Cryptographic operations and PVM execution can be significantly slower than in compiled languages like Rust or C++.
- Memory Management: Handling large state tries and network buffers efficiently requires careful memory management to avoid excessive consumption or garbage collection pauses.
- Cryptographic Library Availability: Mature and performant Python libraries for newer primitives like Bandersnatch curve operations (VRFs, signatures) might be scarce or require bindings to C/Rust libraries.
- Concurrency Model: Leveraging `asyncio` effectively for network I/O and concurrent task handling is crucial, but requires careful design to avoid blocking operations.
- Potential Solutions: Utilizing optimized libraries (e.g., `numpy` for some math), implementing critical sections in C/Cython/Rust via FFI, aggressive caching, efficient data structures, and potentially multi-processing for CPU-bound tasks where possible.
Towards a Pythonic JAM Client
Ready to Create Something Amazing?
Let's discuss how we can help you achieve similar results with a custom solution tailored to your specific needs and goals.
