From b8855459ab2ec1d2376cd3c4ca773a918371a080 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 17 Sep 2020 16:41:32 +0200 Subject: [PATCH 1/8] Adding inspection scripts for beacon groups and ecdsa keeps - Added inspect-beacon-group.js - Added inspect-ecdsa-keep.js Both scripts can be used for ropsten/mainnet investigation of current states. Example call: ETH_HOSTNAME="https://mainnet.infura.io/v3/PROJECT_ID" truffle exec ./scripts/inspect-ecdsa-keep.js --network mainnet --- inspector/scripts/inspect-beacon-group.js | 87 +++++++++++++++++++++++ inspector/scripts/inspect-ecdsa-keep.js | 76 ++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 inspector/scripts/inspect-beacon-group.js create mode 100644 inspector/scripts/inspect-ecdsa-keep.js diff --git a/inspector/scripts/inspect-beacon-group.js b/inspector/scripts/inspect-beacon-group.js new file mode 100644 index 0000000..a7acd37 --- /dev/null +++ b/inspector/scripts/inspect-beacon-group.js @@ -0,0 +1,87 @@ +const truffleContract = require("@truffle/contract") +const KeepRandomBeaconOperatorJson = require("@keep-network/keep-core/artifacts/KeepRandomBeaconOperator.json") + +module.exports = async function() { + const deploymentBlock = 10834116 + + try { + const KeepRandomBeaconOperator = truffleContract(KeepRandomBeaconOperatorJson) + KeepRandomBeaconOperator.setProvider(web3.currentProvider) + + const keepRandomBeaconOperator = await KeepRandomBeaconOperator.deployed() + + const numberOfGroups = await keepRandomBeaconOperator.numberOfGroups() + const entryRequestedEvents = await keepRandomBeaconOperator.getPastEvents( + "RelayEntryRequested", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + ) + const entrySubmittedEvents = await keepRandomBeaconOperator.getPastEvents( + "RelayEntrySubmitted", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + ) + const timeoutEvents = await keepRandomBeaconOperator.getPastEvents( + "RelayEntryTimeoutReported", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + ) + + console.log(`Number of groups: ${numberOfGroups}`) + console.log(`Relay entries requested: ${entryRequestedEvents.length}`) + console.log(`Relay entries submitted: ${entrySubmittedEvents.length}`) + console.log(`Number of timed-out entries: ${timeoutEvents.length}`) + if (timeoutEvents.length > 0) { + console.log(`timed out entry group indices: ${timeoutEvents.map(event => event.returnValues.groupIndex)}`) + } + console.log(``) + + const dkgSubmittedEvents = (await keepRandomBeaconOperator.getPastEvents( + "DkgResultSubmittedEvent", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + )) + + const allOperators = new Set() + + for (i = 0; i < numberOfGroups; i++) { + const groupPubKey = await keepRandomBeaconOperator.getGroupPublicKey(i) + const groupMembers = await keepRandomBeaconOperator.getGroupMembers(groupPubKey) + + const uniqueMembers = new Set() + groupMembers.forEach((member) => { + uniqueMembers.add(member) + allOperators.add(member) + }) + + const dkgSubmittedEvent = dkgSubmittedEvents.find((event) => { + return event.returnValues.groupPubKey == groupPubKey + }) + + const {memberIndex, misbehaved} = dkgSubmittedEvent.returnValues + + console.log(`Group ${groupPubKey}:`) + console.log(` - has index ${i}`) + console.log(` - has ${groupMembers.length} members`) + console.log(` - its DKG result was submitted by member ${memberIndex}`) + console.log(` - misbehaved members bytes: ${misbehaved}`) + console.log(` - has ${uniqueMembers.size} unique members`) + console.log(``) + } + + console.log(`There are ${allOperators.size} unique operators in all groups`) + + process.exit() + } catch (error) { + console.log(error) + process.exit() + } +} \ No newline at end of file diff --git a/inspector/scripts/inspect-ecdsa-keep.js b/inspector/scripts/inspect-ecdsa-keep.js new file mode 100644 index 0000000..02ccfc7 --- /dev/null +++ b/inspector/scripts/inspect-ecdsa-keep.js @@ -0,0 +1,76 @@ +const truffleContract = require("@truffle/contract") + +const BondedECDSAKeepFactoryJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeepFactory.json") +const BondedECDSAKeepJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json") + +module.exports = async function () { + try { + const BondedECDSAKeepFactory = truffleContract(BondedECDSAKeepFactoryJson) + BondedECDSAKeepFactory.setProvider(web3.currentProvider) + const BondedECDSAKeep = truffleContract(BondedECDSAKeepJson) + BondedECDSAKeep.setProvider(web3.currentProvider) + + const factory = await BondedECDSAKeepFactory.deployed() + + const keepCount = await factory.getKeepCount() + console.log(`created keeps count: ${keepCount}`) + + const allOperators = new Set() + const goodOperators = new Set() + + for (i = 0; i < keepCount; i++) { + const keepAddress = await callWithRetry(() => factory.getKeepAtIndex(i)) + const keep = await BondedECDSAKeep.at(keepAddress) + const keepPublicKey = await callWithRetry(() => keep.publicKey()) + const members = await callWithRetry(() => keep.getMembers()) + const isActive = await callWithRetry(() => keep.isActive()) + const bond = await callWithRetry(()=> keep.checkBondAmount()) + + console.log(`keep address: ${keepAddress}`) + console.log(`keep index: ${i}`) + console.log(`pubkey: ${keepPublicKey}`) + console.log(`members: ${members}`) + console.log(`isActive: ${isActive}`) + console.log(`bond [wei]: ${bond}`) + console.log(`bond [eth]: ${web3.utils.fromWei(bond)}`) + + members.forEach((member) => allOperators.add(member)) + if (keepPublicKey) { + members.forEach((member) => goodOperators.add(member)) + } + + console.log(``) + } + + // all operators who are members of keeps + console.log(`all operators = ${new Array(...allOperators).join(', ')}`) + console.log(``) + + // if the operator is a member of at least one keep which generated + // a public key, it's here + console.log(`good operators = ${new Array(...goodOperators).join(', ')}`) + console.log(``) + + // if the operator is a member of at least one keep and that operator + // is NOT a member of at least one keep which successfully generated + // a public key, this operator is here + let potentiallyBadOperators = new Set(allOperators) + for (let goodOperator of goodOperators) { + potentiallyBadOperators.delete(goodOperator) + } + console.log(`potentially bad operators = ${new Array(...potentiallyBadOperators).join(', ')}`) + + process.exit() + } catch (error) { + console.log(error) + } +} + +async function callWithRetry(fn) { + try { + return await fn() + } catch (error) { + console.log(`Error ${error} occurred; retrying...`) + return await fn() + } +} \ No newline at end of file From 10bdc4ca3c7a6489f402d754d0b791d537544e6b Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 11:40:39 +0200 Subject: [PATCH 2/8] Adding a script to inspect deposit/redemptions in tbtc --- inspector/package-lock.json | 72 +++++++++++++ inspector/scripts/inspect-tbtc.js | 170 ++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 inspector/scripts/inspect-tbtc.js diff --git a/inspector/package-lock.json b/inspector/package-lock.json index 4e7b149..5fe37a5 100644 --- a/inspector/package-lock.json +++ b/inspector/package-lock.json @@ -788,6 +788,65 @@ } } }, + "@ledgerhq/hw-transport": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-5.23.0.tgz", + "integrity": "sha512-ICTG3Bst62SkC+lYYFgpKk5G4bAOxeIvptXnTLOhf6VqeN7gdHfiRzZwNPnKzI2pxmcEVbBitgsxEIEQJmDKVA==", + "requires": { + "@openzeppelin/contracts": "^2.4.0" + } + }, + "@keep-network/tbtc": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@keep-network/tbtc/-/tbtc-1.1.0.tgz", + "integrity": "sha512-V4sGR/t61PgkEF11GDZL5QNijVSdDhL7A7larcOSSCmKJOugxd5s+d+NdhYcHZhX9IS58ebtepvZan8TydHUHw==", + "requires": { + "@keep-network/keep-ecdsa": "1.2.1", + "@summa-tx/bitcoin-spv-sol": "^3.1.0", + "@summa-tx/relay-sol": "^2.0.2", + "openzeppelin-solidity": "2.3.0" + }, + "dependencies": { + "openzeppelin-solidity": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/openzeppelin-solidity/-/openzeppelin-solidity-2.3.0.tgz", + "integrity": "sha512-QYeiPLvB1oSbDt6lDQvvpx7k8ODczvE474hb2kLXZBPKMsxKT1WxTCHBYrCU7kS7hfAku4DcJ0jqOyL+jvjwQw==" + } + } + }, + "@ledgerhq/devices": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-5.23.0.tgz", + "integrity": "sha512-XR9qTwn14WwN8VSMsYD9NTX/TgkmrTnXEh0pIj6HMRZwFzBPzslExOcXuCm3V9ssgAEAxv3VevfV8UulvvZUXA==", + "requires": { + "@ledgerhq/errors": "^5.23.0", + "@ledgerhq/logs": "^5.23.0", + "rxjs": "^6.6.3" + } + }, + "@ledgerhq/errors": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-5.23.0.tgz", + "integrity": "sha512-qtpX8aFrUUlYfOMu7BxTvxqUa8CniE+tEBpVEjYUhVbFdVJjM4ouwJD++RtQkMAU2c5jE7xb12WnUnf5BlAgLQ==" + }, + "@ledgerhq/hw-app-eth": { + "version": "5.24.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-app-eth/-/hw-app-eth-5.24.0.tgz", + "integrity": "sha512-DWwvFIABiAI07u4gSHhdTsClUXNXRy19dXv8WcJ2mPAphkY1FFaQ7IFxW+Mq4OcRTWWoDQkZBWQzSI2HD6YLHg==", + "requires": { + "@ledgerhq/errors": "^5.23.0", + "@ledgerhq/hw-transport": "^5.23.0", + "bignumber.js": "^9.0.0", + "rlp": "^2.2.6" + }, + "dependencies": { + "bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + } + } + }, "@ledgerhq/hw-transport": { "version": "5.23.0", "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-5.23.0.tgz", @@ -7689,6 +7748,14 @@ "web3-utils": "1.2.2" }, "dependencies": { + "@web3-js/scrypt-shim": { + "version": "github:web3-js/scrypt-shim#aafdadda13e660e25e1c525d1f5b2443f5eb1ebb", + "from": "github:web3-js/scrypt-shim", + "requires": { + "scryptsy": "^2.1.0", + "semver": "^6.3.0" + } + }, "eth-lib": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.2.7.tgz", @@ -7699,6 +7766,11 @@ "xhr-request-promise": "^0.1.2" } }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + }, "uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", diff --git a/inspector/scripts/inspect-tbtc.js b/inspector/scripts/inspect-tbtc.js new file mode 100644 index 0000000..e25e9b7 --- /dev/null +++ b/inspector/scripts/inspect-tbtc.js @@ -0,0 +1,170 @@ +const DepositJson = require("@keep-network/tbtc/artifacts/Deposit.json") +const DepositFactoryJson = require("@keep-network/tbtc/artifacts/DepositFactory.json") +const BondedECDSAKeepJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json") + +const truffleContract = require("@truffle/contract") + +const deploymentBlock = 10867764 + +module.exports = async function() { + try { + const DepositFactory = truffleContract(DepositFactoryJson) + DepositFactory.setProvider(web3.currentProvider) + const Deposit = truffleContract(DepositJson) + Deposit.setProvider(web3.currentProvider) + + const factory = await DepositFactory.deployed() + + const depositCreatedEvents = await factory.getPastEvents( + "DepositCloneCreated", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + ) + + console.log(`Number of created deposits: ${depositCreatedEvents.length}`) + + const depositAddresses = [] + depositCreatedEvents.forEach((event) => + depositAddresses.push(event.args.depositCloneAddress) + ) + + for (i = 0; i < depositAddresses.length; i++) { + const deposit = await Deposit.at(depositAddresses[i]) + const state = await deposit.currentState() + let stateString = "" + switch(state.toString()) { + case "0": stateString = "START"; break + case "1": stateString = "AWAITING_SIGNER_SETUP"; break + case "2": stateString = "AWAITING_BTC_FUNDING_PROOF"; break + case "3": stateString = "FAILED_SETUP"; break + case "4": stateString = "ACTIVE"; break + case "5": stateString = "AWAITING_WITHDRAWAL_SIGNATURE"; break + case "6": stateString = "AWAITING_WITHDRAWAL_PROOF"; break + case "7": stateString = "REDEEMED"; break + case "8": stateString = "COURTESY_CALL"; break + case "9": stateString = "FRAUD_LIQUIDATION_IN_PROGRESS"; break + case "10": stateString = "LIQUIDATION_IN_PROGRESS"; break + case "11": stateString = "LIQUIDATED"; break + default: stateString = "<< UNKNOWN >>"; break + } + const keepAddress = await deposit.keepAddress() + const lotSizeSatoshis = await deposit.lotSizeSatoshis() + const lotSizeTbtc = await deposit.lotSizeTbtc() + + console.log(`deposit address: ${depositAddresses[i]}`) + console.log(`deposit index: ${i}`) + console.log(`deposit state: ${stateString}`) + console.log(`keep address: ${keepAddress}`) + console.log(`lot size [sat]: ${lotSizeSatoshis}`) + console.log(`lot size [tbtc]: ${lotSizeTbtc}`) + + if (stateString == "AWAITING_SIGNER_SETUP") { + await retrieveSignerPubkey(deposit) + } else if (stateString == "AWAITING_BTC_FUNDING_PROOF") { + await notifyFundingTimedOut(deposit) + } else if (stateString == "AWAITING_WITHDRAWAL_SIGNATURE") { + await provideRedemptionSignature(deposit, keepAddress) + } else if (stateString == "AWAITING_WITHDRAWAL_PROOF") { + await notifyRedemptionProofTimeout(deposit) + } + + console.log(``) + } + + process.exit() + } catch (error) { + console.log(error) + process.exit() + } +} + +async function notifySignerSetupFailed(deposit) { + console.log(`Notifying signer setup failed...`) + try { + const receipt = await deposit.notifySignerSetupFailed() + console.log(`TX: ${receipt.tx}`) + } catch (error) { + console.log(`Failed with: ${JSON.stringify(error)}`) + } +} + +async function retrieveSignerPubkey(deposit) { + console.log(`Retrieving signer pubkey...`) + try { + const receipt = await deposit.retrieveSignerPubkey() + console.log(`TX: ${receipt.tx}`) + } catch (error) { + console.log(`Failed with: ${JSON.stringify(error)}`) + } +} + +async function notifyFundingTimedOut(deposit) { + console.log(`Notifying funding timeout...`) + try { + const receipt = await deposit.notifyFundingTimedOut() + console.log(`TX: ${receipt.tx}`) + } catch (error) { + console.log(`Failed with: ${JSON.stringify(error)}`) + } +} + +async function provideRedemptionSignature(deposit, keepAddress) { + const BondedECDSAKeep = truffleContract(BondedECDSAKeepJson) + BondedECDSAKeep.setProvider(web3.currentProvider) + + const keep = await BondedECDSAKeep.at(keepAddress) + + console.log(`Looking for the signature from keep ${keepAddress}...`) + + console.log(await keep.digest()) + const signatureSubmittedEvents = await keep.getPastEvents( + "SignatureSubmitted", + { + fromBlock: deploymentBlock, + toBlock: "latest", + } + ) + + const signaturesCount = signatureSubmittedEvents.length + console.log(`Number of signatures submitted: ${signaturesCount}`) + + if (signaturesCount == 0) { + // no signatures, nothing to do here + return + } + const lastSignature = signatureSubmittedEvents[signaturesCount - 1] + + const {digest, r, s, recoveryID } = lastSignature.returnValues + // A constant in the Ethereum ECDSA signature scheme, used for public key recovery [1] + // Value is inherited from Bitcoin's Electrum wallet [2] + // [1] https://bitcoin.stackexchange.com/questions/38351/ecdsa-v-r-s-what-is-v/38909#38909 + // [2] https://github.com/ethereum/EIPs/issues/155#issuecomment-253810938 + const ETHEREUM_ECDSA_RECOVERY_V = web3.utils.toBN(27) + const v = web3.utils.toBN(recoveryID).add(ETHEREUM_ECDSA_RECOVERY_V) + + console.log(`digest = ${digest}, r = ${r}, s = ${s}, v = ${v}`) + + try { + console.log(`Providing redemption signature...`) + const receipt = await deposit.provideRedemptionSignature( + v, + r.toString(), + s.toString() + ) + console.log(`TX: ${receipt.tx}`) + } catch (error) { + console.log(`Failed with: ${JSON.stringify(error)}`) + } +} + +async function notifyRedemptionProofTimeout(deposit) { + console.log(`Notifying redemption proof timeout...`) + try { + const receipt = await deposit.notifyRedemptionProofTimedOut() + console.log(`TX: ${receipt.tx}`) + } catch (error) { + console.log(`Failed with: ${JSON.stringify(error)}`) + } +} \ No newline at end of file From bc22857e6d6ea4d7eace185425ac9cc6c66c68d2 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 14:59:46 +0200 Subject: [PATCH 3/8] Renaming inspect-beacon-group.js -> inspect-beacon.js --- inspector/scripts/{inspect-beacon-group.js => inspect-beacon.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename inspector/scripts/{inspect-beacon-group.js => inspect-beacon.js} (100%) diff --git a/inspector/scripts/inspect-beacon-group.js b/inspector/scripts/inspect-beacon.js similarity index 100% rename from inspector/scripts/inspect-beacon-group.js rename to inspector/scripts/inspect-beacon.js From 5736a7b3c8410434f198ec288b6a96d21569a2cc Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 16:56:31 +0200 Subject: [PATCH 4/8] Adding package-lock.json --- inspector/package-lock.json | 59 ------------------------------------- 1 file changed, 59 deletions(-) diff --git a/inspector/package-lock.json b/inspector/package-lock.json index 5fe37a5..b9c7163 100644 --- a/inspector/package-lock.json +++ b/inspector/package-lock.json @@ -788,65 +788,6 @@ } } }, - "@ledgerhq/hw-transport": { - "version": "5.23.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-5.23.0.tgz", - "integrity": "sha512-ICTG3Bst62SkC+lYYFgpKk5G4bAOxeIvptXnTLOhf6VqeN7gdHfiRzZwNPnKzI2pxmcEVbBitgsxEIEQJmDKVA==", - "requires": { - "@openzeppelin/contracts": "^2.4.0" - } - }, - "@keep-network/tbtc": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@keep-network/tbtc/-/tbtc-1.1.0.tgz", - "integrity": "sha512-V4sGR/t61PgkEF11GDZL5QNijVSdDhL7A7larcOSSCmKJOugxd5s+d+NdhYcHZhX9IS58ebtepvZan8TydHUHw==", - "requires": { - "@keep-network/keep-ecdsa": "1.2.1", - "@summa-tx/bitcoin-spv-sol": "^3.1.0", - "@summa-tx/relay-sol": "^2.0.2", - "openzeppelin-solidity": "2.3.0" - }, - "dependencies": { - "openzeppelin-solidity": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/openzeppelin-solidity/-/openzeppelin-solidity-2.3.0.tgz", - "integrity": "sha512-QYeiPLvB1oSbDt6lDQvvpx7k8ODczvE474hb2kLXZBPKMsxKT1WxTCHBYrCU7kS7hfAku4DcJ0jqOyL+jvjwQw==" - } - } - }, - "@ledgerhq/devices": { - "version": "5.23.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-5.23.0.tgz", - "integrity": "sha512-XR9qTwn14WwN8VSMsYD9NTX/TgkmrTnXEh0pIj6HMRZwFzBPzslExOcXuCm3V9ssgAEAxv3VevfV8UulvvZUXA==", - "requires": { - "@ledgerhq/errors": "^5.23.0", - "@ledgerhq/logs": "^5.23.0", - "rxjs": "^6.6.3" - } - }, - "@ledgerhq/errors": { - "version": "5.23.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-5.23.0.tgz", - "integrity": "sha512-qtpX8aFrUUlYfOMu7BxTvxqUa8CniE+tEBpVEjYUhVbFdVJjM4ouwJD++RtQkMAU2c5jE7xb12WnUnf5BlAgLQ==" - }, - "@ledgerhq/hw-app-eth": { - "version": "5.24.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-app-eth/-/hw-app-eth-5.24.0.tgz", - "integrity": "sha512-DWwvFIABiAI07u4gSHhdTsClUXNXRy19dXv8WcJ2mPAphkY1FFaQ7IFxW+Mq4OcRTWWoDQkZBWQzSI2HD6YLHg==", - "requires": { - "@ledgerhq/errors": "^5.23.0", - "@ledgerhq/hw-transport": "^5.23.0", - "bignumber.js": "^9.0.0", - "rlp": "^2.2.6" - }, - "dependencies": { - "bignumber.js": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", - "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" - } - } - }, "@ledgerhq/hw-transport": { "version": "5.23.0", "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-5.23.0.tgz", From 89e9a1f4caeabd635b71408cad78cdd433c41b63 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 16:59:06 +0200 Subject: [PATCH 5/8] Reading deployment block number from chain instead of hardcoding --- inspector/scripts/inspect-beacon.js | 6 ++++-- inspector/scripts/inspect-tbtc.js | 9 +++++---- inspector/scripts/lib/contract-helper.js | 11 +++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 inspector/scripts/lib/contract-helper.js diff --git a/inspector/scripts/inspect-beacon.js b/inspector/scripts/inspect-beacon.js index a7acd37..4b478b8 100644 --- a/inspector/scripts/inspect-beacon.js +++ b/inspector/scripts/inspect-beacon.js @@ -1,10 +1,12 @@ const truffleContract = require("@truffle/contract") const KeepRandomBeaconOperatorJson = require("@keep-network/keep-core/artifacts/KeepRandomBeaconOperator.json") -module.exports = async function() { - const deploymentBlock = 10834116 +const contractHelper = require("./lib/contract-helper") +module.exports = async function() { try { + const deploymentBlock = await contractHelper.getDeploymentBlockNumber(KeepRandomBeaconOperatorJson, web3) + const KeepRandomBeaconOperator = truffleContract(KeepRandomBeaconOperatorJson) KeepRandomBeaconOperator.setProvider(web3.currentProvider) diff --git a/inspector/scripts/inspect-tbtc.js b/inspector/scripts/inspect-tbtc.js index e25e9b7..a725fb4 100644 --- a/inspector/scripts/inspect-tbtc.js +++ b/inspector/scripts/inspect-tbtc.js @@ -3,11 +3,12 @@ const DepositFactoryJson = require("@keep-network/tbtc/artifacts/DepositFactory. const BondedECDSAKeepJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json") const truffleContract = require("@truffle/contract") - -const deploymentBlock = 10867764 +const contractHelper = require("./lib/contract-helper") module.exports = async function() { try { + const factoryDeploymentBlock = await contractHelper.getDeploymentBlockNumber(DepositFactoryJson, web3) + const DepositFactory = truffleContract(DepositFactoryJson) DepositFactory.setProvider(web3.currentProvider) const Deposit = truffleContract(DepositJson) @@ -18,7 +19,7 @@ module.exports = async function() { const depositCreatedEvents = await factory.getPastEvents( "DepositCloneCreated", { - fromBlock: deploymentBlock, + fromBlock: factoryDeploymentBlock, toBlock: "latest", } ) @@ -122,7 +123,7 @@ async function provideRedemptionSignature(deposit, keepAddress) { const signatureSubmittedEvents = await keep.getPastEvents( "SignatureSubmitted", { - fromBlock: deploymentBlock, + fromBlock: factoryDeploymentBlock, toBlock: "latest", } ) diff --git a/inspector/scripts/lib/contract-helper.js b/inspector/scripts/lib/contract-helper.js new file mode 100644 index 0000000..a3bde53 --- /dev/null +++ b/inspector/scripts/lib/contract-helper.js @@ -0,0 +1,11 @@ +const getDeploymentBlockNumber = async function(contractJSON, web3) { + const networkId = Object.keys(contractJSON.networks)[0] + const transactionHash = contractJSON.networks[networkId].transactionHash + const transaction = await web3.eth.getTransaction(transactionHash) + + return transaction.blockNumber +} + +module.exports = { + getDeploymentBlockNumber: getDeploymentBlockNumber +} From e0784d1dc8fa6d396f8cd26a15683fb8bc5d7d6d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 17:11:50 +0200 Subject: [PATCH 6/8] Removing operators logs which are replaced in inspect-operators.js --- inspector/scripts/inspect-ecdsa-keep.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/inspector/scripts/inspect-ecdsa-keep.js b/inspector/scripts/inspect-ecdsa-keep.js index 02ccfc7..a282ebe 100644 --- a/inspector/scripts/inspect-ecdsa-keep.js +++ b/inspector/scripts/inspect-ecdsa-keep.js @@ -42,15 +42,6 @@ module.exports = async function () { console.log(``) } - // all operators who are members of keeps - console.log(`all operators = ${new Array(...allOperators).join(', ')}`) - console.log(``) - - // if the operator is a member of at least one keep which generated - // a public key, it's here - console.log(`good operators = ${new Array(...goodOperators).join(', ')}`) - console.log(``) - // if the operator is a member of at least one keep and that operator // is NOT a member of at least one keep which successfully generated // a public key, this operator is here From 2e061cef8795b4181a6b91525bfbb78e57b2cbc6 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 18 Sep 2020 17:19:56 +0200 Subject: [PATCH 7/8] Removing state transition --- inspector/scripts/inspect-tbtc.js | 102 +----------------------------- 1 file changed, 1 insertion(+), 101 deletions(-) diff --git a/inspector/scripts/inspect-tbtc.js b/inspector/scripts/inspect-tbtc.js index a725fb4..831683e 100644 --- a/inspector/scripts/inspect-tbtc.js +++ b/inspector/scripts/inspect-tbtc.js @@ -1,6 +1,5 @@ const DepositJson = require("@keep-network/tbtc/artifacts/Deposit.json") const DepositFactoryJson = require("@keep-network/tbtc/artifacts/DepositFactory.json") -const BondedECDSAKeepJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json") const truffleContract = require("@truffle/contract") const contractHelper = require("./lib/contract-helper") @@ -24,7 +23,7 @@ module.exports = async function() { } ) - console.log(`Number of created deposits: ${depositCreatedEvents.length}`) + console.log(`Number of created deposits: ${depositCreatedEvents.length} \n`) const depositAddresses = [] depositCreatedEvents.forEach((event) => @@ -61,16 +60,6 @@ module.exports = async function() { console.log(`lot size [sat]: ${lotSizeSatoshis}`) console.log(`lot size [tbtc]: ${lotSizeTbtc}`) - if (stateString == "AWAITING_SIGNER_SETUP") { - await retrieveSignerPubkey(deposit) - } else if (stateString == "AWAITING_BTC_FUNDING_PROOF") { - await notifyFundingTimedOut(deposit) - } else if (stateString == "AWAITING_WITHDRAWAL_SIGNATURE") { - await provideRedemptionSignature(deposit, keepAddress) - } else if (stateString == "AWAITING_WITHDRAWAL_PROOF") { - await notifyRedemptionProofTimeout(deposit) - } - console.log(``) } @@ -80,92 +69,3 @@ module.exports = async function() { process.exit() } } - -async function notifySignerSetupFailed(deposit) { - console.log(`Notifying signer setup failed...`) - try { - const receipt = await deposit.notifySignerSetupFailed() - console.log(`TX: ${receipt.tx}`) - } catch (error) { - console.log(`Failed with: ${JSON.stringify(error)}`) - } -} - -async function retrieveSignerPubkey(deposit) { - console.log(`Retrieving signer pubkey...`) - try { - const receipt = await deposit.retrieveSignerPubkey() - console.log(`TX: ${receipt.tx}`) - } catch (error) { - console.log(`Failed with: ${JSON.stringify(error)}`) - } -} - -async function notifyFundingTimedOut(deposit) { - console.log(`Notifying funding timeout...`) - try { - const receipt = await deposit.notifyFundingTimedOut() - console.log(`TX: ${receipt.tx}`) - } catch (error) { - console.log(`Failed with: ${JSON.stringify(error)}`) - } -} - -async function provideRedemptionSignature(deposit, keepAddress) { - const BondedECDSAKeep = truffleContract(BondedECDSAKeepJson) - BondedECDSAKeep.setProvider(web3.currentProvider) - - const keep = await BondedECDSAKeep.at(keepAddress) - - console.log(`Looking for the signature from keep ${keepAddress}...`) - - console.log(await keep.digest()) - const signatureSubmittedEvents = await keep.getPastEvents( - "SignatureSubmitted", - { - fromBlock: factoryDeploymentBlock, - toBlock: "latest", - } - ) - - const signaturesCount = signatureSubmittedEvents.length - console.log(`Number of signatures submitted: ${signaturesCount}`) - - if (signaturesCount == 0) { - // no signatures, nothing to do here - return - } - const lastSignature = signatureSubmittedEvents[signaturesCount - 1] - - const {digest, r, s, recoveryID } = lastSignature.returnValues - // A constant in the Ethereum ECDSA signature scheme, used for public key recovery [1] - // Value is inherited from Bitcoin's Electrum wallet [2] - // [1] https://bitcoin.stackexchange.com/questions/38351/ecdsa-v-r-s-what-is-v/38909#38909 - // [2] https://github.com/ethereum/EIPs/issues/155#issuecomment-253810938 - const ETHEREUM_ECDSA_RECOVERY_V = web3.utils.toBN(27) - const v = web3.utils.toBN(recoveryID).add(ETHEREUM_ECDSA_RECOVERY_V) - - console.log(`digest = ${digest}, r = ${r}, s = ${s}, v = ${v}`) - - try { - console.log(`Providing redemption signature...`) - const receipt = await deposit.provideRedemptionSignature( - v, - r.toString(), - s.toString() - ) - console.log(`TX: ${receipt.tx}`) - } catch (error) { - console.log(`Failed with: ${JSON.stringify(error)}`) - } -} - -async function notifyRedemptionProofTimeout(deposit) { - console.log(`Notifying redemption proof timeout...`) - try { - const receipt = await deposit.notifyRedemptionProofTimedOut() - console.log(`TX: ${receipt.tx}`) - } catch (error) { - console.log(`Failed with: ${JSON.stringify(error)}`) - } -} \ No newline at end of file From 0437233d684a24095eee06670d4c0582a035d2dc Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 21 Sep 2020 11:54:43 +0200 Subject: [PATCH 8/8] Removing conole log with indices - Removed console.log because these indices are not the timeout entry group indices. The indices are changes in signRelayEntry. --- inspector/scripts/inspect-beacon.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/inspector/scripts/inspect-beacon.js b/inspector/scripts/inspect-beacon.js index 4b478b8..002a7d4 100644 --- a/inspector/scripts/inspect-beacon.js +++ b/inspector/scripts/inspect-beacon.js @@ -39,9 +39,6 @@ module.exports = async function() { console.log(`Relay entries requested: ${entryRequestedEvents.length}`) console.log(`Relay entries submitted: ${entrySubmittedEvents.length}`) console.log(`Number of timed-out entries: ${timeoutEvents.length}`) - if (timeoutEvents.length > 0) { - console.log(`timed out entry group indices: ${timeoutEvents.map(event => event.returnValues.groupIndex)}`) - } console.log(``) const dkgSubmittedEvents = (await keepRandomBeaconOperator.getPastEvents(