Skip to content

chore: refactor AccountVaultDelta to track generic assets - #3485

Merged
mmagician merged 8 commits into
nextfrom
pgackst-account-vault-delta
Aug 10, 2026
Merged

chore: refactor AccountVaultDelta to track generic assets#3485
mmagician merged 8 commits into
nextfrom
pgackst-account-vault-delta

Conversation

@PhilippGackstatter

@PhilippGackstatter PhilippGackstatter commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

AccountVaultDelta no longer splits vault changes into a fungible and a non-fungible half. It now stores a single map of generic AssetDelta entries keyed by AssetId, which matches how the transaction kernel already reports vault changes.

Changes

AccountVaultDelta is now BTreeMap<AssetId, AssetDelta> with AssetDelta moving to miden-protocol.

Commitment format is unchanged.

read_from now routes through the validating new constructor, so a crafted byte stream that lists the same asset in both the added and the removed section is rejected.

closes #3175

@PhilippGackstatter PhilippGackstatter added the pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority label Aug 4, 2026
@PhilippGackstatter
PhilippGackstatter force-pushed the pgackst-account-vault-delta branch from e31bd2c to ba068da Compare August 4, 2026 13:45
@PhilippGackstatter
PhilippGackstatter marked this pull request as ready for review August 4, 2026 13:46

@zeapoz zeapoz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! No major complaints, but I think we could return the previous (overwritten) value and pass it down the call stack

Comment thread crates/miden-protocol/src/account/delta/vault.rs Outdated
Comment thread crates/miden-protocol/src/testing/vault_delta.rs
Comment thread crates/miden-tx/src/host/vault_update_tracker.rs Outdated

@mmagician mmagician left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one point to discuss: we used to have normalization for non-zero fungible assets as:

// Only track non-zero amounts.
if delta != 0 {
    entry.insert(delta);
}

which is now gone.

This means "no net change" & "empty delta" used to be the same, and with this PR that's no longer the case.

Also the kernel only commits to entires in the map, so before building a delta containing an Add(amount=0) would still match the kernel-computed commitment. Now, Rust side will contain an entry while the kernel can never emit such a delta.

@PhilippGackstatter

Copy link
Copy Markdown
Contributor Author

This means "no net change" & "empty delta" used to be the same, and with this PR that's no longer the case.

Also the kernel only commits to entires in the map, so before building a delta containing an Add(amount=0) would still match the kernel-computed commitment. Now, Rust side will contain an entry while the kernel can never emit such a delta.

Good point, thanks for bringing this up!

I think the need for this extra logic went away with #2630.

For example, consider the case of asset 1 in this test setup:

/// Tests that increasing, decreasing the amount of a fungible asset results in the correct update.
///
/// - Asset0 starts at 300, is increased by 100 and decreased by 200 -> Delta: -100, Patch: 200.
/// - Asset1 starts at 200, is increased by 100 and decreased by 100 -> Delta: 0, Patch: None.
/// - Asset2 starts at 100, is increased by 200 and decreased by 100 -> Delta: 100, Patch: 200.
/// - Asset3 starts at MAX, is decreased by MAX -> Delta: -MAX, Patch: 0.
/// - Asset4 starts at 0, is increased by MAX -> Delta: MAX, Patch: MAX.
#[tokio::test]
async fn fungible_asset_update() -> anyhow::Result<()> {

The tx kernel tracks [INIT_VALUE, CURRENT_VALUE]. Since the asset is increased and decreased by the same amount, init and current value end up the same. When computing the delta, entries whose values are the same are skipped. This means no event for asset1 is emitted and it is not added to the AccountVaultDelta by the VaultUpdateTracker.

In other words, the special Rust logic is no longer necessary because the consistency between the in-kernel delta and the host delta is guaranteed by constructing the host delta from the in-kernel delta with normalization in mind.

@mmagician
mmagician added this pull request to the merge queue Aug 10, 2026
Merged via the queue into next with commit d6d1d21 Aug 10, 2026
19 checks passed
@mmagician
mmagician deleted the pgackst-account-vault-delta branch August 10, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor AccountVaultDelta to track generic Assets

3 participants