编译器
0.8.24+commit.e11b9ed9
文件 1 的 5:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 5:IRollupVerifier.sol
pragma solidity ^0.8.24;
interface IRollupVerifier {
function verifyAggregateProof(
uint256 batchIndex,
bytes calldata aggrProof,
bytes32 publicInputHash
) external view;
function verifyAggregateProof(
uint256 version,
uint256 batchIndex,
bytes calldata aggrProof,
bytes32 publicInputHash
) external view;
function verifyBundleProof(
uint256 version,
uint256 batchIndex,
bytes calldata bundleProof,
bytes calldata publicInput
) external view;
}
文件 3 的 5:IZkEvmVerifier.sol
pragma solidity ^0.8.24;
interface IZkEvmVerifierV1 {
function verify(bytes calldata aggrProof, bytes32 publicInputHash) external view;
}
interface IZkEvmVerifierV2 {
function verify(bytes calldata bundleProof, bytes calldata publicInput) external view;
}
文件 4 的 5:MultipleVersionRollupVerifier.sol
pragma solidity =0.8.24;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IRollupVerifier} from "../../libraries/verifier/IRollupVerifier.sol";
import {IZkEvmVerifierV1, IZkEvmVerifierV2} from "../../libraries/verifier/IZkEvmVerifier.sol";
contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
event UpdateVerifier(uint256 version, uint256 startBatchIndex, address verifier);
error ErrorZeroAddress();
error ErrorStartBatchIndexTooSmall();
struct Verifier {
uint64 startBatchIndex;
address verifier;
}
mapping(uint256 => Verifier[]) public legacyVerifiers;
mapping(uint256 => Verifier) public latestVerifier;
constructor(uint256[] memory _versions, address[] memory _verifiers) {
for (uint256 i = 0; i < _versions.length; i++) {
if (_verifiers[i] == address(0)) revert ErrorZeroAddress();
latestVerifier[_versions[i]].verifier = _verifiers[i];
emit UpdateVerifier(_versions[i], 0, _verifiers[i]);
}
}
function legacyVerifiersLength(uint256 _version) external view returns (uint256) {
return legacyVerifiers[_version].length;
}
function getVerifier(uint256 _version, uint256 _batchIndex) public view returns (address) {
Verifier memory _verifier = latestVerifier[_version];
if (_verifier.startBatchIndex > _batchIndex) {
uint256 _length = legacyVerifiers[_version].length;
unchecked {
for (uint256 i = _length; i > 0; --i) {
_verifier = legacyVerifiers[_version][i - 1];
if (_verifier.startBatchIndex <= _batchIndex) break;
}
}
}
return _verifier.verifier;
}
function verifyAggregateProof(
uint256 _batchIndex,
bytes calldata _aggrProof,
bytes32 _publicInputHash
) external view override {
address _verifier = getVerifier(0, _batchIndex);
IZkEvmVerifierV1(_verifier).verify(_aggrProof, _publicInputHash);
}
function verifyAggregateProof(
uint256 _version,
uint256 _batchIndex,
bytes calldata _aggrProof,
bytes32 _publicInputHash
) external view override {
address _verifier = getVerifier(_version, _batchIndex);
IZkEvmVerifierV1(_verifier).verify(_aggrProof, _publicInputHash);
}
function verifyBundleProof(
uint256 _version,
uint256 _batchIndex,
bytes calldata _bundleProof,
bytes calldata _publicInput
) external view override {
address _verifier = getVerifier(_version, _batchIndex);
IZkEvmVerifierV2(_verifier).verify(_bundleProof, _publicInput);
}
function updateVerifier(
uint256 _version,
uint64 _startBatchIndex,
address _verifier
) external onlyOwner {
Verifier memory _latestVerifier = latestVerifier[_version];
if (_startBatchIndex < _latestVerifier.startBatchIndex) revert ErrorStartBatchIndexTooSmall();
if (_verifier == address(0)) revert ErrorZeroAddress();
if (_latestVerifier.startBatchIndex < _startBatchIndex) {
if (_latestVerifier.verifier != address(0)) {
legacyVerifiers[_version].push(_latestVerifier);
}
_latestVerifier.startBatchIndex = _startBatchIndex;
}
_latestVerifier.verifier = _verifier;
latestVerifier[_version] = _latestVerifier;
emit UpdateVerifier(_version, _startBatchIndex, _verifier);
}
}
文件 5 的 5:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
{
"compilationTarget": {
"src/L1/rollup/MultipleVersionRollupVerifier.sol": "MultipleVersionRollupVerifier"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256[]","name":"_versions","type":"uint256[]"},{"internalType":"address[]","name":"_verifiers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ErrorStartBatchIndexTooSmall","type":"error"},{"inputs":[],"name":"ErrorZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"version","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startBatchIndex","type":"uint256"},{"indexed":false,"internalType":"address","name":"verifier","type":"address"}],"name":"UpdateVerifier","type":"event"},{"inputs":[{"internalType":"uint256","name":"_version","type":"uint256"},{"internalType":"uint256","name":"_batchIndex","type":"uint256"}],"name":"getVerifier","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"latestVerifier","outputs":[{"internalType":"uint64","name":"startBatchIndex","type":"uint64"},{"internalType":"address","name":"verifier","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"legacyVerifiers","outputs":[{"internalType":"uint64","name":"startBatchIndex","type":"uint64"},{"internalType":"address","name":"verifier","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_version","type":"uint256"}],"name":"legacyVerifiersLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_version","type":"uint256"},{"internalType":"uint64","name":"_startBatchIndex","type":"uint64"},{"internalType":"address","name":"_verifier","type":"address"}],"name":"updateVerifier","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_version","type":"uint256"},{"internalType":"uint256","name":"_batchIndex","type":"uint256"},{"internalType":"bytes","name":"_aggrProof","type":"bytes"},{"internalType":"bytes32","name":"_publicInputHash","type":"bytes32"}],"name":"verifyAggregateProof","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_batchIndex","type":"uint256"},{"internalType":"bytes","name":"_aggrProof","type":"bytes"},{"internalType":"bytes32","name":"_publicInputHash","type":"bytes32"}],"name":"verifyAggregateProof","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_version","type":"uint256"},{"internalType":"uint256","name":"_batchIndex","type":"uint256"},{"internalType":"bytes","name":"_bundleProof","type":"bytes"},{"internalType":"bytes","name":"_publicInput","type":"bytes"}],"name":"verifyBundleProof","outputs":[],"stateMutability":"view","type":"function"}]