Skip to content

Commit

Permalink
chore: return block number
Browse files Browse the repository at this point in the history
  • Loading branch information
excaliborr committed Nov 21, 2023
1 parent 691a227 commit 7e8fe64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion solidity/contracts/VerifierModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ contract VerifierModule is IVerifierModule {
*
* @param _storageMirrorAccountProof The account proof of the StorageMirror contract from the latest block
* @param _blockHeader The block header of the latest block
* @return _storageRoot The verified storage root
* @return _blockNumber The block number from the _blockHeader
*/
function extractStorageMirrorStorageRoot(
bytes memory _storageMirrorAccountProof,
bytes memory _blockHeader
) external view returns (bytes32 _storageRoot) {
) external view returns (bytes32 _storageRoot, uint256 _blockNumber) {
// Verify and parse the blockheader for the state root
StateVerifier.BlockHeader memory _parsedBlockHeader = StateVerifier.verifyBlockHeader(_blockHeader);

Expand All @@ -95,6 +97,7 @@ contract VerifierModule is IVerifierModule {

// Extract the storage root from the output of the MPT
_storageRoot = StateVerifier.extractStorageRootFromAccount(_rlpAccount);
_blockNumber = _parsedBlockHeader.number;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion solidity/interfaces/IVerifierModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ interface IVerifierModule {
*
* @param _storageMirrorAccountProof The account proof of the StorageMirror contract from the latest block
* @param _blockHeader The block header of the latest block
* @return _storageRoot The verified storage root
* @return _blockNumber The block number from the _blockHeader
*/
function extractStorageMirrorStorageRoot(
bytes memory _storageMirrorAccountProof,
bytes memory _blockHeader
) external view returns (bytes32 _storageRoot);
) external view returns (bytes32 _storageRoot, uint256 _blockNumber);

/**
* @notice Verifies the new settings that are incoming against a storage proof from the StorageMirror on the home chain
Expand Down
12 changes: 9 additions & 3 deletions solidity/test/unit/VerifierModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,20 @@ contract TestVerifierModule is VerifierModule {
function extractStorageMirrorStorageRootTest(
bytes memory _storageMirrorAccountProof,
bytes memory _blockHeader
) external view returns (bytes32 _storageRoot) {
) external view returns (bytes32 _storageRoot, uint256 _blockNumber) {
// Verify and parse the blockheader for the state root
StateVerifier.BlockHeader memory _parsedBlockHeader = mpt.verifyBlockHeader(_blockHeader);

// Verify the account proof against the state root
bytes memory _rlpAccount = mpt.extractProofValue(
_parsedBlockHeader.stateRootHash,
abi.encodePacked(keccak256(abi.encode(STORAGE_MIRROR))),
_storageMirrorAccountProof
);

// Extract the storage root from the output of the MPT
_storageRoot = mpt.extractStorageRootFromAccount(_rlpAccount);
_blockNumber = 500;
}
}

Expand Down Expand Up @@ -746,12 +750,14 @@ contract UnitStorageRoot is Base {

vm.mockCall(
address(mpt),
abi.encodeWithSelector(TestMPT.extractStorageRootFromAccount.selector, abi.encodePacked(_fakeAccount)),
abi.encodeWithSelector(TestMPT.extractStorageRootFromAccount.selector, _fakeAccount),
abi.encode(_fakeStorageRoot)
);

bytes32 _storageRoot = verifierModule.extractStorageMirrorStorageRootTest(_accountProof, _rlpHeader);
(bytes32 _storageRoot, uint256 _blockNumber) =
verifierModule.extractStorageMirrorStorageRootTest(_accountProof, _rlpHeader);

assertEq(_storageRoot, _fakeStorageRoot, 'Storage root should match');
assertEq(_blockNumber, _fakeHeader.number, 'Should match the block header');
}
}

0 comments on commit 7e8fe64

Please sign in to comment.