Git Product home page Git Product logo

kevlar's Introduction

Kevlar

Join the chat at https://discord.gg/ePV3prSPGW KevlarArchitecture

Kevlar is a CLI tool to run a light client-based RPC Proxy for PoS Ethereum. Kevlar can be used to make your Metamask or any RPC-based wallet completely trustless! Kevlar first syncs to the latest header of the beacon chain and then starts an RPC server. This local RPC server can be added to MetaMask or any other RPC-based wallet. Every RPC call made by the wallet is now verified using Merkle Inclusion proofs to the latest block header. Currently Kevlar supports two kinds of sync methods: the Light Sync based on the light client sync protocol specified by the Ethereum Specification and the Optimistic Sync (which is 100x faster than Light Sync) based on construction from the research paper Proofs of Proof of Stake in Sublinear Complexity.

Start the RPC Proxy

npm i -g @lightclients/kevlar
kevlar

The RPC is now available at http://localhost:8546. Add this local network to MetaMask.

kevlar --help
Options:
      --help        Show help                                          [boolean]
      --version     Show version number                                [boolean]
  -n, --network     chain id to start the proxy on (1, 5)        [choices: 1, 5]
  -c, --client      type of the client          [choices: "light", "optimistic"]
  -o, --provers     comma separated prover urls
  -u, --rpc         rpc url to proxy
  -p, --port        port to start the proxy                             [number]
  -a, --beacon-api  beacon chain api URL

Build Locally

Clone the repo and perform the following commands

yarn install
yarn build

Run Server

cp .env.example .env
yarn start

Deploy Server to Heroku

bash src/provers/light-optimistic/deploy-heroku.sh <heroku-app-name>

Deploy to Docker

docker run -p 8546:8546 --name kevlar shresthagrawal/kevlar
curl -X POST --header "Content-type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8546/

kevlar's People

Contributors

ardislu avatar gubatron avatar pkakelas avatar shresthagrawal avatar thefrozenfire avatar tzinas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kevlar's Issues

yarn build fails on unmet dep

https://www.npmjs.com/package/json-rpc-engine doesn't appear to be pulled in properly. If you look at https://github.com/lightclients/kevlar/blob/90b1c7f2f56efa0669368ced93d12c1824f3dbd7/src/rpc-bundle/rpc-lightclient-middleware.ts#L1 the node module json-rpc-engine is not pulled in from anywhere.

So you'll get something like:

> yarn build
yarn run v1.22.19
$ tsc
src/rpc-bundle/rpc-lightclient-middleware.ts:1:39 - error TS2307: Cannot find module 'json-rpc-engine' or its corresponding type declarations.

1 import { createAsyncMiddleware } from 'json-rpc-engine';
                                        ~~~~~~~~~~~~~~~~~


Found 1 error in src/rpc-bundle/rpc-lightclient-middleware.ts:1

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If you try to build.

PROVIDER_URL?

PROVIDER_URL from the .env.example doesn't seem to be used anywhere in the code? What is the intended purpose of that argument - specifying an RPC endpoint, instead of the hardcoded default RPCs?

Goerli Testnet no longer works

When trying to run the latest version with "-n 5" (Goerli), on both Mac and Linux, I get this:

root@139-144-74-59:~# kevlar -n 5
Sync started using 2 Provers from period(466) to period(646)
failed GET request (https://light-optimistic-goerli-2.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-1.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-2.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-1.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-2.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-1.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed GET request (https://light-optimistic-goerli-2.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed to fetch committee hash for prover(1) at period(467) Error: GET request failed: https://light-optimistic-goerli-2.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180
at handleGETRequest (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/utils.js:62:15)
at handleGETRequest (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/utils.js:70:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async LightOptimisticProver._getHashes (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/provers/light-optimistic/client.js:17:21)
at async LightOptimisticProver.getCommitteeHash (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/provers/light-optimistic/client.js:23:26)
at async file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/optimistic/index.js:97:28
at async Promise.all (index 1)
at async OptimisticLightClient.syncFromGenesis (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/optimistic/index.js:95:37)
at async OptimisticLightClient.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/base-client.js:24:33)
at async ClientManager.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/client-manager.js:33:9)
at async main (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/start-rpc.js:52:26)
failed GET request (https://light-optimistic-goerli-1.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180): Request failed with status code 503
failed to fetch committee hash for prover(0) at period(467) Error: GET request failed: https://light-optimistic-goerli-1.herokuapp.com/sync-committee/hashes?startPeriod=467&maxCount=180
at handleGETRequest (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/utils.js:62:15)
at handleGETRequest (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/utils.js:70:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async LightOptimisticProver._getHashes (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/provers/light-optimistic/client.js:17:21)
at async LightOptimisticProver.getCommitteeHash (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/provers/light-optimistic/client.js:23:26)
at async file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/optimistic/index.js:97:28
at async Promise.all (index 0)
at async OptimisticLightClient.syncFromGenesis (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/optimistic/index.js:95:37)
at async OptimisticLightClient.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/base-client.js:24:33)
at async ClientManager.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/client-manager.js:33:9)
at async main (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/start-rpc.js:52:26)
Error: none of the provers responded honestly :(
at OptimisticLightClient.syncFromGenesis (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/optimistic/index.js:159:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async OptimisticLightClient.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/base-client.js:24:33)
at async ClientManager.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/client-manager.js:33:9)
at async main (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/start-rpc.js:52:26)

root@139-144-74-59:~# kevlar -n 5 -c light
Sync started using 1 Provers from period(466) to period(646)
Validating Prover(0)
failed to fetch sync update for period(466)
Error: no honest prover found
at LightClient.syncFromGenesis (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/light/index.js:59:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async LightClient.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/clients/base-client.js:24:33)
at async ClientManager.sync (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/client-manager.js:33:9)
at async main (file:///usr/local/share/.config/yarn/global/node_modules/@lightclients/kevlar/dist/rpc-bundle/start-rpc.js:52:26)

Mainnet works for both client types:

root@139-144-74-59:~# kevlar
Sync started using 4 Provers from period(738) to period(744)
Optimistic update verified for slot 6099971
RPC Server started at http://localhost:8546

root@139-144-74-59:~# kevlar -c light
Sync started using 1 Provers from period(738) to period(744)
Validating Prover(0)
Optimistic update verified for slot 6099972
RPC Server started at http://localhost:8546

Add support for light client API specified by the Ethereum specification

When we started building Kevlar the Light Client API to fetch Sync Protocol information was not specified. But the Lodestar client already had some custom endpoints for Light Clients which were not a part of the Ethereum specification, hence we decided to use them instead of waiting for the Ethereum specification to get finalised.

@etan-status pointed me to the finalised API specification for Light Clients. We should add support for both Libp2p API and REST API.
P2P Interface: https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md
REST API: ethereum/beacon-APIs#247

mainnet provers stopped working

AFAICT https://light-optimistic-mainnet-1.herokuapp.com/sync-committee/hashes?startPeriod=767&maxCount=148 and https://light-optimistic-mainnet-2.herokuapp.com/sync-committee/hashes?startPeriod=767&maxCount=148 are not working anymore. They throw server errors.

eth_sendRawTransaction and eth_getBalance keep repeating and failing

An unexpected error occurred while executing "eth_sendRawTransaction" JSON-RPC method: Error: RPC request failed
    at RPC.<anonymous> (/home/ubuntu/.nvm/versions/node/v18.12.1/lib/node_modules/@lightclients/kevlar/node_modules/@lightclients/patronum/lib/rpc.js:93:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/ubuntu/.nvm/versions/node/v18.12.1/lib/node_modules/@lightclients/kevlar/node_modules/@lightclients/patronum/lib/rpc.js:28:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

An unexpected error occurred while executing "eth_getBalance" JSON-RPC method: Error: RPC request failed
    at RPC.<anonymous> (/home/ubuntu/.nvm/versions/node/v18.12.1/lib/node_modules/@lightclients/kevlar/node_modules/@lightclients/patronum/lib/rpc.js:93:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/ubuntu/.nvm/versions/node/v18.12.1/lib/node_modules/@lightclients/kevlar/node_modules/@lightclients/patronum/lib/rpc.js:28:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

these two errors keep showing up, my guess is that wallet will keep calling this rpc and rpc failed without sending error to wallet so that wallet will keep calling.

How to fix this issue? And how to reset?

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.