Skip to content
Open
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
13 changes: 4 additions & 9 deletions src/contracts/block-hash-pusher/BaseBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ abstract contract BaseBuffer is IBuffer {
/// @dev For a parent chain with a block time of 12s (Ethereum), this is equivalent to roughly 54 days of history.
uint256 private constant _BUFFER_SIZE = 393168; // 48 * 8191, where 8191 is the EIP-2935 history storage window

/// @dev The block number of the newest block in the buffer.
uint256 private _newestBlockNumber;
/// @notice The block number of the newest block in the buffer.
uint256 public newestBlockNumber;

/// @dev Mapping of block numbers to block hashes.
mapping(uint256 blockNumber => bytes32 blockHash) private _blockHashes;
Expand Down Expand Up @@ -66,16 +66,11 @@ abstract contract BaseBuffer is IBuffer {

uint256 lastBlockNumber = firstBlockNumber + blockHashesLength - 1;

if (lastBlockNumber > _newestBlockNumber) {
if (lastBlockNumber > newestBlockNumber) {
// update the newest block number
_newestBlockNumber = lastBlockNumber;
newestBlockNumber = lastBlockNumber;
}

emit BlockHashesPushed(firstBlockNumber, lastBlockNumber);
}

/// @inheritdoc IBuffer
function newestBlockNumber() public view returns (uint256) {
return _newestBlockNumber;
}
}
15 changes: 5 additions & 10 deletions src/contracts/block-hash-pusher/linea/LineaBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ contract LineaBuffer is BaseBuffer {
/// @dev The address of the L2MessageService contract on L2.
address private immutable _l2MessageService;

/// @dev The address of the pusher contract on L1.
address private immutable _pusher;
/// @notice The address of the pusher contract on L1.
address public immutable pusher;

/// @notice Thrown when attempting to set an invalid L2MessageService address.
error InvalidL2MessageServiceAddress();
Expand All @@ -34,7 +34,7 @@ contract LineaBuffer is BaseBuffer {

constructor(address l2MessageService_, address pusher_) {
_l2MessageService = l2MessageService_;
_pusher = pusher_;
pusher = pusher_;

if (l2MessageService_ == address(0)) {
revert InvalidL2MessageServiceAddress();
Expand All @@ -48,21 +48,16 @@ contract LineaBuffer is BaseBuffer {
if (msg.sender != address(l2MessageServiceCached)) {
revert InvalidSender();
}
if (_pusher == address(0)) {
if (pusher == address(0)) {
revert InvalidPusherAddress();
}
if (l2MessageServiceCached.sender() != _pusher) {
if (l2MessageServiceCached.sender() != pusher) {
revert SenderMismatch();
}

_receiveHashes(firstBlockNumber, blockHashes);
}

/// @inheritdoc IBuffer
function pusher() public view returns (address) {
return _pusher;
}

/// @notice The address of the Linea L2MessageService contract on L2.
/// @return The address of the Linea L2MessageService contract on L2.
function l2MessageService() public view returns (address) {
Expand Down
14 changes: 4 additions & 10 deletions src/contracts/block-hash-pusher/linea/LineaPusher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {IMessageService} from "@linea-contracts/messaging/interfaces/IMessageSer
/// via the Linea MessageService's `sendMessage` function. The pusher must be configured
/// with the correct rollup address.
contract LineaPusher is BlockHashArrayBuilder, IPusher {
/// @dev The address of the Linea Rollup contract on L1.
address private immutable _lineaRollup;
/// @notice The address of the Linea Rollup contract on L1.
address public immutable lineaRollup;

/// @notice Parameters for the L2 transaction that will be executed on Linea.
/// @param _fee The fee paid for the postman to claim the message on L2
Expand All @@ -22,7 +22,7 @@ contract LineaPusher is BlockHashArrayBuilder, IPusher {
}

constructor(address rollup_) {
_lineaRollup = rollup_;
lineaRollup = rollup_;
}

/// @inheritdoc IPusher
Expand All @@ -39,14 +39,8 @@ contract LineaPusher is BlockHashArrayBuilder, IPusher {

LineaL2Transaction memory l2Transaction = abi.decode(l2TransactionData, (LineaL2Transaction));

IMessageService(lineaRollup()).sendMessage{value: msg.value}(buffer, l2Transaction._fee, l2Calldata);
IMessageService(lineaRollup).sendMessage{value: msg.value}(buffer, l2Transaction._fee, l2Calldata);

emit BlockHashesPushed(firstBlockNumber, firstBlockNumber + batchSize - 1);
}

/// @notice The address of the Linea Rollup contract on L1.
/// @return The address of the Linea Rollup contract on L1.
function lineaRollup() public view returns (address) {
return _lineaRollup;
}
}
15 changes: 5 additions & 10 deletions src/contracts/block-hash-pusher/scroll/ScrollBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ contract ScrollBuffer is BaseBuffer {
/// @dev The address of the L2ScrollMessenger contract on L2.
address private immutable _l2ScrollMessenger;

/// @dev The address of the pusher contract on L1.
address private immutable _pusher;
/// @notice The address of the pusher contract on L1.
address public immutable pusher;

/// @notice Thrown when attempting to set an invalid L2ScrollMessenger address.
error InvalidL2ScrollMessengerAddress();
Expand All @@ -31,7 +31,7 @@ contract ScrollBuffer is BaseBuffer {

constructor(address l2ScrollMessenger_, address pusher_) {
_l2ScrollMessenger = l2ScrollMessenger_;
_pusher = pusher_;
pusher = pusher_;

if (l2ScrollMessenger_ == address(0)) {
revert InvalidL2ScrollMessengerAddress();
Expand All @@ -45,21 +45,16 @@ contract ScrollBuffer is BaseBuffer {
if (msg.sender != address(l2ScrollMessengerCached)) {
revert InvalidSender();
}
if (_pusher == address(0)) {
if (pusher == address(0)) {
revert InvalidPusherAddress();
}
if (l2ScrollMessengerCached.xDomainMessageSender() != _pusher) {
if (l2ScrollMessengerCached.xDomainMessageSender() != pusher) {
revert DomainMessageSenderMismatch();
}

_receiveHashes(firstBlockNumber, blockHashes);
}

/// @inheritdoc IBuffer
function pusher() public view returns (address) {
return _pusher;
}

/// @notice The address of the L2ScrollMessenger contract on L2.
/// @return The address of the L2ScrollMessenger contract on L2.
function l2ScrollMessenger() public view returns (address) {
Expand Down
14 changes: 4 additions & 10 deletions src/contracts/block-hash-pusher/scroll/ScrollPusher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {IL1ScrollMessenger} from "@scroll-tech/scroll-contracts/L1/IL1ScrollMess
/// via the Scroll L1ScrollMessenger's `sendMessage` function. The pusher must be configured
/// with the correct L1ScrollMessenger address.
contract ScrollPusher is BlockHashArrayBuilder, IPusher {
/// @dev The address of the Scroll L1ScrollMessenger contract on L1.
address private immutable _l1ScrollMessenger;
/// @notice The address of the Scroll L1ScrollMessenger contract on L1.
address public immutable l1ScrollMessenger;

/// @notice Parameters for the L2 transaction that will be executed on Scroll.
/// @param gasLimit The gas limit for the L2 transaction.
Expand All @@ -24,7 +24,7 @@ contract ScrollPusher is BlockHashArrayBuilder, IPusher {
}

constructor(address l1ScrollMessenger_) {
_l1ScrollMessenger = l1ScrollMessenger_;
l1ScrollMessenger = l1ScrollMessenger_;
}

/// @inheritdoc IPusher
Expand All @@ -41,7 +41,7 @@ contract ScrollPusher is BlockHashArrayBuilder, IPusher {

ScrollL2Transaction memory l2Transaction = abi.decode(l2TransactionData, (ScrollL2Transaction));

IL1ScrollMessenger(l1ScrollMessenger()).sendMessage{value: msg.value}(
IL1ScrollMessenger(l1ScrollMessenger).sendMessage{value: msg.value}(
buffer,
0,
l2Calldata,
Expand All @@ -51,10 +51,4 @@ contract ScrollPusher is BlockHashArrayBuilder, IPusher {

emit BlockHashesPushed(firstBlockNumber, firstBlockNumber + batchSize - 1);
}

/// @notice The address of the Scroll L1ScrollMessenger contract on L1.
/// @return The address of the Scroll L1ScrollMessenger contract on L1.
function l1ScrollMessenger() public view returns (address) {
return _l1ScrollMessenger;
}
}
15 changes: 5 additions & 10 deletions src/contracts/block-hash-pusher/zksync/ZkSyncBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {IBuffer} from "../interfaces/IBuffer.sol";
/// When a message is sent from L1 to L2 via ZkSync's Mailbox, the sender address is aliased.
/// The buffer only accepts hash pushes from the aliased pusher address.
contract ZkSyncBuffer is BaseBuffer {
/// @dev The address of the pusher contract on L1.
address private immutable _pusher;
/// @notice The address of the pusher contract on L1.
address public immutable pusher;

/// @notice Thrown when attempting to set an invalid pusher address.
error InvalidPusherAddress();

constructor(address pusher_) {
_pusher = pusher_;
pusher = pusher_;

if (pusher_ == address(0)) {
revert InvalidPusherAddress();
Expand All @@ -34,16 +34,11 @@ contract ZkSyncBuffer is BaseBuffer {
_receiveHashes(firstBlockNumber, blockHashes);
}

/// @inheritdoc IBuffer
function pusher() public view returns (address) {
return _pusher;
}

/// @notice The aliased address of the pusher contract on L2.
function aliasedPusher() public view returns (address) {
if (_pusher == address(0)) {
if (pusher == address(0)) {
revert InvalidPusherAddress();
}
return AddressAliasHelper.applyL1ToL2Alias(_pusher);
return AddressAliasHelper.applyL1ToL2Alias(pusher);
}
}
14 changes: 4 additions & 10 deletions src/contracts/block-hash-pusher/zksync/ZkSyncPusher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface IMailbox {
/// via the ZkSync Mailbox's `requestL2Transaction` function. The pusher must be configured
/// with the correct ZkSync Diamond proxy address.
contract ZkSyncPusher is BlockHashArrayBuilder, IPusher {
/// @dev The address of the ZkSync Diamond proxy contract on L1.
address private immutable _zkSyncDiamond;
/// @notice The address of the ZkSync Diamond proxy contract on L1.
address public immutable zkSyncDiamond;

/// @notice Thrown when the L2 transaction request fails.
error FailedToPushHashes();
Expand All @@ -41,7 +41,7 @@ contract ZkSyncPusher is BlockHashArrayBuilder, IPusher {
}

constructor(address zkSyncDiamond_) {
_zkSyncDiamond = zkSyncDiamond_;
zkSyncDiamond = zkSyncDiamond_;
}

/// @inheritdoc IPusher
Expand All @@ -60,7 +60,7 @@ contract ZkSyncPusher is BlockHashArrayBuilder, IPusher {

/// In the current behavior of the ZkSync Mailbox, the `l2GasPerPubdataByteLimit` value must be equal to the `REQUIRED_L2_GAS_PRICE_PER_PUBDATA` value,
/// which is a constant defined by ZkSync. The current value is 800. However, since this might change in the future, the value must be passed in as a parameter.
bytes32 canonicalTxHash = IMailbox(zkSyncDiamond()).requestL2Transaction{value: msg.value}(
bytes32 canonicalTxHash = IMailbox(zkSyncDiamond).requestL2Transaction{value: msg.value}(
buffer,
0,
l2Calldata,
Expand All @@ -76,10 +76,4 @@ contract ZkSyncPusher is BlockHashArrayBuilder, IPusher {

emit BlockHashesPushed(firstBlockNumber, firstBlockNumber + batchSize - 1);
}

/// @notice The address of the ZkSync Diamond proxy contract on L1.
/// @return The address of the ZkSync Diamond proxy contract on L1.
function zkSyncDiamond() public view returns (address) {
return _zkSyncDiamond;
}
}