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

draft PR for chained l1 message queue #69

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zimpha
Copy link
Member

@zimpha zimpha commented Dec 30, 2024

No description provided.

*********************/

/// @dev The list of queued cross domain messages.
mapping(uint256 => bytes32) private messageRollingHashes;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to have the memory layout here in the description

src/L1/L1ScrollMessenger.sol Show resolved Hide resolved
Comment on lines +157 to +163
function estimatedL2BaseFee() public view returns (uint256) {
L2BaseFeeParameters memory parameters = l2BaseFeeParameters;
// this is unlikely to happen, use unchecked here
unchecked {
return (block.basefee * parameters.scalar) / PRECISION + parameters.overhead;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea here that we will no longer use gas-oracle to write l2 base fee here?

If yes, would it make sense to move configs such as L2BaseFeeParameters into a SystemConfig contract (the same that @ranchalp will use to store the current authorized L2 signer)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we use formula to compute the l2 base fee. Sure, it is better to add it into SystemConfig contract.

) external {
if (_msgSender() != enforcedTxGateway) revert ErrorCallerIsNotEnforcedTxGateway();
// We will check it in EnforcedTxGateway, just in case.
if (_sender.code.length > 0) revert ErrorCallerIsNotEOA();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not compatible with EIP-7702. Do we need this restriction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this and also remove check in EnforcedTxGateway.

_updateL2BaseFeeParameters(_params.overhead, _params.scalar);
_updateMaxGasLimit(_maxGasLimit);

uint256 _nextCrossDomainMessageIndex = IL1MessageQueueV1(messageQueueV1).nextCrossDomainMessageIndex();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a convenience, we could consider storing this as something like firstMessageIndex, to know which contract a specific index belongs to.

/// @notice Update the parameters for l2 base fee formula.
/// @param overhead The value of overhead in l2 base fee formula.
/// @param scalar The value of scalar in l2 base fee formula.
function updateL2BaseFeeParameters(uint128 overhead, uint128 scalar) external onlyOwner {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: These will need to be configured on ScrollOwner

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will move this function SystemConfig contract.

/// @param _value The value passed
/// @param _gasLimit The maximum gas should be used for this transaction in L2.
/// @param _data The calldata passed to target contract.
function _queueTransaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will be the impact of this added hashing on ETH and ERC20 deposit gas costs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my estimation is adding 2000~5000 gas.

/// @param hash The rolling hash.
/// @param enqueueTimestamp The enqueue timestamp.
/// @return The encoded rolling hash for storage.
function _encodeRollingHash(bytes32 hash, uint256 enqueueTimestamp) internal pure returns (bytes32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention the use case of enqueueTimestamp somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should combine with enforces messages PR #61. I'll add comments about this.

src/L1/rollup/L1MessageQueueV2.sol Show resolved Hide resolved
src/L1/rollup/L1MessageQueueV2.sol Show resolved Hide resolved
@@ -121,7 +122,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
uint64 public immutable layer2ChainId;

/// @notice The address of L1MessageQueue contract.
address public immutable messageQueue;
address public immutable messageQueueV1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will we switch from V1 to V2 in ScrollChain and in L1ScrollMessenger?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not done yet. I have discussed with @jonastheis, quote the results here

  1. after queue v2 is initialized, every new message goes to queue v2

  2. for remaining messages in queue v1: we keep it in queue v1 and continue consuming them until the upgrade happens on L2

  3. there will be multiple hours of time between upgrade tx on L1 and the actual upgrade time on L2 -> we should have consumed and finalized all messages from queue v1

  4. once the upgrade happened on L2: in l2geth we need to implement relaying the messages from queue v2 anyway. We add a condition that we only do that after the upgrade is activated.

  5. once we commit with new commit method we check that all messages of queue v1 are finalized. otherwise reject or alternatively migrate to queue v2. since we left enough time in step 3 there should be no message anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So it's likely that deposits will be on hold / delayed for a few hours during the upgrade?

/// @title L1MessageQueueV2
/// @notice This contract will hold all L1 to L2 messages.
/// Each appended message is assigned with a unique and increasing `uint256` index.
contract L1MessageQueueV2 is OwnableUpgradeable, IL1MessageQueueV2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonastheis Just highlighting here that we'll need to add the new message queue (and the switch-over logic) to l2geth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants