-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: interchain check batch verification (#2521)
* Scaffold new verification function * Update DB tests * Update ClientV1 test * Feat: check batch verification * Test: ClientV1 should revert on incorrect entryIndex/proof * Expose generic `getEntryValue` * Use `checkBatchVerification` in Client * Rm unused harness * Deprecate `checkVerification` * Cleanup: isolate batch root logic * Scaffold new getter in `InterchainDB` * Specify unit tests for the new getter * Implement batch root getter * Cleanup: isolate entry + proof -> batch root logic * Cleanup: tests * chore: InterchainDB interface clean up
- Loading branch information
1 parent
fe52a70
commit fa2e1a0
Showing
18 changed files
with
277 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/contracts-communication/contracts/libs/BatchingV1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {InterchainEntryLib} from "./InterchainEntry.sol"; | ||
|
||
library BatchingV1Lib { | ||
error BatchingV1__IncorrectEntryIndex(uint64 entryIndex); | ||
error BatchingV1__IncorrectProof(); | ||
|
||
/// @notice Get the batch root containing the Interchain Entry with the given index. | ||
/// @param srcWriter The entry writer of the source chain | ||
/// @param dataHash The hash of the data of the entry | ||
/// @param entryIndex The index of the entry in the batch | ||
/// @param proof The Merkle proof of inclusion for the entry in the batch | ||
/// @return batchRoot The root of the batch containing the entry | ||
function getBatchRoot( | ||
bytes32 srcWriter, | ||
bytes32 dataHash, | ||
uint64 entryIndex, | ||
bytes32[] calldata proof | ||
) | ||
internal | ||
pure | ||
returns (bytes32 batchRoot) | ||
{ | ||
// In "no batching" mode: entry index is 0, proof is empty | ||
if (entryIndex != 0) { | ||
revert BatchingV1__IncorrectEntryIndex(entryIndex); | ||
} | ||
if (proof.length != 0) { | ||
revert BatchingV1__IncorrectProof(); | ||
} | ||
// In "no batching" mode: the batch root is the same as the entry value | ||
return InterchainEntryLib.getEntryValue({srcWriter: srcWriter, dataHash: dataHash}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.