-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
…a-contracts into bh/full-merkle-tests
- Loading branch information
Showing
45 changed files
with
2,213 additions
and
885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,8 +92,8 @@ jobs: | |
- name: Run Era test node | ||
uses: dutterbutter/[email protected] | ||
|
||
- name: Copy typechain | ||
run: yarn sc copy:typechain | ||
- name: Copy typechain from System Contracts | ||
run: yarn sc build && yarn sc copy:typechain | ||
|
||
- name: Run tests | ||
run: yarn l2 test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,7 @@ pragma solidity 0.8.24; | |
// solhint-disable reason-string, gas-custom-errors | ||
|
||
import {UncheckedMath} from "../../common/libraries/UncheckedMath.sol"; | ||
// This importing issue should not be pushed to main, we only need this while we did not import OZ-v5 and v4 in parallel. Once we merge that it will be removed | ||
import {Arrays} from "./openzeppelin/Arrays.sol"; | ||
import {Hashes} from "./openzeppelin/Hashes.sol"; | ||
import {Merkle} from "./Merkle.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -22,7 +20,7 @@ library FullMerkle { | |
} | ||
|
||
/** | ||
* @dev Initialize a {Bytes32PushTree} using {Hashes-Keccak256} to hash internal nodes. | ||
* @dev Initialize a {Bytes32PushTree} using {Merkle.efficientHash} to hash internal nodes. | ||
* The capacity of the tree (i.e. number of leaves) is set to `2**levels`. | ||
* | ||
* Calling this function on MerkleTree that was already setup and used will reset it to a blank state. | ||
|
@@ -32,8 +30,7 @@ library FullMerkle { | |
*/ | ||
function setup(FullTree storage self, bytes32 zero) internal returns (bytes32 initialRoot) { | ||
// Store depth in the dynamic array | ||
Arrays.unsafeSetLength(self._zeros, 1); | ||
Arrays.unsafeAccess(self._zeros, 0).value = zero; | ||
self._zeros.push(zero); | ||
self._nodes.push([zero]); | ||
|
||
return zero; | ||
|
@@ -47,7 +44,7 @@ library FullMerkle { | |
uint256 newHeight = self._height.uncheckedInc(); | ||
self._height = newHeight; | ||
bytes32 topZero = self._zeros[newHeight - 1]; | ||
bytes32 newZero = Hashes.Keccak256(topZero, topZero); | ||
bytes32 newZero = Merkle.efficientHash(topZero, topZero); | ||
self._zeros.push(newZero); | ||
self._nodes.push([newZero]); | ||
} | ||
|
@@ -74,12 +71,12 @@ library FullMerkle { | |
bytes32 currentHash = _itemHash; | ||
for (uint256 i; i < self._height; i = i.uncheckedInc()) { | ||
if (_index % 2 == 0) { | ||
currentHash = Hashes.Keccak256( | ||
currentHash = Merkle.efficientHash( | ||
currentHash, | ||
maxNodeNumber == _index ? self._zeros[i] : self._nodes[i][_index + 1] | ||
); | ||
} else { | ||
currentHash = Hashes.Keccak256(self._nodes[i][_index - 1], currentHash); | ||
currentHash = Merkle.efficientHash(self._nodes[i][_index - 1], currentHash); | ||
} | ||
_index /= 2; | ||
maxNodeNumber /= 2; | ||
|
@@ -112,10 +109,10 @@ library FullMerkle { | |
self._nodes[_height][i] = _newNodes[i]; | ||
if (i + 1 < length) { | ||
self._nodes[_height][i + 1] = _newNodes[i + 1]; | ||
_newRow[i / 2] = Hashes.Keccak256(_newNodes[i], _newNodes[i + 1]); | ||
_newRow[i / 2] = Merkle.efficientHash(_newNodes[i], _newNodes[i + 1]); | ||
} else { | ||
// Handle odd number of nodes by hashing the last node with zero | ||
_newRow[i / 2] = Hashes.Keccak256(_newNodes[i], self._zeros[_height]); | ||
_newRow[i / 2] = Merkle.efficientHash(_newNodes[i], self._zeros[_height]); | ||
} | ||
} | ||
return updateAllNodesAtHeight(self, _height + 1, _newRow); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.