-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
15 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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol"; | |
import {LibMap} from "./libraries/LibMap.sol"; | ||
import {IExecutor} from "./chain-interfaces/IExecutor.sol"; | ||
import {IStateTransitionManager} from "./IStateTransitionManager.sol"; | ||
import {PriorityOpsBatchInfo} from "./libraries/PriorityTree.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -180,20 +181,39 @@ contract ValidatorTimelock is IExecutor, Ownable2Step { | |
|
||
/// @dev Check that batches were committed at least X time ago and | ||
/// make a call to the hyperchain diamond contract with the same calldata. | ||
function executeBatches(StoredBatchInfo[] calldata _newBatchesData) external onlyValidator(ERA_CHAIN_ID) { | ||
_executeBatchesInner(ERA_CHAIN_ID, _newBatchesData); | ||
} | ||
// function executeBatches(StoredBatchInfo[] calldata _newBatchesData) external onlyValidator(ERA_CHAIN_ID) { | ||
// _executeBatchesInner(ERA_CHAIN_ID, _newBatchesData, emptyPriorityOpsData()); | ||
// } | ||
|
||
/// @dev Check that batches were committed at least X time ago and | ||
/// make a call to the hyperchain diamond contract with the same calldata. | ||
// function executeBatchesSharedBridge( | ||
// uint256 _chainId, | ||
// StoredBatchInfo[] calldata _newBatchesData | ||
// ) external onlyValidator(_chainId) { | ||
// _executeBatchesInner(_chainId, _newBatchesData, emptyPriorityOpsData()); | ||
// } | ||
|
||
function executeBatches( | ||
StoredBatchInfo[] calldata _batchesData, | ||
PriorityOpsBatchInfo[] calldata _priorityOpsData | ||
) external onlyValidator(ERA_CHAIN_ID) { | ||
_executeBatchesInner(ERA_CHAIN_ID, _batchesData, _priorityOpsData); | ||
} | ||
|
||
function executeBatchesSharedBridge( | ||
uint256 _chainId, | ||
StoredBatchInfo[] calldata _newBatchesData | ||
StoredBatchInfo[] calldata _newBatchesData, | ||
PriorityOpsBatchInfo[] calldata _priorityOpsData | ||
) external onlyValidator(_chainId) { | ||
_executeBatchesInner(_chainId, _newBatchesData); | ||
_executeBatchesInner(ERA_CHAIN_ID, _newBatchesData, _priorityOpsData); | ||
} | ||
|
||
function _executeBatchesInner(uint256 _chainId, StoredBatchInfo[] calldata _newBatchesData) internal { | ||
function _executeBatchesInner( | ||
uint256 _chainId, | ||
StoredBatchInfo[] calldata _newBatchesData, | ||
PriorityOpsBatchInfo[] calldata | ||
) internal { | ||
uint256 delay = executionDelay; // uint32 | ||
unchecked { | ||
// solhint-disable-next-line gas-length-in-loops | ||
|
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
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
62 changes: 62 additions & 0 deletions
62
l1-contracts/contracts/state-transition/libraries/PriorityTree.sol
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
import {DynamicIncrementalMerkle} from "../../common/libraries/openzeppelin/IncrementalMerkle.sol"; | ||
import {Merkle} from "./Merkle.sol"; | ||
|
||
struct PriorityOpsBatchInfo { | ||
bytes32[] leftPath; | ||
bytes32[] rightPath; | ||
bytes32[] itemHashes; | ||
} | ||
|
||
library PriorityTree { | ||
using PriorityTree for Tree; | ||
using DynamicIncrementalMerkle for DynamicIncrementalMerkle.Bytes32PushTree; | ||
|
||
struct Tree { | ||
uint256 startIndex; | ||
uint256 unprocessedIndex; // relative to `startIndex` | ||
DynamicIncrementalMerkle.Bytes32PushTree tree; | ||
} | ||
|
||
/// @notice Returns zero if and only if no operations were processed from the queue | ||
/// @return Index of the oldest priority operation that wasn't processed yet | ||
function getFirstUnprocessedPriorityTx(Tree storage _tree) internal view returns (uint256) { | ||
return _tree.startIndex + _tree.unprocessedIndex; | ||
} | ||
|
||
/// @return The total number of priority operations that were added to the priority queue, including all processed ones | ||
function getTotalPriorityTxs(Tree storage _tree) internal view returns (uint256) { | ||
return _tree.startIndex + _tree.tree._nextLeafIndex; | ||
} | ||
|
||
/// @return The total number of unprocessed priority operations in a priority queue | ||
function getSize(Tree storage _tree) internal view returns (uint256) { | ||
return uint256(_tree.tree._nextLeafIndex - _tree.unprocessedIndex); | ||
} | ||
|
||
/// @notice Add the priority operation to the end of the priority queue | ||
function push(Tree storage _tree, bytes32 _hash) internal { | ||
_tree.tree.push(_hash); | ||
} | ||
|
||
function setup(Tree storage _tree, bytes32 _zero, uint256 _startIndex) internal { | ||
_tree.tree.setup(_zero); | ||
_tree.startIndex = _startIndex; | ||
} | ||
|
||
function processBatch( | ||
Tree storage _tree, | ||
PriorityOpsBatchInfo calldata _priorityOpsData | ||
) internal { | ||
bytes32 expectedRoot = Merkle.calculateRoot( | ||
_priorityOpsData.leftPath, | ||
_priorityOpsData.rightPath, | ||
_tree.unprocessedIndex, | ||
_priorityOpsData.itemHashes | ||
); | ||
require(expectedRoot == _tree.tree.root(), ""); | ||
_tree.unprocessedIndex += _priorityOpsData.itemHashes.length; | ||
} | ||
} | ||
|
||
|