Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Fix configuration and improve ci time
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkanani authored Aug 6, 2018
1 parent dacba8b commit a2f1205
Show file tree
Hide file tree
Showing 56 changed files with 3,001 additions and 2,046 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.md]
trim_trailing_whitespace = false
max_line_length = 80
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
node_modules
build
MaticChannel0.sol

test-blockchain/geth
test-blockchain/history
.DS_Store
test-blockchain/data/**
!test-blockchain/data/.gitkeep

*.pid
*.log

.DS_Store
9 changes: 0 additions & 9 deletions .solhint.json

This file was deleted.

1 change: 1 addition & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
28 changes: 28 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"imports-on-top": 1,
"variable-declarations": 1,
"array-declarations": 1,
"operator-whitespace": 1,
"lbrace": 0,
"mixedcase": 0,
"camelcase": 1,
"uppercase": 1,
"no-empty-blocks": 1,
"no-unused-vars": 1,
"quotes": 1,
"error-reason": 0,
"indentation": ["error", 2],
"arg-overflow": ["error", 8],
"whitespace": 1,
"deprecated-suicide": 1,
"pragma-on-top": 1,
"no-experimental": 0,
"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["warning"],
"security/no-low-level-calls": 0,
"security/no-inline-assembly": 0
}
}
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ cache:
- node_modules
matrix:
fast_finish: true
before_install:
- sudo add-apt-repository -y ppa:ethereum/ethereum
install:
- sudo apt-get -qq update
- sudo apt-get install ethereum-unstable
- sudo apt-get --yes install snapd
- sudo snap install parity --stable
- snap list
before_script:
- export PATH=/snap/bin:${PATH}
script:
- npm run test-ci
- npm run test:ci
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Run test cases:

```
# run test cases
$ npm run test-ci
$ npm run test:ci
```
3 changes: 2 additions & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.23;
pragma solidity 0.4.24;


contract Migrations {
address public owner;
Expand Down
143 changes: 143 additions & 0 deletions contracts/PriorityQueue.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
pragma solidity 0.4.24;

import "./lib/SafeMath.sol";


/**
* @title PriorityQueue
* @dev A priority queue implementation.
*/
contract PriorityQueue {
using SafeMath for uint256;

/**
* Storage
*/
address owner;
uint256[] heapList;
uint256 public currentSize;

/**
* Modifiers
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}

/**
* Constructor
*/
constructor() public {
owner = msg.sender;
heapList = [0];
currentSize = 0;
}

/**
* Internal functions
*/

/**
* @dev Inserts an element into the priority queue.
* @param _priority Priority to insert.
* @param _value Some additional value.
*/
function insert(uint256 _priority, uint256 _value) public onlyOwner {
uint256 element = _priority << 128 | _value;
heapList.push(element);
currentSize = currentSize.add(1);
_percUp(currentSize);
}

/**
* @dev Returns the top element of the heap.
* @return The smallest element in the priority queue.
*/
function getMin() public view returns (uint256, uint256) {
return _splitElement(heapList[1]);
}

/**
* @dev Deletes the top element of the heap and shifts everything up.
* @return The smallest element in the priorty queue.
*/
function delMin() public onlyOwner returns (uint256, uint256) {
uint256 retVal = heapList[1];
heapList[1] = heapList[currentSize];
delete heapList[currentSize];
currentSize = currentSize.sub(1);
_percDown(1);
heapList.length = heapList.length.sub(1);
return _splitElement(retVal);
}

/*
* Private functions
*/

/**
* @dev Determines the minimum child of a given node in the tree.
* @param _index Index of the node in the tree.
* @return The smallest child node.
*/
function _minChild(uint256 _index) private view returns (uint256) {
if (_index.mul(2).add(1) > currentSize) {
return _index.mul(2);
} else {
if (heapList[_index.mul(2)] < heapList[_index.mul(2).add(1)]) {
return _index.mul(2);
} else {
return _index.mul(2).add(1);
}
}
}

/**
* @dev Bubbles the element at some index up.
*/
function _percUp(uint256 _index) private {
uint256 index = _index;
uint256 j = index;
uint256 newVal = heapList[index];

while (newVal < heapList[index.div(2)]) {
heapList[index] = heapList[index.div(2)];
index = index.div(2);
}

if (index != j) {
heapList[index] = newVal;
}
}

/**
* @dev Bubbles the element at some index down.
*/
function _percDown(uint256 _index) private {
uint256 index = _index;
uint256 j = index;
uint256 newVal = heapList[index];
uint256 mc = _minChild(index);
while (mc <= currentSize && newVal > heapList[mc]) {
heapList[index] = heapList[mc];
index = mc;
mc = _minChild(index);
}

if (index != j) {
heapList[index] = newVal;
}
}

/**
* @dev Split an element into its priority and value.
* @param _element Element to decode.
* @return A tuple containing the priority and value.
*/
function _splitElement(uint256 _element) private pure returns (uint256, uint256) {
uint256 priority = _element >> 128;
uint256 value = uint256(uint128(_element));
return (priority, value);
}
}
67 changes: 34 additions & 33 deletions contracts/RootChain.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./lib/SafeMath.sol";
import "./lib/MerklePatriciaProof.sol";
Expand All @@ -25,14 +25,14 @@ contract RootChain is Ownable {

// bytes32 constants
// 0x2e1a7d4d = sha3('withdraw(uint256)')
bytes4 constant public withdrawSignature = 0x2e1a7d4d;
bytes4 constant public WITHDRAW_SIGNATURE = 0x2e1a7d4d;
// keccak256('Withdraw(address,address,uint256)')
bytes32 constant public withdrawEventSignature = 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb;
bytes32 constant public WITHDRAW_EVENT_SIGNATURE = 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb;
// chain identifier
// keccak256('Matic Network v0.0.1-beta.1')
bytes32 public chain = 0x2984301e9762b14f383141ec6a9a7661409103737c37bba9e0a22be26d63486d;
// networkId
bytes public networkId = '\x0d';
bytes public networkId = "\r";

// WETH address
address public wethToken;
Expand Down Expand Up @@ -304,22 +304,6 @@ contract RootChain is Ownable {
_depositEvent(token, user, amount);
}

function _depositEvent(address token, address user, uint256 amount) internal {
// broadcast deposit event
emit Deposit(user, token, amount, depositCount);

// add deposit into deposits
deposits[depositCount] = DepositBlock({
header: currentHeaderBlock,
owner: user,
token: token,
amount: amount
});

// increase deposit counter
depositCount = depositCount.add(1);
}

// withdraw tokens
function withdraw(
uint256 headerNumber,
Expand Down Expand Up @@ -375,9 +359,35 @@ contract RootChain is Ownable {
);
}

//
// Slashing conditions
//

// slash stakers if fraud is detected
function slash() public isValidator(msg.sender) {
// TODO pass block/proposer
}

//
// Internal functions
//

function _depositEvent(address token, address user, uint256 amount) internal {
// broadcast deposit event
emit Deposit(user, token, amount, depositCount);

// add deposit into deposits
deposits[depositCount] = DepositBlock({
header: currentHeaderBlock,
owner: user,
token: token,
amount: amount
});

// increase deposit counter
depositCount = depositCount.add(1);
}

function _withdraw(
uint256 headerNumber,
bytes headerProof,
Expand Down Expand Up @@ -435,7 +445,7 @@ contract RootChain is Ownable {
// Data check
require(txList[5].toData().length == 36);
// check withdraw data function signature
require(BytesLib.toBytes4(BytesLib.slice(txList[5].toData(), 0, 4)) == withdrawSignature);
require(BytesLib.toBytes4(BytesLib.slice(txList[5].toData(), 0, 4)) == WITHDRAW_SIGNATURE);
// check amount
require(amount > 0 && amount == BytesLib.toUint(txList[5].toData(), 4));

Expand Down Expand Up @@ -473,16 +483,16 @@ contract RootChain is Ownable {
RLP.RLPItem[] memory items = receiptBytes.toRLPItem().toList();
require(items.length == 4);

// [3][0] -> [child token address, [withdrawEventSignature, root token address, sender], amount]
// [3][0] -> [child token address, [WITHDRAW_EVENT_SIGNATURE, root token address, sender], amount]
items = items[3].toList()[0].toList();
require(items.length == 3);
address childToken = items[0].toAddress(); // child token address
amount = items[2].toUint(); // amount

// [3][0][1] -> [withdrawEventSignature, root token address, sender]
// [3][0][1] -> [WITHDRAW_EVENT_SIGNATURE, root token address, sender]
items = items[1].toList();
require(items.length == 3);
require(items[0].toBytes32() == withdrawEventSignature); // check for withdraw event signature
require(items[0].toBytes32() == WITHDRAW_EVENT_SIGNATURE); // check for withdraw event signature

// check if root token is mapped to child token
rootToken = BytesLib.toAddress(items[1].toData(), 12); // fetch root token address
Expand All @@ -494,13 +504,4 @@ contract RootChain is Ownable {
// Make sure this receipt is the value on the path via a MerklePatricia proof
require(MerklePatriciaProof.verify(receiptBytes, path, receiptProof, receiptRoot) == true);
}

//
// Slashing conditions
//

// slash stakers if fraud is detected
function slash() public isValidator(msg.sender) {
// TODO pass block/proposer
}
}
2 changes: 1 addition & 1 deletion contracts/RootChainInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity 0.4.24;


interface RootChainInterface {
Expand Down
3 changes: 1 addition & 2 deletions contracts/StakeManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity 0.4.24;

import "./lib/SafeMath.sol";
import "./lib/ECVerify.sol";
Expand Down Expand Up @@ -158,7 +158,6 @@ contract StakeManager is StakeManagerInterface, Lockable {
return false;
}


// optional
// function lastStakedFor(address addr) public view returns (uint256);
// function totalStakedForAt(address addr, uint256 blockNumber) public view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/StakeManagerInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity 0.4.24;

interface StakeManagerInterface {

Expand Down
Loading

0 comments on commit a2f1205

Please sign in to comment.