Git Product home page Git Product logo

shutter-network / rolling-shutter Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 7.0 4.07 MB

Rolling Shutter is an MEV protection system to be plugged into rollups.

Home Page: https://twitter.com/project_shutter/

JavaScript 4.93% Solidity 1.49% Makefile 0.55% Go 82.99% Shell 0.83% Clojure 8.16% PLpgSQL 0.47% Dockerfile 0.50% Python 0.08%
blockchain ethereum frontrunning mev rollups threshold-encryption

rolling-shutter's People

Contributors

bilbeyt avatar cducrest avatar dependabot[bot] avatar ezdac avatar jannikluhn avatar konradkonrad avatar schmir avatar ulope 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rolling-shutter's Issues

Send placeholder decryption signatures

When a new key or cipher batch is received, check if we have now both of them and if so create a (placeholder) signature. Store it in the database and broadcast it.

Aggregate epoch key share messages

The keyper should listen for epoch key shares of their peers, validate them, and store them in their db. When it has enough, it should aggregate them, store the resulting decryption key in their db, and send a corresponding decryption key message to the decryptors.

Send epoch key shares

  • In the keyper, when decryption trigger is received, generate and broadcast epoch decryption key share
  • only do it once (even if multiple decryption triggers for same epoch are received)
  • share should be stored in db

Add decryption key message validator

check that they key matches the eon public key for the given epoch

register the validator for both the decryptor and the keyper

c.f. decryption key input handler which already does validation

Connect to database on startup

  • read connection details from config
  • close database if something crashes
  • crash if database is not initialized (for now: check if one particular table exists)

Simple peer management

Right now, the p2p thing connects to all peers on startup. If a single connection fails, it exits. If over time peers disconnect, we might end up with too few peers.

Instead, on startup we should create a dedicated goroutine responsible for peer management. The goroutine regularly checks if we have too few connections. If so it tries to connect to more peers (using addresses from the config file). If there is an error (e.g., because the peer is offline), it doesn't quit but logs the error. The goroutine should be part of the error group already used for the topic subscriptions so that it's automatically stopped.

The goroutine should also regularly log the number of peers it is connected to.

Later, we can improve by syncing peer lists from other peers.

Use proper hash to curve algorithm for BLS signatures

To create BLS signatures in G2, we need to first map the message to a point in G2. At the moment, we do this by hashing the message to a string, interpreting it as an integer, and multiplying it by the base point. This is not the proper way to do it.

  • The cloudflare library has an issue for this: cloudflare/bn256#17
  • If EIP-2537 is activated, we should probably switch to the BLS12-381 curve and we can use whatever the Eth2 clients use.
  • If we have to implement it ourselves, we have two options:
    • Implement a proper algorithm, e.g., described here: https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/
    • Implement "hash and check" which supposedly is insecure, but should be acceptable for our use case (because the attacker cannot choose the message that's signed) -- see here for a description, but in the context of BLS12-381.

Decryptor panics when receiving bad signature

I ran three keypers and let them generate a eon public key. Then I manually inserted the key into the dbs of three decryptors and started them too. Finally, I ran the mocknode. Two of the three keypers paniced with the following message:

2021/10/15 18:09:11.657826 inputhandling.go:57: attempted to store multiple keys for same epoch 29
2021/10/15 18:09:11.681066 inputhandling.go:57: attempted to store multiple keys for same epoch 29
2021/10/15 18:09:11.684321 inputhandling.go:215: decrypting batch for epoch 29
panic: could not verify aggregated signature for epochID 29

goroutine 41 [running]:
github.com/shutter-network/shutter/shuttermint/decryptor.handleSignatureInput({0x176a3f0, 0xc000dd1a00}, {{0x178ecc0, 0xc000030990}, {0xc000dc6c40, 0x7, 0x7}, {0xc000121320, 0x1a}, 0xc000deaf60, ...}, ...)
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/inputhandling.go:167 +0x99f
github.com/shutter-network/shutter/shuttermint/decryptor.handleEpoch({0x176a3f0, 0xc000dd1a00}, {{0x178ecc0, 0xc000030990}, {0xc000dc6c40, 0x7, 0x7}, {0xc000121320, 0x1a}, 0xc000deaf60, ...}, ...)
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/inputhandling.go:234 +0x5be
github.com/shutter-network/shutter/shuttermint/decryptor.handleCipherBatchInput({0x176a3f0, 0xc000dd1a00}, {{0x178ecc0, 0xc000030990}, {0xc000dc6c40, 0x7, 0x7}, {0xc000121320, 0x1a}, 0xc000deaf60, ...}, ...)
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/inputhandling.go:80 +0x296
github.com/shutter-network/shutter/shuttermint/decryptor.(*Decryptor).handleMessage(0xc00023e880, {0x176a3f0, 0xc000dd1a00}, 0xc000f9c300)
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/decryptor.go:120 +0x375
github.com/shutter-network/shutter/shuttermint/decryptor.(*Decryptor).handleMessages(0xc00023e880, {0x176a3f0, 0xc000dd1a00})
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/decryptor.go:95 +0x10a
github.com/shutter-network/shutter/shuttermint/decryptor.(*Decryptor).Run.func1()
	/home/jannik/Projects/Brainbot/rolling-shutter/rolling-shutter/decryptor/decryptor.go:77 +0x25
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/jannik/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/home/jannik/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x92
Error while executing task: d

Define decryptor database schema placeholder

Tables:

  • keys:
    • round id (uint64)
    • key placeholder (bytes32)
  • cipher batches
    • round id (uint64)
    • cipher batch placeholder (bytes32)
  • signature shares
    • round id (uint64)
    • signer index (uint64)
    • signature placeholder (bytes32)

Set this up in initdb subcommand

Aggregate epoch decryption keys

Keypers should listen for decryption key shares of their peers and when they have enough of them aggregate and broadcast them.

Write decryptor logic

assume it will be notified whenever new cipher batches or decryption keys are available

decrypt batch, sign the result, send it to p2p layer

Send aggregated signatures to dedicated topic

Decryptors already send it to the decryption signatures topic. Create a new topic (e.g. aggregatedDecryptionSignature) and send it there.

Decryptors should also connect to this topic and validate messages.

Define protobufs for messages

message types, only for gossiping:

  • epoch end trigger
  • epoch decryption key
  • cipher batch
  • signature
  • aggregated signature

Add config file containing peer addresses

Config file is read at startup. The p2p layer of the application should connect to these addresses. The addresses should use libp2p multiaddr format. The config file should be validated. Format: TOML. Read it with viper. c.f. shuttermint config file validation.

Avoid sending decryption signatures multiple times

At the moment, sending a new aggregated decryption signature is triggered by receiving a new unaggregated signature (and we have enough of them in the db). This means we send many unnecessary ones.

  • store aggregated signatures in db table (one per hash)
  • only broadcast signature when none is in db already

Properly decrypt batches

When decryption key and cipher batch are received, decrypt.

We already send a fake signature (see #19). Update this to send a proper one.

Test node tool

Write a tool that

  • connects to keypers and/or decryptors
  • sends decryption triggers, decryption keys, cipher batches, etc.
  • logs messages it receives

The goal is to be able to easily test the decryptor and the keyper node, without spinning up a whole network.

Check that batches are decrypted properly in mocknode

The mocknode should

  • remember which transactions it encrypted and sent
  • check that decryption signatures it receives are attesting to the right value

To check the signature, they'll need to know who signed it. Since we don't handle signer indices yet, nor have a list of decryptors yet, it's fine to put a single decryptor identity in the config file and check against that.

Make DKG work again with Tendermint

when running the keyper command, it should

  • connect to a shuttermint chain (url from config)
  • participate in DKG process

Eon key generation only

Validate and parse incoming gossip messages

  • parse them and the included data types
  • convert them to a struct (one per message type)
  • the struct should conform to an interface (c.f. gossip message interface already defined in shmsg)
  • reject messages that are not parsable or have easily detectable invalid values

The libp2p validation interface should be able to do both parsing and validation at the same time. If not, revise.

Select library for BLS signatures

  • should support keys from G1
  • needs support aggregate BLS signatures
  • needs hashing for G1 (we can also implement this by ourselves)

Initialize database subcommand

Add subcommands to initialize database

  • <root cmd> keyper initdb
  • <root cmd> decryptor initdb

Should check that db doesn't exist yet and if so creates tables. For now just a placeholder table.

Test keyper and decryptor compatibility

  • Run the keypers
  • Configure mocknode such that it sends messages encrypted with eon public key generated by keypers.
  • Add eon public key to decryptor db
  • Run decryptors

Check that messages are properly decrypted and signatures are produced.

(if possible, update readme in rs-play repo)

Setup test setup repository

The repo should contain

  • config files for keypers, decryptors, and mocknode(s)
  • script(s) to setup the database(s)
  • a readme that describes how you can run the test setup

example name: rolling-shutter-samples , rsspl, rllngshttrsmpls

Validate decryption keys

when the decryptor receives a key, they should check that it's valid. They can do so by comparing it against the eon public key and the epoch id. The eon public key is hardcoded as a constant somewhere -- this is a temporary solution. In the future, we might read it from Shuttermint or from a different blockchain

Start epoch key generation when trigger is received

When the keyper receives a decryption trigger message for the first time, it should launch the epoch key generation process for the given epoch. In particular, as a result it should send an epoch key share message.

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.