Skip to content
Business logic Audit finding Intermediate

Cairo factory referral percentages never update

The NFTFactory contract's referral percentage setter appends new values to a persistent vector instead of replacing the existing ones, so admin updates have no effect. An attacker cannot directly exploit this, but referral rewards stay frozen at the original schedule, which may cause continued payouts at outdated rates.

s8olidity Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57307 sc low cairo factory referral percentages never update

Submitted on Oct 25th 2025 at 05:15:44 UTC by @s8olidity for Audit Comp | Belong

Description

Brief / Intro

NFTFactory._set_referral_percentages appends percentages to persistent storage without clearing prior values. Subsequent admin updates silently fail, leaving referral rewards frozen at the original schedule. Operators cannot adjust tiers, breaking platform economics.

{% hint style="warning" %} This is a logical bug that causes admin updates to referral percentages to have no practical effect because new values are appended rather than replacing the previous values. {% endhint %}

Vulnerability Details

  • Function: NFTFactory._set_referral_percentages (src/nftfactory/nftfactory.cairo:451-457)
  • Behavior: Iterates over the provided array and calls self.used_to_percentage.append().write(...).
  • Root cause: used_to_percentage is a persistent Vec. Appending adds new entries rather than replacing existing ones.
  • Reads: Code that reads referral percentages (src/nftfactory/nftfactory.cairo:230-240) indexes the vector by timesUsed and thus still reads the original indices (0..4). The newly appended values live at indices 5..9 and are never used.
  • Result: Admin attempts to adjust referral tiers via setReferralPercentages appear successful but do not change the system behavior.

Impact Details

  • Severity classification: Medium logic bug impact (documented here as Low report severity per reporter).
  • Effect: Referral pressure cannot be adjusted. This may lead to continued payouts at outdated/higher rates, undermining platform economics and potentially causing excessive fee leakage if percentages were intended to mitigate abuse.

Proof of Concept

Test showing append-only update behavior

  // src/tests/test_nftfactory.cairo
  #[test]
  fn test_referral_percentages_update_appends_only() {
      let contract = deploy_initialize(constants::SIGNER());
      let nft_factory = INFTFactoryDispatcher { contract_address: contract };

      assert_eq!(nft_factory.usedToPercentage(0), 0);
      assert_eq!(nft_factory.usedToPercentage(1), 5000);

      let new_percentages = array![100, 200, 300, 400, 500].span();

      start_cheat_caller_address(contract, constants::OWNER());
      nft_factory.setReferralPercentages(new_percentages);
      stop_cheat_caller_address(contract);

      assert_eq!(nft_factory.usedToPercentage(0), 0);     // original value remains
      assert_eq!(nft_factory.usedToPercentage(1), 5000);  // original value remains
      assert_eq!(nft_factory.usedToPercentage(5), 100);   // new value appended at index 5
  }

After invoking setReferralPercentages, indices 0 and 1 remain unchanged while new values appear at index 5+, proving the update mechanism is ineffective.

References

<details> <summary>Relevant source locations</summary>
  • Append-only "update": src/nftfactory/nftfactory.cairo:451-457
  • Reads assume indices 0..4: src/nftfactory/nftfactory.cairo:236-240
</details>

Suggested Fix (high-level)

  • Replace the append semantics in _set_referral_percentages with logic that either:
    • Overwrites existing elements in used_to_percentage up to the provided length, and truncates any excess old entries, or
    • Clears used_to_percentage before writing the new sequence, then appends the new values.

Do not modify any links or code beyond the intended fix described above.

The original report as published on Immunefi, by s8olidity. 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

The setter uses append on a persistent vector rather than overwriting or clearing existing entries, so reads that index the original positions never see the new values.

Impact

Referral tiers cannot be adjusted, so payouts may continue at outdated or higher rates, potentially causing excessive fee leakage if the percentages were meant to mitigate abuse.

What the attacker needed

Owner/admin role; none for the bug to exist

The fix

The setter should overwrite existing entries up to the new length and truncate any excess, or clear the vector before writing the new sequence.

How it was found

  1. Deploy and initialise the contract.
  2. Read the referral percentage at index 0 and index 1 to confirm the original values.
  3. Call setReferralPercentages with a new array of five values as the owner.
  4. Read the same indices again and observe they are unchanged.
  5. Read index 5 and observe the new value was appended there.

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 stores referral reward percentages in a list. When an admin tries to change them, the new numbers are added to the end of the list instead of replacing the old ones, so the code that reads the list keeps using the old numbers. This means the admin's changes never actually take effect.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by s8olidity

View all

3 more disclosed reports, 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.