Giter Club home page Giter Club logo

unionlabs / union Goto Github PK

View Code? Open in Web Editor NEW
54.0 5.0 8.0 261.43 MB

The trust-minimized, zero-knowledge bridging protocol, designed for censorship resistance, extremely high security, and usage in decentralized finance.

Home Page: https://union.build

License: Apache License 2.0

Solidity 2.52% Nix 1.40% Rust 89.56% Go 1.99% Shell 0.01% PLpgSQL 0.01% JavaScript 0.01% CSS 0.09% Svelte 1.69% TypeScript 2.08% MDX 0.36% Astro 0.29% HTML 0.01%
blockchain cosmos evm golang rust solidity bridge ethereum cosmwasm nix

union's Issues

Optimize circuit inputs

Currently, we have the six following public inputs to the circuit:

  • The trusted validator set root hash ($F_{r^{2}}$ element)
  • The untrusted validator set root hash ($F_{r^{2}}$ element)
  • The block header hashed to the field ($F_{r^{2}}$ element)

We could shrink the validator set root hash by truncating the top three bits of the sha256 hash to fit in a single $F_{r}$ element.
This would require upgrading the circuit to truncate the bits, updating its interface, and updating the prover, and the solidity verifier.
We would end up with four public inputs, reducing the evm gas cost by approximately 15k.

Integrate ZKP verifiers for all networks

We need to generate multiple instances of the ZKP verifier contracts.
For each of them, it would be nice to have few tests with hardcoded block transition and their proofs.
We also need to upload the circuit and it's verifiying/proving keys.

  • Unmarshall and verification
  • Devnet/Testnet verifier (16 validators)
    • Tests
    • Upload circuit and verifying/proving keys (available through nix run .#download-circuit -- testnet <to_path>
  • Mainnet verifier (128 validators)
    • Tests
    • Upload circuit and verifying/proving keys (available through nix run .#download-circuit -- mainnet <to_path>

Ethereum devnet is not producing blocks

The eth local devnet is broken since our migration to prysm. The execution layer is no longer producing block, transitively blocking the beacon node from producing blocks as well.

Wrap EVM contracts in nix and create CI package

We need to move from the foundry impure build to a nix build for the EVM contracts. The package must consists of the contracts ABI that could be released along the other products. Big advantage here would be reproducible build for the contracts, checkable by anyone willing to verify the deployed bytecode.

Add section about CometBLS

Under the Architecture tab, we should have a page dedicated to CometBLS to explain what part of our core tech is.

Root repository restructure

I think it'd be good if we structure the root repository such that we have all libraries under a lib directory. forks doesn't make too much sense at the moment, as it doesn't contain git submodules (and thus they're not forks). Ideally, to keep them updated we'd make them git submodules, and add them to the lib directory. serde-utils could be moved there as well then.

Move cargo workspace to root of repo

Currently, we have rust/ as the root of the workspace. The top-level Cargo.toml should be moved up to the root of the repo, and the various workspace members can be placed wherever makes sense for them.

Script to generate EVM test data from devnet/testnet

It would be great to have a small script that dump a sequence of blocks / validators / signatures from the devnet/testnet and produce a ZKP of each transition so that we can have a complete test suite implemented in EVM (IBC UpdateClient sequence).

Deployment script for EVM on devnet

We need to introduce a script to deploys EVM contracts on the devnet (testnet later). The script should compile and list the contracts addresses.

Host docs on Vercel

We can generate docs but do not yet host them anywhere. Vercel is a nice option as it offers auth, reviewing and other stuff.

Move more checks into checkPhase

Right now we are defining many top-level checks, which is quite noisy. Derivations export a checkPhase, which means that for each derivation, we could verify the integrity of that output without cluttering the global namespace.

Update README.md

The README.md is mainly listing developer-specific stuff. Instead it should describe what Union is; and be a better entryway into other ALL_CAPS files.

Restructure Validator & Nodes section

The current section is a little bit disorganized and weirdly named. I suggest we rename it to Operators or Infrastructure, and change to contents to divide it between three target audiences:

  • Users running on bare metal, ssh-ing into machines (most validators)
  • Docker users, geared towards docker-compose (the professional ones)
  • NixOS users, basically for just us.

Each should describe how to obtain artifacts, what infrastructure to use, and how to run in testnet, and extend the configuration for mainnet production.

Devnet app-key addresses are non-deterministic

When running the devnet-genesis check and others depending on it - it's possible to generate and use keys that aren't present in the generated genesis file.

Error: failed to get genesis app state from config: account union1rjc32uesdxwp6deen0u2cx2u98u922sxxgap82 balance not in genesis state: map[union12mj7hhjydergxntzrhl08edf8ghnl0xyvzvegw:{Address:union12mj7hhjydergxntzrhl08edf8ghnl0xyvzvegw Coins:100000000000000000000000000stake} union1fyhvpf7zam8cl33r44w0h9yzjnl0uv4zfep3gv:{Address:union1fyhvpf7zam8cl33r44w0h9yzjnl0uv4zfep3gv Coins:100000000000000000000000000stake} union1jk9psyhvgkrt2cumz8eytll2244m2nnz4yt2g2:{Address:union1jk9psyhvgkrt2cumz8eytll2244m2nnz4yt2g2 Coins:10000000000000000000000000stake} union1n4v8mkhz2exfl9zs38aaegwdvjkwcqsrp2vstv:{Address:union1n4v8mkhz2exfl9zs38aaegwdvjkwcqsrp2vstv Coins:100000000000000000000000000stake} union1rm23j4guh6hqwm5pzj3hx7ncwywam777kxmjvf:{Address:union1rm23j4guh6hqwm5pzj3hx7ncwywam777kxmjvf Coins:100000000000000000000000000stake}]

We need to find a way to deterministically generate app-keys for the union devnet.

Remove buf-based code generation

buf is a service for storing and sharing protobuf definitions. This is convenient if you have a public API or microservices. For our usecase it is simply extra work and not worth the added maintenance.

Link to preview deployments

If a PR alters the docs, we should do a preview deployment to vercel and show the preview URL in a comment. This should be possible by checking if nixbuild.net built the docs, or if it already had it in cache. If built, the docs should be fetched and uploaded.

This can be achieved with something like

run: |
  nix copy --from nixbuild.net $(type -p ./#docs)
  vercel build
  vercel deploy > url.txt
working-directory: docs  
continue-on-error: true    
run: |
  if test -f url.txt; then
    create comment
  fi

With this, we'll get links to previews only if the docs changed. A downside is that the nix store can remove cached docs if they haven't been built in a while. Alternatively we can also only run the preview URL if the docs directory is changed; but that however means that if docs depend on anything outside of the docs directory, we might build broken docs without knowing it.

Update uniond/README.md

The current README is generated by ignite (which we do not even use). It should probably explain:

  • What it is
  • Link to releases
  • How to develop on it.

Implement membership verification in ethereum light client

Membership verification verifies if the counterparty light client stores a certain data. There are several data types that we need to verify.
Implementation

Membership verification payload is the following:

 verifyMembershipInnerPayload struct {
    Height           exported.Height `json:"height"`
    DelayTimePeriod  uint64          `json:"delay_time_period"`
    DelayBlockPeriod uint64          `json:"delay_block_period"`
    Proof            []byte          `json:"proof"`
    Path             exported.Path   `json:"path"`
    Value            []byte          `json:"value"`
}
  • Proof is just arbitrary bytes. It is provided by the relayer and directly passed to the wasm client.
  • Path is the key that the light client expects a certain element to be stored under. (Eg. connection state is stored under the key connections/<conn-id>.)
  • Value is the data that we expect the counterparty client to store. This is given to the wasm light client in protobuf encoded format. So it is the wasm light client's job to make sure to convert it to correct encoding before verification.

Data types and their formats in the EVM are the following:

Data Type Commitment Path Encoding
ConnectionEnd connections/<CONN_ID> protobuf
ClientState clients/<CLIENT_ID>/clientState eth abi
ConsensusState clients/<CLIENT_ID>/consensusStates/<HEIGHT> eth abi encoded OptimizedConsensusState
ChannelEnd channelEnds/ports/<PORT_ID>/channels/<CHANNEL_ID> protobuf
Packet commitment `commitments/ports/<PORT_ID>/channels/<CHANNEL_ID>/sequences/ opaque (we verify this as is)
Packet acknowledgement `acks/ports/<PORT_ID>/channels/<CHANNEL_ID>/sequences/ sha256 of acknowledgement (we verify this as is as well)
Next sequence recv `nextSequenceRecv/ports/<PORT_ID>/channels/<CHANNEL_ID> big endian u64 sequence (verify as is)

Roughly, the implementation steps should be:

  1. Determine the data type by looking at Path.
  2. Convert the data to the target format if necessary.
  3. Calculate the slot number based on the data types. Assert if this slot number matches the given slot number in the proof.
  4. Verify if the data is really stored.

Migrate to multiplatform containers

Currently, we're publishing different tags for each architecture we support. Instead, we should use containers multiplatform support, and update the manifest step in CI.

Add a NixOS module for Unionvisor

It'd be convenient for NixOS users to have a module to run a node, something like

imports = [ union.nix ]

union = {
   bundle = bundle;
   home = /path/to/home;
   config = { ... } // config.toml override, merged with existing/default
   app = { ... } // app.toml override, merged with existing/default
}

For this; there are a few changes that have to be made:

  1. unionvisor init should have a flag to exit with status 0 if a home is already initialized.
  2. unionvisor should get the capability to merge toml configurations ({a: 1, b: 2}, {b: 3}) -> {a: 1, b: 3}.
  3. Bundles have to be updated with the latest release.

Create dummy EVM contract to simplify ABI export

EVM tools to generate contracts based on ABI files are very limited. In order to simplify the code generation process, we should expose a dummy contract having the sole purpose of providing the types that must be exposed for generation.

Add unionvisor/README.md

This readme can be linked in the code to also serve as the entrypoint doc comment.

It should describe:

  • Unionvisors model.
  • What it expects and creates on the machine.
  • How to build it.
  • How to run it with NixOS if we add the module

Rotate nixbuild subkeys

We currently share a single nixbuild ssh key for access, payment, and configuration. Instead, we should regenerate keys, where we securely preserve 1 key as root and have user-specific keys for @cor and @hussein-aitlahcen

Solidity gas optimizations

Figure out where we can cut gas by optimizing the UpdateClient and ReceivePacket handlers.

For the former, we currently apply:

  • smallest possible set for the public input of the ZK circuit
  • ClientState using ETH ABI instead of Protobuf
  • optimized, evm slot-friendly ConsensusState structure using ETH ABI insteand of Protobuf
  • inline merkle root for block header

More optimizations (probably v2):

  • move everything in the ZKP circuit (would require non-trivial upgrade of the circuit, not sure it is worth the effort)
  • use ZK friendly hashing like MiMC in place of sha256 (require the above to be implemented first)

For packets, the relayer could bulk them and provide a ZKP of aggregated membership proof verification (circuit yet to be done).

Add unionpd/README

Unionpd should have a README.md, describing what it does and how to build the binary.

Run buf generate inside of mkDerivation

We currently run nix run .\#gen-proto in order to generate go code based on .proto definitions without the need for Docker images or Makefiles, but due to buf accessing the Buf Schema Registry under the hood, we haven't executed buf generate offline inside of a derivation yet.

This would be a nice addition as we can use it to validate that the .proto and .pb.go sources are in sync as part of nix build .\#uniond.

Deploy testnet prover

We need to deploy unionpd somewhere for relayers to generate ZKP in the testnet. I am personally deploying an instance over prover.cryptware.io:443. The instance is behind cloudflare and require TLS to be enabled on the client.

Provide all version of the docs

I like how the cosmos-sdk docs are versioned. https://docs.cosmos.network/main If you go to an older version, there's a link at the top that you can go to the latest one. If you go to main, there's a link to the latest release. It appears that they are also using Docusaurus, so we can adopt a similar approach.

I'm open to suggestions for other docs versioning schemes, feel free to make suggestions in the comments

Add a CI job to test the validity of the light client binary.

The wasm light client can be invalid because of several factors such as having floating point operations. The validity of the client should be tested in the CI. An easy and legit way to do this is to specify the binary in the genesis and see if it failed. Or we can also just write an integration test in Go code.

Move spellchecking into fmt

We currently do loads of fixup commits in PRs because of spelling errors due to two reasons:

  • nix fmt is great, but misses out on spellchecking. nix build ./#checks.{system}.spellcheck is verbose.
  • cspell isn't great at checking rust and golang code, and errors on variable names, function names etc. Ideally we would ignore code and only check doc comments.

It'd be nice if tree-fmt supported spellchecking, and more specifically would set regexes per language to ensure we only check what we care about.

Rename unionpd to galoisd

As agreed in Matrix we're naming the prover 'Galois'.

Make sure that all references to unionpd are updated, including the packages hosted in ghcr.

Implement ethereum verification library

We should implement our own ethereum-verifier library that verifies header updates, storage proofs, account state proofs, etc. There are few libraries out there which defines the ethereum consensus spec types. We will just need to follow the implementation that is nicely documented in the official consensus-specs.

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.