GithubHelp home page GithubHelp logo

zeropool-relayer's Introduction

Relayer for ZkBob application

Relayer's primary role is to deliver user-prepared ZkBob transactions to the private pool contract. Also, it can be used as cache service to conveniently retrieve information about previous transactions, current Merkle Tree state, transaction fees, etc.

How to start locally

Docker:

You can use a pre-built image from registry. List of env configuration parameters can be found in zp-relayer/.env.example. The repository zkBob/relayer-launch can be used to run the relayer with the docker-compose facility.

Tests

Unit tests:

cd zp-relayer && yarn test:unit

Workflow

High-level overview:

  1. Client fetches all commitments and memo blocks (either from relayer or directly from the blockchain) and decrypts their notes and accounts. All commitments should be stored in local Merkle tree, together with found notes and accounts.
  2. Client builds a zk-SNARK proof for the transaction using previously fetched notes and the most recent account. This proof, together with public inputs, memo block, and optional nullifier signature (used only for deposits), is sent to the relayer.
  3. Relayer adds a job to the queue. It checks that the tx proof is valid, builds another zk-SNARK proof for tree update, sends tx to the blockchain, and updates the local Merkle tree using sent data. It also locally stores commitment hash (one of the public inputs) and memo messages.

You can use already implemented client to check for details.

sequenceDiagram
    actor U as User
    participant R as Relayer
    participant P as Private pool
    U->>R: /transactions/v2
    R->>U: transaction batch
    Note Over U: Update Merkle Tree
    Note Over U: Build ZK proof
    U->>R: /sendTransactions
    Note Over R: Validate transactions
    Note Over R: Add transactions to <br /> optimistic state
    R->>P: Submit transactions
    R->>U: jobId
    loop Until mined
        Note Over R: Check if transaction <br /> is mined
        Note Over R: Update gasPrice
        R->>P: Re-submit transaction
    end
    Note Over R: Update confirmed state
    par Wait for transaction
        U->>R: /job/:jobId
        R->>U: job status
    and Update local state
        U->>R: /transactions/v2
        R->>U: transaction batch
    end

API

For a detailed description of each method's payload you can refer to zp-relayer/validation/validation.ts file with JSON validation schemas.

  • /sendTransaction - submit a transaction to relayer (deprecated).

  • /sendTransactions - submit batch of transaction to relayer.

  • /transactions?limit=${limit}&offset=${offset}&optimistic=${true|false} - list of transaction memo blocks (deprecated).

  • /transactions/v2?limit=${limit}&offset=${offset} - list of encoded transactions data in the following format "${stateBit}${txHash}${outCommit}${memo}". stateBit is 1 if transaction is in confirmed state and 0 otherwise.

  • /merkle/root/:index? - get Merkle Tree root at specified index.

  • /siblings?index=${index} - get left siblings starting from a leaf node at index up to the tree root.

    Response

    "${height}${sibling_index}${sibling_value}"[]
    
  • /job/:id - information about user's job state.

    Response

    {
        resolvedJobId // Resolved job id as job can be re-tried several times
        createdOn
        failedReason
        finishedOn
        state
        txHash
    }
    
  • /info - information about current pool state.

    Response

    {
        root // Confirmed tree root
        optimisticRoot // Optimistic tree root
        deltaIndex // Confirmed tree root index
        optimisticDeltaIndex // Optimistic tree root index
    }
    
  • /fee - current relayer fee.

    Response

    {
        fee // Fee in pool tokens
    }
    
  • /limits?address=${ethAddress} - current pool limits.

    Response

    {
        deposit: {
            singleOperation // Limit for single pool operation
            daylyForAddress: { // Daily deposit limits for address
              total
              available
            },
            daylyForAll: { // Daily deposit limits  for all users
              total
              available
            },
            poolLimit: { // Daily pool limit
              total 
              available
            },
        },
        withdraw: {
            daylyForAll: { // Daily withdraw limit for all users
              total
              available
            },
        },
        tier // Address tier
    }
    
  • /params/hash/tree - hash of pool tree proving parameters.

  • /params/hash/tx - hash of pool transaction proving parameters.

zeropool-relayer's People

Contributors

akolotov avatar allfi avatar evgenkor avatar r0wdy1 avatar voidxnull avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.