Pathfinder Documentation

repository·main·Indexed 20 days ago

https://github.com/equilibriumco/pathfinder

Pathfinder is a Starknet full node providing a safe and reliable interface for interacting with the Starknet blockchain. The project includes crates for consensus mechanisms, cryptographic primitives (pathfinder_crypto) supporting Pedersen and Poseidon hashes, class hash computation for Cairo 0.x and Sierra contracts, and P2P protocol implementations. It also provides tools for JSON RPC API load testing and a p2p-stream protocol for single-request, multi-response communication.

Tokens
127.4K
Snippets
447
Records
580
Agent score
71%

What's inside Pathfinder

  1. Overview of Pathfinder

    main

    Pathfinder is a Rust-based full node implementation for the Starknet blockchain. It provides a secure, verifiable view of the entire Starknet state history, enabling users to query contract code, storage, and transactions.

    Key Capabilities

    • Full State Access: Retrieve complete history of contracts, transactions, and storage.
    • Ethereum-Based Verification: Ensures data correctness by verifying the Starknet state against Ethereum using Patricia-Merkle Trie roots.
    • JSON-RPC Support: Fully compatible with the Starknet JSON-RPC API, making it usable with standard tools like starknet.js and starknet.py.
    • Local State Execution: Execute Starknet functions locally without submitting an actual transaction to the network.
    • Gas Estimation: Estimate transaction fees before submission.
  2. Compute class hashes for Cairo 0.x and Sierra contracts

    main
    The pathfinder-class-hash crate provides tools to compute class hashes for Starknet contracts. It supports both Cairo 0.x and Sierra (Cairo 1.x+) versions, implementing the official Starknet class hash computation algorithm. This ensures compatibility with Starknet network expectations when identifying contract classes.
  3. Switching between archive and pruned modes

    main

    You cannot switch directly between archive and pruned modes while the node is running.

    To switch modes:

    • From Archive to Pruned: Download a pruned Database Snapshot or re-sync using the --storage.state-tries=<k> option.
    • Pruned Mode Adjustments: You can change the k value in pruned mode between runs.
  4. Use Pathfinder JSON Extensions

    main

    Pathfinder provides a specialized set of extension methods for advanced use cases that are not part of the standard Starknet JSON-RPC specification. These include:

    • Verifying storage proofs
    • Generating special debug information

    These methods are exposed via the /rpc/pathfinder/v0_1 endpoint. The full specification for these methods is maintained in the Pathfinder repository's JSON schema.

  5. Understand pathfinder_crypto optimizations and lookup tables

    main

    The crate uses space-time trade-offs to reduce the cost of elliptic curve operations. This is achieved through the generation of lookup tables for:

    • The elliptic curve generator.
    • The four constant EC-points used by the Pedersen hash.
    • Round constants for the Poseidon hash (which may be compressed).

    Generated Constants Locations

    • src/algebra/curve/consts.rs: Constants for curve generator G.
    • src/hash/pedersen/consts.rs: Constants for Pedersen hash generator points.
    • src/hash/poseidon/consts.rs: Constants for Poseidon hash.

    Configuration

    The space-time trade-off for elliptic curves is set to use chunks of eight bits per lookup by default. This can be reconfigured by running the generator scripts located in the examples folder.

  6. Understand the structure of generated P2P code

    main

    The p2p_proto crate uses Protocol Buffers to define the Starknet P2P protocol. The code is managed as follows:

    • Definitions: The raw .proto files are located in the proto/ directory.
    • Generation: Rust bindings are automatically generated during the build process via build.rs.
    • Access: The generated code is exposed through the src/lib.rs module.
  7. Understand the p2p-stream protocol model

    main
    The p2p-stream crate provides a generic "single request - stream of responses" protocol. This model is similar to gRPC's server streaming RPC, where a single request can trigger zero or more responses over a continuous stream. This differs from the standard libp2p-request-response crate, which is limited to exactly one response per request.
  8. Type Requirements for Addresses and Values

    main

    Pathfinder Consensus is generic over validator addresses and consensus values.

    • Address Type: Must implement ValidatorAddress. This is automatically implemented for types that are Sync + Send + Ord + Display + Debug + Default + Clone + Into<Vec<u8>> + Serialize + DeserializeOwned.
    • Value Type: Must implement ValuePayload. This is automatically implemented for types that are Sync + Send + Ord + Display + Debug + Default + Clone + Serialize + DeserializeOwned.
  9. Getting Started with Pathfinder

    main

    To begin using Pathfinder, follow these primary workflows:

    • Setting Up Pathfinder: Learn how to install, set up, and operate your own node.
    • Configuring Your Node: Tailor node behavior and performance using available settings.
    • Interacting with Pathfinder: Use the JSON-RPC and WebSocket interfaces to query data, execute calls, and perform transactions.
    • Database Snapshots: Speed up the initial synchronization of your node by importing pre-compressed snapshots of the Starknet state.

    Validator Setup: If you are using Pathfinder as part of a validator setup, you should also install the attestation tool.