Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro m6 + l6 #4408

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,27 @@ contract ZkSyncHubConnector is HubConnector, GasCap {
}

/**
* @dev Sends `aggregateRoot` to messaging on l2
* @notice Sends `aggregateRoot` to messaging on l2.
* @dev Caller must provide the following:
* - L2 gas: gas limit of l2 transaction
* - l2GasPerPubdataByteLimit: gas required to publish l1 -> l2 transactions
* - refund recipient: who gets excess fees on executino. If the _refundRecipient is a smart contract,
* then during the L1 to L2 transaction its address is aliased.
*/
function _sendMessage(bytes memory _data, bytes memory _encodedData) internal override {
// Should include L2 gas that transaction can consume during execution on L2
require(_encodedData.length == 32, "!data length");
// Should include L2 gas that transaction can consume during execution on L2 + address of
// refund recipient (32 + 20 bytes)
require(_encodedData.length == 52, "!data length");
// Should always be dispatching the aggregate root
require(_data.length == 32, "!length");
// Get the calldata
bytes memory _calldata = abi.encodeWithSelector(Connector.processMessage.selector, _data);

// Maximum amount of L2 gas that transaction can consume during execution on L2
uint256 l2GasLimit = abi.decode(_encodedData, (uint256));

// The maximum amount L2 gas that the operator may charge the user for.
uint256 l2GasPerPubdataByteLimit = 800;
// Decode all passed-through data
(uint256 l2GasLimit, uint256 l2GasPerPubdataByteLimit, address refundRecipient) = abi.decode(
_encodedData,
(uint256, uint256, address)
);

// Get the max supplied
uint256 fee = _getGas(msg.value);
Expand All @@ -79,7 +85,8 @@ contract ZkSyncHubConnector is HubConnector, GasCap {
l2GasPerPubdataByteLimit,
// factory dependencies
new bytes[](0),
msg.sender
// fee refund address
refundRecipient
);
}

Expand Down Expand Up @@ -121,12 +128,11 @@ contract ZkSyncHubConnector is HubConnector, GasCap {
// NOTE: there are no guarantees the messages are processed once, so processed roots
// must be tracked within the connector. See:
// https://v2-docs.zksync.io/dev/developer-guides/Bridging/l2-l1.html#prove-inclusion-of-the-message-into-the-l2-block
if (!processed[_root]) {
// set root to processed
processed[_root] = true;
// update the root on the root manager
IRootManager(ROOT_MANAGER).aggregate(MIRROR_DOMAIN, _root);
emit MessageProcessed(_message, msg.sender);
} // otherwise root was already sent to root manager
require(!processed[_root], "processed");
LayneHaber marked this conversation as resolved.
Show resolved Hide resolved
// set root to processed
processed[_root] = true;

IRootManager(ROOT_MANAGER).aggregate(MIRROR_DOMAIN, _root);
emit MessageProcessed(_message, msg.sender);
}
}