Advisory

GHSA-v358-wf77-39xv

Details, part 2 of 2. The advisory

Details

"split recipient must receive the full royalty pool")
require.Greater(t, credited, int64(0))

// (2) the sender's royalty debit was NEVER called -> value created.
require.Equal(t, 0, r.subFromCalls,
"BUG CONFIRMED: SubFromBalance (sender royalty debit) was skipped by the <=0 early-return")
require.Equal(t, int64(0), debited)

// credited > debited => mint of royaltyAmount.
require.Equal(t, royaltyAmount, mintDelta,
"fix is INCOMPLETE: %d of %s minted (recipient credited, sender never debited)",
mintDelta, assetIDStr)
})

// ---- 50% split contrast: NO early-return, sender IS debited -> conserved. ----
t.Run("split_50pct_conserves", func(t *testing.T) {
r := run(t, core.HundredPercent/2) // 5000 == 50%

require.NoError(t, r.err)
require.Equal(t, transaction.Transaction_Ok, r.resCode)

credited := r.addToRecipient + r.addToOwnerRem
debited := r.subFromAmount

t.Logf("[50%% case] split recipient credited = %d", r.addToRecipient)
t.Logf("[50%% case] owner-remainder credited = %d", r.addToOwnerRem)
t.Logf("[50%% case] total credited = %d", credited)
t.Logf("[50%% case] sender royalty-debit calls = %d", r.subFromCalls)
t.Logf("[50%% case] sender royalty amount debited = %d", debited)
t.Logf("[50%% case] net (credited - debited) = %d (0 => conserved)", credited-debited)

// Sender IS debited the full royalty pool exactly once.
require.Equal(t, 1, r.subFromCalls,
"sibling path: at <100%% the early-return does NOT fire, so the sender royalty debit runs")
require.Equal(t, royaltyAmount, debited)

// Split (20) + owner remainder (20) == debited (40): value conserved.
require.Equal(t, royaltyAmount/2, r.addToRecipient)
require.Equal(t, royaltyAmount/2, r.addToOwnerRem)
require.Equal(t, debited, credited, "50%% case conserves: total credited == debited")
})
}

</details>

### On-chain reproduction (live single-node localnet)
Asset `F07-3NG3` was created with a 10% transfer royalty (`percentage: 1000`) and a single 100% split
(`percentTransferPercentage: 10000`) to address `R` (`klv1qeh4py4…qcv2xjm`). A transfer of `100,000,000,000` units
(with `kdaRoyalties = 10,000,000,000`, i.e. the 10% pool) then produced **two** credit receipts: the recipient gets
the `100,000,000,000` transfer, and `R` is credited the **`10,000,000,000`** royalty — while the sender was debited
only the transfer amount, never the royalty. Net: 10,000 F07 created on the transfer.

<details><summary>Create tx — <code>F07-3NG3</code>, 10% transfer royalty + single 100% split to <code>R</code> (hash <code>ec2a8e8d…af12bc7f</code>)</summary>

```json
{
    "hash": "ec2a8e8d17136986756141f598f869803528ab12840416671b09622eaf12bc7f",
    "blockNum": 104,
    "status": "success",
    "resultCode": "Ok",
    "chainID": "420420",
    "contract": [
        {
            "type": 1,
            "typeString": "CreateAssetContractType",
            "parameter": {
                "type": "Fungible",
                "name": "Finding07",
                "ticker": "F07",
                "precision": 6,
                "initialSupply": 1000000000000,
                "maxSupply": 0,
                "royalties": {
                    "address": "klv1ddnnxjrt4jhus4ddtzmp6ccpcu3us78ndrn4qet0x0vegpg4995qv4nctq",
                    "transferPercentage": [
                        { "percentage": 1000 }
                    ],
                    "splitRoyalties": [
                        {
                            "address": "klv1qeh4py4p5zzy94l2hnygpfklug82gpzw08u680ycwp00njxyhgdqcv2xjm",
                            "percentTransferPercentage": 10000
                        }
                    ]
                }
            }
        }
    ]
}

</details>

<details><summary>Transfer tx — royalty pool 10,000,000,000 credited to <code>R</code> with no source debit (hash <code>37527757…bf3706b1</code>)</summary>

{
    "hash": "37527757b10dcf968b86cc3c0abf971c70e81aef0348b4a5b7d4ccc1bf3706b1",
    "blockNum": 120,
    "status": "success",
    "resultCode": "Ok",
    "chainID": "420420",
    "receipts": [
        {
            "assetId": "F07-3NG3",
            "from": "klv1ddnnxjrt4jhus4ddtzmp6ccpcu3us78ndrn4qet0x0vegpg4995qv4nctq",
            "to": "klv1qeh4py4p5zzy94l2hnygpfklug82gpzw08u680ycwp00njxyhgdqcv2xjm",
            "type": 0,
            "typeString": "Transfer",
            "value": 10000000000
        },
        {
            "assetId": "F07-3NG3",
            "from": "klv1ddnnxjrt4jhus4ddtzmp6ccpcu3us78ndrn4qet0x0vegpg4995qv4nctq",
            "to": "klv1fttx7kd0mzw3t8nekmh98489dwqq6mehs98nfcuvewwz0yt776aqf5ydfa",
            "type": 0,
            "typeString": "Transfer",
            "value": 100000000000
        }
    ],
    "contract": [
        {
            "type": 0,
            "typeString": "TransferContractType",
            "parameter": {
                "assetId": "F07-3NG3",
                "toAddress": "klv1fttx7kd0mzw3t8nekmh98489dwqq6mehs98nfcuvewwz0yt776aqf5ydfa",
                "amount": 100000000000,
                "kdaRoyalties": 10000000000
            }
        }
    ]
}

</details>

Remediation
Reorder so the royalty pool is debited from the sender before the split distribution, mirroring
processFixedRoyaltiesTransfer:

err := acntSrc.SubFromBalance(royaltyAmount, assetID, ...)   // debit FIRST
// ... then the split loop and `if royaltiesToPay <= 0 { return Ok }` (now only skips a zero owner-remainder)

Add the unit test above as a regression guard. Consensus-affecting → gate behind the next activation flag.

Sources & licences