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,
r,
s,
signatures,
txHash,
address,
gasPrice
}) {
try {
const gasEstimate = await foreignBridge.methods
.executeSignatures(message, v, r, s)
.executeSignatures(message, signatures)
.estimateGas({
from: address,
gasPrice

@ -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,

@ -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
}