From a3bf8819dddba4b8e5b96cadee825057fb25e87a Mon Sep 17 00:00:00 2001 From: Sladuca Date: Fri, 4 Aug 2023 14:26:20 -0400 Subject: [PATCH] add comment tying together subtreeupdate circuit & OffchainMerkle --- packages/contracts/contracts/libs/OffchainMerkleTree.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/contracts/contracts/libs/OffchainMerkleTree.sol b/packages/contracts/contracts/libs/OffchainMerkleTree.sol index c42aaadae0..e98355723d 100644 --- a/packages/contracts/contracts/libs/OffchainMerkleTree.sol +++ b/packages/contracts/contracts/libs/OffchainMerkleTree.sol @@ -86,6 +86,14 @@ library LibOffchainMerkleTree { ) internal { uint256[] memory pis = _calculatePublicInputs(self, newRoot); + // 1) this library computes accumulatorHash on its own, + // the definition of accumulatorHash prevents collisions (different batch with same hash), + // and the subtree update circuit guarantees `accumulatorHash` is re-computed correctly, + // so if the circuit accepts, the only possible batch the updater could be inserting is precisely + // the batch we've enqueued here on-chain + // 2) the subtree update circuit guarantees that the new root is computed correctly, + // so due to (1), the only possible newRoot is the newRoot that results from inserting + // the batch we've enqueued here on-chain require( self.subtreeUpdateVerifier.verifyProof(proof, pis), "subtree update proof invalid"