Pack signatures when processing amb collectedSignatures event in Oracle

This commit is contained in:
Gerardo Nardelli 2019-08-22 11:06:44 -03:00
parent ab5166b895
commit 43609d739d
3 changed files with 37 additions and 7 deletions

@ -20,13 +20,14 @@ async function estimateGas({
v, v,
r, r,
s, s,
signatures,
txHash, txHash,
address, address,
gasPrice gasPrice
}) { }) {
try { try {
const gasEstimate = await foreignBridge.methods const gasEstimate = await foreignBridge.methods
.executeSignatures(message, v, r, s) .executeSignatures(message, signatures)
.estimateGas({ .estimateGas({
from: address, from: address,
gasPrice gasPrice

@ -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 } = require('../../utils/message') const { signatureToVRS, signatureToVRSAMB, packSignatures } = require('../../utils/message')
const { parseAMBMessage } = require('../../../../commons') const { parseAMBMessage } = require('../../../../commons')
const { generateGasPriceOptions } = require('../../utils/utils') const { generateGasPriceOptions } = require('../../utils/utils')
const estimateGas = require('./estimateGas') const estimateGas = require('./estimateGas')
@ -64,18 +64,22 @@ 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)
const recover = signatureToVRSAMB(signature)
signaturesArray.push(recover)
}) })
await Promise.all(signaturePromises) await Promise.all(signaturePromises)
const signatures = packSignatures(signaturesArray)
const { dataType, gasPrice, gasPriceSpeed, txHash } = parseAMBMessage(message) const { dataType, gasPrice, gasPriceSpeed, txHash } = parseAMBMessage(message)
@ -88,6 +92,7 @@ function processCollectedSignaturesBuilder(config) {
v, v,
r, r,
s, s,
signatures,
message, message,
numberOfCollectedSignatures: NumberOfCollectedSignatures, numberOfCollectedSignatures: NumberOfCollectedSignatures,
txHash, txHash,

@ -68,8 +68,32 @@ function signatureToVRS(signature) {
return { v, r, s } 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 = { module.exports = {
createMessage, createMessage,
parseMessage, parseMessage,
signatureToVRS signatureToVRS,
signatureToVRSAMB,
packSignatures
} }