From f35bdb84722dbd01535da5542a0ec7c1fb96e5c7 Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:52:05 +0000 Subject: [PATCH] refactor: Remove unnecessary computation (#4133) The merkle tree computations were done a bit hastily so seems like it was forgotten to reduce how much was computed. Not producing unexpected results, just computing unused hashes, so this pr is removing those unneeded computations. --- l1-contracts/src/core/libraries/decoders/Decoder.sol | 1 + l1-contracts/src/core/libraries/decoders/TxsDecoder.sol | 1 + 2 files changed, 2 insertions(+) diff --git a/l1-contracts/src/core/libraries/decoders/Decoder.sol b/l1-contracts/src/core/libraries/decoders/Decoder.sol index 178e91acda2..39efa07f04d 100644 --- a/l1-contracts/src/core/libraries/decoders/Decoder.sol +++ b/l1-contracts/src/core/libraries/decoders/Decoder.sol @@ -385,6 +385,7 @@ library Decoder { for (uint256 j = 0; j < treeSize; j += 2) { _leafs[j / 2] = sha256(bytes.concat(_leafs[j], _leafs[j + 1])); } + treeSize /= 2; } return _leafs[0]; diff --git a/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol b/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol index c58b10b377e..93bb8d922d4 100644 --- a/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol +++ b/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol @@ -268,6 +268,7 @@ library TxsDecoder { for (uint256 j = 0; j < treeSize; j += 2) { _leafs[j / 2] = sha256(bytes.concat(_leafs[j], _leafs[j + 1])); } + treeSize /= 2; } return _leafs[0];