Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate enforces batch PR
Browse files Browse the repository at this point in the history
zimpha committed Dec 5, 2024
1 parent 2d06562 commit aee35b9
Showing 7 changed files with 294 additions and 1,313 deletions.
68 changes: 33 additions & 35 deletions src/L1/rollup/IScrollChain.sol
Original file line number Diff line number Diff line change
@@ -68,19 +68,6 @@ interface IScrollChain {
* Public Mutating Functions *
*****************************/

/// @notice Commit a batch of transactions on layer 1.
///
/// @param version The version of current batch.
/// @param parentBatchHeader The header of parent batch, see the comments of `BatchHeaderV0Codec`.
/// @param chunks The list of encoded chunks, see the comments of `ChunkCodec`.
/// @param skippedL1MessageBitmap The bitmap indicates whether each L1 message is skipped or not.
function commitBatch(
uint8 version,
bytes calldata parentBatchHeader,
bytes[] memory chunks,
bytes calldata skippedL1MessageBitmap
) external;

/// @notice Commit a batch of transactions on layer 1 with blob data proof.
///
/// @dev Memory layout of `blobDataProof`:
@@ -107,28 +94,6 @@ interface IScrollChain {
/// @param lastBatchHeader The header of last batch to revert, see the encoding in comments of `commitBatch`.
function revertBatch(bytes calldata firstBatchHeader, bytes calldata lastBatchHeader) external;

/// @notice Finalize a committed batch (with blob) on layer 1.
///
/// @dev Memory layout of `blobDataProof`:
/// | z | y | kzg_commitment | kzg_proof |
/// |---------|---------|----------------|-----------|
/// | bytes32 | bytes32 | bytes48 | bytes48 |
///
/// @param batchHeader The header of current batch, see the encoding in comments of `commitBatch.
/// @param prevStateRoot The state root of parent batch.
/// @param postStateRoot The state root of current batch.
/// @param withdrawRoot The withdraw trie root of current batch.
/// @param blobDataProof The proof for blob data.
/// @param aggrProof The aggregation proof for current batch.
function finalizeBatchWithProof4844(
bytes calldata batchHeader,
bytes32 prevStateRoot,
bytes32 postStateRoot,
bytes32 withdrawRoot,
bytes calldata blobDataProof,
bytes calldata aggrProof
) external;

/// @notice Finalize a list of committed batches (i.e. bundle) on layer 1.
/// @param batchHeader The header of last batch in current bundle, see the encoding in comments of `commitBatch.
/// @param postStateRoot The state root after current bundle.
@@ -140,4 +105,37 @@ interface IScrollChain {
bytes32 withdrawRoot,
bytes calldata aggrProof
) external;

/// @param The struct for batch committing.
/// @param version The version of current batch.
/// @param parentBatchHeader The header of parent batch, see the comments of `BatchHeaderV0Codec`.
/// @param chunks The list of encoded chunks, see the comments of `ChunkCodec`.
/// @param blobDataProof The proof for blob data.
struct CommitStruct {
uint8 version;
bytes parentBatchHeader;
bytes[] chunks;
bytes skippedL1MessageBitmap;
bytes blobDataProof;
}

/// @param The struct for batch finalization.
/// @param batchHeader The header of current batch, see the encoding in comments of `commitBatch`.
/// @param postStateRoot The state root after current batch.
/// @param withdrawRoot The withdraw trie root after current batch.
/// @param zkProof The zk proof for current batch (single-batch bundle).
/// @param teeProof The tee proof for current batch (single-batch bundle).
struct FinalizeStruct {
bytes batchHeader;
bytes32 postStateRoot;
bytes32 withdrawRoot;
bytes zkProof;
bytes teeProof;
}

/// @notice Commit a batch of transactions on layer 1 with blob data proof and finalize it.
/// @param commitStruct The data needed for commit.
/// @param finalizeStruct The data needed for finalize.
function commitAndFinalizeBatch(CommitStruct calldata commitStruct, FinalizeStruct calldata finalizeStruct)
external;
}
700 changes: 241 additions & 459 deletions src/L1/rollup/ScrollChain.sol

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/libraries/codec/BatchHeaderV3Codec.sol
Original file line number Diff line number Diff line change
@@ -46,6 +46,15 @@ library BatchHeaderV3Codec {
}
}

/// @notice Get the blob versioned hash of the batch header.
/// @param batchPtr The start memory offset of the batch header in memory.
/// @return _lastBlockTimestamp The timestamp of the last block in this batch.
function getLastBlockTimestamp(uint256 batchPtr) internal pure returns (uint256 _lastBlockTimestamp) {
assembly {
_lastBlockTimestamp := mload(shr(192, add(batchPtr, 121)))
}
}

/// @notice Store the last block timestamp of batch header.
/// @param batchPtr The start memory offset of the batch header in memory.
/// @param _lastBlockTimestamp The timestamp of the last block in this batch.
7 changes: 6 additions & 1 deletion src/mocks/ScrollChainMockBlob.sol
Original file line number Diff line number Diff line change
@@ -50,7 +50,12 @@ contract ScrollChainMockBlob is ScrollChain {
overrideBatchHashCheck = status;
}

function _getBlobVersionedHash() internal virtual override returns (bytes32 _blobVersionedHash) {
function _checkAndGetBlobVersionedHash(bytes calldata)
internal
virtual
override
returns (bytes32 _blobVersionedHash)
{
_blobVersionedHash = blobVersionedHash;
}

28 changes: 0 additions & 28 deletions src/mocks/ScrollChainMockFinalize.sol
Original file line number Diff line number Diff line change
@@ -27,34 +27,6 @@ contract ScrollChainMockFinalize is ScrollChain {
* Public Mutating Functions *
*****************************/

/// @notice Finalize 4844 batch without proof, See the comments of {ScrollChain-finalizeBatchWithProof4844}.
function finalizeBatch4844(
bytes calldata _batchHeader,
bytes32, /*_prevStateRoot*/
bytes32 _postStateRoot,
bytes32 _withdrawRoot,
bytes calldata _blobDataProof
) external OnlyProver whenNotPaused {
(uint256 batchPtr, bytes32 _batchHash, uint256 _batchIndex) = _beforeFinalizeBatch(
_batchHeader,
_postStateRoot
);

// verify blob versioned hash
bytes32 _blobVersionedHash = BatchHeaderV1Codec.getBlobVersionedHash(batchPtr);
_checkBlobVersionedHash(_blobVersionedHash, _blobDataProof);

// Pop finalized and non-skipped message from L1MessageQueue.
uint256 _totalL1MessagesPoppedOverall = BatchHeaderV0Codec.getTotalL1MessagePopped(batchPtr);
_popL1MessagesMemory(
BatchHeaderV1Codec.getSkippedBitmapPtr(batchPtr),
_totalL1MessagesPoppedOverall,
BatchHeaderV0Codec.getL1MessagePopped(batchPtr)
);

_afterFinalizeBatch(_totalL1MessagesPoppedOverall, _batchIndex, _batchHash, _postStateRoot, _withdrawRoot);
}

/// @notice Finalize bundle without proof, See the comments of {ScrollChain-finalizeBundleWithProof}.
function finalizeBundle(
bytes calldata _batchHeader,
6 changes: 3 additions & 3 deletions src/test/L1GatewayTestBase.t.sol
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
// rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();

bytes memory batchHeader1 = new bytes(121);
@@ -176,14 +176,14 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
}

hevm.startPrank(address(0));
rollup.finalizeBatchWithProof4844(
/*rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
messageHash,
blobDataProof,
new bytes(0)
);
);*/
hevm.stopPrank();
}
}
789 changes: 2 additions & 787 deletions src/test/ScrollChain.t.sol

Large diffs are not rendered by default.

0 comments on commit aee35b9

Please sign in to comment.