AndyHydro / plasma-contracts

Solidity Smart Contracts for Plasma Cash Implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub license Node Version Truffle Version SolC Version Travis (.org) Codecov Telegram

Elph Network Plasma Contracts

Elph Network's Plasma contracts are a full implementation of Plasma Cash. With support for Ether, ERC20 & ERC721 tokens these contracts act as the root chain bridge allowing assets to be securely transfered to and from the Elph Network.

Testnet

These contracts are live on Rinkeby and are being actively used on the Elph Network Testnet.

Further interactions with these contracts and the Elph Network can be done using the Block Explorer or the Plasma Demo, which both showcase the power a plasma network can have as a layer-2 solution.

Key Features

  • Plasma Cash security guarantees
  • Ether, ERC20 and ERC721 Support
  • Full challengable exit support
    • Challenge "Double Spend"
    • Challenge "Exit Spend"
    • Challenge "Invalid history"
  • Bonding and slashing for challenges and exits

Development

Installation

To clone and run this application, you'll need Git and Node.js. We also recommend using Yarn over NPM. From your command line:

# Clone this repository
$ git clone https://github.com/elphnetwork/plasma-contracts.git

# Go into the repository
$ cd plasma-contracts

# Install dependencies
$ yarn install

Note: If you're using Linux Bash for Windows, see this guide or use node from the command prompt.

Usage

In order to make changes or run tests, a local blockchain must be running. Since we have ganache-cli as a dependency, that's the easiest way to run a local blockchain to deploy the contracts to.

# Start ganache-cli in the background
$ yarn blockchain:start
# Stop any ganache-cli
$ yarn blockchain:stop

Testing

With ganache running:

# Runs all tests in repository
$ yarn test

Deployment

Local Ganache

# Deploy this repository
$ yarn deploy

Rinkeby

First create a .env file by copying .env.sample and fill in the appropriate values

INFURA_API_KEY=''    # Represents your Infura API Key
RINKEBY_ADDRESS=''   # Represents the address which will deploy the contract
RINKEBY_MNEMONIC=''  # Mnemonic phrase representing the seed phrase for the address

After the environment is setup, run:

# Deploy this repository to rinkeby
$ yarn deploy:rinkeby

Use the Rinkeby Faucet to get some testnet ETH to test out the deployed contract.

Mainnet

These contracts are still undergoing testing and security audits, therefore have not yet been deployed to mainnet. However, if you choose to use/deploy, simply add the mainnet network to truffle.js and the deployment will be similar to Rinkeby.

Testing

RootChain Solidity Contract Tests

This section details the current set of tests in the repository to ensure the contract is working as intended. More tests will be added to this repository over time.

  • Deposits
    • Send ETH / ERC721 to the RootChain contract
      • Ensure balance is updated accordingly on the original account
      • A new slot is created and a deposit event is emitted
    • Multi-deposits
      • Two owners deposit a coin each, exchange it with each other and are able to withdraw the other coin.
  • Exit / Withdraw
    • Associated events (i.e., StartExit, Withdrew) are emitted by the contract
    • Should require bond for exiting (and challenging)
    • Withdraw initial deposit transaction
    • Exitor withdraws a coin that was deposited and sent to them
    • Exitor withdraws a coin that was deposited (and sent to multiple participants) prior to being sent to them
    • Inability for the exitor to withdraw a coin before the maturity period
    • Inability for a random participant to withdraw your coin
    • Inability for the exitor to withdraw a coin after sending it away to another participant
    • Multiple participants should be able to withdraw coins they received from each other
    • Bonds are slashed and routed to the correct recipient (challenger or exitor) accordingly.
  • General Flow
    • Signature checks and transaction inclusion checks
    • Authority should be able to submit blocks
    • Correct Merkle Tree implementation (membership checks, proofs of inclusion)
  • Challenge: "Double Spend" multi-participant scenario
    • Successful "double spend" scenario challenge
    • "Double spend" scenario that is not challenged in time, hence a successful exit
    • "Double spend" scenario that is challenged and fails (despite collusion with operator)
  • Challenge: "Exit Spend" multi-participant scenario
    • Successful "exit spend" schenario challenge
    • "Exit spend" scenario that is not challenged in time, hence a successful exit
    • "Exit spend" scenario that and is challenged and fails (despite collusion with operator)
  • Challenge: "Invalid history" multi-participant scenario
    • Invalid history scenario that is challenged successfully
    • Invalid history scenario that is challenged and responded to with an invalid response (no exit)
    • Invalid history scenario that is challenged by multiple participants, followed by an invalid response (no exit)
    • Invalid history scenario that is challenged by multiple participants, followed by no response from the exitor
    • Invalid history scenario that is not challenged in time (exit)
    • Valid history scenario that is challenged but responded to with a valid response (exit)
    • Ensure all guarantees hold even if operator is byzantine

Roadmap

We're working on improving these contracts with the newest research coming out (including adding Plasma Debit / XT / Cashflow).

We're also looking to release our side chain implementation to allow for full local development.

Related

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Contact

Interested in getting touch with the Elph team? Feel free to join our Telegram to ask any questions or share any feedback!

Acknowledgements

Our implementation was inspired from a lot of the research and work done by various organizations working on Plasma as well, including omisego, Loom, and many folks on ethresearch.

License

GPLv2

About

Solidity Smart Contracts for Plasma Cash Implementation

License:GNU General Public License v2.0


Languages

Language:JavaScript 65.8%Language:Solidity 34.0%Language:Shell 0.2%