From 4487ad9e5a4f60da794ce4dac7e380adbf2c5b1c Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Tue, 26 Nov 2019 20:22:28 +0300 Subject: [PATCH 1/4] Set CI badge to track master branch --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de70b41..cf14c7f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CircleCI](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/dev.svg?style=svg)](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/dev) +[![CircleCI](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/master.svg?style=svg)](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/master) ## Ethereum to Binance Chain bridge @@ -21,4 +21,4 @@ Collecting confirmations for the Binance Chain is made in form of mutlisig walle At this version the tool for TSS is used as is. It is assumed that later part of TSS orchestration will be moved to the orchestration contract. So far, the orchestration contract is used as a database to keep data required by TSS parties during the signature generation. -Read [an instruction how to run a demo](DEMO.md) for the bridge. \ No newline at end of file +Read [an instruction how to run a demo](DEMO.md) for the bridge. From 7e4a58f52f3caabb8358b70aa56f3f166db56ffe Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Tue, 26 Nov 2019 20:23:01 +0300 Subject: [PATCH 2/4] Careful side oracle initialization --- src/ethereum-testnet/side-oracle/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ethereum-testnet/side-oracle/index.js b/src/ethereum-testnet/side-oracle/index.js index d90ecfc..352b35d 100644 --- a/src/ethereum-testnet/side-oracle/index.js +++ b/src/ethereum-testnet/side-oracle/index.js @@ -63,6 +63,9 @@ async function initialize() { sideProvider = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL) homeProvider = new ethers.providers.JsonRpcProvider(HOME_RPC_URL) + await sideProvider.getNetwork() + await homeProvider.getNetwork() + homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider) bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet) sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider) From de075e3f41510866697363d589ef2861aaaaa713 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Tue, 26 Nov 2019 20:24:46 +0300 Subject: [PATCH 3/4] Explicit new epoch address in message --- .../deploy-home/contracts/BasicBridge.sol | 12 +++++- src/oracle/ethWatcher/ethWatcher.js | 43 +++++++++++++++---- src/oracle/tss-sign/signer.js | 11 ++--- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/deploy/deploy-home/contracts/BasicBridge.sol b/src/deploy/deploy-home/contracts/BasicBridge.sol index 86a2e08..3589447 100644 --- a/src/deploy/deploy-home/contracts/BasicBridge.sol +++ b/src/deploy/deploy-home/contracts/BasicBridge.sol @@ -123,11 +123,19 @@ contract BasicBridge { } function getX() view public returns (uint) { - return states[epoch].x; + return getX(epoch); + } + + function getX(uint16 _epoch) view public returns (uint) { + return states[_epoch].x; } function getY() view public returns (uint) { - return states[epoch].y; + return getY(epoch); + } + + function getY(uint16 _epoch) view public returns (uint) { + return states[_epoch].y; } function getCloseEpoch() view public returns (bool) { diff --git a/src/oracle/ethWatcher/ethWatcher.js b/src/oracle/ethWatcher/ethWatcher.js index e26d430..82e7632 100644 --- a/src/oracle/ethWatcher/ethWatcher.js +++ b/src/oracle/ethWatcher/ethWatcher.js @@ -23,6 +23,8 @@ const bridgeAbi = [ 'event EpochStart(uint16 indexed epoch, uint256 x, uint256 y)', 'event EpochClose(uint16 indexed epoch)', 'event ForceSign()', + 'function getX(uint16 epoch) view returns (uint256)', + 'function getY(uint16 epoch) view returns (uint256)', 'function getThreshold(uint16 epoch) view returns (uint16)', 'function getParties(uint16 epoch) view returns (uint16)', 'function getRangeSize(uint16 epoch) view returns (uint16)', @@ -92,11 +94,15 @@ async function resetFutureMessages(queue) { async function sendKeygen(event) { const { newEpoch } = event.values + const [threshold, parties] = await Promise.all([ + bridge.getThreshold(newEpoch), + bridge.getParties(newEpoch) + ]) keygenQueue.send({ epoch: newEpoch, blockNumber, - threshold: await bridge.getThreshold(newEpoch), - parties: await bridge.getParties(newEpoch) + threshold, + parties }) logger.debug('Sent keygen start event') } @@ -112,13 +118,26 @@ function sendKeygenCancellation(event) { async function sendSignFundsTransfer(event) { const { newEpoch, oldEpoch } = event.values + const [ + x, y, threshold, parties + ] = await Promise.all([ + bridge.getX(newEpoch).then((value) => new BN(value).toString(16)), + bridge.getY(newEpoch).then((value) => new BN(value).toString(16)), + bridge.getThreshold(oldEpoch), + bridge.getParties(oldEpoch) + ]) + const recipient = publicKeyToAddress({ + x, + y + }) signQueue.send({ epoch: oldEpoch, blockNumber, newEpoch, nonce: foreignNonce[oldEpoch], - threshold: await bridge.getThreshold(oldEpoch), - parties: await bridge.getParties(oldEpoch) + recipient, + threshold, + parties }) logger.debug('Sent sign funds transfer event') foreignNonce[oldEpoch] += 1 @@ -161,12 +180,16 @@ async function sendSign(event, transactionHash) { } async function sendStartSign() { + const [threshold, parties] = await Promise.all([ + bridge.getThreshold(epoch), + bridge.getParties(epoch) + ]) signQueue.send({ epoch, blockNumber, nonce: foreignNonce[epoch], - threshold: await bridge.getThreshold(epoch), - parties: await bridge.getParties(epoch) + threshold, + parties }) foreignNonce[epoch] += 1 redisTx.incr(`foreignNonce${epoch}`) @@ -189,12 +212,16 @@ async function processEpochStart(event) { async function sendEpochClose() { logger.debug(`Consumed epoch ${epoch} close event`) + const [threshold, parties] = await Promise.all([ + bridge.getThreshold(epoch), + bridge.getParties(epoch) + ]) signQueue.send({ closeEpoch: epoch, blockNumber, nonce: foreignNonce[epoch], - threshold: await bridge.getThreshold(epoch), - parties: await bridge.getParties(epoch) + threshold, + parties }) foreignNonce[epoch] += 1 redisTx.incr(`foreignNonce${epoch}`) diff --git a/src/oracle/tss-sign/signer.js b/src/oracle/tss-sign/signer.js index b7e0d14..514b7ba 100644 --- a/src/oracle/tss-sign/signer.js +++ b/src/oracle/tss-sign/signer.js @@ -222,7 +222,9 @@ function getAccountBalance(account, asset) { } async function buildTx(from, account, data) { - const { closeEpoch, newEpoch, nonce } = data + const { + closeEpoch, newEpoch, nonce, recipient: to + } = data const txOptions = { from, @@ -237,13 +239,6 @@ async function buildTx(from, account, data) { txOptions.flags = 0x01 } else if (newEpoch) { - const newKeysFile = `/keys/keys${newEpoch}.store` - const to = getAccountFromFile(newKeysFile).address - - if (to === '') { - return { tx: null } - } - logger.info(`Building corresponding transaction for transferring all funds, nonce ${nonce}, recipient ${to}`) const fee = await getFee() From 410f6f6eb310878137323fb0e8e8174fcc69ef48 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Wed, 27 Nov 2019 09:48:51 +0300 Subject: [PATCH 4/4] Fixed side oracle --- README.md | 4 ++-- src/ethereum-testnet/side-oracle/index.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cf14c7f..38efb27 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CircleCI](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/master.svg?style=svg)](https://circleci.com/gh/k1rill-fedoseev/eth-to-bnc-bridge/tree/master) +[![CircleCI](https://circleci.com/gh/poanetwork/eth-to-bnc-bridge/tree/master.svg?style=svg)](https://circleci.com/gh/poanetwork/eth-to-bnc-bridge/tree/master) ## Ethereum to Binance Chain bridge @@ -21,4 +21,4 @@ Collecting confirmations for the Binance Chain is made in form of mutlisig walle At this version the tool for TSS is used as is. It is assumed that later part of TSS orchestration will be moved to the orchestration contract. So far, the orchestration contract is used as a database to keep data required by TSS parties during the signature generation. -Read [an instruction how to run a demo](DEMO.md) for the bridge. +Read [an instruction how to run a demo](DEMO.md) for the bridge. \ No newline at end of file diff --git a/src/ethereum-testnet/side-oracle/index.js b/src/ethereum-testnet/side-oracle/index.js index 352b35d..64d075b 100644 --- a/src/ethereum-testnet/side-oracle/index.js +++ b/src/ethereum-testnet/side-oracle/index.js @@ -65,18 +65,18 @@ async function initialize() { await sideProvider.getNetwork() await homeProvider.getNetwork() - - homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider) - bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet) - sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider) - - nonce = await homeWallet.getTransactionCount() break } catch (e) { console.log('Cannot create providers') await delay(1000) } } + + homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider) + bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet) + sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider) + + nonce = await homeWallet.getTransactionCount() } async function loop() {