Updated oracle watchers to use blob version of execute signatures (#269)

This commit is contained in:
Kirill Fedoseev 2020-01-21 00:11:26 +03:00 committed by Alexander Kolotov
parent edc51c78e2
commit 8650ba4d21
8 changed files with 36 additions and 31 deletions

@ -1 +1 @@
Subproject commit c85aeb737bfd684b20b99520bd632ba4b8866583
Subproject commit e0d54bf38c233c978a3373d1d527fc9f1d3f1784

@ -46,7 +46,7 @@ async function estimateGas({
// check if all the signatures were made by validators
for (let i = 0; i < v.length; i++) {
const address = web3.eth.accounts.recover(message, web3.utils.toHex(v[i]), r[i], s[i])
const address = web3.eth.accounts.recover(message, `0x${v[i]}`, `0x${r[i]}`, `0x${s[i]}`)
logger.debug({ address }, 'Check that signature is from a validator')
const isValidator = await validatorContract.methods.isValidator(address).call()

@ -4,7 +4,7 @@ const { HttpListProviderError } = require('http-list-provider')
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
const rootLogger = require('../../services/logger')
const { web3Home, web3Foreign } = require('../../services/web3')
const { signatureToVRS, signatureToVRSAMB, packSignatures } = require('../../utils/message')
const { signatureToVRS, packSignatures } = require('../../utils/message')
const { parseAMBMessage } = require('../../../../commons')
const estimateGas = require('./estimateGas')
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
@ -63,8 +63,7 @@ function processCollectedSignaturesBuilder(config) {
v.push(vrs.v)
r.push(vrs.r)
s.push(vrs.s)
const recover = signatureToVRSAMB(signature)
signaturesArray.push(recover)
signaturesArray.push(vrs)
})
await Promise.all(signaturePromises)

@ -9,9 +9,18 @@ const logger = require('../../services/logger').child({
const web3 = new Web3()
const { toBN } = Web3.utils
async function estimateGas({ foreignBridge, validatorContract, message, numberOfCollectedSignatures, v, r, s }) {
async function estimateGas({
foreignBridge,
validatorContract,
message,
numberOfCollectedSignatures,
v,
r,
s,
signatures
}) {
try {
const gasEstimate = await foreignBridge.methods.executeSignatures(v, r, s, message).estimateGas()
const gasEstimate = await foreignBridge.methods.executeSignatures(message, signatures).estimateGas()
return gasEstimate
} catch (e) {
if (e instanceof HttpListProviderError) {
@ -35,7 +44,7 @@ async function estimateGas({ foreignBridge, validatorContract, message, numberOf
// check if all the signatures were made by validators
for (let i = 0; i < v.length; i++) {
const address = web3.eth.accounts.recover(message, web3.utils.toHex(v[i]), r[i], s[i])
const address = web3.eth.accounts.recover(message, `0x${v[i]}`, `0x${r[i]}`, `0x${s[i]}`)
logger.debug({ address }, 'Check that signature is from a validator')
const isValidator = await validatorContract.methods.isValidator(address).call()

@ -4,7 +4,7 @@ const { HttpListProviderError } = require('http-list-provider')
const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons')
const rootLogger = require('../../services/logger')
const { web3Home, web3Foreign } = require('../../services/web3')
const { signatureToVRS } = require('../../utils/message')
const { signatureToVRS, packSignatures } = require('../../utils/message')
const estimateGas = require('./estimateGas')
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
const { MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
@ -52,18 +52,21 @@ function processCollectedSignaturesBuilder(config) {
requiredSignatures.length = NumberOfCollectedSignatures
requiredSignatures.fill(0)
const signaturesArray = []
const [v, r, s] = [[], [], []]
logger.debug('Getting message signatures')
const signaturePromises = requiredSignatures.map(async (el, index) => {
logger.debug({ index }, 'Getting message signature')
const signature = await homeBridge.methods.signature(messageHash, index).call()
const recover = signatureToVRS(signature)
v.push(recover.v)
r.push(recover.r)
s.push(recover.s)
const vrs = signatureToVRS(signature)
v.push(vrs.v)
r.push(vrs.r)
s.push(vrs.s)
signaturesArray.push(vrs)
})
await Promise.all(signaturePromises)
const signatures = packSignatures(signaturesArray)
let gasEstimate
try {
@ -74,6 +77,7 @@ function processCollectedSignaturesBuilder(config) {
v,
r,
s,
signatures,
message,
numberOfCollectedSignatures: NumberOfCollectedSignatures
})
@ -92,7 +96,7 @@ function processCollectedSignaturesBuilder(config) {
throw e
}
}
const data = await foreignBridge.methods.executeSignatures(v, r, s, message).encodeABI()
const data = await foreignBridge.methods.executeSignatures(message, signatures).encodeABI()
txToSend.push({
data,
gasEstimate,

@ -50,17 +50,9 @@ function parseMessage(message) {
}
}
function signatureToVRS(signature) {
assert.strictEqual(signature.length, 2 + 32 * 2 + 32 * 2 + 2)
signature = strip0x(signature)
const v = parseInt(signature.substr(64 * 2), 16)
const r = `0x${signature.substr(0, 32 * 2)}`
const s = `0x${signature.substr(32 * 2, 32 * 2)}`
return { v, r, s }
}
function signatureToVRSAMB(rawSignature) {
function signatureToVRS(rawSignature) {
const signature = strip0x(rawSignature)
assert.strictEqual(signature.length, 2 + 32 * 2 + 32 * 2)
const v = signature.substr(64 * 2)
const r = signature.substr(0, 32 * 2)
const s = signature.substr(32 * 2, 32 * 2)
@ -85,6 +77,5 @@ module.exports = {
createMessage,
parseMessage,
signatureToVRS,
signatureToVRSAMB,
packSignatures
}

@ -259,9 +259,9 @@ describe('message utils', () => {
const { v, r, s } = signatureToVRS(signature)
// then
expect(v).to.equal(27)
expect(r).to.equal('0xed157c39b80281741e7d4075655f25b11a9182f12d90878a1ba9bfed111c8996')
expect(s).to.equal('0x20b74dc25ba2f581be753e11673413eb90f1f08285c2100d8e16c6799818c77d')
expect(v).to.equal('1b')
expect(r).to.equal('ed157c39b80281741e7d4075655f25b11a9182f12d90878a1ba9bfed111c8996')
expect(s).to.equal('20b74dc25ba2f581be753e11673413eb90f1f08285c2100d8e16c6799818c77d')
})
it('should fail if signature is too short', () => {

@ -2,7 +2,7 @@ const { expect } = require('chai').use(require('chai-as-promised'))
const sinon = require('sinon')
const Web3 = require('web3')
const { HttpListProviderError } = require('http-list-provider')
const { createMessage } = require('../src/utils/message')
const { createMessage, signatureToVRS } = require('../src/utils/message')
const estimateGas = require('../src/events/processCollectedSignatures/estimateGas')
const errors = require('../src/utils/errors')
@ -116,10 +116,11 @@ describe('processCollectedSignatures', () => {
}
const message = randomMessage()
const { v, r, s } = web3.eth.accounts.sign(
const { signature } = web3.eth.accounts.sign(
message,
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
)
const { v, r, s } = signatureToVRS(signature)
// when
const result = estimateGas({
@ -155,10 +156,11 @@ describe('processCollectedSignatures', () => {
}
const message = randomMessage()
const { v, r, s } = web3.eth.accounts.sign(
const { signature } = web3.eth.accounts.sign(
message,
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
)
const { v, r, s } = signatureToVRS(signature)
// when
const result = estimateGas({