Skip to content

Commit

Permalink
chore(*): release version 0.1.0
Browse files Browse the repository at this point in the history
LIT-16
  • Loading branch information
DZariusz committed Oct 31, 2018
1 parent 0d89a37 commit 04c9728
Show file tree
Hide file tree
Showing 70 changed files with 12,145 additions and 1,023 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Unifying editor configurations for all developers:
# For details see http://editorconfig.org/

root = true

[*]
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
30 changes: 30 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "airbnb-base",
"env": {
"mocha": true
},
"globals": {
"artifacts": true,
"assert": true,
"beforeEach": true,
"contract": true,
"describe": true,
"it": true,
"web3": true
},
"rules": {
"no-console": "off",
"prefer-destructuring": ["error", {
"VariableDeclarator": {
"array": true,
"object": true
},
"AssignmentExpression": {
"array": false, // this will allow for: var bar = foo[0] <- access array with index
"object": true
}
}, {
"enforceForRenamedProperties": false
}]
}
}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.idea/

build/

node_modules/
package-lock.json
coverage/
8 changes: 8 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
copyPackages: ['openzeppelin-solidity', 'zeppelin-solidity', 'pokedex', 'token-sale-contracts'],
port: 8545,
norpc: false,
compileCommand: 'truffle compile --all',
testCommand: 'truffle test --network coverage',
skipFiles: ['lib/ECRecovery.sol', 'lib/RLP.sol']
}
6 changes: 6 additions & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
helpers
migrations
test
contracts/Migrations.sol
coverage
19 changes: 19 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "solium:recommended",
"plugins": [
"security"
],
"rules": {
"quotes": [
"error",
"double"
],
"indentation": [
"error",
2
],
"security/no-inline-assembly": 0,
"security/no-assign-params": 0,
"security/no-block-members": [0, ["timestamp"]]
}
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2018-10-31

Plasma Cash:
- Ethereum smart contract for on-chain plasma cash
- Plasma participants: users, operator
Empty file modified LICENSE.txt
100644 → 100755
Empty file.
114 changes: 91 additions & 23 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,35 +1,103 @@
# Lucidity Plasma
# Lucidity Plasma Cash :collision:

Implements a Solidity contract to manage Plasma side-chain on Ethereum.
PoC implementation of Plasma Cash.
Smart contract is written in Solidity for Ethereum.
Sidechain functionality (plasma user and operator) is written in Javascript.

## Install dependencies with
![plasma cash](./sdo_solareruption_nasa.jpg)

```
$ npm install
```
## Overview

This implementation of plasma cash is a bit different from general specification/guidelines.
Main differences:
- it treats each deposit as individual tree/chain.
- exits are stored in matrix, where keys are `depositNonce` and `childBlockIndex`
so each exit has its own place.
- every deposit has its own exit queue
- priority is not based on exit time, but based on block index
- challenges uses single transaction instead of two (current and previous)
- there is no need to reply to challenge
- you need to finalize exits for each deposit separately

## Run test cases:
The implementation was tested against below scenarios and all test are done with success:
* exits on deposit scenario
* spend scenario
* double spent scenario
* invalid block scenario
* withheld block scenario

```
# start ganache CLI
$ ./ganache-cli
## Install

$ truffle test
```
To run this, you will need on your machine:
- nodejs
- truffle
- ganache-cli

## Details
then:

The implementation is based on UTXO model. It allows depositing, submitting blocks and withdrawing.
The current implementation is not designed to withstand double-spends caused by fraudulent operators.
Operators are selected by the contract creator. PoS consensus mechanism is coming in the future.

## TODO
```
$ npm install
$ git hf init
```

- Implement a way to challenge withdrawals;
- Implement a consensus layer;
- Optimize the code in order to spend less gas;
- Implement a better serialization mechanism.
## Run tests

**Warning** - there are around 135 tests.
Tests include delay that is needed for challenge time.
Because of that, they will take some time - up to several minutes.
Depend on how fast is your machine, there might be a need to adjust delay time.
Test error message will let you know if you need to set higher delay time or not.
You can do it in `./test/helpers/createScenarioObjects.js`,
find `challengeTimeoutSec` variable and set valid time.

You can choose different tests to run:

* `truffle test` or `npm run test`
* check for linters errors: `npm run lint`
* With code coverage: `npm run coverage` -
**IMPORTANT**: turn off local RPC client before run this test.
Coverage results:
![coverage test results](./coverage-tests.png "coverage test results")

### Issues during tests

* `Error: ENOENT: no such file or directory, open './allFiredEvents'`

If you experience above issue during coverage test, then create file
`touch ./allFiredEvents` each time before you run test command, it should help.

### Test results

Here you can see results and path for main tests scenarios for plasma cash:

* exits on deposit scenario
![deposit scenario](./scenario-deposits.png)
* spend scenario
![spent scenario](./scenario-spent.png)
* double spent scenario
![double spent scenario](./scenario-double-spent.png)
* invalid block scenario
![invalid block scenario](./scenario-invalid-history.png)
* withheld block scenario
![withheld block scenario](./scenario-withheld-block.png)

You can find files with this tests in `test/scenarios/` directory.

### TODO

- test multiple tx for single submit block
- optimize SparseMerkleTree:
ie. if we have deposits for #3, #9, #20, then not create merkle tree for all slots,
instead just for #3..#21.
- make exit bond to be maximum of (exit bond, deposit amount)?
- test if we could optimize storage for history of transactions ie:
resign from storing empty blocks (where no tx on our deposit was made)
- maybe add max number of exits at one time,
when finalizing or stop after first valid one?
- add support for tokens (`_currency`)
- try to simplify implementation
by removing signature/spender check in plasma contract
- test it against invalid `targetBlock`

## Licensed under MIT.

Expand All @@ -43,4 +111,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

## Notice

Except as contained in this notice, the name of KR8OS shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from KR8OS, Inc.
Except as contained in this notice, the name of KR8OS shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from KR8OS, Inc.
4 changes: 2 additions & 2 deletions contracts/Migrations.sol
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;

contract Migrations {
address public owner;
Expand All @@ -8,7 +8,7 @@ contract Migrations {
if (msg.sender == owner) _;
}

function Migrations() public {
constructor() public {
owner = msg.sender;
}

Expand Down
25 changes: 25 additions & 0 deletions contracts/Operable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

contract Operable is Ownable {

mapping(address => bool) public operators;

event LogSetOperator(address executor, address operator, bool status);

modifier onlyOperator() {
require(operators[msg.sender], "you are not the operator");
_;
}

function setOperator(address _operator, bool _status)
public
onlyOwner
returns (bool) {
operators[_operator] = _status;
emit LogSetOperator(msg.sender, _operator, _status);
return true;
}

}
Loading

0 comments on commit 04c9728

Please sign in to comment.