Skip to content

Commit

Permalink
Update execute batches to allow for default before priority tree (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
koloz193 authored Jul 11, 2024
1 parent 2aab26a commit 07e3d32
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions l1-contracts/test/foundry/unit/concrete/Executor/Executing.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}

0 comments on commit 07e3d32

Please sign in to comment.