-
Notifications
You must be signed in to change notification settings - Fork 56
feat(drive-abci): add shielded pool drive-abci integration (medusa part 3) #3220
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ed3a886
feat(drive-abci): add shielded pool drive-abci integration
QuantumExplorer 4e84d4f
fix(drive-abci): fix shielded test compilation and proof verification…
QuantumExplorer c9a74f7
chore(drive-abci): cargo fmt
QuantumExplorer cfa16af
refactor(drive): remove unused PenalizeShieldedPoolAction
QuantumExplorer 1771400
fix(drive-abci): gate shielded basic_structure validation on platform…
QuantumExplorer 75f5650
docs(drive-abci): explain why ShieldFromAssetLock skips early proof v…
QuantumExplorer c1de6f0
Merge branch 'v3.1-dev' into feat/zk-drive-abci
QuantumExplorer f104242
fix(drive-abci): audit fixes for shielded pool integration
QuantumExplorer fe0697e
fix(drive): adapt proof verification for shielded pool tree structure…
QuantumExplorer 1486922
fix(drive-abci): address CodeRabbit review comments
QuantumExplorer db74541
refactor(drive): store anchors as key with O(1) lookup and dedicated …
QuantumExplorer b17ad9e
feat(drive): add anchors-by-height reverse index tree for pruning sup…
QuantumExplorer d1297b7
feat(drive-abci): prune shielded pool anchors older than 1000 blocks
QuantumExplorer 22354c0
perf(drive-abci): only prune shielded anchors every 100 blocks
QuantumExplorer 2b93bd4
fix(drive-abci): reject zero value_balance in shielded transfer and a…
QuantumExplorer 1518d6a
docs(drive-abci): update audit findings statuses and clarify strategy…
QuantumExplorer 738b243
fix(drive-abci): fix CI failures - formatting, clippy, and drive init…
QuantumExplorer 5712538
refactor(drive-abci): rename err to consensus_error in transform_into…
QuantumExplorer e0a8c54
Merge branch 'v3.1-dev' into feat/zk-drive-abci
QuantumExplorer f7fb180
refactor(drive-abci): extract anchor pruning interval to version field
QuantumExplorer 001b40f
Merge branch 'v3.1-dev' into feat/zk-drive-abci
QuantumExplorer 5d1a593
refactor(drive): extract shielded pool GroveDB operations into Drive …
QuantumExplorer af1fb34
fix(wasm-dpp2): replace missing impl_wasm_conversions with impl_wasm_…
QuantumExplorer 8e6764c
chore(drive-abci): comment out shielded strategy tests temporarily
QuantumExplorer 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
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
1 change: 1 addition & 0 deletions
1
packages/rs-drive-abci/src/execution/platform_events/block_processing_end_events/mod.rs
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| mod add_process_epoch_change_operations; | ||
| pub mod process_block_fees_and_validate_sum_trees; | ||
| mod record_shielded_pool_anchor; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; |
40 changes: 40 additions & 0 deletions
40
.../execution/platform_events/block_processing_end_events/record_shielded_pool_anchor/mod.rs
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,40 @@ | ||
| mod v0; | ||
|
|
||
| use crate::error::execution::ExecutionError; | ||
| use crate::error::Error; | ||
| use crate::platform_types::platform::Platform; | ||
| use crate::rpc::core::CoreRPCLike; | ||
| use dpp::version::PlatformVersion; | ||
| use drive::grovedb::Transaction; | ||
|
|
||
| impl<C> Platform<C> | ||
| where | ||
| C: CoreRPCLike, | ||
| { | ||
| /// Records the current shielded pool anchor if the commitment tree changed this block. | ||
| pub(in crate::execution) fn record_shielded_pool_anchor_if_changed( | ||
| &self, | ||
| block_height: u64, | ||
| transaction: &Transaction, | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<(), Error> { | ||
| match platform_version | ||
| .drive_abci | ||
| .methods | ||
| .block_end | ||
| .record_shielded_pool_anchor | ||
| { | ||
| None => Ok(()), | ||
| Some(0) => self.record_shielded_pool_anchor_if_changed_v0( | ||
| block_height, | ||
| transaction, | ||
| platform_version, | ||
| ), | ||
| Some(version) => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { | ||
| method: "record_shielded_pool_anchor_if_changed".to_string(), | ||
| known_versions: vec![0], | ||
| received: version, | ||
| })), | ||
| } | ||
| } | ||
| } |
109 changes: 109 additions & 0 deletions
109
...ecution/platform_events/block_processing_end_events/record_shielded_pool_anchor/v0/mod.rs
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,109 @@ | ||
| use crate::error::Error; | ||
| use crate::platform_types::platform::Platform; | ||
| use crate::rpc::core::CoreRPCLike; | ||
| use dpp::version::PlatformVersion; | ||
| use drive::drive::shielded::paths::{ | ||
| shielded_credit_pool_anchors_path, shielded_credit_pool_path, SHIELDED_NOTES_KEY, | ||
| }; | ||
| use drive::grovedb::query_result_type::QueryResultType; | ||
| use drive::grovedb::{Element, PathQuery, Query, QueryItem, SizedQuery, Transaction}; | ||
|
|
||
| impl<C> Platform<C> | ||
| where | ||
| C: CoreRPCLike, | ||
| { | ||
| /// Records the current shielded pool anchor if the commitment tree changed this block. | ||
| /// | ||
| /// After all state transitions are processed, reads the current Sinsemilla anchor | ||
| /// from the CommitmentTree at [AddressBalances, "s", [1]]. If it differs from the | ||
| /// most recently stored anchor (or no anchor exists yet), inserts | ||
| /// `block_height.to_be_bytes() → anchor_bytes` into the anchors tree at | ||
| /// [AddressBalances, "s", [6]]. | ||
| /// | ||
| /// This ensures anchors are only recorded once per block (not per-transaction), | ||
| /// and only when the commitment tree actually changed. | ||
| pub(super) fn record_shielded_pool_anchor_if_changed_v0( | ||
| &self, | ||
| block_height: u64, | ||
| transaction: &Transaction, | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<(), Error> { | ||
| let grove_version = &platform_version.drive.grove_version; | ||
| let pool_path = shielded_credit_pool_path(); | ||
|
|
||
| // 1. Read current anchor from CommitmentTree | ||
| let current_anchor = self | ||
|
shumkov marked this conversation as resolved.
Outdated
|
||
| .drive | ||
| .grove | ||
| .commitment_tree_anchor( | ||
| &pool_path, | ||
| &[SHIELDED_NOTES_KEY], | ||
| Some(transaction), | ||
| grove_version, | ||
| ) | ||
| .unwrap() | ||
| .map_err(|e| Error::Drive(drive::error::Error::from(e)))?; | ||
|
|
||
| let current_anchor_bytes: [u8; 32] = current_anchor.to_bytes(); | ||
|
|
||
| // 2. Query latest stored anchor (descending, limit 1) | ||
| let anchors_path = shielded_credit_pool_anchors_path(); | ||
| let mut query = Query::new(); | ||
| query.insert_item(QueryItem::RangeFull(..)); | ||
| let path_query = PathQuery { | ||
| path: anchors_path.iter().map(|p| p.to_vec()).collect(), | ||
| query: SizedQuery { | ||
| query, | ||
| limit: Some(1), | ||
| offset: None, | ||
| }, | ||
| }; | ||
|
|
||
| let (results, _) = self.drive.grove_get_raw_path_query( | ||
| &path_query, | ||
| Some(transaction), | ||
| QueryResultType::QueryKeyElementPairResultType, | ||
| &mut vec![], | ||
| &platform_version.drive, | ||
| )?; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| let latest_stored_anchor: Option<[u8; 32]> = results | ||
| .to_key_elements() | ||
| .into_iter() | ||
| .last() | ||
| .and_then(|(_key, element)| { | ||
| if let Element::Item(value, _) = element { | ||
| value.try_into().ok() | ||
| } else { | ||
| None | ||
| } | ||
| }); | ||
|
|
||
| // 3. Only store if different (or none stored yet) | ||
| let should_store = match latest_stored_anchor { | ||
| None => { | ||
| // No anchors stored yet — only store if the tree has notes | ||
| // (an empty tree has a zero anchor which isn't useful) | ||
| current_anchor_bytes != [0u8; 32] | ||
| } | ||
| Some(stored) => stored != current_anchor_bytes, | ||
| }; | ||
|
|
||
| if should_store { | ||
| self.drive | ||
| .grove | ||
| .insert( | ||
| &anchors_path, | ||
| &block_height.to_be_bytes(), | ||
| Element::new_item(current_anchor_bytes.to_vec()), | ||
| None, | ||
| Some(transaction), | ||
| grove_version, | ||
| ) | ||
| .unwrap() | ||
| .map_err(|e| Error::Drive(drive::error::Error::from(e)))?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
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
41 changes: 41 additions & 0 deletions
41
...latform_events/state_transition_processing/cleanup_recent_block_storage_nullifiers/mod.rs
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,41 @@ | ||
| mod v0; | ||
|
|
||
| use crate::error::execution::ExecutionError; | ||
| use crate::error::Error; | ||
| use crate::platform_types::platform::Platform; | ||
| use crate::rpc::core::CoreRPCLike; | ||
| use dpp::block::block_info::BlockInfo; | ||
| use dpp::version::PlatformVersion; | ||
| use drive::grovedb::Transaction; | ||
|
|
||
| impl<C> Platform<C> | ||
| where | ||
| C: CoreRPCLike, | ||
| { | ||
| /// Cleans up expired compacted nullifier entries from recent block storage. | ||
| pub(in crate::execution) fn cleanup_recent_block_storage_nullifiers( | ||
| &self, | ||
| block_info: &BlockInfo, | ||
| transaction: &Transaction, | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<(), Error> { | ||
| match platform_version | ||
| .drive_abci | ||
| .methods | ||
| .state_transition_processing | ||
| .cleanup_recent_block_storage_nullifiers | ||
| { | ||
| None => Ok(()), | ||
| Some(0) => self.cleanup_recent_block_storage_nullifiers_v0( | ||
| block_info, | ||
| transaction, | ||
| platform_version, | ||
| ), | ||
| Some(version) => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { | ||
| method: "cleanup_recent_block_storage_nullifiers".to_string(), | ||
| known_versions: vec![0], | ||
| received: version, | ||
| })), | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
...form_events/state_transition_processing/cleanup_recent_block_storage_nullifiers/v0/mod.rs
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,27 @@ | ||
| use crate::error::Error; | ||
| use crate::platform_types::platform::Platform; | ||
| use crate::rpc::core::CoreRPCLike; | ||
| use dpp::block::block_info::BlockInfo; | ||
| use dpp::version::PlatformVersion; | ||
| use drive::grovedb::Transaction; | ||
|
|
||
| impl<C> Platform<C> | ||
| where | ||
| C: CoreRPCLike, | ||
| { | ||
| /// Version 0 implementation of cleaning up expired compacted nullifier entries. | ||
| pub(super) fn cleanup_recent_block_storage_nullifiers_v0( | ||
| &self, | ||
| block_info: &BlockInfo, | ||
| transaction: &Transaction, | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<(), Error> { | ||
| self.drive.cleanup_expired_nullifier_compactions( | ||
| block_info.time_ms, | ||
| Some(transaction), | ||
| platform_version, | ||
| )?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.