From 07e3d3258a66cf1f06785c21be44a649718a81f4 Mon Sep 17 00:00:00 2001 From: koloz193 Date: Thu, 11 Jul 2024 15:47:43 -0400 Subject: [PATCH] Update execute batches to allow for default before priority tree (#610) --- .../chain-deps/facets/Executor.sol | 8 +++++--- .../unit/concrete/Executor/Executing.t.sol | 18 ++++++++++++------ .../test/foundry/unit/concrete/Utils/Utils.sol | 10 ++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/l1-contracts/contracts/state-transition/chain-deps/facets/Executor.sol b/l1-contracts/contracts/state-transition/chain-deps/facets/Executor.sol index df540b4dc..7c5909528 100644 --- a/l1-contracts/contracts/state-transition/chain-deps/facets/Executor.sol +++ b/l1-contracts/contracts/state-transition/chain-deps/facets/Executor.sol @@ -392,13 +392,15 @@ contract ExecutorFacet is ZkSyncHyperchainBase, IExecutor { PriorityOpsBatchInfo[] calldata _priorityOpsData ) internal { uint256 nBatches = _batchesData.length; - uint256 dataIndex = 0; + require(_batchesData.length == _priorityOpsData.length, "bp"); for (uint256 i = 0; i < nBatches; i = i.uncheckedInc()) { if (s.priorityTree.startIndex <= s.priorityQueue.getFirstUnprocessedPriorityTx()) { - // solhint-disable-next-line gas-increment-by-one - _executeOneBatch(_batchesData[i], _priorityOpsData[dataIndex++], i); + _executeOneBatch(_batchesData[i], _priorityOpsData[i], i); } else { + require(_priorityOpsData[i].leftPath.length == 0, "le"); + require(_priorityOpsData[i].rightPath.length == 0, "re"); + require(_priorityOpsData[i].itemHashes.length == 0, "ih"); _executeOneBatch(_batchesData[i], i); } emit BlockExecution(_batchesData[i].batchNumber, _batchesData[i].batchHash, _batchesData[i].commitment); diff --git a/l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol b/l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol index 131746fa8..5f5c4b9d8 100644 --- a/l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol +++ b/l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol @@ -103,7 +103,7 @@ contract ExecutingTest is ExecutorTest { vm.prank(validator); vm.expectRevert(bytes.concat("k")); - executor.executeBatches(storedBatchInfoArray, Utils.emptyData()); + executor.executeBatches(storedBatchInfoArray, Utils.generatePriorityOps(storedBatchInfoArray.length)); } function test_RevertWhen_ExecutingBlockWithWrongData() public { @@ -115,7 +115,7 @@ contract ExecutingTest is ExecutorTest { vm.prank(validator); vm.expectRevert(bytes.concat("exe10")); - executor.executeBatches(storedBatchInfoArray, Utils.emptyData()); + executor.executeBatches(storedBatchInfoArray, Utils.generatePriorityOps(storedBatchInfoArray.length)); } function test_RevertWhen_ExecutingRevertedBlockWithoutCommittingAndProvingAgain() public { @@ -127,7 +127,7 @@ contract ExecutingTest is ExecutorTest { vm.prank(validator); vm.expectRevert(bytes.concat("n")); - executor.executeBatches(storedBatchInfoArray, Utils.emptyData()); + executor.executeBatches(storedBatchInfoArray, Utils.generatePriorityOps(storedBatchInfoArray.length)); } function test_RevertWhen_ExecutingUnavailablePriorityOperationHash() public { @@ -185,7 +185,10 @@ contract ExecutingTest is ExecutorTest { vm.prank(validator); vm.expectRevert(bytes.concat("s")); - executor.executeBatches(correctNewStoredBatchInfoArray, Utils.emptyData()); + executor.executeBatches( + correctNewStoredBatchInfoArray, + Utils.generatePriorityOps(correctNewStoredBatchInfoArray.length) + ); } function test_RevertWhen_ExecutingWithUnmatchedPriorityOperationHash() public { @@ -263,7 +266,10 @@ contract ExecutingTest is ExecutorTest { vm.prank(validator); vm.expectRevert(bytes.concat("x")); - executor.executeBatches(correctNewStoredBatchInfoArray, Utils.emptyData()); + executor.executeBatches( + correctNewStoredBatchInfoArray, + Utils.generatePriorityOps(correctNewStoredBatchInfoArray.length) + ); } function test_RevertWhen_CommittingBlockWithWrongPreviousBatchHash() public { @@ -297,7 +303,7 @@ contract ExecutingTest is ExecutorTest { storedBatchInfoArray[0] = newStoredBatchInfo; vm.prank(validator); - executor.executeBatches(storedBatchInfoArray, Utils.emptyData()); + executor.executeBatches(storedBatchInfoArray, Utils.generatePriorityOps(storedBatchInfoArray.length)); uint256 totalBlocksExecuted = getters.getTotalBlocksExecuted(); assertEq(totalBlocksExecuted, 1); diff --git a/l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol b/l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol index 97a5169ca..7b7ad25be 100644 --- a/l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol +++ b/l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol @@ -518,6 +518,16 @@ library Utils { } } + function generatePriorityOps(uint256 len) internal pure returns (PriorityOpsBatchInfo[] memory _ops) { + _ops = new PriorityOpsBatchInfo[](len); + bytes32[] memory empty; + PriorityOpsBatchInfo memory info = PriorityOpsBatchInfo({leftPath: empty, rightPath: empty, itemHashes: empty}); + + for (uint256 i = 0; i < len; ++i) { + _ops[i] = info; + } + } + // add this to be excluded from coverage report function test() internal {} }