single array proof

This commit is contained in:
poma 2019-10-06 10:55:24 +03:00
parent 45414ae010
commit 9449e2a8b6
2 changed files with 8 additions and 25 deletions

@ -52,7 +52,7 @@ app.post('/relay', async (req, resp) => {
return resp.status(400).json({ error: 'This relayer does not support the token' })
}
let { pi_a, pi_b, pi_c, publicSignals } = req.body.proof
let { proof, publicSignals } = req.body.proof
const relayer = toChecksumAddress(`0x${publicSignals[3].slice(26)}`)
if (relayer !== web3.eth.defaultAccount) {
@ -95,8 +95,8 @@ app.post('/relay', async (req, resp) => {
if (!isKnownRoot) {
return resp.status(400).json({ error: 'The merkle root is too old or invalid.' })
}
const gas = await mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).estimateGas({ value: refund })
const result = mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).send({
const gas = await mixer.methods.withdraw(proof, publicSignals).estimateGas({ value: refund })
const result = mixer.methods.withdraw(proof, publicSignals).send({
value: refund,
gas: numberToHex(gas + 50000),
gasPrice: toHex(toWei(gasPrices.fast.toString(), 'gwei')),

@ -45,42 +45,25 @@ async function fetchDAIprice({ ethPriceInDai, web3 }) {
function isValidProof(proof) {
// validator expects `websnarkUtils.toSolidityInput(proof)` output
if (!(proof.pi_a && proof.pi_b && proof.pi_c && proof.publicSignals)) {
return { valid: false, reason: 'One of inputs is empty. There must be pi_a, pi_b, pi_c and publicSignals' }
if (!(proof.proof && proof.publicSignals)) {
return { valid: false, reason: 'One of inputs is empty. There must be proof and publicSignals' }
}
Object.keys(proof).forEach(key => {
if (!Array.isArray(proof[key])) {
return { valid: false, reason: `Corrupted ${key}` }
}
if (key === 'pi_b') {
if (!Array.isArray(proof[key][0]) || !Array.isArray(proof[key][1])) {
return { valid: false, reason: `Corrupted ${key}` }
}
}
})
if (proof.pi_a.length !== 2) {
return { valid: false, reason: 'Corrupted pi_a' }
if (proof.proof.length !== 8) {
return { valid: false, reason: 'Corrupted proof' }
}
if (proof.pi_b.length !== 2 || proof.pi_b[0].length !== 2 || proof.pi_b[1].length !== 2) {
return { valid: false, reason: 'Corrupted pi_b' }
}
if (proof.pi_c.length !== 2) {
return { valid: false, reason: 'Corrupted pi_c' }
}
if (proof.publicSignals.length !== 5) {
if (proof.publicSignals.length !== 6) {
return { valid: false, reason: 'Corrupted publicSignals' }
}
for (let [key, input] of Object.entries(proof)) {
if (key === 'pi_b') {
input = input[0].concat(input[1])
}
for (let i = 0; i < input.length; i++ ) {
if (!isHexStrict(input[i]) || input[i].length !== 66) {
return { valid: false, reason: `Corrupted ${key}` }