Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed May 30, 2024
1 parent 129684c commit 61d1a35
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridgehub/IMessageRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import {IBridgehub} from "./IBridgehub.sol";
interface IMessageRoot {
function BRIDGE_HUB() external view returns (IBridgehub);

// function chainMessageRoot(uint256 _chainId) external view returns (bytes32);
function chainMessageRoot(uint256 _chainId) external view returns (bytes32);
}
20 changes: 12 additions & 8 deletions l1-contracts/contracts/bridgehub/MessageRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ contract MessageRoot is IMessageRoot, ReentrancyGuard, Ownable2StepUpgradeable,
/// @dev Bridgehub smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication.
IBridgehub public immutable override BRIDGE_HUB;

FullMerkle.FullTree public sharedTree;

/// @dev the incremental merkle tree storing the chain message roots
mapping(uint256 chainId => DynamicIncrementalMerkle.Bytes32PushTree tree) internal chainTree;
uint256 public chainCount;

mapping(uint256 chainId => uint256 chainIndex) public chainIndex;

uint256 public chainCount;

mapping(uint256 chainIndex => uint256 chainId) public chainIndexToId;

FullMerkle.FullTree public sharedTree;

/// @dev the incremental merkle tree storing the chain message roots
mapping(uint256 chainId => DynamicIncrementalMerkle.Bytes32PushTree tree) internal chainTree;

/// @notice only the bridgehub can call
modifier onlyBridgehub() {
require(msg.sender == address(BRIDGE_HUB), "MR: only bridgehub");
Expand All @@ -54,16 +54,20 @@ contract MessageRoot is IMessageRoot, ReentrancyGuard, Ownable2StepUpgradeable,
BRIDGE_HUB = _bridgehub;
}

function chainMessageRoot(uint256 _chainId) external view override returns (bytes32) {
return chainTree[_chainId].root();
}

/// @dev add a new chainBatchRoot to the chainTree
function addChainBatchRoot(
uint256 _chainId,
bytes32 _chainBatchRoot,
bool _updateFMT
bool _updateFullTree
) external onlyChain(_chainId) {
bytes32 chainRoot;
(, chainRoot) = chainTree[_chainId].push(_chainBatchRoot);

if (_updateFMT) {
if (_updateFullTree) {
sharedTree.updateLeaf(chainIndex[_chainId], chainRoot);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,8 @@ library DynamicIncrementalMerkle {
/**
* @dev Tree's height (set at initialization)
*/
function height(Bytes32PushTree storage self) internal view returns (uint256) {
return self._height;
}

function root(Bytes32PushTree storage self) internal view returns (bytes32) {
return Arrays.unsafeAccess(self._sides, self._height).value;
}

function nextLeafIndex(Bytes32PushTree storage self) internal view returns (uint256) {
return self._nextLeafIndex;
}

function side(Bytes32PushTree storage self, uint256 i) internal view returns (bytes32) {
return Arrays.unsafeAccess(self._sides, i).value;
}

function zeros(Bytes32PushTree storage self, uint256 i) internal view returns (bytes32) {
return Arrays.unsafeAccess(self._zeros, i).value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
pragma solidity 0.8.24;

import {DynamicIncrementalMerkle} from "../../common/libraries/openzeppelin/IncrementalMerkle.sol";
import {Arrays} from "../../common/libraries/openzeppelin/Arrays.sol";


contract IncrementalMerkleTest {
using DynamicIncrementalMerkle for DynamicIncrementalMerkle.Bytes32PushTree;
Expand All @@ -22,18 +24,18 @@ contract IncrementalMerkleTest {
}

function height() external view returns (uint256) {
return tree.height();
return tree._height;
}

function index() external view returns (uint256) {
return tree.nextLeafIndex();
return tree._nextLeafIndex;
}

function side(uint256 _index) external view returns (bytes32) {
return tree.side(_index);
return Arrays.unsafeAccess(tree._sides, _index).value;
}

function zeros(uint256 _index) external view returns (bytes32) {
return tree.zeros(_index);
return Arrays.unsafeAccess(tree._zeros, _index).value;
}
}

0 comments on commit 61d1a35

Please sign in to comment.