Updated oracle watchers to use blob version of execute signatures (#269)
This commit is contained in:
parent
edc51c78e2
commit
8650ba4d21
@ -1 +1 @@
|
|||||||
Subproject commit c85aeb737bfd684b20b99520bd632ba4b8866583
|
Subproject commit e0d54bf38c233c978a3373d1d527fc9f1d3f1784
|
@ -46,7 +46,7 @@ async function estimateGas({
|
|||||||
|
|
||||||
// check if all the signatures were made by validators
|
// check if all the signatures were made by validators
|
||||||
for (let i = 0; i < v.length; i++) {
|
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')
|
logger.debug({ address }, 'Check that signature is from a validator')
|
||||||
const isValidator = await validatorContract.methods.isValidator(address).call()
|
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 bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
||||||
const rootLogger = require('../../services/logger')
|
const rootLogger = require('../../services/logger')
|
||||||
const { web3Home, web3Foreign } = require('../../services/web3')
|
const { web3Home, web3Foreign } = require('../../services/web3')
|
||||||
const { signatureToVRS, signatureToVRSAMB, packSignatures } = require('../../utils/message')
|
const { signatureToVRS, packSignatures } = require('../../utils/message')
|
||||||
const { parseAMBMessage } = require('../../../../commons')
|
const { parseAMBMessage } = require('../../../../commons')
|
||||||
const estimateGas = require('./estimateGas')
|
const estimateGas = require('./estimateGas')
|
||||||
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
||||||
@ -63,8 +63,7 @@ function processCollectedSignaturesBuilder(config) {
|
|||||||
v.push(vrs.v)
|
v.push(vrs.v)
|
||||||
r.push(vrs.r)
|
r.push(vrs.r)
|
||||||
s.push(vrs.s)
|
s.push(vrs.s)
|
||||||
const recover = signatureToVRSAMB(signature)
|
signaturesArray.push(vrs)
|
||||||
signaturesArray.push(recover)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(signaturePromises)
|
await Promise.all(signaturePromises)
|
||||||
|
@ -9,9 +9,18 @@ const logger = require('../../services/logger').child({
|
|||||||
const web3 = new Web3()
|
const web3 = new Web3()
|
||||||
const { toBN } = Web3.utils
|
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 {
|
try {
|
||||||
const gasEstimate = await foreignBridge.methods.executeSignatures(v, r, s, message).estimateGas()
|
const gasEstimate = await foreignBridge.methods.executeSignatures(message, signatures).estimateGas()
|
||||||
return gasEstimate
|
return gasEstimate
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof HttpListProviderError) {
|
if (e instanceof HttpListProviderError) {
|
||||||
@ -35,7 +44,7 @@ async function estimateGas({ foreignBridge, validatorContract, message, numberOf
|
|||||||
|
|
||||||
// check if all the signatures were made by validators
|
// check if all the signatures were made by validators
|
||||||
for (let i = 0; i < v.length; i++) {
|
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')
|
logger.debug({ address }, 'Check that signature is from a validator')
|
||||||
const isValidator = await validatorContract.methods.isValidator(address).call()
|
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 { BRIDGE_VALIDATORS_ABI } = require('../../../../commons')
|
||||||
const rootLogger = require('../../services/logger')
|
const rootLogger = require('../../services/logger')
|
||||||
const { web3Home, web3Foreign } = require('../../services/web3')
|
const { web3Home, web3Foreign } = require('../../services/web3')
|
||||||
const { signatureToVRS } = require('../../utils/message')
|
const { signatureToVRS, packSignatures } = require('../../utils/message')
|
||||||
const estimateGas = require('./estimateGas')
|
const estimateGas = require('./estimateGas')
|
||||||
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
||||||
const { MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
const { MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||||
@ -52,18 +52,21 @@ function processCollectedSignaturesBuilder(config) {
|
|||||||
requiredSignatures.length = NumberOfCollectedSignatures
|
requiredSignatures.length = NumberOfCollectedSignatures
|
||||||
requiredSignatures.fill(0)
|
requiredSignatures.fill(0)
|
||||||
|
|
||||||
|
const signaturesArray = []
|
||||||
const [v, r, s] = [[], [], []]
|
const [v, r, s] = [[], [], []]
|
||||||
logger.debug('Getting message signatures')
|
logger.debug('Getting message signatures')
|
||||||
const signaturePromises = requiredSignatures.map(async (el, index) => {
|
const signaturePromises = requiredSignatures.map(async (el, index) => {
|
||||||
logger.debug({ index }, 'Getting message signature')
|
logger.debug({ index }, 'Getting message signature')
|
||||||
const signature = await homeBridge.methods.signature(messageHash, index).call()
|
const signature = await homeBridge.methods.signature(messageHash, index).call()
|
||||||
const recover = signatureToVRS(signature)
|
const vrs = signatureToVRS(signature)
|
||||||
v.push(recover.v)
|
v.push(vrs.v)
|
||||||
r.push(recover.r)
|
r.push(vrs.r)
|
||||||
s.push(recover.s)
|
s.push(vrs.s)
|
||||||
|
signaturesArray.push(vrs)
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(signaturePromises)
|
await Promise.all(signaturePromises)
|
||||||
|
const signatures = packSignatures(signaturesArray)
|
||||||
|
|
||||||
let gasEstimate
|
let gasEstimate
|
||||||
try {
|
try {
|
||||||
@ -74,6 +77,7 @@ function processCollectedSignaturesBuilder(config) {
|
|||||||
v,
|
v,
|
||||||
r,
|
r,
|
||||||
s,
|
s,
|
||||||
|
signatures,
|
||||||
message,
|
message,
|
||||||
numberOfCollectedSignatures: NumberOfCollectedSignatures
|
numberOfCollectedSignatures: NumberOfCollectedSignatures
|
||||||
})
|
})
|
||||||
@ -92,7 +96,7 @@ function processCollectedSignaturesBuilder(config) {
|
|||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const data = await foreignBridge.methods.executeSignatures(v, r, s, message).encodeABI()
|
const data = await foreignBridge.methods.executeSignatures(message, signatures).encodeABI()
|
||||||
txToSend.push({
|
txToSend.push({
|
||||||
data,
|
data,
|
||||||
gasEstimate,
|
gasEstimate,
|
||||||
|
@ -50,17 +50,9 @@ function parseMessage(message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function signatureToVRS(signature) {
|
function signatureToVRS(rawSignature) {
|
||||||
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) {
|
|
||||||
const signature = strip0x(rawSignature)
|
const signature = strip0x(rawSignature)
|
||||||
|
assert.strictEqual(signature.length, 2 + 32 * 2 + 32 * 2)
|
||||||
const v = signature.substr(64 * 2)
|
const v = signature.substr(64 * 2)
|
||||||
const r = signature.substr(0, 32 * 2)
|
const r = signature.substr(0, 32 * 2)
|
||||||
const s = signature.substr(32 * 2, 32 * 2)
|
const s = signature.substr(32 * 2, 32 * 2)
|
||||||
@ -85,6 +77,5 @@ module.exports = {
|
|||||||
createMessage,
|
createMessage,
|
||||||
parseMessage,
|
parseMessage,
|
||||||
signatureToVRS,
|
signatureToVRS,
|
||||||
signatureToVRSAMB,
|
|
||||||
packSignatures
|
packSignatures
|
||||||
}
|
}
|
||||||
|
@ -259,9 +259,9 @@ describe('message utils', () => {
|
|||||||
const { v, r, s } = signatureToVRS(signature)
|
const { v, r, s } = signatureToVRS(signature)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(v).to.equal(27)
|
expect(v).to.equal('1b')
|
||||||
expect(r).to.equal('0xed157c39b80281741e7d4075655f25b11a9182f12d90878a1ba9bfed111c8996')
|
expect(r).to.equal('ed157c39b80281741e7d4075655f25b11a9182f12d90878a1ba9bfed111c8996')
|
||||||
expect(s).to.equal('0x20b74dc25ba2f581be753e11673413eb90f1f08285c2100d8e16c6799818c77d')
|
expect(s).to.equal('20b74dc25ba2f581be753e11673413eb90f1f08285c2100d8e16c6799818c77d')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should fail if signature is too short', () => {
|
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 sinon = require('sinon')
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const { HttpListProviderError } = require('http-list-provider')
|
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 estimateGas = require('../src/events/processCollectedSignatures/estimateGas')
|
||||||
const errors = require('../src/utils/errors')
|
const errors = require('../src/utils/errors')
|
||||||
|
|
||||||
@ -116,10 +116,11 @@ describe('processCollectedSignatures', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const message = randomMessage()
|
const message = randomMessage()
|
||||||
const { v, r, s } = web3.eth.accounts.sign(
|
const { signature } = web3.eth.accounts.sign(
|
||||||
message,
|
message,
|
||||||
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
|
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
|
||||||
)
|
)
|
||||||
|
const { v, r, s } = signatureToVRS(signature)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const result = estimateGas({
|
const result = estimateGas({
|
||||||
@ -155,10 +156,11 @@ describe('processCollectedSignatures', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const message = randomMessage()
|
const message = randomMessage()
|
||||||
const { v, r, s } = web3.eth.accounts.sign(
|
const { signature } = web3.eth.accounts.sign(
|
||||||
message,
|
message,
|
||||||
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
|
'0xf41510ea3e58c22cbabe881c9c87e60078dac25b23f93319e355c9ae0562987a'
|
||||||
)
|
)
|
||||||
|
const { v, r, s } = signatureToVRS(signature)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const result = estimateGas({
|
const result = estimateGas({
|
||||||
|
Loading…
Reference in New Issue
Block a user