Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
062985a
disable whitelist
ericnien Nov 8, 2018
c4e7661
[Add version field to distinguish same requestId]
XinruiWu Nov 28, 2018
78655a3
sync solc v0.5.x support to beta branch
dryruner Dec 5, 2018
127086b
[AskMeAnything.sol update to 0.5.1]
XinruiWu Dec 6, 2018
b27d113
[add version to system random]
XinruiWu Dec 10, 2018
f32310f
disable whitelist
ericnien Nov 8, 2018
4636cd0
[Add version field to distinguish same requestId]
XinruiWu Nov 28, 2018
1d15371
[AskMeAnything.sol update to 0.5.1]
XinruiWu Dec 6, 2018
5e46fe5
[add version to system random]
XinruiWu Dec 10, 2018
ef053be
merge
dryruner Dec 15, 2018
5e3d748
Fix pairing check issue.
Dec 21, 2018
8b0505a
Revert "Fix pairing check issue."
Dec 21, 2018
1bd961a
[Handle multi-grouping logic]
XinruiWu Jan 29, 2019
9b2412e
[add group dismiss logic]
XinruiWu Feb 5, 2019
16fbb42
[add getter of workingGroup size and pendingGroup size]
XinruiWu Feb 15, 2019
11387cc
[Add getter for pendingGroup data]
XinruiWu Feb 16, 2019
af3ed0f
[Assign groupId to new groups to make sure publickeys going to correc…
XinruiWu Feb 16, 2019
8fc34d8
[use mapping to store pending groups]
XinruiWu Feb 19, 2019
74be7c5
[Dismiss the group when is is assigned to form new groups]
XinruiWu Feb 19, 2019
6ca3bd1
1. Sync to solidity v0.5.0
dryruner Feb 28, 2019
9f2ece1
support truffle v0.5
dryruner Feb 28, 2019
5af412c
update logged events
dryruner Mar 5, 2019
234d22e
update comment
dryruner Mar 7, 2019
e6abdd3
Get rid of random engine idling, each system randomness covers severa…
dryruner Mar 22, 2019
41f680d
Add guardian functions. Every one, including but not limited to DOS
dryruner Mar 25, 2019
dd90f6d
decouple groupId between request & response, simplify group decomposi…
dryruner Mar 25, 2019
2d842c5
Add groupId to event and add a bootStrap function for testing
ericnien Mar 27, 2019
cc8ed53
Add a CommitReveal to generate a random number for bootstraping
ericnien Mar 28, 2019
6a6985d
Add support for DOSCommitReveal contract
ericnien Mar 28, 2019
c8699b7
Rename CommitReveal to DOSCommitReveal and add addressbridge
ericnien Mar 28, 2019
39e2ddd
Add DOSCommitReveal for bootstraping and add AddressBridge to use rig…
ericnien Mar 28, 2019
d65e19d
Add BootStraping function
ericnien Mar 29, 2019
1f7a2cc
Fix logic issue in bootstraping issue
ericnien Apr 1, 2019
4cc7f5a
Fix the wrong event issue
ericnien Apr 1, 2019
be94b27
__callback__ shoulb be public to match the declaration
ericnien Apr 2, 2019
8e8d962
Merge pull request #11 from DOSNetwork/dismiss
ericnien Apr 2, 2019
a51f0dc
CommitReveal only generate a new random number if reveal number large…
ericnien Apr 2, 2019
3aaa1c8
Add two workaround for issues.
ericnien Apr 5, 2019
484c64e
Beta (1/n)
dryruner Apr 17, 2019
43f4870
Beta (2/n)
dryruner Apr 24, 2019
b78bb57
beta 3/n
dryruner Apr 28, 2019
b3cd237
bugfix
dryruner Apr 29, 2019
9a4f251
beta 4/n
dryruner Apr 30, 2019
3bd944e
lower number of bootstrap nodes to get rid to ensure cost less than b…
dryruner Apr 30, 2019
8f8de19
beta 5/n add basic payment
dryruner May 1, 2019
384c8b9
update pendingNode array with linkedlist to save gas
dryruner May 2, 2019
f9da770
bugfix
dryruner May 2, 2019
b70a8cc
beta (6/n) linkedlist bugfix
dryruner May 2, 2019
6d9af15
gas optimization reduce SSTORE
dryruner May 3, 2019
8b088a2
gas optimization 2
dryruner May 4, 2019
b86deda
beta (7/n) - handling expired pending groups
dryruner May 5, 2019
8755148
gas optimization 3 - switch to external function, packing struct writ…
dryruner May 5, 2019
bc72a52
put back registerGroupPublicKey protection
dryruner May 5, 2019
671002e
update payment conttract staking part.
dryruner May 7, 2019
4b444f4
event nodes' failing conditions
dryruner May 8, 2019
8daca19
update DB token testnet address
dryruner May 8, 2019
87549fc
dissolve expired pending group
dryruner May 10, 2019
47c2c00
fixing bug of updating tail of the linkedlist
dryruner May 10, 2019
6c5dd40
minor update
dryruner May 10, 2019
d6d0f7a
(8/n) - update nodeToGroupIdList correctly
dryruner May 12, 2019
477c1e8
update beta parameters
dryruner May 14, 2019
69ed011
(9/n)
dryruner May 14, 2019
019c4b6
typo fix
dryruner May 14, 2019
24ada32
fixed require usage if state change already triggered.
dryruner May 15, 2019
d28b153
update
dryruner May 15, 2019
f3a3322
Sync bootstrapRevealThreshold to bootstrapStartThreshold
dryruner May 15, 2019
a8d1086
Expose expired working group length
dryruner May 15, 2019
b2902ae
(10/10) beta1.0
dryruner May 17, 2019
67dfc1c
Beta 1.0 Rinkeby
ericnien May 17, 2019
19c6105
Merge remote-tracking branch 'origin/master' into beta
ericnien May 17, 2019
9f10101
update library utils
dryruner May 21, 2019
7f14218
Update DOSOnChainSDK.sol
dryruner May 23, 2019
f5b2aaa
Only fail registerNewNode if it is not a valid stacking node
ericnien May 24, 2019
1bc08ab
cleanup expired working group or expired pending group together
dryruner May 28, 2019
37b01b2
syntax sugar
dryruner May 29, 2019
1b09947
Fix a typo error
ericnien May 29, 2019
1b5e12e
Beta 1.1
ericnien May 29, 2019
a0500ec
Add unregisterNode function and a DOSProxyMock for unit test.
ericnien Jun 26, 2019
bd98562
Merge pull request #20 from DOSNetwork/unregister
ericnien Aug 5, 2019
e0c6510
Use expiredWorkingGroup to mix with pendingNodes to form three new gr…
ericnien Aug 30, 2019
58f37de
Add life to avoid dissolving groups at the same time
ericnien Aug 31, 2019
e3075e5
Add signalUnregister for guardian
ericnien Aug 31, 2019
578d7f7
Fix issue that don't bootstrap when working group is 0.
ericnien Aug 31, 2019
4bff581
Dissolving working or expired group if unregister node is in that group.
ericnien Sep 4, 2019
2143841
Fixed issue that can't register back after unregister
ericnien Sep 5, 2019
495e479
Fix unregister issue that pendingNodeTail is not correct.
ericnien Sep 6, 2019
c376525
Decreas bootStrapThreshold to GroupToPick *3
ericnien Sep 6, 2019
1a47546
fix lodash vulnerability
dryruner Sep 14, 2019
c504c0f
Add payment.
ericnien Sep 19, 2019
f4d5872
signal functions should not include tokenAddr.
ericnien Sep 20, 2019
27f44f7
Merge pull request #22 from DOSNetwork/payment
ericnien Sep 24, 2019
48cfc36
Refactored payment interface and adjusted grouping strategy.
ericnien Oct 3, 2019
16a032f
Merge pull request #23 from DOSNetwork/payment
ericnien Oct 3, 2019
92396c4
update random api and documentation
dryruner Oct 3, 2019
6bdf61d
Remove some set functions to reduce code size
ericnien Oct 4, 2019
43a71a6
Merge branch 'master' of https://github.com/DOSNetwork/eth-contracts
ericnien Oct 4, 2019
ebc4cec
Unregister refactoring without breaking change; minor bug fixes; event
dryruner Oct 10, 2019
4cb358a
make unregister event message accurate
dryruner Oct 10, 2019
e7730cf
Integrate staking and proxy contract.
ericnien Nov 7, 2019
21aae40
Pass bridgeaddr through constuctor instead of hardcoding
ericnien Nov 8, 2019
a135e89
remove fromValidStakingNode function and remove hardcoding
ericnien Nov 8, 2019
45d40a0
minor change
ericnien Nov 8, 2019
0695d02
Add more events for explorer
ericnien Nov 9, 2019
cb0493b
Add setStakingAddr and getStakingAddr in bridge
ericnien Nov 10, 2019
17fbc3e
Add getNodeUptime for explorer
ericnien Nov 11, 2019
b5e7ed1
Add node description for explorer`
ericnien Nov 11, 2019
fcff270
Add pendingWithdrawToken and pendingWithdrawDB
ericnien Nov 12, 2019
49296a2
Call nodeStart and nodeStop of staking contract from proxy contract
ericnien Nov 12, 2019
2ad83ac
Fixed a typo issue that can't delete a nodeAddr in nodeAddrs array
ericnien Nov 13, 2019
3247aad
Remove some set functions to fix out of gas issue when deploying
ericnien Nov 13, 2019
c365067
Fix an issue tha node can be registered by multiple owners
ericnien Nov 15, 2019
f534d4e
Add initBlkN for explorer to set fromBlk to fetch events
ericnien Nov 15, 2019
aaef81a
Add nodeWithdrawAble and delegatorWithdrawAble for explorer
ericnien Nov 20, 2019
f3ee93f
Add whitelist for signalUnregister
ericnien Nov 25, 2019
99a2e0b
Disable maxStakePerNode
ericnien Nov 26, 2019
155865b
Add getBootStrapUrl and setBootStrapUrl
ericnien Nov 27, 2019
ec74129
Change minStakePerNode to 100000 and fix a issue.
ericnien Nov 29, 2019
1e32ca4
Fixed total staked token ,delegatorWithdrawAble and nodeWithdrawAble …
ericnien Dec 10, 2019
087f823
Fix a typo issue that causes node stop after unbond
ericnien Dec 10, 2019
bc5cc5b
Add enableStaking parameter
ericnien Dec 11, 2019
20d0db4
Fix an issue that node is stop after unbond
ericnien Dec 11, 2019
fd75329
Generate random every 6 hours and regroup every 7 days.
ericnien Dec 12, 2019
07e3f2c
Add setBootstrapStartThreshold
ericnien Dec 13, 2019
cc85d30
bump up npm version to get rid of potential security vulnerabilities …
dryruner Jan 26, 2020
4eb4542
bump up npm version to get rid of potential security vulnerabilities …
dryruner Jan 26, 2020
8c8992e
Using proxy delegatecall pattern for staking contract
dryruner Jan 26, 2020
bd4fc87
update dependency
dryruner Feb 5, 2020
843cfa8
rm package-lock.json
dryruner Feb 5, 2020
629b303
update staking contracts
dryruner Feb 5, 2020
ef1e932
add DSMath RAY math library
dryruner Feb 20, 2020
1398e47
using ray math in staking contracts
dryruner Feb 20, 2020
cf5bc0e
fix node stop and uptime bug
dryruner Mar 3, 2020
3091136
minor fixed + normalize staking contract events
dryruner Mar 4, 2020
c545a44
normalize staking event name
dryruner Mar 8, 2020
83e3baf
Staking interest calculating (2/2)
dryruner Mar 14, 2020
39c5858
security update to bump up minimist version
dryruner Mar 15, 2020
1649d13
update with methods' access control
dryruner Mar 20, 2020
cbada7a
update SDK contract and Payment contract. Fix minor issues
dryruner Apr 1, 2020
8da458f
using abi.encode() to get rid of requestId collision
dryruner Apr 1, 2020
6d9e289
align SDK contract function name
dryruner Apr 1, 2020
a96f3de
update deploy script
dryruner Apr 1, 2020
21888db
update staking contract & deploy script
dryruner Apr 5, 2020
c63d5f2
update staking test
dryruner Apr 5, 2020
5f13f4e
fix state variable initialization errors in proxy delegation pattern
dryruner May 19, 2020
f6b6252
rm
dryruner May 19, 2020
f201412
update example usage contracts
dryruner May 20, 2020
31e3567
update example usage contracts
dryruner May 20, 2020
f66540e
bugfix
dryruner May 20, 2020
168b704
Revert "update staking test" as Staking constructor re-applied.
dryruner May 26, 2020
6b431bf
update example code to request from random oracle
dryruner May 29, 2020
f9214c4
Update staking algorithm by seperating staked amount from node status
dryruner Jun 1, 2020
4474fcc
hasOracleFee modifier
dryruner Jun 4, 2020
48e815a
remove indexed argument
dryruner Jun 4, 2020
608f878
reduct codesize for deployment 1/n
dryruner Jun 4, 2020
2c7372c
reduce codesize for deployment 1/n
dryruner Jun 4, 2020
137d511
reduct codesize for deployment 1/n
dryruner Jun 4, 2020
91e3d2f
strict security check for bootstrapping phase
dryruner Jun 8, 2020
9d01cb9
reduce deployment code size 2/n
dryruner Jun 8, 2020
873453d
sync parameter between contract and clients
dryruner Jun 8, 2020
e9477cf
proxy delegatecall pattern for Payment contract as it deals with mone…
dryruner Jun 10, 2020
732abcd
optimize system parameter
dryruner Jun 10, 2020
9aac791
state flip for group formation guarian function; update tests
dryruner Jun 19, 2020
2b2a438
update mainnet bridge address in SDK
dryruner Jul 3, 2020
64e8a3b
update checksumed mainnet bridge address in SDK contract
dryruner Jul 3, 2020
88021e0
Bump npm from 6.13.7 to 6.14.6 (#28)
dependabot[bot] Jul 7, 2020
7f98aa4
deployed meta info
dryruner Jul 12, 2020
0270f06
Bump lodash to 4.17.19
dryruner Jul 20, 2020
ee82506
update
dryruner Jul 24, 2020
05a1a62
update deployed.json
dryruner Jul 24, 2020
671b00d
tune commit reveal duration(# of blocks)
dryruner Jul 24, 2020
b759021
update test
dryruner Jul 24, 2020
c9e8ed5
update payment contract
dryruner Jul 24, 2020
9ba4aad
bump up elliptic version to reduce vulnerability alert
dryruner Aug 3, 2020
696ac53
expose service type fee info
dryruner Aug 5, 2020
eb1dbee
update dependencies & testnet bootstrap seeds
dryruner Aug 19, 2020
8fa8bbe
update rinkeby deployment
dryruner Aug 19, 2020
7d66819
update
dryruner Aug 19, 2020
8fb1eab
update
dryruner Aug 19, 2020
8f868da
delete obsoleted config file
dryruner Aug 20, 2020
380275a
add truffle-config.js
dryruner Aug 20, 2020
6d4345c
update
dryruner Aug 20, 2020
bba24a3
bump up version to get rid of security alerts
dryruner Sep 28, 2020
d93a2c2
update Staking Implementation to allow node logo customization
dryruner Sep 28, 2020
4edf575
update deployed staking implementation address on rinkeby testnet
dryruner Sep 28, 2020
bc07cb8
update deployed staking implementation on mainnet
dryruner Oct 2, 2020
e59dce2
merge to master (#33)
dryruner Dec 15, 2020
a740a6f
expose pendingGroup to public field for off-chain nodes to query
dryruner Dec 15, 2020
8ee19a1
update deployed address
dryruner Dec 16, 2020
8700329
cleanup unused code
dryruner Dec 17, 2020
227e3d1
Update deployed.json
dryruner Dec 18, 2020
34dad2f
re-delegate from nodeA to nodeB with without 7 days' unbonding period…
dryruner Jan 23, 2021
8ba64a2
update reDelegate algo
dryruner Jan 23, 2021
7e65066
merge branch (#35)
dryruner Mar 8, 2021
a2192ec
fix Dependabot alert
dryruner Mar 9, 2021
171a27a
update
dryruner Mar 10, 2021
afda24e
Release v1.0.4-m (#37)
dryruner Jun 4, 2021
47688d6
Resolve Dependabot alert
j3rrvliv Sep 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
package-lock.json
build/
*.*swp
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
### Dev:
- `$ git clone https://github.com/DOSNetwork/eth-contracts`
- `$ git clone https://github.com/DOSNetwork/smart-contracts`
- `$ npm install`
- `$ npm -g install truffle`
- `$ npm install -g ganache-cli` or installing its [graphic interface](https://truffleframework.com/ganache)
- `$ npm -g install ganache-cli` or installing its [graphic interface](https://truffleframework.com/ganache)
- Required truffle/solcjs version: >= 0.5

### Compile:
- `$ truffle compile`

### Deploy:
### Deploy to local development network:
- `$ ganache-cli`
- `$ truffle migrate --reset`


### Deploy to rinkeby testnet without dryrun:
- `$ truffle compile --all`
- `$ truffle migrate --reset --network rinkeby --skip-dry-run`


### Deploy to mainnet without dryrun:
- `$ truffle compile --all`
- `$ truffle migrate --reset --network live --skip-dry-run`


### Test:
- `$ ganache-cli -a 20`; // Config more than 10 test accounts
- `$ truffle test`

### Deployed:
See `deployed.json`.
53 changes: 53 additions & 0 deletions contracts/CoingeckoParserV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pragma solidity ^0.5.0;

import "./lib/SafeMath.sol";
import "./lib/StringUtils.sol";

// A simple parser to parse coingecko api data.
// Coingecko data api: https://www.coingecko.com/en/api.
// e.g. source: "https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=ethereum,bitcoin,polkadot,huobi-token"
// e.g. selector: "$..usd"
// e.g. Return: "[48766,1524.21,13.99,34.64]"
contract CoingeckoParserV2 {
using StringUtils for *;
using SafeMath for uint;

string public constant description = "Coingecko API Data Parser V2";
uint private constant ten = 10;

// e.g.:
// floatStr2Uint("123.4567", 0) => 123
// floatStr2Uint("123.4567", 2) => 12345
// floatStr2Uint("123.4567", 8) => 12345670000
function floatStr2Uint(string memory raw, uint decimal) public pure returns(uint) {
uint integral = raw.str2Uint();
uint fractional = 0;
uint dotIdx = raw.indexOf('.');
uint fracIdx = dotIdx + 1;
if (dotIdx != bytes(raw).length && fracIdx < bytes(raw).length) {
string memory fracStr = raw.subStr(fracIdx, decimal);
fractional = fracStr.str2Uint();
if (decimal > bytes(fracStr).length) {
fractional = fractional.mul(ten.pow(decimal - bytes(fracStr).length));
}
}
return integral.mul(ten.pow(decimal)).add(fractional);
}

function floatBytes2UintArray(bytes memory raw, uint decimal) public pure returns (uint[] memory) {
uint len = raw.length;
string[] memory s_arr = string(raw.subStr(1, len - 2)).split(',');
uint[] memory uint_arr = new uint[](s_arr.length);
for (uint i = 0; i < s_arr.length; i++) {
uint_arr[i] = floatStr2Uint(s_arr[i], decimal);
}
return uint_arr;
}

// e.g.:
// floatStrs2UintArray("[48766,1524.21,13.99,34.64]", 8) => [4876600000000,152421000000,1399000000,3464000000]
// floatStrs2UintArray("[12.34]", 8) => [1234000000]
function floatStrs2UintArray(string memory raw, uint decimal) public pure returns (uint[] memory) {
return floatBytes2UintArray(bytes(raw), decimal);
}
}
119 changes: 119 additions & 0 deletions contracts/CommitReveal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
pragma solidity ^0.5.0;

contract DOSAddressBridgeI {
function getProxyAddress() public view returns(address);
}

contract CommitReveal {
struct Participant {
uint secret;
bytes32 commitment;
bool revealed;
}

struct Campaign {
uint startBlock;
uint commitDuration; // in blocks
uint revealDuration; // in blocks
uint revealThreshold;
uint commitNum;
uint revealNum;
uint generatedRandom;
mapping(address => Participant) participants;
mapping(bytes32 => bool) commitments;
}

Campaign[] public campaigns;
DOSAddressBridgeI public addressBridge;

modifier checkCommit(uint _cid, bytes32 _commitment) {
Campaign storage c = campaigns[_cid];
require(_cid != 0 &&
block.number >= c.startBlock &&
block.number < c.startBlock + c.commitDuration,
"not-in-commit");
require(_commitment != "", "empty-commitment");
require(!c.commitments[_commitment], "duplicate-commitment");
_;
}
modifier checkReveal(uint _cid) {
Campaign storage c = campaigns[_cid];
require(_cid != 0 &&
block.number >= c.startBlock + c.commitDuration &&
block.number < c.startBlock + c.commitDuration + c.revealDuration,
"not-in-reveal");
_;
}
modifier checkFinish(uint _cid) {
Campaign storage c = campaigns[_cid];
require(_cid != 0 &&
block.number >= c.startBlock + c.commitDuration + c.revealDuration,
"commit-reveal-not-finished");
_;
}
modifier onlyFromProxy() {
require(msg.sender == addressBridge.getProxyAddress(), "not-from-dos-proxy");
_;
}

event LogStartCommitReveal(uint cid, uint startBlock, uint commitDuration, uint revealDuration, uint revealThreshold);
event LogCommit(uint cid, address from, bytes32 commitment);
event LogReveal(uint cid, address from, uint secret);
event LogRandom(uint cid, uint random);
event LogRandomFailure(uint cid, uint commitNum, uint revealNum, uint revealThreshold);

constructor(address _bridgeAddr) public {
// campaigns[0] is not used.
campaigns.length++;
addressBridge = DOSAddressBridgeI(_bridgeAddr);
}

// Returns new campaignId.
function startCommitReveal(
uint _startBlock,
uint _commitDuration,
uint _revealDuration,
uint _revealThreshold
)
public
onlyFromProxy
returns(uint)
{
uint newCid = campaigns.length;
campaigns.push(Campaign(_startBlock, _commitDuration, _revealDuration, _revealThreshold, 0, 0, 0));
emit LogStartCommitReveal(newCid, _startBlock, _commitDuration, _revealDuration, _revealThreshold);
return newCid;
}

function commit(uint _cid, bytes32 _secretHash) public checkCommit(_cid, _secretHash) {
Campaign storage c = campaigns[_cid];
c.commitments[_secretHash] = true;
c.participants[msg.sender] = Participant(0, _secretHash, false);
c.commitNum++;
emit LogCommit(_cid, msg.sender, _secretHash);
}

function reveal(uint _cid, uint _secret) public checkReveal(_cid) {
Campaign storage c = campaigns[_cid];
Participant storage p = c.participants[msg.sender];
require(!p.revealed && keccak256(abi.encodePacked(_secret)) == p.commitment,
"revealed-secret-not-match-commitment");
p.secret = _secret;
p.revealed = true;
c.revealNum++;
c.generatedRandom ^= _secret;
emit LogReveal(_cid, msg.sender, _secret);
}

// Return value of 0 representing invalid random output.
function getRandom(uint _cid) public checkFinish(_cid) returns (uint) {
Campaign storage c = campaigns[_cid];
if (c.revealNum >= c.revealThreshold) {
emit LogRandom(_cid, c.generatedRandom);
return c.generatedRandom;
} else{
emit LogRandomFailure(_cid, c.commitNum, c.revealNum, c.revealThreshold);
return 0;
}
}
}
Loading