From f7bca0848055ef1e3e7711e49f5e6429d6cd6c31 Mon Sep 17 00:00:00 2001
From: poma <Semenov.Roman@mail.ru>
Date: Thu, 18 Jul 2019 16:30:24 +0300
Subject: [PATCH] Check merkle root

---
 index.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/index.js b/index.js
index 559d19f..23951ff 100644
--- a/index.js
+++ b/index.js
@@ -42,6 +42,11 @@ app.post('/relay', async (req, resp) => {
     if (isSpent) {
       throw new Error('The note has been spent')
     }
+    const root = publicSignals[0]
+    const isKnownRoot = await mixer.methods.isKnownRoot(root).call()
+    if (!isKnownRoot) {
+      throw new Error('The merkle root is too old or invalid')
+    }
     const gas = await mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).estimateGas()
     const result = mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).send({
       gas: numberToHex(gas + 50000),