single array proof
This commit is contained in:
parent
45414ae010
commit
9449e2a8b6
6
index.js
6
index.js
@ -52,7 +52,7 @@ app.post('/relay', async (req, resp) => {
|
|||||||
return resp.status(400).json({ error: 'This relayer does not support the token' })
|
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)}`)
|
const relayer = toChecksumAddress(`0x${publicSignals[3].slice(26)}`)
|
||||||
if (relayer !== web3.eth.defaultAccount) {
|
if (relayer !== web3.eth.defaultAccount) {
|
||||||
@ -95,8 +95,8 @@ app.post('/relay', async (req, resp) => {
|
|||||||
if (!isKnownRoot) {
|
if (!isKnownRoot) {
|
||||||
return resp.status(400).json({ error: 'The merkle root is too old or invalid.' })
|
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 gas = await mixer.methods.withdraw(proof, publicSignals).estimateGas({ value: refund })
|
||||||
const result = mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).send({
|
const result = mixer.methods.withdraw(proof, publicSignals).send({
|
||||||
value: refund,
|
value: refund,
|
||||||
gas: numberToHex(gas + 50000),
|
gas: numberToHex(gas + 50000),
|
||||||
gasPrice: toHex(toWei(gasPrices.fast.toString(), 'gwei')),
|
gasPrice: toHex(toWei(gasPrices.fast.toString(), 'gwei')),
|
||||||
|
27
utils.js
27
utils.js
@ -45,42 +45,25 @@ async function fetchDAIprice({ ethPriceInDai, web3 }) {
|
|||||||
function isValidProof(proof) {
|
function isValidProof(proof) {
|
||||||
// validator expects `websnarkUtils.toSolidityInput(proof)` output
|
// validator expects `websnarkUtils.toSolidityInput(proof)` output
|
||||||
|
|
||||||
if (!(proof.pi_a && proof.pi_b && proof.pi_c && proof.publicSignals)) {
|
if (!(proof.proof && proof.publicSignals)) {
|
||||||
return { valid: false, reason: 'One of inputs is empty. There must be pi_a, pi_b, pi_c and publicSignals' }
|
return { valid: false, reason: 'One of inputs is empty. There must be proof and publicSignals' }
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(proof).forEach(key => {
|
Object.keys(proof).forEach(key => {
|
||||||
if (!Array.isArray(proof[key])) {
|
if (!Array.isArray(proof[key])) {
|
||||||
return { valid: false, reason: `Corrupted ${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) {
|
if (proof.proof.length !== 8) {
|
||||||
return { valid: false, reason: 'Corrupted pi_a' }
|
return { valid: false, reason: 'Corrupted proof' }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proof.pi_b.length !== 2 || proof.pi_b[0].length !== 2 || proof.pi_b[1].length !== 2) {
|
if (proof.publicSignals.length !== 6) {
|
||||||
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) {
|
|
||||||
return { valid: false, reason: 'Corrupted publicSignals' }
|
return { valid: false, reason: 'Corrupted publicSignals' }
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let [key, input] of Object.entries(proof)) {
|
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++ ) {
|
for (let i = 0; i < input.length; i++ ) {
|
||||||
if (!isHexStrict(input[i]) || input[i].length !== 66) {
|
if (!isHexStrict(input[i]) || input[i].length !== 66) {
|
||||||
return { valid: false, reason: `Corrupted ${key}` }
|
return { valid: false, reason: `Corrupted ${key}` }
|
||||||
|
Loading…
Reference in New Issue
Block a user