Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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

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.

97 changes: 95 additions & 2 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.

378 changes: 376 additions & 2 deletions bindings/bindings/rollup.go

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contracts/contracts/l1/rollup/IL1MessageQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ interface IL1MessageQueue {
/// @notice The start index of all pending inclusion messages.
function pendingQueueIndex() external view returns (uint256);

/// @notice Return the enqueue timestamp of the first unfinalized message.
/// @dev Used for checking if L1 messages are being processed within acceptable time.
/// @return timestamp The block.timestamp when the first unfinalized message was enqueued.
function getFirstUnfinalizedMessageEnqueueTime() external view returns (uint256 timestamp);

/// @notice Return the index of next appended message.
/// @dev Also the total number of appended messages.
function nextCrossDomainMessageIndex() external view returns (uint256);
Expand Down
13 changes: 13 additions & 0 deletions contracts/contracts/l1/rollup/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ interface IRollup {
/// @notice error zero address
error ErrZeroAddress();

/// @notice error invalid timing for permissionless batch submission
error InvalidTiming();

/**********
* Events *
**********/
Expand All @@ -86,6 +89,11 @@ interface IRollup {
/// @param batchHash The hash of the batch
event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);

/// @notice Emitted when a range of batches is reverted in commitBatchWithProof.
/// @param startBatchIndex The starting batch index (inclusive).
/// @param count The number of batches reverted.
event RevertBatchRange(uint256 indexed startBatchIndex, uint256 count);

/// @notice Emitted when a batch is finalized.
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch
Expand Down Expand Up @@ -118,6 +126,11 @@ interface IRollup {
/// @param newPercent The new proofRewardPercent.
event UpdateProofRewardPercent(uint256 oldPercent, uint256 newPercent);

/// @notice Emitted when the rollup delay period is updated.
/// @param oldPeriod The old rollupDelayPeird.
/// @param newPeriod The new rollupDelayPeird.
event RollupDelayPeirdUpdate(uint256 oldPeriod, uint256 newPeriod);

/// @notice Emit when prove remaining claimed.
/// @param receiver receiver address.
/// @param amount claimed amount.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
/// @inheritdoc IL1MessageQueueWithGasPriceOracle
address public whitelistChecker;

mapping(uint256 => uint256) public messageEnqueueTime;

/**********************
* Function Modifiers *
**********************/
Expand Down Expand Up @@ -260,6 +262,14 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
return hash;
}

function getFirstUnfinalizedMessageEnqueueTime() external view returns (uint256 timestamp) {
return messageEnqueueTime[pendingQueueIndex];
}

function getMessageEnqueueTimestamp(uint256 index) external view returns (uint256 timestamp) {
return messageEnqueueTime[index];
}

/*****************************
* Public Mutating Functions *
*****************************/
Expand Down Expand Up @@ -363,6 +373,7 @@ contract L1MessageQueueWithGasPriceOracle is OwnableUpgradeable, IL1MessageQueue
uint256 _queueIndex = messageQueue.length;
bytes32 _hash = computeTransactionHash(_sender, _queueIndex, _value, _target, _gasLimit, _data);
messageQueue.push(_hash);
messageEnqueueTime[_queueIndex] = block.timestamp;

// emit event
emit QueueTransaction(_sender, _target, _value, uint64(_queueIndex), _gasLimit, _data);
Expand Down
126 changes: 123 additions & 3 deletions contracts/contracts/l1/rollup/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
/// @notice committedStateRoots
mapping(uint256 batchIndex => bytes32 stateRoot) public committedStateRoots;

uint256 public rollupDelayPeird;

Comment thread
Kukoomomo marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
/**********************
* Function Modifiers *
**********************/
Expand Down Expand Up @@ -183,6 +185,11 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
}
}

function initialize3(uint256 _rollupDelayPeird) external reinitializer(3) {
require(_rollupDelayPeird != 0, "invalid rollup delay peird");
rollupDelayPeird = _rollupDelayPeird;
emit RollupDelayPeirdUpdate(0, _rollupDelayPeird);
}
Comment thread
Kukoomomo marked this conversation as resolved.
/************************
* Restricted Functions *
************************/
Expand Down Expand Up @@ -220,6 +227,13 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
BatchDataInput calldata batchDataInput,
BatchSignatureInput calldata batchSignatureInput
) external payable override onlyActiveStaker nonReqRevert whenNotPaused {
_commitBatchWithBatchData(batchDataInput, batchSignatureInput);
}
Comment thread
Kukoomomo marked this conversation as resolved.

function _commitBatchWithBatchData(
BatchDataInput calldata batchDataInput,
BatchSignatureInput calldata batchSignatureInput
) internal {
require(batchDataInput.version == 0 || batchDataInput.version == 1, "invalid version");
require(batchDataInput.prevStateRoot != bytes32(0), "previous state root is zero");
require(batchDataInput.postStateRoot != bytes32(0), "new state root is zero");
Expand Down Expand Up @@ -259,7 +273,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
}
bytes32 _blobVersionedHash = (blobhash(0) == bytes32(0)) ? ZERO_VERSIONED_HASH : blobhash(0);

{
{
uint256 _headerLength = BatchHeaderCodecV0.BATCH_HEADER_LENGTH;
if (batchDataInput.version == 1) {
_headerLength = BatchHeaderCodecV1.BATCH_HEADER_LENGTH;
Expand Down Expand Up @@ -318,6 +332,55 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
emit CommitBatch(_batchIndex, committedBatches[_batchIndex]);
}

function commitBatchWithProof(
BatchDataInput calldata batchDataInput,
BatchSignatureInput calldata batchSignatureInput,
bytes calldata _batchHeader,
bytes calldata _batchProof
) external payable nonReqRevert whenNotPaused {
require(!inChallenge, "already in challenge");
(uint256 _parentBatchPtr, ) = _loadBatchHeader(batchDataInput.parentBatchHeader);
uint256 _parentBatchIndex = BatchHeaderCodecV0.getBatchIndex(_parentBatchPtr);
require(_parentBatchIndex == lastFinalizedBatchIndex, "incorrect batch index");

// check delay timing - allow if EITHER batch submission OR L1 message processing is stalled
// This enables permissionless batch submission when sequencers are offline or censoring
if (batchDataStore[lastCommittedBatchIndex].originTimestamp + rollupDelayPeird >= block.timestamp &&
IL1MessageQueue(messageQueue).getFirstUnfinalizedMessageEnqueueTime() + rollupDelayPeird >= block.timestamp
) {
revert InvalidTiming();
}
// revert batch from the parent batch to the last committed batch
uint256 revertCount = lastCommittedBatchIndex - _parentBatchIndex;
if (revertCount > 0) {
uint256 startBatchIndex = _parentBatchIndex + 1;
for (uint256 i = startBatchIndex; i <= lastCommittedBatchIndex; i++) {
committedBatches[i] = bytes32(0);
}
emit RevertBatchRange(startBatchIndex, revertCount);
}
lastCommittedBatchIndex = _parentBatchIndex;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

_commitBatchWithBatchData(batchDataInput, batchSignatureInput);

// get batch data from batch header
(uint256 memPtr, bytes32 _batchHash) = _loadBatchHeader(_batchHeader);
// check batch hash
uint256 _batchIndex = BatchHeaderCodecV0.getBatchIndex(memPtr);
require(committedBatches[_batchIndex] == _batchHash, "incorrect batch hash");
Comment thread
Kukoomomo marked this conversation as resolved.

// verify consistency between batchDataInput and batchHeader
_verifyBatchConsistency(batchDataInput, memPtr);
Comment thread
Kukoomomo marked this conversation as resolved.
Outdated

// Override finalizeTimestamp for ZKP-backed immediate finality
batchDataStore[_batchIndex].finalizeTimestamp = block.timestamp;

// verify proof
_verifyProof(memPtr, _batchProof);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// finalize batch
finalizeBatch(_batchHeader);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

/// @inheritdoc IRollup
/// @dev If the owner wants to revert a sequence of batches by sending multiple transactions,
/// make sure to revert recent batches first.
Expand Down Expand Up @@ -407,6 +470,15 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
emit UpdateFinalizationPeriodSeconds(_oldFinalizationPeriodSeconds, finalizationPeriodSeconds);
}

/// @notice Update rollupDelayPeird.
/// @param _newPeriod New rollup delay period.
function updateRollupDelayPeird(uint256 _newPeriod) external onlyOwner {
require(_newPeriod > 0 && _newPeriod != rollupDelayPeird, "invalid new rollup delay period");
uint256 _oldRollupDelayPeird = rollupDelayPeird;
rollupDelayPeird = _newPeriod;
emit RollupDelayPeirdUpdate(_oldRollupDelayPeird, rollupDelayPeird);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

/// @notice Add an account to the challenger list.
/// @param _account The address of account to add.
function addChallenger(address _account) external onlyOwner {
Expand Down Expand Up @@ -477,7 +549,10 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
*****************************/

/// @dev proveState proves a batch by submitting a proof.
function proveState(bytes calldata _batchHeader, bytes calldata _batchProof) external nonReqRevert whenNotPaused onlyActiveStaker{
function proveState(
bytes calldata _batchHeader,
bytes calldata _batchProof
) external nonReqRevert whenNotPaused onlyActiveStaker {
// get batch data from batch header
(uint256 memPtr, bytes32 _batchHash) = _loadBatchHeader(_batchHeader);
// check batch hash
Expand Down Expand Up @@ -614,6 +689,51 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
}
}

/// @dev Internal function to verify consistency between BatchDataInput and batch header.
/// @param batchDataInput The batch data input from the caller.
/// @param memPtr The memory pointer to the loaded batch header.
function _verifyBatchConsistency(
BatchDataInput calldata batchDataInput,
uint256 memPtr
) private pure {
// verify version
require(
batchDataInput.version == BatchHeaderCodecV0.getVersion(memPtr),
"batch version mismatch"
);

// verify number of L1 messages
require(
batchDataInput.numL1Messages == BatchHeaderCodecV0.getL1MessagePopped(memPtr),
"l1 message count mismatch"
);

// verify previous state root
require(
batchDataInput.prevStateRoot == BatchHeaderCodecV0.getPrevStateHash(memPtr),
"prev state root mismatch"
);

// verify post state root
require(
batchDataInput.postStateRoot == BatchHeaderCodecV0.getPostStateHash(memPtr),
"post state root mismatch"
);

// verify withdrawal root
require(
batchDataInput.withdrawalRoot == BatchHeaderCodecV0.getWithdrawRootHash(memPtr),
"withdrawal root mismatch"
);

// verify parent batch hash
(, bytes32 _parentBatchHash) = _loadBatchHeader(batchDataInput.parentBatchHeader);
require(
_parentBatchHash == BatchHeaderCodecV0.getParentBatchHash(memPtr),
"parent batch hash mismatch"
);
}

/// @dev Internal function to verify the zk proof.
function _verifyProof(uint256 memPtr, bytes calldata _batchProof) private view {
// Check validity of proof
Expand Down Expand Up @@ -727,7 +847,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
if (_version == 0) {
(_memPtr, _length) = BatchHeaderCodecV0.loadAndValidate(_batchHeader);
} else if (_version == 1) {
(_memPtr, _length) = BatchHeaderCodecV1.loadAndValidate(_batchHeader);
(_memPtr, _length) = BatchHeaderCodecV1.loadAndValidate(_batchHeader);
} else {
revert("Unsupported batch version");
}
Expand Down
Loading
Loading