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.
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.
- 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
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.
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
With ganache running:
# Runs all tests in repository
$ yarn test
# Deploy this repository
$ yarn deploy
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.
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.
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.
- Send ETH / ERC721 to the RootChain contract
- 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
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.
- elphnetwork/elph-sdk: Elph Javascript SDK to communicate with these contracts.
- elphnetwork/block-explorer: Elph Block Explorer that shows the Elph Plasma Chain testnet using these contracts on Rinkeby.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Interested in getting touch with the Elph team? Feel free to join our Telegram to ask any questions or share any feedback!
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.