Skip to content

Commit

Permalink
fix refund address of zksync
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Apr 17, 2024
1 parent c55044f commit e99c878
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions contracts/gateway/zksync/ZkSyncL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
bytes memory executeData = abi.encodeCall(IMessageClaimer.claimMessageCallback, (_value, _callData));
bytes32 messageHash = keccak256(executeData);
// If the l2 transaction fails to execute, for example l2GasLimit is too small
// The l2 value will be refunded to the l1 gateway alias address.
// The l2 value will be refunded to the l2 gateway address.
// Then the relayer can retry failed tx from L1
bytes32 l2TxHash = MESSAGE_SERVICE.requestL2Transaction{value: msg.value}(
remoteGateway,
Expand All @@ -66,7 +66,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
_l2GasLimit,
_l2GasPerPubdataByteLimit,
new bytes[](0),
address(this)
remoteGateway
);
executedMessage[l2TxHash] = messageHash;
}
Expand Down Expand Up @@ -123,6 +123,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
/// @param _executeData The message data
/// @param _l2GasLimit Maximum amount of L2 gas that transaction can consume during execution on L2
/// @param _l2GasPerPubdataByteLimit The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
/// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
/// @param _failedL2TxHash The L2 transaction hash of the failed finalization
/// @param _l2BatchNumber The L2 batch number where the finalization was processed
/// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
Expand All @@ -132,6 +133,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
bytes calldata _executeData,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit,
address _refundRecipient,
bytes32 _failedL2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
Expand All @@ -154,14 +156,15 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
delete executedMessage[_failedL2TxHash];

// Retry the message without l2 value
// Excess fee will be refunded to the `_refundRecipient`
bytes32 replacedL2TxHash = MESSAGE_SERVICE.requestL2Transaction{value: msg.value}(
remoteGateway,
0,
_executeData,
_l2GasLimit,
_l2GasPerPubdataByteLimit,
new bytes[](0),
address(this)
_refundRecipient
);
executedMessage[replacedL2TxHash] = messageHash;
emit RetryFailedMessage(_failedL2TxHash, replacedL2TxHash);
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/zksync/ZkSyncL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ contract ZkSyncL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway {
}

function claimMessageCallback(uint256 _value, bytes calldata _callData) external payable onlyRemoteGateway {
require(msg.value == _value, "Invalid value");

// when l1 to l2 executed failed then the l2 value will be refunded to L2 gateway
// we can retry the failed tx on l1(without l2 value) so we should not check msg.value here
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
Expand Down

0 comments on commit e99c878

Please sign in to comment.