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 drop messages function #681

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion bindings/bin/l1crossdomainmessenger_deployed.hex

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bin/rollup_deployed.hex

Large diffs are not rendered by default.

231 changes: 33 additions & 198 deletions bindings/bindings/l1crossdomainmessenger.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bindings/bindings/l1crossdomainmessenger_more.go

Large diffs are not rendered by default.

190 changes: 2 additions & 188 deletions bindings/bindings/l1messagequeuewithgaspriceoracle.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bindings/bindings/l1messagequeuewithgaspriceoracle_more.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/rollup.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/rollup_more.go

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions contracts/contracts/l1/IL1CrossDomainMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ interface IL1CrossDomainMessenger is ICrossDomainMessenger {
bytes message
);

/// @notice Emitted when have message dropped.
/// @param nonce The index of the message to be dropped.
event DropMessage(uint256 indexed nonce);

/*****************************
* Public Mutating Functions *
*****************************/
Expand Down Expand Up @@ -80,12 +76,4 @@ interface IL1CrossDomainMessenger is ICrossDomainMessenger {
uint32 newGasLimit,
address refundAddress
) external payable;

/// @notice Drop a skipped message.
/// @param from The address of the sender of the message.
/// @param to The address of the recipient of the message.
/// @param value The msg.value passed to the message call.
/// @param messageNonce The nonce for the message to drop.
/// @param message The content of the message.
function dropMessage(address from, address to, uint256 value, uint256 messageNonce, bytes memory message) external;
}
59 changes: 2 additions & 57 deletions contracts/contracts/l1/L1CrossDomainMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract L1CrossDomainMessenger is IL1CrossDomainMessenger, CrossDomainMessenger
mapping(bytes32 => uint256) public messageSendTimestamp;

/// @notice Mapping from L1 message hash to drop status.
mapping(bytes32 => bool) public isL1MessageDropped;
mapping(bytes32 => bool) public __isL1MessageDropped;

/// @notice The address of Rollup contract.
address public rollup;
Expand Down Expand Up @@ -192,7 +192,7 @@ contract L1CrossDomainMessenger is IL1CrossDomainMessenger, CrossDomainMessenger

require(messageSendTimestamp[_xDomainCalldataHash] > 0, "Provided message has not been enqueued");
// cannot replay dropped message
require(!isL1MessageDropped[_xDomainCalldataHash], "Message already dropped");
require(!__isL1MessageDropped[_xDomainCalldataHash], "Message already dropped");

// compute and deduct the messaging fee to fee vault.
uint256 _fee = IL1MessageQueue(_messageQueue).estimateCrossDomainMessageFee(_from, _newGasLimit);
Expand Down Expand Up @@ -243,61 +243,6 @@ contract L1CrossDomainMessenger is IL1CrossDomainMessenger, CrossDomainMessenger
}
}

/// @inheritdoc IL1CrossDomainMessenger
function dropMessage(
address _from,
address _to,
uint256 _value,
uint256 _messageNonce,
bytes memory _message
) external override whenNotPaused notInExecution {
// The criteria for dropping a message:
// 1. The message is a L1 message.
// 2. The message has not been dropped before.
// 3. the message and all of its replacement are finalized in L1.
// 4. the message and all of its replacement are skipped.
//
// Possible denial of service attack:
// + replayMessage is called every time someone want to drop the message.
// + replayMessage is called so many times for a skipped message, thus results a long list.
//
// We limit the number of `replayMessage` calls of each message, which may solve the above problem.

address _messageQueue = messageQueue;

// check message exists
bytes memory _xDomainCalldata = _encodeXDomainCalldata(_from, _to, _value, _messageNonce, _message);
bytes32 _xDomainCalldataHash = keccak256(_xDomainCalldata);
require(messageSendTimestamp[_xDomainCalldataHash] > 0, "Provided message has not been enqueued");

// check message not dropped
require(!isL1MessageDropped[_xDomainCalldataHash], "Message already dropped");

// check message is finalized
uint256 _lastIndex = replayStates[_xDomainCalldataHash].lastIndex;
if (_lastIndex == 0) _lastIndex = _messageNonce;

// check message is skipped and drop it.
// @note If the list is very long, the message may never be dropped.
while (true) {
IL1MessageQueue(_messageQueue).dropCrossDomainMessage(_lastIndex);
_lastIndex = prevReplayIndex[_lastIndex];
if (_lastIndex == 0) break;
unchecked {
_lastIndex = _lastIndex - 1;
}
}

isL1MessageDropped[_xDomainCalldataHash] = true;
emit DropMessage(_messageNonce);

// set execution context
xDomainMessageSender = Constants.DROP_XDOMAIN_MESSAGE_SENDER;
IMessageDropCallback(_from).onDropMessage{value: _value}(_message);
// clear execution context
xDomainMessageSender = Constants.DEFAULT_XDOMAIN_MESSAGE_SENDER;
}

/************************
* Restricted Functions *
************************/
Expand Down
11 changes: 0 additions & 11 deletions contracts/contracts/l1/rollup/IL1MessageQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ interface IL1MessageQueue {
/// @param count The number of messages popped.
event DequeueTransaction(uint256 startIndex, uint256 count);

/// @notice Emitted when a message is dropped from L1.
/// @param index The index of message dropped.
event DropTransaction(uint256 index);

/// @notice Emitted when owner updates gas oracle contract.
/// @param _oldGasOracle The address of old gas oracle contract.
/// @param _newGasOracle The address of new gas oracle contract.
Expand Down Expand Up @@ -95,10 +91,6 @@ interface IL1MessageQueue {
bytes calldata data
) external view returns (bytes32);

/// @notice Return whether the message is dropped.
/// @param queueIndex The queue index of the message to check.
function isMessageDropped(uint256 queueIndex) external view returns (bool);

/*****************************
* Public Mutating Functions *
*****************************/
Expand Down Expand Up @@ -132,7 +124,4 @@ interface IL1MessageQueue {
/// @param startIndex The start index to pop.
/// @param count The number of messages to pop.
function popCrossDomainMessage(uint256 startIndex, uint256 count) external;

/// @notice Drop a skipped message from the queue.
function dropCrossDomainMessage(uint256 index) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
/// @notice The max gas limit of L1 transactions.
uint256 public maxGasLimit;

/// @dev The bitmap for dropped messages, where `droppedMessageBitmap[i]` keeps the bits from `[i*256, (i+1)*256)`.
BitMapsUpgradeable.BitMap private droppedMessageBitmap;
/// @dev The bitmap for dropped messages, where `droppedMessageBitmap[i]` keeps the bits from `[i*256, (i+1)*256)`. Deprecated.
BitMapsUpgradeable.BitMap private __droppedMessageBitmap;

/// @dev The bitmap for skipped messages, where `skippedMessageBitmap[i]` keeps the bits from `[i*256, (i+1)*256)`. Deprecated.
mapping(uint256 => uint256) private __skippedMessageBitmap;
Expand Down Expand Up @@ -260,11 +260,6 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
return hash;
}

/// @inheritdoc IL1MessageQueue
function isMessageDropped(uint256 _queueIndex) external view returns (bool) {
return droppedMessageBitmap.get(_queueIndex);
}

/*****************************
* Public Mutating Functions *
*****************************/
Expand Down Expand Up @@ -325,16 +320,6 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
emit DequeueTransaction(_startIndex, _count);
}

/// @inheritdoc IL1MessageQueue
function dropCrossDomainMessage(uint256 _index) external onlyMessenger {
require(_index < pendingQueueIndex, "cannot drop pending message");

require(!droppedMessageBitmap.get(_index), "message already dropped");
droppedMessageBitmap.set(_index);

emit DropTransaction(_index);
}

/************************
* Restricted Functions *
************************/
Expand Down
Loading