Skip to content
Business logic Audit finding Beginner

get_cost_amount allows unlimited free domain registrations

The get_cost_amount function sets the price for domain names of length 7 or more to zero, allowing users to register unlimited long domains for free. An attacker could hoard domains, front-run legitimate users, or grief the system by registering many free domains.

SadBase Follow with danzero

Originally disclosed on Code4rena

Submitted by SadBase, also found by danzero

The get_cost_amount function unintentionally sets the price for domain names of length greater than or equal to 7 to zero. This behavior is due to the following code logic:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) { // FREE_LENGTH = 7
        module_store.config.price_per_year_default
    } else {
        0
    };

Here, FREE_LENGTH is defined as 7. When the length of the domain name is greater than or equal to 7, the else branch is executed, setting the price_per_year to 0. While this behavior may be intentional to make longer domain names free, it opens the system to abuse.

Impact

  • Abuse of free registrations: Users can register unlimited long domain names at zero cost, leading to resource hoarding and potential abuse of the system.
  • Front-running attacks: Malicious users could register desired long domain names before legitimate users, reducing availability.
  • Griefing: Attackers can clog the domain name system by registering a large volume of free domains, creating disruptions for legitimate users.

The lack of cost for these registrations incentivizes malicious behavior, as attackers only incur transaction fees.

Proof of Concept

Exploitation Steps:

  1. A user selects a domain name of 7 or more characters.
  2. The get_cost_amount function assigns a cost of 0 due to the else branch in the logic.
  3. The user registers the domain name for free.

Code Reference:

The issue originates from the following code snippet:

if (len < FREE_LENGTH) { // FREE_LENGTH = 7
    module_store.config.price_per_year_default
} else {
    0
}

As long as len >= 7, the else branch ensures the price_per_year is zero, enabling free registrations for long domain names.

See code reference from the relevant GitHub repository here.

Recommended mitigation steps

To prevent abuse and ensure proper pricing for all domain names, update the logic in the get_cost_amount function as follows:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) {
        module_store.config.price_per_year_default
    } else {
        module_store.config.price_per_year_default // Assign a default cost for longer names
    };

andrew (Initia) confirmed and commented:

We decided to remove the free username and just keep 3 prices (3 char, 4 char and 5+ char). Here’s the commit.


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

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. 4 min read.

Context

Initia Move is a Move-based chain, and the audited code is the usernames-module, which implements a name service for domain names. The module prices registrations per year, with separate configured prices for 3-character names, 4-character names and a default price for names shorter than 7 characters. The pricing is computed by the get_cost_amount function in name_service.move.

The report concerns a logic error in that function: names of a certain length and above are priced at zero, so they can be registered without paying the registration cost.

Setup

This is a code review finding from a Code4rena audit of the Initia Move repository, so there is no live target, account or tooling to set up. The relevant precondition is simply the code: the constant FREE_LENGTH is set to 7, and the price configuration (price_per_year_3char, price_per_year_4char, price_per_year_default) is read from module_store.config.

Finding it

The researcher read the price selection logic in get_cost_amount and noticed that the final branch returns a literal 0 rather than a configured price:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) { // FREE_LENGTH = 7
        module_store.config.price_per_year_default
    } else {
        0
    };

FREE_LENGTH is defined as 7. For any name whose length is greater than or equal to 7, none of the first three conditions match, so the else branch runs and price_per_year becomes 0. The researcher notes that this may have been intended to make longer names free, but that it opens the system to abuse.

Exploitation

The report describes the abuse in three steps.

Step 1: choose a long name

A user selects a domain name of 7 or more characters.

Step 2: the price resolves to zero

The get_cost_amount function assigns a cost of 0 because of the else branch shown above. The condition that matters is:

if (len < FREE_LENGTH) { // FREE_LENGTH = 7
    module_store.config.price_per_year_default
} else {
    0
}

As long as len >= 7, the else branch ensures price_per_year is zero.

Step 3: register for free

The user registers the domain name for free. The report does not show a transaction, a call payload or a response; the exploitation is described at the level of the pricing logic.

The code reference given for the issue is the get_cost_amount region of usernames-module/sources/name_service.move (lines 590 to 613 in the linked repository).

Root cause

The mistake is in the branch structure of get_cost_amount: the fall-through case for names of length 7 or more returns the constant 0 instead of a configured price. Because FREE_LENGTH is 7 and the preceding branches only cover lengths 3, 4 and anything below 7, every longer name lands in the zero-price branch. The report does not describe any other check that would override this price before registration, so the zero price is what the registration path uses.

Impact

The report lists three consequences:

  • Abuse of free registrations: users can register unlimited long domain names at zero cost, leading to resource hoarding and potential abuse of the system.
  • Front-running attacks: malicious users could register desired long domain names before legitimate users, reducing availability.
  • Griefing: attackers can clog the domain name system by registering a large volume of free domains, creating disruptions for legitimate users.

The lack of cost for these registrations incentivises malicious behaviour, since attackers only incur transaction fees.

Fix

The report recommends giving longer names the default price instead of zero:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) {
        module_store.config.price_per_year_default
    } else {
        module_store.config.price_per_year_default // Assign a default cost for longer names
    };

The project confirmed the finding and took a different route: andrew (Initia) commented that they decided to remove the free username and keep three prices, for 3-character, 4-character and 5+ character names, linking the corresponding commit in the usernames-module repository.

Variants to test

  • Tiered pricing functions elsewhere: look for price or fee selection written as an if/else if chain over a size or length, and check what the final else returns. A positive result is a final branch that returns a literal zero, a missing assignment, or a default that is lower than the smallest paid tier.
  • Boundary constants: find constants such as FREE_LENGTH and compare them with the branches that use them. A positive result is a gap or overlap where a range of inputs falls into a branch that was meant for something else.
  • Free tiers in registration or minting flows: check whether any length, count or tier is deliberately free, and whether the free path has a cap. A positive result is an uncapped free path that still consumes shared namespace or storage.
  • Front-running exposure: for any namespace where names are first-come-first-served, check whether a cheap or free registration lets an attacker take names ahead of legitimate users. A positive result is a name that can be claimed at negligible cost relative to its value.

Hunting notes

This kind of bug hides in pricing and fee helpers that branch on input size, tier or category, especially where a constant like FREE_LENGTH suggests a deliberate free band. During review, the signal is a branch chain whose last arm returns a literal value rather than reading configuration, and a constant whose name implies free service. The impact case here rests on volume and availability: unlimited zero-cost registrations, front-running of desirable names and namespace clogging, with only transaction fees as a cost to the attacker. The report does not include a transaction-level proof, so the argument is made from the code path itself.

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. 10 min read.

What happened, in plain words

Initia Move is a blockchain project, and the piece of code examined here is its name service: a system that lets people register domain names, much like buying a web address. The service charges a yearly fee for a name, and the fee depends on how long the name is.

The bug is simple to state. A function called get_cost_amount works out that yearly fee. For any name of seven characters or more, it returns a price of zero. So anyone can register as many long names as they like without paying the registration cost. The code does exactly what it is written to do, but what it is written to do is wrong.

A quick comparison: imagine a car park with a sign saying "first hour free, then £2 per hour". If the attendant's rulebook says "if the stay is under one hour, charge nothing; otherwise charge nothing", every driver parks for free. Nobody broke into the till. The rule itself was written badly. That is the shape of this finding.

This was found during a Code4rena audit. An audit is a review where independent researchers read a project's code and report problems. Code4rena is a platform that runs these audits and publishes the findings. The researcher credited here is SadBase, and the same issue was also found by danzero. The project team confirmed the finding and described a change to the pricing.

The product and the feature

Initia Move is a chain built on Move, a programming language designed for blockchain code. You do not need to know Move to follow this. What matters is that the name service module, called usernames-module, stores a set of prices in a configuration object and reads them whenever someone registers a name.

The prices are kept in three settings:

  • price_per_year_3char: the yearly price for a three-character name.
  • price_per_year_4char: the yearly price for a four-character name.
  • price_per_year_default: the yearly price for other lengths.

There is also a constant called FREE_LENGTH, set to 7. A constant is a named value fixed in the code, used so the same number does not have to be typed in several places. Its name suggests a deliberate free band for longer names.

The function that turns a name's length into a price is get_cost_amount, in the file name_service.move. That function is where the problem lives.

Finding it

The researcher read the part of get_cost_amount that picks the price and noticed that the last branch hands back a plain 0 instead of looking up a configured price:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) { // FREE_LENGTH = 7
        module_store.config.price_per_year_default
    } else {
        0
    };

Line by line, in plain words:

  • let price_per_year = starts a new value called price_per_year, which will hold the yearly price. let is how Move introduces a variable, a named box that stores a value.
  • if (len == 3) { asks: is the name exactly three characters long? len is the length of the name. == means "is equal to".
  • module_store.config.price_per_year_3char is the answer if so: read the three-character price from the stored configuration.
  • } else if (len == 4) { otherwise, is it exactly four characters?
  • module_store.config.price_per_year_4char is then the four-character price.
  • } else if (len < FREE_LENGTH) { otherwise, is the length less than FREE_LENGTH? Since FREE_LENGTH is 7, this means lengths of 5 or 6, because 3 and 4 were already handled above.
  • module_store.config.price_per_year_default is the default price for those 5 and 6 character names.
  • } else { catches everything left over: every name of length 7 or more.
  • 0 is the price for all of them. Not a configured price, just the number zero.
  • }; closes the assignment.

So the chain of questions covers lengths 3, 4, 5 and 6, and then dumps every longer name into a branch that returns zero. The researcher notes that this may have been intended to make long names free, but that it opens the system to abuse.

Exploitation

The report describes the abuse in three steps.

Step 1: choose a long name

A user selects a domain name of 7 or more characters. Nothing special is needed here: any name that long will do, because the length alone decides the price.

Step 2: the price resolves to zero

The get_cost_amount function assigns a cost of 0 because of the else branch shown above. The condition that matters is:

if (len < FREE_LENGTH) { // FREE_LENGTH = 7
    module_store.config.price_per_year_default
} else {
    0
}

Line by line:

  • if (len < FREE_LENGTH) { checks whether the name is shorter than the free threshold. With FREE_LENGTH at 7, that means 6 characters or fewer at this point in the chain.
  • module_store.config.price_per_year_default charges the normal default price for those shorter names.
  • } else { covers every name that is not shorter than 7, in other words 7 characters or more.
  • 0 sets the price to zero for all of them.

As long as len >= 7, the else branch ensures price_per_year is zero. >= means "greater than or equal to".

Step 3: register for free

The user registers the domain name for free. The report does not show a transaction, a call payload or a response; the exploitation is described at the level of the pricing logic. In other words, the argument is made by reading the code, not by running an attack against a live system.

The code reference given for the issue is the get_cost_amount region of usernames-module/sources/name_service.move, lines 590 to 613 in the linked repository.

Root cause

The mistake is in the branch structure of get_cost_amount: the fall-through case for names of length 7 or more returns the constant 0 instead of a configured price. Because FREE_LENGTH is 7 and the preceding branches only cover lengths 3, 4 and anything below 7, every longer name lands in the zero-price branch. The report does not describe any other check that would override this price before registration, so the zero price is what the registration path uses.

A useful way to think about it: the code has four doors, labelled "3 characters", "4 characters", "shorter than 7" and "everything else". The last door was meant to be a small side room for a few free names, but it is actually the main entrance, and behind it the till is switched off.

Impact

The report lists three consequences:

  • Abuse of free registrations: users can register unlimited long domain names at zero cost, leading to resource hoarding and potential abuse of the system. Resource hoarding means taking and holding a shared resource, here names and the storage behind them, so others cannot use it.
  • Front-running attacks: malicious users could register desired long domain names before legitimate users, reducing availability. Front-running is acting just ahead of someone else to take what they were about to take. If a name is about to become valuable, an attacker can grab it first because grabbing costs nothing.
  • Griefing: attackers can clog the domain name system by registering a large volume of free domains, creating disruptions for legitimate users. Griefing is causing harm for its own sake, or to make a system unusable for others, without direct profit.

The lack of cost for these registrations incentivises malicious behaviour, since attackers only incur transaction fees. A transaction fee is the small charge a blockchain network takes to process any action. It is the only thing standing between an attacker and an unlimited number of free names.

Fix

The report recommends giving longer names the default price instead of zero:

let price_per_year =
    if (len == 3) {
        module_store.config.price_per_year_3char
    } else if (len == 4) {
        module_store.config.price_per_year_4char
    } else if (len < FREE_LENGTH) {
        module_store.config.price_per_year_default
    } else {
        module_store.config.price_per_year_default // Assign a default cost for longer names
    };

Line by line:

  • let price_per_year = again starts the price variable.
  • if (len == 3) { and module_store.config.price_per_year_3char keep the three-character price as before.
  • } else if (len == 4) { and module_store.config.price_per_year_4char keep the four-character price as before.
  • } else if (len < FREE_LENGTH) { and module_store.config.price_per_year_default keep the default price for names shorter than 7.
  • } else { still catches names of 7 or more characters.
  • module_store.config.price_per_year_default // Assign a default cost for longer names is the change: instead of 0, the same default price is charged. The text after // is a comment, a note for human readers that the computer ignores.

The project confirmed the finding and took a different route: andrew (Initia) commented that they decided to remove the free username and keep three prices, for 3-character, 4-character and 5+ character names, linking the corresponding commit in the usernames-module repository. So rather than patching the last branch, the team decided to remove the free username and keep three prices.

Variants to test

These are patterns to look for in other code, written for someone new to reviewing.

  • Tiered pricing functions elsewhere: look for price or fee selection written as an if/else if chain over a size or length, and check what the final else returns. A positive result is a final branch that returns a literal zero, a missing assignment, or a default that is lower than the smallest paid tier. In plain terms: find the last catch-all rule and ask what it charges.
  • Boundary constants: find constants such as FREE_LENGTH and compare them with the branches that use them. A positive result is a gap or overlap where a range of inputs falls into a branch that was meant for something else. Boundaries are where off-by-one mistakes live: is it "less than 7" or "less than or equal to 7"?
  • Free tiers in registration or minting flows: check whether any length, count or tier is deliberately free, and whether the free path has a cap. A positive result is an uncapped free path that still consumes shared namespace or storage. A cap is a limit, such as "one free name per account".
  • Front-running exposure: for any namespace where names are first-come-first-served, check whether a cheap or free registration lets an attacker take names ahead of legitimate users. A positive result is a name that can be claimed at negligible cost relative to its value.

Hunting notes

This kind of bug hides in pricing and fee helpers that branch on input size, tier or category, especially where a constant like FREE_LENGTH suggests a deliberate free band. During review, the signal is a branch chain whose last arm returns a literal value rather than reading configuration, and a constant whose name implies free service. The impact case here rests on volume and availability: unlimited zero-cost registrations, front-running of desirable names and namespace clogging, with only transaction fees as a cost to the attacker. The report does not include a transaction-level proof, so the argument is made from the code path itself.

Glossary

  • Audit: a structured review of a project's code by independent researchers looking for security problems.
  • Blockchain: a shared record of transactions kept by many computers, where entries are hard to change after the fact.
  • Branch: one path through an if/else decision in code, taken when a particular condition is true.
  • Code4rena: a platform that runs code audits and publishes the findings.
  • Comment: text in code after // that the computer ignores and that is there for human readers.
  • Configuration: stored settings that code reads at runtime, such as the three price values here.
  • Constant: a named value fixed in the code, such as FREE_LENGTH = 7.
  • Domain name: a human-friendly name registered in a naming system, like the names this service sells.
  • else branch: the path taken when none of the earlier conditions in an if chain matched.
  • Front-running: acting just before someone else to take an opportunity they were about to take.
  • Function: a named block of code that performs a task and can return a result, such as working out a price.
  • Griefing: causing harm or disruption to other users without direct benefit to the attacker.
  • if/else if chain: a series of conditions checked in order, where the first true one wins.
  • Impact: the harm a security issue can cause if it is not fixed.
  • Initia Move: the blockchain project whose name service module is examined here.
  • Length (len): the number of characters in a name.
  • Logic error: a bug where the code runs as written but the written rule is wrong.
  • Mitigation: a change that removes or reduces the risk.
  • Move: the programming language this module is written in.
  • Namespace: the shared pool of names available in a naming system.
  • Price tier: a price band that applies to a group of inputs, such as 3-character names.
  • Resource hoarding: taking and holding a shared resource so others cannot use it.
  • Root cause: the underlying mistake that produces a bug.
  • Transaction fee: the small charge a blockchain network takes to process an action.
  • Variable: a named box in code that holds a value, such as price_per_year.
  • usernames-module: the part of the project that implements the name service.
  • get_cost_amount: the function that calculates the yearly price of a name.
  • name_service.move: the source file containing that function.
  • FREE_LENGTH: the constant set to 7 that marks the free threshold in the pricing logic.

More from Initia Move

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.