From 8c8dad07caac6141cadc9b61b2c3bede4d02704d Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Mon, 4 Nov 2019 12:53:58 +0300 Subject: [PATCH] Closes #13 --- DEMO.md | 14 +++++++------- src/deploy/deploy-home/.env.development | 2 +- src/deploy/deploy-home/.env.staging | 2 +- src/deploy/deploy-home/contracts/Bridge.sol | 10 +++++++--- src/oracle/tss-keygen/keygen.js | 2 +- src/oracle/tss-sign/signer.js | 2 +- tests/test/index.js | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/DEMO.md b/DEMO.md index 6294efe..a408598 100644 --- a/DEMO.md +++ b/DEMO.md @@ -197,11 +197,11 @@ The public Binance Chain testnet will keep a BEP2 token. "nextEpoch": 3, // threshold number for current epoch, - // threshold + 1 votes are required for any changes in next epoch - "threshold": 1, + // at least threshold votes are required for any changes in next epoch + "threshold": 2, // threshold number for next epoch - "nextThreshold": 1, + "nextThreshold": 2, // current bridge addresses in home and foreign networks "homeBridgeAddress": "0x44c158FE850821ae69DaF37AADF5c539e9d0025B", @@ -239,13 +239,13 @@ The public Binance Chain testnet will keep a BEP2 token. "confirmationsForFundsTransfer": 0 } ``` - * (7.1) Start voting process for next epoch, via sending `$THRESHOLD + 1` requests to `/vote/startVoting` url. Bridge + * (7.1) Start voting process for next epoch, via sending `$THRESHOLD` requests to `/vote/startVoting` url. Bridge state should be successfully changed to `voting`. * 7.2 Changing next epoch bridge validators / threshold - * (7.2.1) Add / remove validator in next validators list, via sending `$THRESHOLD + 1` requests to + * (7.2.1) Add / remove validator in next validators list, via sending `$THRESHOLD` requests to `/vote/addValidator/$ADDRESS` / `/vote/removeValidator/$ADDRESS`. - * (7.2.2) Change threshold for the next epoch, via sending `$THRESHOLD + 1` requests to `/vote/changeThreshold/$THRESHOLD`. - * (7.3) Start keygen process for next epoch, via sending `$THRESHOLD + 1` requests to `/vote/startKeygen` url. Bridge + * (7.2.2) Change threshold for the next epoch, via sending `$THRESHOLD` requests to `/vote/changeThreshold/$THRESHOLD`. + * (7.3) Start keygen process for next epoch, via sending `$THRESHOLD` requests to `/vote/startKeygen` url. Bridge state should be successfully changed to `keygen`, and in some time to `funds_transfer`, and then to `ready`. * (7.4) If keygen process at some state was stopped(i. e. one validator turned of his oracle), it can be cancelled via via sending `$THRESHOLD + 1` requests to `/vote/cancelKeygen` url. After diff --git a/src/deploy/deploy-home/.env.development b/src/deploy/deploy-home/.env.development index 26e2481..38ec3e0 100644 --- a/src/deploy/deploy-home/.env.development +++ b/src/deploy/deploy-home/.env.development @@ -9,7 +9,7 @@ VALIDATOR_ADDRESS_2=0xaa006899b0ec407de930ba8a166defe59bbfd3dc VALIDATOR_ADDRESS_3=0x6352e3e6038e05b9da00c84ae851308f9774f883 #VALIDATOR_ADDRESS_4=0x4db6b4bd0a3fdc03b027a60f1c48f05c572312aa -THRESHOLD=1 +THRESHOLD=2 MIN_TX_LIMIT=10000000000000000 MAX_TX_LIMIT=100000000000000000000 diff --git a/src/deploy/deploy-home/.env.staging b/src/deploy/deploy-home/.env.staging index 5d80c82..550b4bc 100644 --- a/src/deploy/deploy-home/.env.staging +++ b/src/deploy/deploy-home/.env.staging @@ -10,7 +10,7 @@ VALIDATOR_ADDRESS_2=0xbbbb63D6Fc58bD14dAF9eeF653650c4D10f3dBC8 VALIDATOR_ADDRESS_3=0xcccc27ae510b63E30eC3C68AAD7DdD2578bD62ed #VALIDATOR_ADDRESS_4=0xdddd9300e32fe162bA420f7313651Fd901C2ed71 -THRESHOLD=1 +THRESHOLD=2 MIN_TX_LIMIT=10000000000000000 MAX_TX_LIMIT=100000000000000000000 diff --git a/src/deploy/deploy-home/contracts/Bridge.sol b/src/deploy/deploy-home/contracts/Bridge.sol index a964c28..c424563 100644 --- a/src/deploy/deploy-home/contracts/Bridge.sol +++ b/src/deploy/deploy-home/contracts/Bridge.sol @@ -57,7 +57,7 @@ contract Bridge { constructor(uint threshold, address[] memory validators, address _tokenContract, uint[2] memory limits, uint rangeSize) public { require(validators.length > 0); - require(threshold < validators.length); + require(threshold <= validators.length); tokenContract = IERC20(_tokenContract); @@ -280,6 +280,8 @@ contract Bridge { } function voteChangeThreshold(uint threshold) public voting currentValidator { + require(threshold > 0 && threshold <= getParties(), "Invalid threshold value"); + if (tryVote(Vote.CHANGE_THRESHOLD, threshold)) { states[nextEpoch].threshold = threshold; } @@ -292,6 +294,8 @@ contract Bridge { } function voteStartKeygen() public voting currentValidator { + require(getNextThreshold() <= getNextParties(), "Invalid threshold number"); + if (tryVote(Vote.START_KEYGEN)) { status = Status.KEYGEN; @@ -342,7 +346,7 @@ contract Bridge { require(!votes[personalVote], "Voted already"); votes[personalVote] = true; - if (votesCount[vote] == getThreshold()) { + if (votesCount[vote] + 1 == getThreshold()) { votesCount[vote] = 2 ** 255; return true; } else { @@ -356,7 +360,7 @@ contract Bridge { require(!votes[personalVote], "Confirmed already"); votes[personalVote] = true; - if (votesCount[vote] == getNextThreshold()) { + if (votesCount[vote] + 1 == getNextThreshold()) { votesCount[vote] = 2 ** 255; return true; } else { diff --git a/src/oracle/tss-keygen/keygen.js b/src/oracle/tss-keygen/keygen.js index 0f3a067..2315936 100644 --- a/src/oracle/tss-keygen/keygen.js +++ b/src/oracle/tss-keygen/keygen.js @@ -42,7 +42,7 @@ async function main() { logger.debug('Writing params') fs.writeFileSync('./params', JSON.stringify({ parties: parties.toString(), - threshold: threshold.toString() + threshold: (threshold - 1).toString() })) const cmd = exec.execFile('./keygen-entrypoint.sh', [PROXY_URL, keysFile], async () => { currentKeygenEpoch = null diff --git a/src/oracle/tss-sign/signer.js b/src/oracle/tss-sign/signer.js index 1e49e05..c79e5f0 100644 --- a/src/oracle/tss-sign/signer.js +++ b/src/oracle/tss-sign/signer.js @@ -172,7 +172,7 @@ async function main() { logger.debug('Writing params') fs.writeFileSync('./params', JSON.stringify({ parties: parties.toString(), - threshold: threshold.toString() + threshold: (threshold - 1).toString() })) attempt = 1 diff --git a/tests/test/index.js b/tests/test/index.js index 8d661c8..379689c 100644 --- a/tests/test/index.js +++ b/tests/test/index.js @@ -81,7 +81,7 @@ describe('bridge tests', function () { testEthToBnc(() => users) testBncToEth(() => users) - testChangeThreshold(2) + testChangeThreshold(3) testEthToBnc(() => users) testBncToEth(() => users)