Skip to content
Business logic Audit finding Intermediate

User can bypass MAX_EXPIRATION when extend expiration

The extend_expiration function validated the duration by subtracting the old expiration date from the new one, which always equals the duration and thus never exceeds MAX_EXPIRATION. An attacker could extend a domain's expiration far beyond the intended maximum, effectively doubling it.

laksmana Follow with p4y4b13

Originally disclosed on Code4rena

Submitted by laksmana, also found by p4y4b13

https://github.com/code-423n4/2025-01-initia-move/blob/a96f5136c4808f6968564a4592fe2d6ac243a233/usernames-module/sources/name_service.move#L483

Finding Description and Impact

In the extend_expiration function, the validation for the duration is incorrect, allowing the user to bypass MAX_EXPIRATION:

 let expiration_date = metadata::get_expiration_date(token);
        let new_expiration_date = if (expiration_date > timestamp) {
            expiration_date + duration
        } else {
            timestamp + duration
        };

        assert!(
=>            new_expiration_date - expiration_date <= MAX_EXPIRATION,
            error::invalid_argument(EMIN_DURATION),
        );

        metadata::update_expiration_date(token, new_expiration_date);

The issue arises because the code subtracts new_expiration_date - expiration_date for validation.

Assume a user registers a domain and the expiration_date is equal to MAX_EXPIRATION + timestamp. Then, the user performs extend_expiration with a duration value equal to the MAX_EXPIRATION, the new_expiration_date becomes expiration_date + duration.

This leads to the following verification check passing:

assert!(
    new_expiration_date - expiration_date <= MAX_EXPIRATION,
    error::invalid_argument(EMIN_DURATION),
);

Since the new_expiration_date is calculated using expiration_date + duration, the subtraction (new_expiration_date - expiration_date) will always be less than to MAX_EXPIRATION.

As a result, the update_expiration_date function updates the expiration duration to a value far greater than MAX_EXPIRATION, effectively doubling it to MAX_EXPIRATION * 2.

metadata::update_expiration_date(token, new_expiration_date);

Proof of Concept

Add the code below into name_service.move and run the test:

 #[test(chain = @0x1, source = @usernames, user = @0x2, lp_publisher = @0x3)]
    fun test_bypass_max_expiration(
        chain: signer,
        source: signer,
        user: signer,
        lp_publisher: signer,
    ) acquires CoinCapsInit, ModuleStore {
        deploy_dex(&chain, &lp_publisher);

        let addr = signer::address_of(&user);
        init_mint_to(signer::address_of(&chain), &user, 1000000000);

        initialize(
            &source,
            100,
            50,
            10,
            1000,
            1000,
            string::utf8(b"https://test.com/"),
            string::utf8(b"https://test.com/"),
        );

        std::block::set_block_info(100, 100);

        // before register
        assert!(get_name_from_address(addr) == option::none(), 0);
        assert!(get_address_from_name(string::utf8(b"abcd")) == option::none(), 1);
        assert!(get_valid_token(string::utf8(b"abcd")) == option::none(), 2);

        register_domain(&user, string::utf8(b"abcd"), MAX_EXPIRATION);
        let token = *option::borrow(&get_valid_token(string::utf8(b"abcd")));
        let token_object = object::address_to_object<Metadata>(token);
        assert!(initia_std::nft::token_id(token_object) == string::utf8(b"abcd.init.100"), 3);
        set_name(&user, string::utf8(b"abcd"));
        assert!(get_name_from_address(addr) == option::some(string::utf8(b"abcd")), 4);
        assert!(get_address_from_name(string::utf8(b"abcd")) == option::some(addr), 5);

        // extend duration bypass a MAX_EXPIRATION
        extend_expiration(&user, string::utf8(b"abcd"), MAX_EXPIRATION);
        let token = *option::borrow(&get_valid_token(string::utf8(b"abcd")));
        let expiration_date = metadata::get_expiration_date(token);
        assert!( expiration_date >= MAX_EXPIRATION * 2, 6);

    }

Recommended Mitigation Steps

Update the validation logic to ensure the new_expiration_date itself does not exceed MAX_EXPIRATION. The code would look like this:

assert!(
    new_expiration_date <= MAX_EXPIRATION,
    error::invalid_argument(EMIN_DURATION),
);

andrew (Initia) confirmed and commented:

Actually, MAX_EXPIRATION means that you can register/extend to current time + MAX_EXPIRATION. And yes, current logic is not correct. So I updated those in this commit.

        assert!(
            new_expiration_date - timestamp <= MAX_EXPIRATION,
            error::invalid_argument(EMAX_EXPIRATION),
        );

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

The validation compared the new expiration date to the old expiration date rather than to the current timestamp, so the duration check was ineffective.

Impact

A user could extend a domain's expiration to more than double the intended maximum, bypassing the MAX_EXPIRATION limit.

What the attacker needed

A registered domain; ability to call extend_expiration

The fix

The validation should compare the new expiration date to the current timestamp, ensuring it does not exceed MAX_EXPIRATION from now; this was fixed in a commit.

How it was found

  1. Register a domain with an expiration equal to MAX_EXPIRATION plus the current timestamp.
  2. Call extend_expiration with a duration equal to MAX_EXPIRATION.
  3. Observe that the new expiration date is at least twice MAX_EXPIRATION.

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 lets users extend how long they own a name. It was supposed to cap the total time, but the check compared the new end date to the old end date instead of to the current time, so the cap never applied. A user could keep extending and end up with a much longer ownership than allowed.

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 laksmana

View all

1 more disclosed report, best first.

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.