Skip to content

Commit

Permalink
Merge pull request #658 from morph-l2/review
Browse files Browse the repository at this point in the history
feat: Remove skipMap from batch
  • Loading branch information
FletcherMan authored Dec 31, 2024
2 parents 7e788c9 + d06acc3 commit af4158b
Show file tree
Hide file tree
Showing 100 changed files with 974 additions and 1,838 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################## update dependencies ####################

ETHEREUM_TARGET_VERSION := morph-v2.0.1
ETHEREUM_TARGET_VERSION := morph-v2.0.2
TENDERMINT_TARGET_VERSION := v0.3.1

ETHEREUM_MODULE_NAME := github.com/morph-l2/go-ethereum
Expand Down
16 changes: 16 additions & 0 deletions MakefileEc2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ build-bk-prod-morph-prod-mainnet-to-morph-tx-submitter:
cp tx-submitter/tx-submitter dist/
tar -czvf tx-submitter.tar.gz dist
aws s3 cp tx-submitter.tar.gz s3://morph-0582-morph-technical-department-mainnet-data/morph-setup/tx-submitter.tar.gz

# build for holesky
build-bk-prod-morph-prod-testnet-to-morph-node-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
cd $(PWD)/node && make build
cp node/build/bin/morphnode dist/
cp node/build/bin/tendermint dist/
tar -czvf morph-node.tar.gz dist
aws s3 cp morph-node.tar.gz s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/morph-node.tar.gz

build-bk-prod-morph-prod-testnet-to-morph-tx-submitter-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
env GO111MODULE=on CGO_LDFLAGS="-ldl" CGO_ENABLED=1 go build -v $(LDFLAGS) -o tx-submitter/tx-submitter ./tx-submitter/cmd
cp tx-submitter/tx-submitter dist/
tar -czvf tx-submitter.tar.gz dist
aws s3 cp tx-submitter.tar.gz s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/tx-submitter.tar.gz
2 changes: 1 addition & 1 deletion bindings/bin/l1crossdomainmessenger_deployed.hex

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

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.

264 changes: 23 additions & 241 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/l2txfeevault.go

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions 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.

2 changes: 1 addition & 1 deletion bindings/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.1

require github.com/morph-l2/go-ethereum v1.10.14-0.20241021080617-0ff2a10a9625
require github.com/morph-l2/go-ethereum v1.10.14-0.20241224102336-50a1ac889263

require (
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions bindings/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20241021080617-0ff2a10a9625 h1:4+cbRSS4lacSIC81RXxvA04UHhGVC4SHVn+bKeqhPSM=
github.com/morph-l2/go-ethereum v1.10.14-0.20241021080617-0ff2a10a9625/go.mod h1:sMJCfHOBzVRDkM2yF/Hy+oUk2rgC0CQZHTLs0cyzhhk=
github.com/morph-l2/go-ethereum v1.10.14-0.20241224102336-50a1ac889263 h1:/yZ9MGwCQtabc8nWFEEat8ddDhjqwobpl96Gvb7BlF0=
github.com/morph-l2/go-ethereum v1.10.14-0.20241224102336-50a1ac889263/go.mod h1:sMJCfHOBzVRDkM2yF/Hy+oUk2rgC0CQZHTLs0cyzhhk=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
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
21 changes: 2 additions & 19 deletions contracts/contracts/l1/rollup/IL1MessageQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ interface IL1MessageQueue {
/// @notice Emitted when some L1 => L2 transactions are included in L1.
/// @param startIndex The start index of messages popped.
/// @param count The number of messages popped.
/// @param skippedBitmap A bitmap indicates whether a message is skipped.
event DequeueTransaction(uint256 startIndex, uint256 count, uint256 skippedBitmap);

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

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

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

/// @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 @@ -136,9 +123,5 @@ interface IL1MessageQueue {
///
/// @param startIndex The start index to pop.
/// @param count The number of messages to pop.
/// @param skippedBitmap A bitmap indicates whether a message is skipped.
function popCrossDomainMessage(uint256 startIndex, uint256 count, uint256 skippedBitmap) external;

/// @notice Drop a skipped message from the queue.
function dropCrossDomainMessage(uint256 index) external;
function popCrossDomainMessage(uint256 startIndex, uint256 count) external;
}
2 changes: 0 additions & 2 deletions contracts/contracts/l1/rollup/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ interface IRollup {
/// @param version The version of current batch.
/// @param parentBatchHeader The header of parent batch, see the comments of `BatchHeaderV0Codec`.
/// @param blockContexts The block contexts of current batch.
/// @param skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.
/// @param prevStateRoot The state root of parent batch.
/// @param postStateRoot The state root of current batch.
/// @param withdrawalRoot The withdraw trie root of current batch.
struct BatchDataInput {
uint8 version;
bytes parentBatchHeader;
bytes blockContexts;
bytes skippedL1MessageBitmap;
bytes32 prevStateRoot;
bytes32 postStateRoot;
bytes32 withdrawalRoot;
Expand Down
54 changes: 6 additions & 48 deletions contracts/contracts/l1/rollup/L1MessageQueueWithGasPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ 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)`.
mapping(uint256 => uint256) private skippedMessageBitmap;
/// @dev The bitmap for skipped messages, where `skippedMessageBitmap[i]` keeps the bits from `[i*256, (i+1)*256)`. Deprecated.
mapping(uint256 => uint256) private __skippedMessageBitmap;

/// @inheritdoc IL1MessageQueueWithGasPriceOracle
address public whitelistChecker;
Expand Down Expand Up @@ -260,19 +260,6 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
return hash;
}

/// @inheritdoc IL1MessageQueue
function isMessageSkipped(uint256 _queueIndex) external view returns (bool) {
if (_queueIndex >= pendingQueueIndex) return false;

return _isMessageSkipped(_queueIndex);
}

/// @inheritdoc IL1MessageQueue
function isMessageDropped(uint256 _queueIndex) external view returns (bool) {
// it should be a skipped message first.
return _isMessageSkipped(_queueIndex) && droppedMessageBitmap.get(_queueIndex);
}

/*****************************
* Public Mutating Functions *
*****************************/
Expand Down Expand Up @@ -320,39 +307,17 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
}

/// @inheritdoc IL1MessageQueue
function popCrossDomainMessage(uint256 _startIndex, uint256 _count, uint256 _skippedBitmap) external {
function popCrossDomainMessage(uint256 _startIndex, uint256 _count) external {
require(_msgSender() == ROLLUP_CONTRACT, "Only callable by the rollup");

require(_count <= 256, "pop too many messages");
require(pendingQueueIndex == _startIndex, "start index mismatch");

unchecked {
// clear extra bits in `_skippedBitmap`, and if _count = 256, it's designed to overflow.
uint256 mask = (1 << _count) - 1;
_skippedBitmap &= mask;

uint256 bucket = _startIndex >> 8;
uint256 offset = _startIndex & 0xff;
skippedMessageBitmap[bucket] |= _skippedBitmap << offset;
if (offset + _count > 256) {
skippedMessageBitmap[bucket + 1] = _skippedBitmap >> (256 - offset);
}

pendingQueueIndex = _startIndex + _count;
}

emit DequeueTransaction(_startIndex, _count, _skippedBitmap);
}

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

require(_isMessageSkipped(_index), "drop non-skipped message");
require(!droppedMessageBitmap.get(_index), "message already dropped");
droppedMessageBitmap.set(_index);

emit DropTransaction(_index);
emit DequeueTransaction(_startIndex, _count);
}

/************************
Expand Down Expand Up @@ -409,11 +374,4 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
uint256 intrinsicGas = calculateIntrinsicGasFee(_calldata);
require(_gasLimit >= intrinsicGas, "Insufficient gas limit, must be above intrinsic gas");
}

/// @dev Returns whether the bit at `index` is set.
function _isMessageSkipped(uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return skippedMessageBitmap[bucket] & mask != 0;
}
}
Loading

0 comments on commit af4158b

Please sign in to comment.