// 1. In `cabal_token::burn` (called by attacker's `initiate_unstake` in block H)
public fun burn(burn_cap: &BurnCapability, fa: FungibleAsset) acquires ManagingRefs, HolderStore, ModuleStore { // Added missing acquires for context
    let metadata = burn_cap.metadata;
    let metadata_addr = object::object_address(&metadata);
    assert!(exists<ManagingRefs>(metadata_addr), EMANAGING_REFS_NOT_FOUND);
    let refs = borrow_global<ManagingRefs>(metadata_addr);

    // Burn reduces the LIVE supply
    fungible_asset::burn(&refs.burn_ref, fa);

    // --- VULNERABILITY PART 1 ---
    // ATTACKER EXPLOIT: This function is called in block H AFTER cabal_token::snapshot recorded
    // the supply. However, UNLIKE mint_to, this function DOES NOT check if it's the snapshot
    // block and DOES NOT update the HolderStore::supply_snapshots table for block H.
    // The recorded supply for H remains the stale, pre-burn value (S).
    /* Missing logic similar to mint_to:
        if (is_snapshot_block) {
            update supply_snapshots table with new (lower) supply S;
        }
    */
}

// 2. In `cabal_token::check_snapshot` (called during attacker's unstake in block H)
fun check_snapshot(c_balance: &mut CabalBalance, current_snapshot_block: u64, prev_snapshot_block: Option<u64>) {
    let current_block_height = block::get_current_block_height(); // Is H
    let snapshot_block = current_snapshot_block; // is H

    // --- VULNERABILITY PART 2 ---
    if (current_block_height == current_snapshot_block) { // TRUE (H == H)
        // ATTACKER EXPLOIT: This condition is met.The logic inside prevents writing
        // the attacker's PRE-BURN balance to their personal snapshot table for block H.
        if (option::is_none(&prev_snapshot_block)) {
            return; // Early return, no write for H
        };
        // Tries to write for Previous_H instead, still no write for H
        snapshot_block = option::extract(&mut prev_snapshot_block);
    };

    // The code path that writes `table::add(&mut c_balance.snapshot, key, c_balance.balance)`
    // requires `current_block_height > snapshot_block`, which is FALSE here.
    // RESULT: Attacker's balance for H is NOT recorded.
}

// 3. In `cabal_token::get_snapshot_balance_internal` (called during reward calculation for block H)
    fun get_snapshot_balance_internal(cabal_balance: &CabalBalance, block_height: u64): u64 { // block_height is H
    // ... start_block check ...

    // Search attacker's personal table for entry >= H
    let key = table_key::encode_u64(block_height);
    let iter = table::iter(&cabal_balance.snapshot, option::some(key), option::none(), 2);

    // --- VULNERABILITY PART 3 ---
    // Because the write was skipped (Vuln Part 2), no entry >= H is found for the attacker.
    if (!table::prepare<vector<u8>, u64>(iter)) {
        // ATTACKER EXPLOIT: Fallback logic returns the attacker's LIVE balance.
        // At this point (reward calculation time), the live balance is the POST-BURN balance.
        return cabal_balance.balance;
    };

    // This part is not reached for the attacker in this scenario
    let (_, balance) = table::next(iter);
    *balance
}
