Skip to content

Commit

Permalink
Merge pull request #106 from zkLinkProtocol/issue_105
Browse files Browse the repository at this point in the history
fix execute index bug of slaver chain
  • Loading branch information
zkbenny authored Dec 2, 2023
2 parents e3808f4 + d9f09d0 commit 07970b0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions contracts/ZkLink.sol
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,10 @@ contract ZkLink is ReentrancyGuard, Storage, Events, UpgradeableMaster {

uint64 priorityRequestsExecuted = 0;
for (uint32 i = 0; i < nBlocks; ++i) {
uint32 _executedBlockIdx = _totalBlocksExecuted + i + 1;
ExecuteBlockInfo memory _blockExecuteData = _blocksData[i];
require(_blockExecuteData.storedBlock.blockNumber == _totalBlocksExecuted + i + 1, "d2");
executeOneBlock(_blockExecuteData);
require(_blockExecuteData.storedBlock.blockNumber == _executedBlockIdx, "d2");
executeOneBlock(_blockExecuteData, _executedBlockIdx);
priorityRequestsExecuted = priorityRequestsExecuted + _blockExecuteData.storedBlock.priorityOperations;
}

Expand Down Expand Up @@ -612,10 +613,11 @@ contract ZkLink is ReentrancyGuard, Storage, Events, UpgradeableMaster {
uint64 priorityRequestsExecuted = 0;
uint32 latestExecutedBlockNumber = _latestExecutedBlockData.blockNumber;
for (uint32 i = 0; i < nBlocks; ++i) {
uint32 _executedBlockIdx = _totalBlocksExecuted + i + 1;
ExecuteBlockInfo memory _blockExecuteData = _blocksData[i];
require(_blockExecuteData.storedBlock.preCommittedBlockNumber == latestExecutedBlockNumber, "d2");

executeOneBlock(_blockExecuteData);
executeOneBlock(_blockExecuteData, _executedBlockIdx);
priorityRequestsExecuted = priorityRequestsExecuted + _blockExecuteData.storedBlock.priorityOperations;
latestExecutedBlockNumber = _blockExecuteData.storedBlock.blockNumber;
}
Expand Down Expand Up @@ -756,11 +758,11 @@ contract ZkLink is ReentrancyGuard, Storage, Events, UpgradeableMaster {
/// 1. Processes all pending operations (Send Exits, Complete priority requests)
/// 2. Finalizes block on Ethereum
/// _executedBlockIdx is index in the array of the blocks that we want to execute together
function executeOneBlock(ExecuteBlockInfo memory _blockExecuteData) internal {
function executeOneBlock(ExecuteBlockInfo memory _blockExecuteData, uint32 _executedBlockIdx) internal {
// Ensure block was committed
require(
hashStoredBlockInfo(_blockExecuteData.storedBlock) ==
storedBlockHashes[_blockExecuteData.storedBlock.blockNumber],
storedBlockHashes[_executedBlockIdx],
"m0"
);

Expand Down

0 comments on commit 07970b0

Please sign in to comment.