diff --git a/oracle/src/events/processAMBCollectedSignatures/estimateGas.js b/oracle/src/events/processAMBCollectedSignatures/estimateGas.js index 5b3c7504..a87e504d 100644 --- a/oracle/src/events/processAMBCollectedSignatures/estimateGas.js +++ b/oracle/src/events/processAMBCollectedSignatures/estimateGas.js @@ -20,13 +20,14 @@ async function estimateGas({ v, r, s, + signatures, txHash, address, gasPrice }) { try { const gasEstimate = await foreignBridge.methods - .executeSignatures(message, v, r, s) + .executeSignatures(message, signatures) .estimateGas({ from: address, gasPrice diff --git a/oracle/src/events/processAMBCollectedSignatures/index.js b/oracle/src/events/processAMBCollectedSignatures/index.js index e9ffa889..51383492 100644 --- a/oracle/src/events/processAMBCollectedSignatures/index.js +++ b/oracle/src/events/processAMBCollectedSignatures/index.js @@ -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 } = require('../../utils/message') +const { signatureToVRS, signatureToVRSAMB, packSignatures } = require('../../utils/message') const { parseAMBMessage } = require('../../../../commons') const { generateGasPriceOptions } = require('../../utils/utils') const estimateGas = require('./estimateGas') @@ -64,18 +64,22 @@ 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) + const recover = signatureToVRSAMB(signature) + signaturesArray.push(recover) }) await Promise.all(signaturePromises) + const signatures = packSignatures(signaturesArray) const { dataType, gasPrice, gasPriceSpeed, txHash } = parseAMBMessage(message) @@ -88,6 +92,7 @@ function processCollectedSignaturesBuilder(config) { v, r, s, + signatures, message, numberOfCollectedSignatures: NumberOfCollectedSignatures, txHash, diff --git a/oracle/src/utils/message.js b/oracle/src/utils/message.js index a97328e0..2a2966ff 100644 --- a/oracle/src/utils/message.js +++ b/oracle/src/utils/message.js @@ -68,8 +68,32 @@ function signatureToVRS(signature) { return { v, r, s } } +function signatureToVRSAMB(rawSignature) { + const signature = strip0x(rawSignature) + const v = signature.substr(64 * 2) + const r = signature.substr(0, 32 * 2) + const s = signature.substr(32 * 2, 32 * 2) + return { v, r, s } +} + +function packSignatures(array) { + const length = Web3Utils.toHex(array.length) + let v = '' + let r = '' + let s = '' + array.forEach(e => { + v = v.concat(e.v) + r = r.concat(e.r) + s = s.concat(e.s) + }) + + return `${length}${v}${r}${s}` +} + module.exports = { createMessage, parseMessage, - signatureToVRS + signatureToVRS, + signatureToVRSAMB, + packSignatures }