Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
9 changes: 7 additions & 2 deletions hardhat-test/ZkEvmVerifierV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ describe("ZkEvmVerifierV2", async () => {
const chainProxy = await TransparentUpgradeableProxy.deploy(empty.getAddress(), admin.getAddress(), "0x");

const ScrollChainMockBlob = await ethers.getContractFactory("ScrollChainMockBlob", deployer);
const chainImpl = await ScrollChainMockBlob.deploy(layer2ChainId, deployer.address, verifier.getAddress());
const chainImpl = await ScrollChainMockBlob.deploy(
layer2ChainId,
deployer.address,
verifier.getAddress(),
verifier.getAddress()
);
await admin.upgrade(chainProxy.getAddress(), chainImpl.getAddress());

chain = await ethers.getContractAt("ScrollChainMockBlob", await chainProxy.getAddress(), deployer);
Expand Down Expand Up @@ -129,7 +134,7 @@ describe("ZkEvmVerifierV2", async () => {
const withdrawRoot = hexlify(publicInputs.subarray(140, 172));

await chain.setOverrideBatchHashCheck(true);
await chain.setLastFinalizedBatchIndex(lastFinalizedBatchIndex);
await chain.setLastZkpVerifiedBatchIndex(lastFinalizedBatchIndex);
await chain.setFinalizedStateRoots(lastFinalizedBatchIndex, prevStateRoot);
await chain.setCommittedBatches(lastFinalizedBatchIndex, prevBatchHash);
await chain.setCommittedBatches(batchIndex, batchHash);
Expand Down
7 changes: 6 additions & 1 deletion scripts/foundry/DeployL1BridgeContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ contract DeployL1BridgeContracts is Script {
}

function deployScrollChain() internal {
ScrollChain impl = new ScrollChain(CHAIN_ID_L2, L1_MESSAGE_QUEUE_PROXY_ADDR, address(rollupVerifier));
ScrollChain impl = new ScrollChain(
CHAIN_ID_L2,
L1_MESSAGE_QUEUE_PROXY_ADDR,
address(rollupVerifier),
address(0)
);

logAddress("L1_SCROLL_CHAIN_IMPLEMENTATION_ADDR", address(impl));
}
Expand Down
55 changes: 53 additions & 2 deletions src/L1/rollup/IScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,44 @@ interface IScrollChain {
/// @param batchHash The hash of the batch
event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);

/// @notice Emitted when a batch is verified by zk proof
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch
/// @param stateRoot The state root on layer 2 after this batch.
/// @param withdrawRoot The merkle root on layer2 after this batch.
event VerifyBatchWithZkp(
uint256 indexed batchIndex,
bytes32 indexed batchHash,
bytes32 stateRoot,
bytes32 withdrawRoot
);

/// @notice Emitted when a batch is verified by tee proof
/// @dev Tee proof always comes after zk proof. If they match, the state root and withdraw root are the same.
/// If they mismatch, we will emit `StateMismatch` instead. Therefore, the `stateRoot` and `withdrawRoot`
/// is not included in this event.
/// @param batchIndex The index of the batch.
event VerifyBatchWithTee(uint256 indexed batchIndex);

/// @notice Emitted when a batch is finalized.
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch
/// @param stateRoot The state root on layer 2 after this batch.
/// @param withdrawRoot The merkle root on layer2 after this batch.
event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);

/// @notice Emitted when state between zk proof and tee proof mismatch
/// @param batchIndex The index of the batch.
/// @param stateRoot The state root from tee proof.
/// @param withdrawRoot The correct withdraw root from tee proof.
event StateMismatch(uint256 indexed batchIndex, bytes32 stateRoot, bytes32 withdrawRoot);

/// @notice Emitted when mismatched state is resolved.
/// @param batchIndex The index of the batch.
/// @param stateRoot The correct state root.
/// @param withdrawRoot The correct withdraw root.
event ResolveState(uint256 indexed batchIndex, bytes32 stateRoot, bytes32 withdrawRoot);

/// @notice Emitted when owner updates the status of sequencer.
/// @param account The address of account updated.
/// @param status The status of the account updated.
Expand All @@ -45,9 +76,15 @@ interface IScrollChain {
* Public View Functions *
*************************/

/// @return The latest finalized batch index.
/// @return The latest finalized batch index (both zkp and tee verified).
function lastFinalizedBatchIndex() external view returns (uint256);

/// @return The latest verified batch index by zkp proof.
function lastZkpVerifiedBatchIndex() external view returns (uint256);

/// @return The latest verified batch index by tee proof.
function lastTeeVerifiedBatchIndex() external view returns (uint256);

/// @param batchIndex The index of the batch.
/// @return The batch hash of a committed batch.
function committedBatches(uint256 batchIndex) external view returns (bytes32);
Expand Down Expand Up @@ -107,6 +144,7 @@ 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;

/* This function will never be used since we already upgrade to Darwin. We comment out the codes for reference.
/// @notice Finalize a committed batch (with blob) on layer 1.
///
/// @dev Memory layout of `blobDataProof`:
Expand All @@ -128,9 +166,10 @@ interface IScrollChain {
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 batchHeader The header of last batch in current bundle, see the encoding in comments of `commitBatch`.
/// @param postStateRoot The state root after current bundle.
/// @param withdrawRoot The withdraw trie root after current batch.
/// @param aggrProof The aggregation proof for current bundle.
Expand All @@ -140,4 +179,16 @@ interface IScrollChain {
bytes32 withdrawRoot,
bytes calldata aggrProof
) external;

/// @notice Finalize a list of committed batches (i.e. bundle) on layer 1 with TEE proof.
/// @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.
/// @param withdrawRoot The withdraw trie root after current batch.
/// @param teeProof The tee proof for current bundle.
function finalizeBundleWithTeeProof(
bytes calldata batchHeader,
bytes32 postStateRoot,
bytes32 withdrawRoot,
bytes calldata teeProof
) external;
}
Loading