-
Notifications
You must be signed in to change notification settings - Fork 60
feat(platform)!: add IdentityTopUpFromShieldedPool state transition (shielded pool to identity) #4711
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
QuantumExplorer
merged 23 commits into
v4.2-dev
from
claude/identity-topup-from-shielded-pool
Sep 13, 2026
Merged
feat(platform)!: add IdentityTopUpFromShieldedPool state transition (shielded pool to identity) #4711
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
33b6425
feat(platform)!: add ShieldFromIdentity state transition (identity ba…
QuantumExplorer 9376d88
feat(sdk): Swift and Kotlin wrappers for ShieldFromIdentity
QuantumExplorer 164d5d3
fix(platform): address review on ShieldFromIdentity (clippy, key look…
QuantumExplorer 9b85aab
feat(platform)!: add IdentityTopUpFromShieldedPool state transition (…
QuantumExplorer d4ac5a7
style(wasm-dpp2): keep IdentityTopUpFromShieldedPool spec lines under…
QuantumExplorer 20c903a
fix(platform-wallet): persist balance, drop floor fee, keep key-unava…
QuantumExplorer a04449d
Merge branch 'claude/identity-shielded-pool-transition-847713' into c…
QuantumExplorer c98944d
fix(platform-wallet): confirm ShieldFromIdentity only on the identity…
QuantumExplorer 1ce2935
Merge branch 'claude/identity-shielded-pool-transition-847713' into c…
QuantumExplorer bb6836e
fix(platform)!: paid penalty and complete-fee floor for ShieldFromIde…
QuantumExplorer 1437b73
Merge branch 'claude/identity-shielded-pool-transition-847713' into c…
QuantumExplorer 7a3b657
fix(dpp): calibrate the ShieldFromIdentity identity-write allowance t…
QuantumExplorer 98242ca
Merge branch 'claude/identity-shielded-pool-transition-847713' into c…
QuantumExplorer 5b361b3
fix(dpp): calibrate the IdentityTopUpFromShieldedPool identity-write …
QuantumExplorer ead503c
fix(dpp): size the ShieldFromIdentity identity-write component as fla…
QuantumExplorer 007f661
fix(dpp): size the top-up identity-write component as flat replace-on…
QuantumExplorer 424d14c
fix(dpp): resolve merge markers left in shielded/mod.rs
QuantumExplorer 6ab057e
fix(dpp): restore the top-up sighash exports dropped by the marker re…
QuantumExplorer 3c81ea3
Merge branch 'v4.2-dev' into claude/identity-topup-from-shielded-pool
QuantumExplorer 9f0d97e
fix(platform): classify top-up proofs as execution-proving and persis…
QuantumExplorer 69d8939
fix(platform-wallet): hold the shield guard across a shielded identit…
QuantumExplorer ad57dd6
fix(platform): classify top-up proofs as affected state and wait acco…
QuantumExplorer c1c67a7
docs(platform-wallet): record why a shielded identity top-up confirms…
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
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
126 changes: 126 additions & 0 deletions
126
packages/rs-dpp/src/shielded/builder/identity_top_up_from_shielded_pool.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,126 @@ | ||
| use grovedb_commitment_tree::{Anchor, FullViewingKey, SpendAuthorizingKey}; | ||
|
|
||
| use crate::address_funds::OrchardAddress; | ||
| use crate::fee::Credits; | ||
| use crate::shielded::compute_shielded_identity_top_up_fee; | ||
| use crate::state_transition::identity_top_up_from_shielded_pool_transition::methods::IdentityTopUpFromShieldedPoolTransitionMethodsV0; | ||
| use crate::state_transition::identity_top_up_from_shielded_pool_transition::IdentityTopUpFromShieldedPoolTransition; | ||
| use crate::state_transition::StateTransition; | ||
| use crate::ProtocolError; | ||
| use platform_value::Identifier; | ||
| use platform_version::version::PlatformVersion; | ||
|
|
||
| use super::{build_spend_bundle, serialize_authorized_bundle, OrchardProver, SpendableNote}; | ||
|
|
||
| /// Build an `IdentityTopUpFromShieldedPool` transition: spend `spends` so that exactly | ||
| /// `top_up_amount + fee` leaves the pool, sending change back to `change_address`. | ||
| /// The identity receives `top_up_amount`; the flat fee is carved from the value | ||
| /// balance exactly as `Unshield` does. Returns the transition and the fee used. | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub fn build_identity_top_up_from_shielded_pool_transition<P: OrchardProver>( | ||
| spends: Vec<SpendableNote>, | ||
| identity_id: Identifier, | ||
| top_up_amount: u64, | ||
| change_address: &OrchardAddress, | ||
| fvk: &FullViewingKey, | ||
| ask: &SpendAuthorizingKey, | ||
| anchor: Anchor, | ||
| prover: &P, | ||
| memo: [u8; 36], | ||
| platform_version: &PlatformVersion, | ||
| ) -> Result<(StateTransition, Credits), ProtocolError> { | ||
| if top_up_amount > i64::MAX as u64 { | ||
| return Err(ProtocolError::ShieldedBuildError(format!( | ||
| "top up amount {} exceeds maximum allowed value {}", | ||
| top_up_amount, | ||
| i64::MAX as u64 | ||
| ))); | ||
| } | ||
|
|
||
| let total_spent: u64 = spends.iter().map(|s| s.note.value().inner()).sum(); | ||
|
|
||
| let num_actions = spends.len().max(2); | ||
| let fee = compute_shielded_identity_top_up_fee(num_actions, platform_version)?; | ||
|
|
||
| let required = top_up_amount.checked_add(fee).ok_or_else(|| { | ||
| ProtocolError::ShieldedBuildError("fee + top_up_amount overflows u64".to_string()) | ||
| })?; | ||
| if required > total_spent { | ||
| return Err(ProtocolError::ShieldedBuildError(format!( | ||
| "top up amount {} + fee {} = {} exceeds total spendable value {}", | ||
| top_up_amount, fee, required, total_spent | ||
| ))); | ||
| } | ||
|
|
||
| let change_amount = total_spent - required; | ||
|
|
||
| let extra_sighash_data = crate::shielded::identity_top_up_from_shielded_extra_sighash_data( | ||
| &identity_id.to_buffer(), | ||
| required, | ||
| platform_version, | ||
| )?; | ||
|
|
||
| let bundle = build_spend_bundle( | ||
| spends, | ||
| change_address, | ||
| change_amount, | ||
| memo, | ||
| fvk, | ||
| ask, | ||
| anchor, | ||
| prover, | ||
| &extra_sighash_data, | ||
| )?; | ||
|
|
||
| let sb = serialize_authorized_bundle(&bundle); | ||
|
|
||
| let state_transition = IdentityTopUpFromShieldedPoolTransition::try_from_bundle( | ||
| identity_id, | ||
| sb.actions, | ||
| sb.value_balance as u64, | ||
| sb.anchor, | ||
| sb.proof, | ||
| sb.binding_signature, | ||
| platform_version, | ||
| )?; | ||
| Ok((state_transition, fee)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::shielded::builder::test_helpers::{ | ||
| test_orchard_address, test_spendable_note, TestProver, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn test_identity_top_up_insufficient_funds() { | ||
| let platform_version = PlatformVersion::latest(); | ||
| let change_address = test_orchard_address(); | ||
| let spends = vec![test_spendable_note(100)]; | ||
| let sk = grovedb_commitment_tree::SpendingKey::from_bytes([42u8; 32]) | ||
| .expect("valid spending key bytes"); | ||
| let fvk = FullViewingKey::from(&sk); | ||
| let ask = SpendAuthorizingKey::from(&sk); | ||
|
|
||
| let result = build_identity_top_up_from_shielded_pool_transition( | ||
| spends, | ||
| Identifier::from([1u8; 32]), | ||
| 1_000_000, | ||
| &change_address, | ||
| &fvk, | ||
| &ask, | ||
| Anchor::empty_tree(), | ||
| &TestProver, | ||
| [0u8; 36], | ||
| platform_version, | ||
| ); | ||
| let err = result | ||
| .expect_err("must fail on insufficient funds") | ||
| .to_string(); | ||
| assert!( | ||
| err.contains("exceeds total spendable value"), | ||
| "unexpected error: {err}" | ||
| ); | ||
| } | ||
| } |
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
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.