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

Remove most info from relayed L1->GW priority ops #775

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 1 addition & 11 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../comm
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
import {IMessageRoot} from "./IMessageRoot.sol";
import {ISTMDeploymentTracker} from "./ISTMDeploymentTracker.sol";
import {L2CanonicalTransaction} from "../common/Messaging.sol";
import {HyperchainLimitReached, Unauthorized, STMAlreadyRegistered, STMNotRegistered, ZeroChainId, ChainIdTooBig, SharedBridgeNotSet, BridgeHubAlreadyRegistered, AddressTooLow, MsgValueMismatch, WrongMagicValue, ZeroAddress} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
Expand Down Expand Up @@ -567,25 +566,16 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus

/// @notice Used to forward a transaction on the gateway to the chains mailbox (from L1).
/// @param _chainId the chainId of the chain
/// @param _transaction the transaction to be forwarded
/// @param _factoryDeps the factory dependencies for the transaction
/// @param _canonicalTxHash the canonical transaction hash
/// @param _expirationTimestamp the expiration timestamp for the transaction
function forwardTransactionOnGateway(
uint256 _chainId,
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external override onlySettlementLayerRelayedSender {
require(L1_CHAIN_ID != block.chainid, "BH: not in sync layer mode");
address hyperchain = hyperchainMap.get(_chainId);
IZkSyncHyperchain(hyperchain).bridgehubRequestL2TransactionOnGateway(
_transaction,
_factoryDeps,
_canonicalTxHash,
_expirationTimestamp
);
IZkSyncHyperchain(hyperchain).bridgehubRequestL2TransactionOnGateway(_canonicalTxHash, _expirationTimestamp);
}

/// @notice forwards function call to Mailbox based on ChainId
Expand Down
4 changes: 1 addition & 3 deletions l1-contracts/contracts/bridgehub/IBridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.21;

import {IL1AssetRouter} from "../bridge/interfaces/IL1AssetRouter.sol";
import {L2CanonicalTransaction, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {IL1AssetHandler} from "../bridge/interfaces/IL1AssetHandler.sol";
import {ISTMDeploymentTracker} from "./ISTMDeploymentTracker.sol";
import {IMessageRoot} from "./IMessageRoot.sol";
Expand Down Expand Up @@ -206,8 +206,6 @@ interface IBridgehub is IL1AssetHandler {

function forwardTransactionOnGateway(
uint256 _chainId,
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ contract GettersFacet is ZkSyncHyperchainBase, IGetters, ILegacyGetters {

/// @inheritdoc IGetters
function getTotalPriorityTxs() external view returns (uint256) {
if (s.priorityQueue.getFirstUnprocessedPriorityTx() >= s.priorityTree.startIndex) {
return s.priorityTree.getTotalPriorityTxs();
} else {
return s.priorityQueue.getTotalPriorityTxs();
}
return _getTotalPriorityTxs();
}

/// @inheritdoc IGetters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@
/// @inheritdoc IMailbox
function requestL2TransactionToGatewayMailbox(
uint256 _chainId,
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external override onlyL1 returns (bytes32 canonicalTxHash) {
Expand All @@ -379,8 +377,6 @@

BridgehubL2TransactionRequest memory wrappedRequest = _wrapRequest({
_chainId: _chainId,
_transaction: _transaction,
_factoryDeps: _factoryDeps,
_canonicalTxHash: _canonicalTxHash,
_expirationTimestamp: _expirationTimestamp
});
Expand All @@ -389,25 +385,22 @@

/// @inheritdoc IMailbox
function bridgehubRequestL2TransactionOnGateway(
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external override onlyBridgehub {
_writePriorityOp(_transaction, _factoryDeps, _canonicalTxHash, _expirationTimestamp);
_writePriorityOpHash(_canonicalTxHash, _expirationTimestamp);
emit NewRelayedPriorityTransaction(_getTotalPriorityTxs(), _canonicalTxHash, _expirationTimestamp);
}

function _wrapRequest(
uint256 _chainId,
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) internal view returns (BridgehubL2TransactionRequest memory) {
// solhint-disable-next-line func-named-parameters
bytes memory data = abi.encodeCall(
IBridgehub(s.bridgehub).forwardTransactionOnGateway,
(_chainId, _transaction, _factoryDeps, _canonicalTxHash, _expirationTimestamp)
(_chainId, _canonicalTxHash, _expirationTimestamp)
);
return
BridgehubL2TransactionRequest({
Expand Down Expand Up @@ -479,7 +472,7 @@
// Change the sender address if it is a smart contract to prevent address collision between L1 and L2.
// Please note, currently ZKsync address derivation is different from Ethereum one, but it may be changed in the future.
// slither-disable-next-line tx-origin
if (request.sender != tx.origin) {

Check warning on line 475 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 475 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 475 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin
request.sender = AddressAliasHelper.applyL1ToL2Alias(request.sender);
}

Expand All @@ -494,8 +487,6 @@
// slither-disable-next-line unused-return
IMailbox(s.settlementLayer).requestL2TransactionToGatewayMailbox({
_chainId: s.chainId,
_transaction: transaction,
_factoryDeps: _params.request.factoryDeps,
_canonicalTxHash: canonicalTxHash,
_expirationTimestamp: _params.expirationTimestamp
});
Expand Down Expand Up @@ -571,6 +562,14 @@
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) internal {
_writePriorityOpHash(_canonicalTxHash, _expirationTimestamp);

// Data that is needed for the operator to simulate priority queue offchain
// solhint-disable-next-line func-named-parameters
emit NewPriorityRequest(_transaction.nonce, _canonicalTxHash, _expirationTimestamp, _transaction, _factoryDeps);
}

function _writePriorityOpHash(bytes32 _canonicalTxHash, uint64 _expirationTimestamp) internal {
if (s.priorityTree.startIndex > s.priorityQueue.getFirstUnprocessedPriorityTx()) {
s.priorityQueue.pushBack(
PriorityOperation({
Expand All @@ -581,10 +580,6 @@
);
}
s.priorityTree.push(_canonicalTxHash);

// Data that is needed for the operator to simulate priority queue offchain
// solhint-disable-next-line func-named-parameters
emit NewPriorityRequest(_transaction.nonce, _canonicalTxHash, _expirationTimestamp, _transaction, _factoryDeps);
}

/// @notice Hashes the L2 bytecodes and returns them in the format in which they are processed by the bootloader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ pragma solidity 0.8.24;

import {ZkSyncHyperchainStorage} from "../ZkSyncHyperchainStorage.sol";
import {ReentrancyGuard} from "../../../common/ReentrancyGuard.sol";

import {PriorityQueue} from "../../libraries/PriorityQueue.sol";
import {PriorityTree} from "../../libraries/PriorityTree.sol";
import {Unauthorized} from "../../../common/L1ContractErrors.sol";

/// @title Base contract containing functions accessible to the other facets.
/// @author Matter Labs
/// @custom:security-contact [email protected]
contract ZkSyncHyperchainBase is ReentrancyGuard {
using PriorityQueue for PriorityQueue.Queue;
using PriorityTree for PriorityTree.Tree;

// slither-disable-next-line uninitialized-state
ZkSyncHyperchainStorage internal s;

Expand Down Expand Up @@ -64,4 +68,12 @@ contract ZkSyncHyperchainBase is ReentrancyGuard {
}
_;
}

function _getTotalPriorityTxs() internal view returns (uint256) {
if (s.priorityQueue.getFirstUnprocessedPriorityTx() >= s.priorityTree.startIndex) {
return s.priorityTree.getTotalPriorityTxs();
} else {
return s.priorityQueue.getTotalPriorityTxs();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,14 @@ interface IMailbox is IZkSyncHyperchainBase {
) external returns (bytes32 canonicalTxHash);

/// @dev On the Gateway the chain's mailbox receives the tx from the bridgehub.
function bridgehubRequestL2TransactionOnGateway(
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external;
function bridgehubRequestL2TransactionOnGateway(bytes32 _canonicalTxHash, uint64 _expirationTimestamp) external;

/// @dev On L1 we have to forward to the Gateway's mailbox which sends to the Bridgehub on the Gw
/// @param _chainId the chainId of the chain
/// @param _transaction the transaction to be relayed
/// @param _factoryDeps the factory dependencies
/// @param _canonicalTxHash the canonical transaction hash
/// @param _expirationTimestamp the expiration timestamp
function requestL2TransactionToGatewayMailbox(
uint256 _chainId,
L2CanonicalTransaction calldata _transaction,
bytes[] calldata _factoryDeps,
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external returns (bytes32 canonicalTxHash);
Expand Down Expand Up @@ -175,4 +166,13 @@ interface IMailbox is IZkSyncHyperchainBase {
L2CanonicalTransaction transaction,
bytes[] factoryDeps
);

/// @notice New relayed priority request event. It is emitted on a chain that is deployed
/// on top of the gateway when it receives a request relayed via the Bridgehub.
/// @dev IMPORTANT: this event most likely will be removed in the future, so
/// no one should rely on it for indexing purposes.
/// @param txId Serial number of the priority operation
/// @param txHash keccak256 hash of encoded transaction representation
/// @param expirationTimestamp Timestamp up to which priority request should be processed
event NewRelayedPriorityTransaction(uint256 txId, bytes32 txHash, uint64 expirationTimestamp);
}
21 changes: 1 addition & 20 deletions l1-contracts/test/foundry/integration/GatewayTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,9 @@ contract GatewayTests is L1ContractDeployer, HyperchainDeployer, TokenDeployer,
finishMoveChain();

IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress());
L2CanonicalTransaction memory tx = L2CanonicalTransaction({
txType: 255,
from: uint256(0),
to: uint256(0),
gasLimit: 72000000,
gasPerPubdataByteLimit: 800,
maxFeePerGas: 1,
maxPriorityFeePerGas: 0,
paymaster: 0,
// Note, that the priority operation id is used as "nonce" for L1->L2 transactions
nonce: 0,
value: 0,
reserved: [uint256(0), 0, 0, 0],
data: "0x",
signature: new bytes(0),
factoryDeps: new uint256[](0),
paymasterInput: "0x",
reservedDynamic: "0x"
});
vm.chainId(12345);
vm.startBroadcast(SETTLEMENT_LAYER_RELAY_SENDER);
bridgehub.forwardTransactionOnGateway(mintChainId, tx, new bytes[](0), bytes32(0), 0);
bridgehub.forwardTransactionOnGateway(mintChainId, bytes32(0), 0);
vm.stopBroadcast();
}

Expand Down
Loading
Loading