Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha committed Nov 5, 2024
1 parent dc6b99f commit acd550c
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 732 deletions.
6 changes: 3 additions & 3 deletions hardhat-test/ZkEvmVerifierV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable node/no-missing-import */
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import { expect } from "chai";
import { hexlify, ZeroAddress } from "ethers";
import { hexlify } from "ethers";
import fs from "fs";
import { ethers } from "hardhat";

Expand Down Expand Up @@ -99,7 +99,7 @@ describe("ZkEvmVerifierV2", async () => {
layer2ChainId,
deployer.address,
verifier.getAddress(),
ZeroAddress
verifier.getAddress()
);
await admin.upgrade(chainProxy.getAddress(), chainImpl.getAddress());

Expand Down Expand Up @@ -134,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
17 changes: 9 additions & 8 deletions src/L1/rollup/ScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
/// @notice The address of L1MessageQueue contract.
address public immutable messageQueue;

/// @notice The address of RollupVerifier.
address public immutable verifier;
/// @notice The address of `MultipleVersionRollupVerifier` for zk proof.
address public immutable zkpVerifier;

/// @notice The address of RollupVerifier.
/// @notice The address of `MultipleVersionRollupVerifier` for tee proof.
address public immutable teeVerifier;

/***********
Expand Down Expand Up @@ -219,22 +219,23 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
///
/// @param _chainId The chain id of L2.
/// @param _messageQueue The address of `L1MessageQueue` contract.
/// @param _verifier The address of zkevm verifier contract.
/// @param _zkpVerifier The address of zkevm verifier contract.
/// @param _teeVerifier The address of tee verifier contract.
constructor(
uint64 _chainId,
address _messageQueue,
address _verifier,
address _zkpVerifier,
address _teeVerifier
) {
if (_messageQueue == address(0) || _verifier == address(0)) {
if (_messageQueue == address(0) || _zkpVerifier == address(0) || _teeVerifier == address(0)) {
revert ErrorZeroAddress();
}

_disableInitializers();

layer2ChainId = _chainId;
messageQueue = _messageQueue;
verifier = _verifier;
zkpVerifier = _zkpVerifier;
teeVerifier = _teeVerifier;
}

Expand Down Expand Up @@ -620,7 +621,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {

// verify bundle, choose the correct verifier based on the last batch
// our off-chain service will make sure all unfinalized batches have the same batch version.
IRollupVerifier(verifier).verifyBundleProof(batchVersion, _batchIndex, _aggrProof, _publicInput);
IRollupVerifier(zkpVerifier).verifyBundleProof(batchVersion, _batchIndex, _aggrProof, _publicInput);

// store in state
// @note we do not store intermediate finalized roots
Expand Down
16 changes: 6 additions & 10 deletions src/mocks/ScrollChainMockFinalize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,17 @@ contract ScrollChainMockFinalize is ScrollChain {
bytes calldata _batchHeader,
bytes32 _postStateRoot,
bytes32 _withdrawRoot
) external OnlyProver whenNotPaused {
) external OnlyProver whenFinalizeNotPaused {
if (_postStateRoot == bytes32(0)) revert ErrorStateRootIsZero();

// compute pending batch hash and verify
(
uint256 batchPtr,
bytes32 _batchHash,
uint256 _batchIndex,
uint256 _totalL1MessagesPoppedOverall
) = _loadBatchHeader(_batchHeader);
(, bytes32 _batchHash, uint256 _batchIndex, ) = _loadBatchHeader(_batchHeader);

// retrieve finalized state root and batch hash from storage to construct the public input
uint256 _finalizedBatchIndex = lastZkpVerifiedBatchIndex;
if (_batchIndex <= _finalizedBatchIndex) revert ErrorBatchIsAlreadyVerified();

/* @note skip verifier in mock
bytes memory _publicInput = abi.encodePacked(
layer2ChainId,
uint32(_batchIndex - _finalizedBatchIndex), // numBatches
Expand All @@ -87,12 +83,12 @@ contract ScrollChainMockFinalize is ScrollChain {
_withdrawRoot
);
// @note skip verifier in mock
// load version from batch header, it is always the first byte.
// uint256 batchVersion = BatchHeaderV0Codec.getVersion(batchPtr);
uint256 batchVersion = BatchHeaderV0Codec.getVersion(batchPtr);
// verify bundle, choose the correct verifier based on the last batch
// our off-chain service will make sure all unfinalized batches have the same batch version.
// IRollupVerifier(verifier).verifyBundleProof(batchVersion, _batchIndex, _aggrProof, _publicInput);
IRollupVerifier(verifier).verifyBundleProof(batchVersion, _batchIndex, _aggrProof, _publicInput);
*/

// store in state
// @note we do not store intermediate finalized roots
Expand Down
22 changes: 8 additions & 14 deletions src/test/L1GatewayTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
EnforcedTxGateway internal enforcedTxGateway;
ScrollChainMockBlob internal rollup;

MockRollupVerifier internal verifier;
MockRollupVerifier internal zkpVerifier;
MockRollupVerifier internal teeVerifier;

address internal feeVault;
Whitelist private whitelist;
Expand All @@ -91,7 +92,8 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
enforcedTxGateway = EnforcedTxGateway(_deployProxy(address(new EnforcedTxGateway())));
gasOracle = L2GasPriceOracle(_deployProxy(address(new L2GasPriceOracle())));
whitelist = new Whitelist(address(this));
verifier = new MockRollupVerifier();
zkpVerifier = new MockRollupVerifier();
teeVerifier = new MockRollupVerifier();

// deploy proxy and contracts in L2
l2Messenger = L2ScrollMessenger(payable(_deployProxy(address(0))));
Expand Down Expand Up @@ -124,7 +126,7 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
// Upgrade the ScrollChain implementation and initialize
admin.upgrade(
ITransparentUpgradeableProxy(address(rollup)),
address(new ScrollChainMockBlob(1233, address(messageQueue), address(verifier), address(0)))
address(new ScrollChainMockBlob(1233, address(messageQueue), address(zkpVerifier), address(teeVerifier)))
);
rollup.initialize(address(messageQueue), address(0), 44);

Expand Down Expand Up @@ -161,7 +163,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);
Expand All @@ -176,16 +178,8 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
}

hevm.startPrank(address(0));
/*
rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
messageHash,
blobDataProof,
new bytes(0)
);
*/
rollup.finalizeBundleWithProof(batchHeader1, bytes32(uint256(2)), messageHash, new bytes(0));
rollup.finalizeBundleWithTeeProof(batchHeader1, bytes32(uint256(2)), messageHash, new bytes(0));
hevm.stopPrank();
}
}
Loading

0 comments on commit acd550c

Please sign in to comment.