Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: storage mirror root registry #10

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions solidity/contracts/BlockHeaderOracle.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol';
/**
* @title BlockHeaderOracle
* @notice This contract's purpose is to return the latest stored L1 block header and timestamp
* @notice Every X minutes a "magical" off-chain agent provides the latest block header and timestamp
*/
contract BlockHeaderOracle {
/**
* @notice Emits when the block header and timestamp are updated
*/
event BlockHeaderUpdated(bytes _blockHeader, uint256 _blockTimestamp, uint256 _blockNumber);

contract BlockHeaderOracle is IBlockHeaderOracle {
/**
* @notice The block header
*/
Expand Down
61 changes: 61 additions & 0 deletions solidity/contracts/StorageMirrorRootRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol';
import {IVerifierModule} from 'interfaces/IVerifierModule.sol';
import {IStorageMirrorRootRegistry} from 'interfaces/IStorageMirrorRootRegistry.sol';

/**
* @title StorageMirrorRootRegistry
* @notice This contract should accept and store storageRoots of the StorageMirror contract in L1.
*/
contract StorageMirrorRootRegistry is IStorageMirrorRootRegistry {
/**
* @notice The address of the StorageMirror contract in Home chain
*/
address public immutable STORAGE_MIRROR;

/**
* @notice The address of the Verifier Module
*/
IVerifierModule public immutable VERIFIER_MODULE;

/**
* @notice The block header oracle
*/
IBlockHeaderOracle public immutable BLOCK_HEADER_ORACLE;

/**
* @notice The latest verified storage root of the StorageMirror contract in Home chain
*/
bytes32 public latestVerifiedStorageMirrorStorageRoot;

constructor(address _storageMirror, IVerifierModule _verifierModule, IBlockHeaderOracle _blockHeaderOracle) {
STORAGE_MIRROR = _storageMirror;
VERIFIER_MODULE = _verifierModule;
BLOCK_HEADER_ORACLE = _blockHeaderOracle;
}

/**
* @notice Users can use to propose and verify a storage root of the StorageMirror contract in Home chain
* @dev Calls queryL1BlockHeader to get the block header of the Home chain
* @dev Call verifier module for the actual verificationn
* @param _blockNumber The block number in the home chain to get the header from
* @param _accountProof The account proof of the StorageMirror contract in Home chain
*/
function proposeAndVerifyStorageMirrorStorageRoot(uint256 _blockNumber, bytes memory _accountProof) external {
bytes memory _blockHeader = _queryL1BlockHeader();
excaliborr marked this conversation as resolved.
Show resolved Hide resolved
latestVerifiedStorageMirrorStorageRoot =
VERIFIER_MODULE.extractStorageMirrorStorageRoot(_blockHeader, _accountProof);

emit VerifiedStorageMirrorStorageRoot(_blockNumber, latestVerifiedStorageMirrorStorageRoot);
}

/**
* @notice Function that queries an oracle to get the latest bridged block header of the Home chain
* @return _blockHeader The block header of the Home chain
*/
function _queryL1BlockHeader() internal view returns (bytes memory _blockHeader) {
(_blockHeader,) = BLOCK_HEADER_ORACLE.getLatestBlockHeader();
}
}
47 changes: 47 additions & 0 deletions solidity/interfaces/IBlockHeaderOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

interface IBlockHeaderOracle {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Emits when the block header and timestamp are updated
*/
event BlockHeaderUpdated(bytes _blockHeader, uint256 _blockTimestamp, uint256 _blockNumber);

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice The block header
* @return _blockheader The block header
*/
function blockHeader() external view returns (bytes memory _blockheader);

/**
* @notice The block timestamp of the latest block header
* @return _blockTimestamp The block timestamp
*/
function blockTimestamp() external view returns (uint256 _blockTimestamp);

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Updates the block header and timestamp
* @param _blockHeader The block header
* @param _blockTimestamp The block timestamp
* @param _blockNumber The block number
*/
function updateBlockHeader(bytes memory _blockHeader, uint256 _blockTimestamp, uint256 _blockNumber) external;

/**
* @notice Returns the latest block header and timestamp
* @return _blockHeader The block header
* @return _blockTimestamp The block timestamp
*/
function getLatestBlockHeader() external view returns (bytes memory _blockHeader, uint256 _blockTimestamp);
}
62 changes: 62 additions & 0 deletions solidity/interfaces/IStorageMirrorRootRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {IVerifierModule} from 'interfaces/IVerifierModule.sol';
import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol';

interface IStorageMirrorRootRegistry {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Emits after the storage root gets verified
* @param _homeChainBlockNumber The block number of the Home chain
* @param _storageRoot The storage root of the StorageMirror contract in Home chain that was verified
*/
event VerifiedStorageMirrorStorageRoot(uint256 indexed _homeChainBlockNumber, bytes32 _storageRoot);

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice The address of the StorageMirror contract in Home chain
* @return _storageMirror The address of the StorageMirror contract in Home chain
*/
function STORAGE_MIRROR() external view returns (address _storageMirror);

/**
* @notice The address of the Verifier Module
* @return _verifierModule The address of the Verifier Module
*/
function VERIFIER_MODULE() external view returns (IVerifierModule _verifierModule);

/**
* @notice The address of the Block Header Oracle
* @return _blockHeaderOracle The address of the Block Header Oracle
*/
function BLOCK_HEADER_ORACLE() external view returns (IBlockHeaderOracle _blockHeaderOracle);

/**
* @notice The latest verified storage root of the StorageMirror contract in Home chain
* @return _latestVerifiedStorageMirrorStorageRoot The latest verified storage root of the StorageMirror contract in Home chain
*/
function latestVerifiedStorageMirrorStorageRoot()
external
view
returns (bytes32 _latestVerifiedStorageMirrorStorageRoot);

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Users can use to propose and verify a storage root of the StorageMirror contract in Home chain
* @dev Calls queryL1BlockHeader to get the block header of the Home chain
* @dev Call verifier module for the actual verificationn
* @param _blockNumber The block number in the home chain to get the header from
* @param _accountProof The account proof of the StorageMirror contract in Home chain
*/
function proposeAndVerifyStorageMirrorStorageRoot(uint256 _blockNumber, bytes memory _accountProof) external;
}
23 changes: 23 additions & 0 deletions solidity/interfaces/IVerifierModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

interface IVerifierModule {
/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice The timestamp when the latest settings were verified
* @param _safe The address of the safe
* @return _timestamp The timestamp
*/
function latestVerifiedSettingsTimestamp(address _safe) external view returns (uint256 _timestamp);

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/
function extractStorageMirrorStorageRoot(
bytes memory _blockHeader,
bytes memory _accountProof
) external view returns (bytes32 _storageRoot);
}