Giter VIP home page Giter VIP logo

spacefold's Introduction

alt text

Spacefold

Spacefold is a demo and reference implementation of instant cross-evm-chain communication using Connext! Spacefold was built as part of The Great Reddit Scaling Bake-Off in July 2020.

Here's our official submission to the /r/ethereum subreddit!

Quick Resources

Introduction: "Hold up, how does this meet the Reddit requirements outlined above"?

Great question! It doesn't and it's not supposed to.

Connext is the protocol for programmable p2p micropayments. Connext lets users make unbreakable commitments to each other using state channels - these commitments are effectively free to create and send, but must be backed by funds locked up on (any) chain. Unlike other scalability solutions to Ethereum, we're not a consensus system (a blockchain, rollup, etc.), but a point-to-point communication network that enables extremely high volume, private, ultra-cheap transfers (and other more complex commitments) baked directly into existing web paradigms like HTTP requests.

One consequence of the above is that all actions taken within Connext are private to each user. This means that, while we can enable a high volume of Reddit Community Point transfers at low cost, meeting Reddits requirements of scalably minting/burning their points can't be done in a way where subreddit users can actively monitor and interact with each others' balances. Those balances would be necessarily private.

The reality is that every solution has its tradeoffs. Rather than building a custom independent submission, we decided to experiment with mitigating these tradeoffs by combining different existing solutions to make something even better. The biggest vector for improvement we see is the usability and interoperability of new scale-by-more-chains-based approaches like rollups/plasma/sidechains/sharding.

Spacefold demonstrates how Connext can be used to build an internet-of-l2-chains/shards. Users can instantly and seamlessly transfer value between chains/shards, and eventually even make atomic cross-chain contract calls. Most importantly, this can happen in a way where users dont need to know what chain/rollup/shard they are on to begin with.

Table of Contents

  1. Compatibility with Other Chains

  2. Running it Yourself

    a. Setting Up the Demo Locally

    b. Running your own Connext Node on Multiple Chains

  3. How Does it Work?

    a. Background on Connext

    b. Cross-chain Transfers with Connext

    c. How Does it Scale?

  4. Demo Implementation Details

  5. Trust Assumptions and Other Considerations

Compatibility with Other Chains

In general, Connext can support any chain/l2/shard/rollup system that supports turing-complete computation. For limited cases, we may also be able to get away with non-turing-complete chains using a slightly different pattern for cross-chain transfers.

While the above is true, in the ideal case (to avoid custom work), it's best for Connext to work with Ethereum-like systems (that run the EVM and support Solidity). Running Connext on anything else would likely require lots of custom work.

To help with parsing out which solutions can and can't work with Connext, we've created a compatiblity table. Note this table is still a WIP while we get more information from teams. If you feel as though anything here was misrepresented, please submit an issue -- we're happy to amend!

Name Type EVM Compatible Supports Create2 Included in demo Notes Verdict
Matic Plasma chain โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐Ÿ˜
Optimism ORU โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐Ÿ˜
xDai PoS Sidechain โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐Ÿ˜
SKALE Elastic Sidechains โœ”๏ธ โœ”๏ธ Coming soon ๐Ÿ˜
Arbitrum ORU โœ”๏ธ โœ”๏ธ Coming soon ๐Ÿ˜
OMG Plasma chain โœ”๏ธ ๐Ÿคท No confirmation from OMG team yet - we're assuming based on most plasma constructions ๐Ÿ™‚
Hubble ORU Can be supported ๐Ÿ™‚
Fuel ORU Planned for v2 While not currently supported, the Fuel team expressed interest in building support potentially earlier than their v2 ๐Ÿ™‚
Starkware zkRU โŒ No confirmation from team yet, we're assuming based on current zkRU limitations ๐Ÿคท/โ˜น๏ธ
Loopring zkRU โŒ No confirmation from team yet, we're assuming based on current zkRU limitations ๐Ÿคท/โ˜น๏ธ
zkSync zkRU โŒ No confirmation from team yet, we're assuming based on current zkRU limitations ๐Ÿคท/โ˜น๏ธ

Run it Yourself

Running the Spacefold Demo Locally

The spacefold demo is pretty simple to run:

git clone [email protected]:connext/spacefold.git
cd spacefold

By default, the demo will point to a Connext node that we're hosting at https://node.spacefold.io.

You'll need a few environment variables to start the demo.

  1. NEXT_PUBLIC_CHAIN_PROVIDERS= -- JSON string to provide node URLs with chains, i.e. '{"4":"https://rinkeby.infura.io/v3/...","5":"https://goerli.infura.io/v3/...","42":"https://kovan.infura.io/v3/...","80001":"https://rpc-mumbai.matic.today"}'

Then,

yarn && yarn dev

Running your own Connext Node on Multiple Chains

Running your own Connext node locally is also pretty easy!

git clone [email protected]:connext/vector.git
cd vector
make # this will take a while
make start-trio

Please refer to our docs for more info, or ping us in our Discord!

How does it work?

A Quick Background on Connext

Connext is a network of state channels. The core concept behind a channel is very simple:

  • Suppose you're paying your friend Bob for a metered service at the rate of $1 every minute.
  • It would be silly to broadcast every transaction to the blockchain, you would incur lots of fees. At the same time, it also doesn't make sense to pay up front or pay at the end, as that would introduce new trust assumptions.
  • Instead, what you can do is send your funds to a 2/2 multisig controlled by you and Bob. Then, rather than sending onchain transactions, you can send Bob ever updating signatures which give Bob the ability to withdraw up to a certain amount from the multisig.
  • Because Bob can get his funds at any time using his unbreakable commitment from you, you complete a new payment to him every time you send a new signature.

alt text

Connext extends this concept in a couple of ways ways:

  1. Updates within the channel can have any arbitrary conditionality to them. This means you could make your payments conditional upon Bob providing a proof of his work, or based on some real world event, or even based on the outcome of a chess game.

  2. More importantly: the above paradigm requires you to deploy a new multisig with each new person you transact with. Using the conditionality described above, Connext instead lets you use your channel with Bob to atomically interact with anyone that Bob also has a channel with. For instance, you pay Bob $1, who pays Charlie $0.9999 (Bob takes a microfee), who pays Danielle $0.9998 (Charlie takes a microfee).

There's a lot more information available publicly on state channels, here are some great resources:

Cross-chain Transfers with Connext

One big hurdle that we encountered when building our network was the difficulty of managing interactions that could be on different chains or different currencies. This is why, in addition to the above we extend basic channels in another way:

Because of the fact that channels are simple primitives and what links them together is offchain communication, it's possible to transact to Danielle regardless of where Bob and Charlie's channels are or what currency they're using. This means you can pay Bob on Ethereum in Eth, who pays Charlie on Matic in MATIC, who pays Danielle on Arbitrum in aDai, who in turn calls the Uniswap contract running on Optimism on your behalf. This is best shown via the following diagram:

alt text

How Does it Scale?

What you're effectively doing above is freezing funds on an existing ledger and committing to peers that you will pay them out of those funds (sort of like the Gas Station Network, but no one actually needs to submit the transactions to chain unless they want to).

This means that some specific types of activities (anything that is point-to-point and doesn't require global consensus), you are now entirely unconstrained by the limitations of blockchains. Updates in state channels can happen as fast as HTTP messages because... well, they can literally be HTTP messages.

There are of course some limitations, however, which are discussed later in this readme.

Demo Implementation Details

For the purposes of the demo, we've made some simplifying assumptions:

  1. We mint for users using a faucet instead of letting them deposit their own assets. We found that the user experience of getting assets to different chains to test folding with was really poor and took away from the substance of the demo. If spacefold existed as a standalone production app, it would be much easier for users to get value to these other l2s in the first place. ๐Ÿค”

  2. For Optimism, we're using a temporary testnet chain hosted by the team themselves. At the moment, a public testnet does not exist.

  3. Throughout the demo, we use a dummy ERC20 token with a 1:1 swap rate. We considered using Eth for some chains, but decided against it because then we would need to do lots of social verification in a short time to get Eth liquidity and our team only has so many twitter accounts.

  4. We decided against showing mainnet in the demo -- at the time of writing, mainnet gas fees are at 62 gwei. While this code can definitely be run on mainnet, we thought that the it would be annoying for users who just want to understand how it works to have to wait several minutes for a faucet transaction.

  5. There's a LOT more functionality that Connext enables. Even if you're using Connext primarily to bridge between chains, it can be highly cost effective to also use it to further reduce the costs of transfers of tokens like Community points. You can also do more complex constructions such as bounties, or token-proportional content investing. We've left these things out of the demo to specifically highlight the cross-chain functionality.

Trust Assumptions and Considerations

Trust Vectors

Connext is entirely noncustodial for users. No matter what happens, users are always able to withdraw their balance to whatever chain(s) they are actively participating in.

This comes with a couple of caveats, however:

  1. First, users need to hold their latest offchain state to withdraw with. This is typically referred to as the "data availability problem" for solutions like state channels and plasma (as contrasted to solutions that post data to chain -- i.e. rollups). In practice, we've found that this is actually not as big of a problem for users as people think it is, particularly if users are utilizing authenticated sessions. This data storage can also be easily decentralized and outsourced to remote backup providers to ensure user funds remain secure.

  2. Second, users need to monitor the chain to respond to any potential disputes. This is a similar pattern to what users have to do for plasma and optimistic rollup chains. Similar to those approaches, monitoring the chain can be outsourced to third parties who do it as a service (typically referred to as Watchtowers). We have an open source implementation of a watchtower module which can be dropped into any service.

Both of the above problems can be solved in pretty elegant ways in the long run. You can use watchtower pools to back up state -- these can utilize eventually-consistent persistent store systems like IPFS which take in anonymized data plus run our watcher interface. The pools can be held economically liable through value staked upfront on-chain, which is slashed upon pool misbehavior.

In return for these caveats, channels give unparalleled UX. Unless all communication has broken down and you're actively in dispute, getting into and out of a channel is a single onchain transaction, which can also be entirely gas abstracted (as is the case with Connext). You can also onboard users to channels in sticky ways -- for instance, we support referral codes that implementers can create (or users can generate for each other) which create/fund a channel.

Censorship

Because state channel networks are not consensus systems but are instead structurally similar to TCP/IP, the potential exists for censorship by intermediary routers.

This is true in the current implementation of Connext which features a hub-and-spoke pattern over many single nodes. In the current construction, one "full node" provider connects to many users (running fully validating, but browser-compatible light nodes) and acts as the primary router.

Our eventual goal is to move towards a pattern where routing nodes also all connect to each other. Then, censoring transactions becomes much much much tougher. Transfers can be routed over TOR using VPNs and pass through many routers before reaching a destination. They can also be broken up into many smaller transfers/updates which are all atomically routed over many different paths, exactly like how TCP works.

Liquidity

Effectively what you're doing with Connext is doing many many tiny swaps between linked channels when you route a transfer or make an update. These swaps require collateral to happen trustlessly. This means that routing nodes in Connext are also liquidity providers earning fees for their service.

There's a lot of misinformation about the amount and extent to which liquidity is needed within channel networks. The reality is that it's very very hard to judge exactly how much, but as the network gets more connected and transaction volume increases, you start to see more and more transactions flowing in both directions within a routing channel. For each transfer, the node earns fees multiplicatively against the locked up collateral. From internal rough calculations made by some of our users the ROI generated here is more than enough to offset liquidity costs and competitive with existing DeFi returns.

Aside from the cost of liquidity, the base cost of transfers is equal to the cost of bandwidth.

spacefold's People

Contributors

arjunbhuptani avatar heikofisch avatar jakekidd avatar laynehaber avatar luoyang9 avatar manishbhutani avatar mattreyes avatar pedrouid avatar rhlsthrm avatar sanchaymittal avatar sudo-owen avatar uberi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacefold's Issues

[Ops] Host app at public domain

Do we want to set up some sort of CD for this? If the overhead is high it isn't worth it, but it would help with iteration speed when debugging.

[App] Fix onchain withdraw in app

Right now, it fails with:

2020-07-27T13:48:17.231Z [CFCoreService] Failed to deploy multisig with unknown error: Failed to create channel. Multisignature wallet cannot be deployed properly: {
  "reason": null,
  "code": "CALL_EXCEPTION",
  "method": "getOwners()",
  "errorSignature": null,
  "errorArgs": [
    null
  ],
  "address": "0x602091741665ECc2e5E7E4d17AE8B0Da2f21a2eD",
  "args": [],
  "transaction": {
    "data": "0xa0e67e2b",
    "to": "0x602091741665ECc2e5E7E4d17AE8B0Da2f21a2eD"
  }
}. Should use onchain transaction service for this```

Failed on Running the Spacefold Demo Locally

I followed the instructions of ``Running the Spacefold Demo Locally'' but it failed with JSON parsing error.

>> yarn build
yarn run v1.22.10
$ next build && next export
info  - Creating an optimized production build
info  - Compiled successfully

> Build error occurred
SyntaxError: Unexpected token u in JSON at position 0

The commands I ran are

  1. clean clone this repo and then cd in
  2. yarn install
  3. yarn build -> trigger error
    3.1. if I skip 3. to run yarn start, it tells me there's no build file.
>> yarn start
yarn run v1.22.10
$ next start
Error: Could not find a production build in the '$HOME/spacefold/.next' directory. Try building your app with 'next build' before starting the production server. https://err.sh/vercel/next.js/production-start-no-build-id

Can someone point me out how to build it? appreciate it!

[App, Ops] Add support for xDai

TODO:

Ops:

  • Get some xDai funds to use for this
  • Deploy contracts to xDai chain
  • Deploy token on xDai and mint liquidity to node signer
  • Send xDai to node signer so that it can pay gas
  • Health check node xDai deployment (blocked by #19)

App:

  • Spin up xDai client
  • Add xDai as dropdown option in UI
  • Add xBricks as currency in UI + xDai background color
  • Add support for BlockScout as block explorer for xDai when sending onchain tx

[Ops] Remove DaiCard.io Ui from spacefold node

From Bo:

Hacky fix: 1312-fast-track disconnects the daicard ui from prod-mode indra's proxy. It's a quick & clean cut but there are some drawbacks:
 - if we deploy this branch to prod then both rinkeby.daicard.io & daicard.io will be completely broken.
 - daicard CD tests don't work anymore so this branch wouldn't be deployed automatically but we can deploy it locally as needed.
Luckily, it's a single commit so we can cherry-pick it onto eg a spacefold branch.

[Faucet] Should be able to mint to any chain

Pass in chainId context to faucet call so that it can send funds to any chain.

The chain that gets selected for the user on startup on the left side should be randomized. Right side chain should be rinkeby (but changeable).

[App] Allow `transfer` in both directions

Right now it can only happen from left -> right. Users should be able to swap back and forth as much as they'd like before making the onchain tx.

Additionally, the dropdowns on both sides should include all chains (except for the chain which already has funds in it).

Unable to transfer to Arbitrum Testnet V3 from Kovan Testnet

When I try to tranfer from Kovan to Arbitrum I keep getting this alert:

"Alert
The transfer could not complete, likely because of a communication issue. Funds are preserved in the state channel. Refreshing usually works in this scenario."

I have tried refereshing 10 times and it doesn't work, I'm using Metamask on Brave. All other transfers work, except I haven't tried Arbitrum to Kovan.

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.