Skip to content

Commit

Permalink
Merge pull request #11 from zkLinkProtocol/abdk_audit_6_fix
Browse files Browse the repository at this point in the history
Abdk audit 6 fix
  • Loading branch information
zkbenny authored Jun 19, 2024
2 parents df2abae + 8d52ef8 commit 2fbed2d
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions l1-contracts/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,30 +240,28 @@ contract MailboxFacet is Base, IMailbox {
uint256 gatewayLength = _secondaryChainGateways.length;
bytes[] memory gatewayDataList = new bytes[](gatewayLength);
uint256 totalForwardEthAmount = 0;
unchecked {
for (uint256 i = 0; i < gatewayLength; ++i) {
// Secondary chain should be registered
address _secondaryChainGateway = _secondaryChainGateways[i];
SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway];
require(secondaryChain.valid, "bsc");
uint256 _forwardEthAmount = s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw;
// Withdraw eth amount impossible overflow
totalForwardEthAmount += _forwardEthAmount;
s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0;
// Send range batch root to secondary chain
bytes memory gatewayCallData = abi.encodeCall(
IZkLink.syncRangeBatchRoot,
(_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount)
);
gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData);
emit SyncRangeBatchRoot(
_secondaryChainGateway,
_fromBatchNumber,
_toBatchNumber,
rangeBatchRootHash,
_forwardEthAmount
);
}
for (uint256 i = 0; i < gatewayLength; i = i.uncheckedInc()) {
// Secondary chain should be registered
address _secondaryChainGateway = _secondaryChainGateways[i];
SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway];
require(secondaryChain.valid, "bsc");
uint256 _forwardEthAmount = secondaryChain.totalPendingWithdraw;
// Withdraw eth amount impossible overflow
totalForwardEthAmount += _forwardEthAmount;
s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0;
// Send range batch root to secondary chain
bytes memory gatewayCallData = abi.encodeCall(
IZkLink.syncRangeBatchRoot,
(_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount)
);
gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData);
emit SyncRangeBatchRoot(
_secondaryChainGateway,
_fromBatchNumber,
_toBatchNumber,
rangeBatchRootHash,
_forwardEthAmount
);
}

// Forward fee to gateway
Expand Down

0 comments on commit 2fbed2d

Please sign in to comment.