-
Notifications
You must be signed in to change notification settings - Fork 97
[tesseract]: Introduce pallet-outbound-proofs for on-chain consensus proof storage and verification #732
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
Draft
dharjeezy
wants to merge
15
commits into
relayer-v2
Choose a base branch
from
dami/zk-proof-indexer-db
base: relayer-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[tesseract]: Introduce pallet-outbound-proofs for on-chain consensus proof storage and verification #732
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5c25edc
handler v2 implementation
dharjeezy 70277f7
change dependency path
dharjeezy a72ad56
epoch check change
dharjeezy ce460bc
add IConsensusV2 implementations to all existing Beefy consensus clie…
dharjeezy 685493b
post zk proofs into indexer DB
dharjeezy 576f5ff
change set id
dharjeezy d4da9bd
workspace
dharjeezy 8ec8dbd
keep track of finalized parachain height
dharjeezy 5316ae1
move ZK proof indexing from BeefyHost to BeefyProver
dharjeezy 9229df9
remove redundant spawn
dharjeezy 854d8c7
return error instead of catching
dharjeezy 5bfc39b
Merge branch 'relayer-v2' of github.com:polytope-labs/hyperbridge int…
dharjeezy 99c1894
introduce pallet outbound proof
dharjeezy 62f6f1e
remove indexer approach
dharjeezy 345d90f
benchmarks
dharjeezy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| [package] | ||
| name = "pallet-outbound-proofs" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["Polytope Labs <hello@polytope.technology>"] | ||
| license = "Apache-2.0" | ||
| description = "Pallet for storing and rewarding outbound consensus proofs on Hyperbridge" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| codec = { workspace = true } | ||
| pallet-ismp = { workspace = true } | ||
| scale-info = { workspace = true } | ||
| sp1-verifier = { version = "6.0.2", default-features = false, optional = true } | ||
|
|
||
| [dependencies.polkadot-sdk] | ||
| workspace = true | ||
| features = ["frame-support", "frame-system", "sp-io", "sp-runtime"] | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "polkadot-sdk/std", | ||
| "codec/std", | ||
| "pallet-ismp/std", | ||
| "scale-info/std", | ||
| ] | ||
| sp1 = ["sp1-verifier"] | ||
| runtime-benchmarks = [ | ||
| "polkadot-sdk/frame-benchmarking", | ||
| "polkadot-sdk/runtime-benchmarks", | ||
| ] | ||
| try-runtime = ["polkadot-sdk/try-runtime"] |
This file contains hidden or 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,160 @@ | ||
| // Copyright (C) Polytope Labs Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #![cfg(feature = "runtime-benchmarks")] | ||
|
|
||
| use super::*; | ||
| use alloc::vec; | ||
| use frame_benchmarking::v2::*; | ||
| use frame_support::BoundedVec; | ||
| use frame_system::RawOrigin; | ||
| use pallet::{ | ||
| ConsensusState, CurrentEpoch, LatestMessageBlock, LatestProvenParachainHeight, ProvenHeights, | ||
| Sp1VkeyHash, | ||
| }; | ||
| use types::BeefyConsensusState; | ||
|
|
||
| #[benchmarks( | ||
| where | ||
| T::AccountId: From<[u8; 32]>, | ||
| <T::Currency as frame_support::traits::fungible::Inspect<T::AccountId>>::Balance: From<u128>, | ||
| )] | ||
| mod benchmarks { | ||
| use super::*; | ||
|
|
||
| #[benchmark] | ||
| fn submit_proof() { | ||
| let caller: T::AccountId = whitelisted_caller(); | ||
|
|
||
| CurrentEpoch::<T>::put(0u64); | ||
| ConsensusState::<T>::put(BeefyConsensusState::default()); | ||
|
|
||
| let proof: BoundedVec<u8, T::MaxProofSize> = | ||
| vec![0u8; 100].try_into().expect("fits in bounds"); | ||
|
|
||
| #[extrinsic_call] | ||
| _(RawOrigin::Signed(caller), proof, 1000u64, 500u64, 1u64); | ||
|
|
||
| assert!(ProvenHeights::<T>::contains_key(1000u64)); | ||
| assert_eq!(CurrentEpoch::<T>::get(), 1u64); | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn set_proof_reward() { | ||
| let reward: <T::Currency as frame_support::traits::fungible::Inspect<T::AccountId>>::Balance = 1000u128.into(); | ||
| #[extrinsic_call] | ||
| _(RawOrigin::Root, reward); | ||
|
|
||
| assert_eq!(pallet::ProofReward::<T>::get(), reward); | ||
| } | ||
|
|
||
| #[benchmark] | ||
| fn set_sp1_vkey_hash() { | ||
| let vkey = vec![0xabu8; 32]; | ||
| #[extrinsic_call] | ||
| _(RawOrigin::Root, vkey.clone()); | ||
|
|
||
| assert_eq!(Sp1VkeyHash::<T>::get(), vkey); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Minimal test runtime for benchmark tests | ||
| #[cfg(test)] | ||
| use polkadot_sdk::*; | ||
|
|
||
| #[cfg(test)] | ||
| type Block = frame_system::mocking::MockBlock<Test>; | ||
|
|
||
| #[cfg(test)] | ||
| frame_support::construct_runtime!( | ||
| pub enum Test { | ||
| System: frame_system, | ||
| Balances: pallet_balances, | ||
| OutboundProofs: crate::pallet, | ||
| } | ||
| ); | ||
|
|
||
| #[cfg(test)] | ||
| #[frame_support::derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ||
| impl frame_system::Config for Test { | ||
| type Block = Block; | ||
| type AccountData = pallet_balances::AccountData<u128>; | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[frame_support::derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] | ||
| impl pallet_balances::Config for Test { | ||
| type AccountStore = System; | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub struct DummyVerifier; | ||
| #[cfg(test)] | ||
| impl ProofVerifier for DummyVerifier { | ||
| fn verify( | ||
| trusted_state: &BeefyConsensusState, | ||
| _proof: &[u8], | ||
| ) -> Result<BeefyConsensusState, frame_support::pallet_prelude::DispatchError> { | ||
| Ok(trusted_state.clone()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub struct DummyOnDispatch; | ||
| #[cfg(test)] | ||
| impl pallet_ismp::OnDispatch for DummyOnDispatch { | ||
| fn on_dispatch() {} | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| frame_support::parameter_types! { | ||
| pub const TreasuryId: frame_support::PalletId = frame_support::PalletId(*b"hb/trsry"); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub struct TestWeights; | ||
| #[cfg(test)] | ||
| impl pallet::WeightInfo for TestWeights { | ||
| fn submit_proof() -> frame_support::weights::Weight { | ||
| frame_support::weights::Weight::zero() | ||
| } | ||
| fn set_proof_reward() -> frame_support::weights::Weight { | ||
| frame_support::weights::Weight::zero() | ||
| } | ||
| fn set_sp1_vkey_hash() -> frame_support::weights::Weight { | ||
| frame_support::weights::Weight::zero() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| impl crate::pallet::Config for Test { | ||
| type AdminOrigin = frame_system::EnsureRoot<u64>; | ||
| type ProofVerifier = DummyVerifier; | ||
| type Currency = Balances; | ||
| type TreasuryPalletId = TreasuryId; | ||
| type MaxProofSize = frame_support::traits::ConstU32<100_000>; | ||
| type MaxStoredProofs = frame_support::traits::ConstU32<100>; | ||
| type WeightInfo = TestWeights; | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub fn new_test_ext() -> sp_io::TestExternalities { | ||
| use sp_runtime::BuildStorage; | ||
| let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap(); | ||
| let mut ext = sp_io::TestExternalities::new(t); | ||
| ext.execute_with(|| frame_system::Pallet::<Test>::set_block_number(1)); | ||
| ext | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not call it for every message make be call it if the child_trie root changes in onfinalized_hook