Skip to content
DoS Audit finding Intermediate

Unlimited referrals[hashedCode].referralUsers increases gas cost with each new referral, making it very expensive.

The referral system stores each referrer's referred users in a growing array and loops over the whole array on every new referral to check for duplicates. As the array grows, each new referral costs more gas, so at some point referring new users becomes prohibitively expensive or fails.

Oxlookman Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

57467 sc insight unlimited referrals hashedcode referralusers increases gas cost with each new referral making it very expensive

Submitted on Oct 26th 2025 at 13:41:48 UTC by @Oxlookman for Audit Comp | Belong

{% hint style="info" %} Brief/Intro

Growing referrals[hashedCode].referralUsers array will make it difficult for a referrer to refer new users as this array grows. {% endhint %}

Description

Vulnerability Details

Referrer's referral array increases over time. When a new referral is being added in _setReferralUser, the array is iterated to check if the referral is new:

Solidity
for (uint256 i; i < len; ++i) {
    if (users[i] == referralUser) {
        // User already added; no need to add again
        inArray = true;
        break;
    }
}
if (!inArray) users.push(referralUser);

Since this array keeps growing with each new referral it will become very expensive for referrals to use the referrer code and at some point it will be DoSed.

Impact Details

  • The referrer will pay more gas fees as the array keeps growing, discouraging use of their referral code and causing them to lose their intended percentage.
  • Users also incur very expensive transactions.

References

Proof of Concept

<details> <summary>Test demonstrating increasing transaction costs with more referrals</summary>

Add this to factort.test.ts in the describe with referral, setup local network in your config since this test was run on the localhost.

JavaScript
it('Test transaction costs increase with each new refferal', async () => {
    const { factory, signer, alice, bob } = await loadFixture(fixture);

    const hashedCode = EthCrypto.hash.keccak256([
      { type: 'address', value: alice.address },
      { type: 'address', value: factory.address },
      { type: 'uint256', value: chainId },
    ]);
    

  await factory.connect(alice).createReferralCode();

  let nftName = 'Name';
  let nftSymbol = 'AT';
  const contractURI = 'contractURI/AccessToken123';
  const price = ethers.utils.parseEther('0.01');
  const feeNumerator = 500;

  let message = EthCrypto.hash.keccak256([
    { type: 'string', value: nftName },
    { type: 'string', value: nftSymbol },
    { type: 'string', value: contractURI },
    { type: 'uint96' as any, value: feeNumerator },
    { type: 'uint256', value: chainId },
  ]);

  let signature = EthCrypto.sign(signer.privateKey, message);

  let tx = await factory.connect(bob).produce(
      {
        metadata: { name: nftName, symbol: nftSymbol },
        contractURI: contractURI,
        paymentToken: NATIVE_CURRENCY_ADDRESS,
        mintPrice: price,
        whitelistMintPrice: price,
        transferable: true,
        maxTotalSupply: BigNumber.from('1000'),
        feeNumerator: feeNumerator,
        collectionExpire: BigNumber.from('86400'),
        signature: signature,
      } as AccessTokenInfoStruct,
      hashedCode,
    )

  let receipt = await tx.wait();
  const firstGasUsed = receipt.gasUsed;
  console.log(`This is the last receipt: ${ receipt.gasUsed}`)

  let i = 0;

  while( i < 100) {
    let randomWallet = ethers.Wallet.createRandom().connect(ethers.provider);
    await alice.sendTransaction({to: await randomWallet.getAddress(), value: ethers.utils.parseEther('0.1')})

    let nftName = `Name ${ i++ }`;
    let nftSymbol = `AT ${ i++ }`;
    const contractURI = 'contractURI/AccessToken123';
    const price = ethers.utils.parseEther('0.01');
    const feeNumerator = 500;

    let message = EthCrypto.hash.keccak256([
      { type: 'string', value: nftName },
      { type: 'string', value: nftSymbol },
      { type: 'string', value: contractURI },
      { type: 'uint96' as any, value: feeNumerator },
      { type: 'uint256', value: chainId },
    ]);

    let signature = EthCrypto.sign(signer.privateKey, message);

    tx = await factory.connect(randomWallet).produce(
        {
          metadata: { name: nftName, symbol: nftSymbol },
          contractURI: contractURI,
          paymentToken: NATIVE_CURRENCY_ADDRESS,
          mintPrice: price,
          whitelistMintPrice: price,
          transferable: true,
          maxTotalSupply: BigNumber.from('1000'),
          feeNumerator: feeNumerator,
          collectionExpire: BigNumber.from('86400'),
          signature: signature,
        } as AccessTokenInfoStruct,
        hashedCode,
      )
  }

  receipt = await tx.wait();
  const diff = receipt.gasUsed.sub(firstGasUsed);
  const secondCheckpointGasUsed = receipt.gasUsed;
  console.log(`This is the last receipt gasUsed:  ${secondCheckpointGasUsed}`)

  assert(receipt.gasUsed != firstGasUsed && diff.gt(0n))
  console.log(`The gas difference is after around 100 referrals: ${diff}`)
  
  let j = 0;
  while( j < 100) {
    let randomWallet = ethers.Wallet.createRandom().connect(ethers.provider);
    await alice.sendTransaction({to: await randomWallet.getAddress(), value: ethers.utils.parseEther('0.1')})

    let nftName = `Name ${ i++ }`;
    let nftSymbol = `AT ${ i++ }`;
    const contractURI = 'contractURI/AccessToken123';
    const price = ethers.utils.parseEther('0.01');
    const feeNumerator = 500;

    let message = EthCrypto.hash.keccak256([
      { type: 'string', value: nftName },
      { type: 'string', value: nftSymbol },
      { type: 'string', value: contractURI },
      { type: 'uint96' as any, value: feeNumerator },
      { type: 'uint256', value: chainId },
    ]);

    let signature = EthCrypto.sign(signer.privateKey, message);

    tx = await factory.connect(randomWallet).produce(
        {
          metadata: { name: nftName, symbol: nftSymbol },
          contractURI: contractURI,
          paymentToken: NATIVE_CURRENCY_ADDRESS,
          mintPrice: price,
          whitelistMintPrice: price,
          transferable: true,
          maxTotalSupply: BigNumber.from('1000'),
          feeNumerator: feeNumerator,
          collectionExpire: BigNumber.from('86400'),
          signature: signature,
        } as AccessTokenInfoStruct,
        hashedCode,
      )
    j++;
  }
  receipt = await tx.wait();
  const diff2 = receipt.gasUsed.sub(firstGasUsed);
  console.log(`This is the receipt of gasUsed after 200 referrals: ${receipt.gasUsed}`)
  assert(receipt.gasUsed != secondCheckpointGasUsed && diff2 != diff)
  assert(receipt.gasUsed > secondCheckpointGasUsed && diff2 > diff)
  console.log(`The gas difference is from first transaction after around 200 referals: ${diff2}`)

});
</details>

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the duplicate check iterates over an unbounded array of referral users on every new referral, so cost grows linearly with the number of referrals.

Impact

Referrers and referred users pay increasingly high gas fees as the array grows, and the report claims referrals could eventually be denied service, though this is a griefing-style cost issue rather than direct theft.

What the attacker needed

A referral code exists; many users join via that code

How it was found

  1. Create a referral code as the referrer.
  2. Have a first user produce a token using that referral code and record the gas used.
  3. Have around 100 new wallets each produce a token with the same referral code.
  4. Compare the gas used by the latest transaction with the first one and observe it is higher.
  5. Repeat with around 200 referrals and observe the gas cost has risen further.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract is a program on a blockchain, and every operation costs a fee called gas. This contract keeps a list of everyone a referrer has brought in, and each time someone new joins it reads through the entire list to check they are not already there. The longer the list gets, the more work and gas each new sign-up costs, until it becomes too expensive to use.

What is DoS?

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

More by Oxlookman

View all

1 more disclosed report, best first.

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.