Skip to content
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

Bug Report: Unexpected Asset Allocation Merge After Sending Another Asset #290

Open
astral-bitlight opened this issue Mar 7, 2025 · 0 comments

Comments

@astral-bitlight
Copy link

Description
When sending assets of one type (Asset 2), the UTXO allocations of another unrelated asset (Asset 1) are being unexpectedly merged, violating the expected allocation structure.

Context
In a test scenario involving two wallets (wlt_1 and wlt_2) and two distinct assets (contract_id_1 and contract_id_2):

  1. After some transactions, wlt_1 holds allocations for Asset 2 (contract_id_2) as [issued_supply_2 - amount_3, amount_5] (two separate UTXOs).
  2. A subsequent operation sends Asset 1 (contract_id_1) from wlt_1 to wlt_2.
  3. After this send operation, the allocations for Asset 2 in wlt_1 are incorrectly merged into a single UTXO [issued_supply_2 - amount_3 + amount_5], causing an assertion failure.

Expected Behavior
Sending Asset 1 should not affect the UTXO structure of Asset 2. The allocations for Asset 2 in wlt_1 should remain as two separate entries ([issued_supply_2 - amount_3, amount_5]).

Observed Behavior
The UTXOs for Asset 2 are merged into one entry during the send operation for Asset 1, suggesting unintended interaction between asset allocations.

Reproduction Steps

  1. Set up two wallets (wlt_1, wlt_2) and two asset contracts (contract_id_1, contract_id_2).
  2. Perform cross-sends of assets between wallets.
  3. After sending Asset 1, check wlt_1's allocations for Asset 2.
...
    wlt_2.send(&mut wlt_1, wout, contract_id_2, amount_5, sats, None);
    wlt_1.check_allocations(
        contract_id_1,
        asset_schema_1,
        vec![issued_supply_1 - amount_1 - amount_2, amount_4],
        true,
    );
    wlt_1.check_allocations(
        contract_id_2,
        asset_schema_2,
        vec![issued_supply_2 - amount_3, amount_5], // assertion passes
        true,
    );
    wlt_2.check_allocations(
        contract_id_1,
        asset_schema_1,
        vec![amount_1 + amount_2 - amount_4],
        false,
    );
    wlt_2.check_allocations(
        contract_id_2,
        asset_schema_2,
        vec![amount_3 - amount_5],
        false,
    );

    println!("-- DEBUG: wlt_1 spends asset 1, received back");
    let amount_6 = if asset_schema_1 == AssetSchema::Uda {
        1
    } else {
        issued_supply_1 - amount_1 - amount_2 + amount_4
    };
    sats -= 1000;
    // println!("before send, you can dump and debug now...");
    // std::thread::sleep(std::time::Duration::from_secs(30));
    wlt_1.send(&mut wlt_2, wout, contract_id_1, amount_6, sats, None);

    wlt_1.check_allocations(contract_id_1, asset_schema_1, vec![], false);
    wlt_1.check_allocations(
        contract_id_2,
        asset_schema_2,
        vec![issued_supply_2 - amount_3, amount_5], // assertion failes: actual allocation is vec![issued_supply_2 - amount_3 + amount_5]
        true,
    );
...
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

No branches or pull requests

1 participant