Skip to content
Access control Audit finding Beginner

mintToken() , mintWithBudget() , and forge() in the TraitForgeNft contract will fail due to a wrong modifier used in EntropyGenerator.initializeAlphaIndices()

The EntropyGenerator contract's initializeAlphaIndices() function uses the onlyOwner modifier instead of onlyAllowedCaller, so the TraitForgeNft contract cannot call it. This causes mintToken(), mintWithBudget(), and forge() to fail when they try to increment the generation.

0xAadi Follow with LogBytes, Fitro and 48 others

Originally disclosed on Code4rena

Submitted by 0xAadi, also found by LogBytes, Fitro, Abdessamed, avoloder, Tomas0707, synackrst, dontonka, _karanel, lrivo, Autosaida, ZanyBonzy, samuraii77, x0t0wt1w, rndquu, Auditor_Nate, blackVul (1, 2), brevis, 0xAleko, zeroProtocol, MinhTriet, 0xb0k0, 0xHelium, AvantGard, Trooper, Stoicov, 0xcontrol, EdMarcavage, yaioxy, anonymousjoe, federodes, Decap, desaperh, ogKapten, LSHFGJ, PENGUN, 0xDarko, onthehunt11, Trident-Audits, ABAIKUNANBAEV, hakunamatata, MrValioBg, 0xlemon, LeFy, kingnull, PetarTolev, binary, Undefined, Bac0nj, Erko, Daniel_eth, pep7siup, vinica_boy, SharpPeaks, yixxas, kutugu, KaligoAudits, inzinko, BajagaSec, franfran20, jeremie, 0x0bserver, dobrevaleri, DigiSafe, Nihavent, mashbust, McToady, King_, Pataroff, eierina, Shahil_Hussain, bhavya0911, amaron, hail_the_lord, ArsenLupin, KupiaSec, gesha17, zxriptor, klau5, ilchovski, Zac, 0xrex, Kalogerone, dimulski, and ZdravkoHr

The EntropyGenerator contract has an issue where the initializeAlphaIndices() function uses the wrong modifier. This function is supposed to be called by the TraitForgeNft contract, but it currently uses the onlyOwner modifier instead of onlyAllowedCaller.

Impact

The initializeAlphaIndices() function will not be callable by the TraitForgeNft contract as intended. This could lead to failures in the expected functionality of the system, particularly in scenarios where the indices need to be initialized or updated by the TraitForgeNft contract while performing minting or forging. That means this vulnerability will cause DoS on mintToken(), mintWithBudget() and forge().

Proof of Concept

The function initializeAlphaIndices() is intended to be called by the TraitForgeNft contract. However, it is currently protected by the onlyOwner modifier. This means only the owner of the EntropyGenerator contract can call it, not the TraitForgeNft contract. The correct modifier should be onlyAllowedCaller, which restricts the function to be called by the address set as the allowedCaller.

The vulnerability lies in the following line of EntropyGenerator contract:

@>  function initializeAlphaIndices() public whenNotPaused onlyOwner {

https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/EntropyGenerator/EntropyGenerator.sol#L206

The above initializeAlphaIndices() is called by TraitForgeNft._incrementGeneration():

  function _incrementGeneration() private {
    require(
      generationMintCounts[currentGeneration] >= maxTokensPerGen,
      'Generation limit not yet reached'
    );
    currentGeneration++;
    generationMintCounts[currentGeneration] = 0;
    priceIncrement = priceIncrement + priceIncrementByGen;
@>  entropyGenerator.initializeAlphaIndices();
    emit GenerationIncremented(currentGeneration);
  }

https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/TraitForgeNft/TraitForgeNft.sol#L353

Some of the important functions defined in TraitForgeNft contract, such as mintToken(), mintWithBudget() and forge(), internally use _incrementGeneration(). Due to this vulnerability, the execution of these mentioned functions will fail.

Recommended Mitigation Steps

Replace the onlyOwner modifier with the onlyAllowedCaller modifier in the initializeAlphaIndices() function to ensure it can be called by the TraitForgeNft contract.

- function initializeAlphaIndices() public whenNotPaused onlyOwner {
+ function initializeAlphaIndices() public whenNotPaused onlyAllowedCaller {

Assessed type

Access Control

TForge1 (TraitForge) confirmed


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

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 wrong access control modifier (onlyOwner instead of onlyAllowedCaller) was applied to initializeAlphaIndices().

Impact

The functions mintToken(), mintWithBudget(), and forge() will fail when they attempt to increment the generation, causing a denial of service.

What the attacker needed

None

The fix

Replace the onlyOwner modifier with onlyAllowedCaller in initializeAlphaIndices().

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 has functions that can only be called by certain addresses. Here, a function meant to be called by another contract was mistakenly restricted to only the owner, so the other contract's calls fail. This breaks the minting and forging features.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by 0xAadi

View all

13 more disclosed reports, best first.

More from TraitForge

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.