Skip to content

fix(station): make asset ledger canister id immutable after creation - #648

Open
MRmarioruci wants to merge 1 commit into
mainfrom
fix/immutable-asset-ledger-canister-id
Open

fix(station): make asset ledger canister id immutable after creation#648
MRmarioruci wants to merge 1 commit into
mainfrom
fix/immutable-asset-ledger-canister-id

Conversation

@MRmarioruci

@MRmarioruci MRmarioruci commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Change

An asset's ledger_canister_id identifies the token that asset represents. It is resolved from asset metadata at call time by both transfer paths and by account_balance, icrc1_balance_of, transfer_fee and icrc1_fee, so changing it on an existing asset changes which token all of those operations act on.

AssetService::edit() now rejects an edit that repoints or removes it once set. Setting one that was previously absent is still allowed, since an asset without a ledger cannot transact.

To point an asset at a different ledger, detach it from its accounts, remove it, and create a new one. That is the correct handling regardless: balances do not follow the pointer, so an in-place repoint would leave the station reporting holdings that live on the previous ledger.

Tests

  • repointing the ledger canister id is rejected and the stored value is unchanged
  • removing the key is rejected
  • unrelated metadata edits still succeed

cargo test -p station --lib passes (392). Clippy and cargo fmt clean.

Note

AssetService::create takes an optional with_asset_id, which is not reachable from AddAssetOperationInput and is used only by init and migrations. Worth keeping it that way.

The ledger canister id identifies the token an asset represents. It is
resolved from mutable asset metadata at call time by both transfer paths
as well as by balance and fee lookups, so changing it on an existing
asset silently changes which token those operations act on.

Reject edits that repoint or remove the ledger canister id once it is
set. Pointing an asset at a different ledger now requires detaching it
from its accounts, removing it, and creating a new one, which is the
correct semantics anyway since balances do not follow the pointer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MRmarioruci
MRmarioruci marked this pull request as ready for review August 6, 2026 13:10
@MRmarioruci
MRmarioruci requested a review from a team as a code owner August 6, 2026 13:10
@MRmarioruci
MRmarioruci requested a lite review from Copilot August 6, 2026 13:10
@zeropath-ai

zeropath-ai Bot commented Aug 6, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 553a402.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► core/station/impl/src/errors/asset.rs
    Add ImmutableLedgerCanisterId error variant
► core/station/impl/src/services/asset.rs
    Prevent changing ledger canister id after asset creation, add validation against re-pointing ledger
    Preserve original ledger canister id when edit attempts to change it
► core/station/impl/src/services/asset.rs
    Add tests: cannot repoint ledger canister id, cannot remove ledger canister id, allow other metadata changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes an asset’s ledger_canister_id effectively immutable after the asset has been created, preventing previously-approved transfers (and balance/fee lookups) from being redirected to a different ledger by later metadata edits.

Changes:

  • In AssetService::edit(), capture the pre-edit ledger_canister_id and reject edits that remove or change it once it has been set.
  • Introduce AssetError::ImmutableLedgerCanisterId for the new rejection case.
  • Add unit tests covering repointing/removal rejection and allowing unrelated metadata edits.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/station/impl/src/services/asset.rs Enforces immutability of ledger_canister_id during asset edits and adds regression tests.
core/station/impl/src/errors/asset.rs Adds a dedicated error variant for attempted ledger canister id changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants