Loss of funds due to address mappings are not cleaned up after domain expiry
When a domain expires and a new user registers it, the old address mappings are not cleared, so the domain still resolves to the previous owner's address until the new owner calls set_name. This could cause funds sent to the domain name to go to the previous owner instead of the new owner.
Submitted by d4r3d3v1l
Finding description and impact
The register_domain function doesn’t properly clean up old mappings (name_to_addr and addr_to_name) when a new user registers an expired domain. While it removes the old name_to_token mapping, it leaves the previous user’s address mappings.
When a new user re-registers an expired domain:
- The old
name_to_addr,addr_to_namemappings still points to the previous user values. - The
is_expiredcheck in getter functions(get_address_from_name ,get_name_from_address)is bypassed because the domain is now re-registered with a new expiration date results in returning previous user values.
Impact
Loss of Funds: get_address_from_name returns the address of the previous user.
While sending tokens, we can enter either domain or address. If we enter the domain name, it uses get_address_from_name function to retrieve the address. The funds will be transferred to the previous user, not to the one who owns the domain.
Request to fetch the address from the domain name:
https://rest.testnet.initia.xyz/initia/move/v1/accounts/0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a/modules/usernames/view_functions/get_address_from_name
Proof of Concept
Initial State:
- User1 registers domain “abc”.
- User1 calls
set_namefor “abc”. name_to_addr["abc"]points to User1’s address.addr_to_name[User1's address]points to “abc”.
After Domain Expires:
-
User1’s registration for “abc” expires.
-
Old mappings still exist in the tables:
name_to_addr["abc"]→ User1’s address.addr_to_name[User1's address]→ “abc”.
User2 Registers Expired Domain:
-
User2 registers “abc”.
-
A new token is created and assigned to User2.
-
Old mappings are not cleaned up:
name_to_addr["abc"]→ Still points to User1’s address.addr_to_name[User1's address]→ Still points to “abc”.
Note : User2 didn’t call the set_name.
Loss of funds scenario: User X want to transfer some tokens to User2 and type the abc.init in the address input,the function get_address_from_name fetch the User1 address instead and funds will transfer to User1 instead of User2.
Note: I verified the loss of funds scenario in the testnet with the help of this site.
Coded proof of concept
I changed the end_to_end test in name_service.move:
#[test(chain = @0x1, source = @usernames, user1 = @0x2, user2 = @0x3, lp_publisher = @0x3)]
fun end_to_end(
chain: signer,
source: signer,
user1: signer,
user2: signer,
lp_publisher: signer,
) acquires CoinCapsInit, ModuleStore {
deploy_dex(&chain, &lp_publisher);
let chain_addr = signer::address_of(&chain);
let addr1 = signer::address_of(&user1);
let addr2 = signer::address_of(&user2);
init_mint_to(chain_addr, &user1, 100);
init_mint_to(chain_addr, &user2, 100);
initialize(
&source,
100,
50,
10,
1209600,
1209600,
string::utf8(b"https://test.com/"),
string::utf8(b"https://test.com/"),
);
std::block::set_block_info(100, 100);
register_domain(&user1, string::utf8(b"abc"), 31557600);
assert!(primary_fungible_store::balance(addr1, get_init_metadata()) == 90, 0);
set_name(&user1, string::utf8(b"abc"));
assert!(get_name_from_address(addr1) == option::some(string::utf8(b"abc")), 0);
assert!(get_address_from_name(string::utf8(b"abc")) == option::some(addr1), 0);
std::block::set_block_info(200, 100 + 31557600 + 1209600 + 1);
register_domain(&user2, string::utf8(b"abc"), 31557600);// user2 registering the same domain after expiry
assert!(get_name_from_address(addr1) == option::some(string::utf8(b"abc")), 0); // addr1 -> abc
assert!(get_address_from_name(string::utf8(b"abc")) == option::some(addr1), 0); // abc -> addr1
}
Recommended mitigation steps
Remove the previous values after registering the domain in the register_domain function, instead of handling it in set_name.
andrew (Initia) confirmed and commented:
The username follows a consistent rule where it is recognized as my domain only if
set_nameis called.For example, suppose User1 registers the domain
abc.initand also setsset_name. Later, User2 makes a purchase offer, and User1 sells the username NFT. Even in this case, until User2 callsset_name, they merely “own”abc.init; the domain does not actually point to User2.The same principle applies to the given scenario. Registering an expired username only means “ownership” and does not mean the domain points to the owner. Let’s consider another case: suppose a user registers
abc.initand callsset_name, but also registersdef.initwithout callingset_name. If they ask another user to send them money, it would be very odd to tell them to send it todef.init. Naturally, they would direct them toabc.init. Therefore, the rule remains consistent—set_namemust be set for the domain to point to the user, and an expired domain may not necessarily point to the user.Nonetheless, to prevent any unintended issues arising from users misunderstanding the username logic, I believe it is reasonable to clear the existing records when registering an expired domain. Based on this reasoning, I have made the necessary changes and submitted this commit.
LSDan (judge) decreased severity to Medium and commented:
This doesn’t fit as a high to me. There are several things that need to happen in the right order for this issue to add up to lost funds. That said, I also don’t think it can be dismissed (reference here). As a user mistake, since there is no reason any modern tooling would inform the user that this situation exists. I’m open to reasoned arguments this should be lowered further during post-judging QA.
As the judge mentioned, this issue requires specific steps to lead to a loss of funds. However, the issue still breaks a protocol expected functionality and introduces unintended behaviour which could make it as High.
Explanation:
When a domain expires,
get_address_from_namecorrectly returnsNone. However, when another user re-registers the domain, it unexpectedly returns the previous owner’s address, even though the domain now belongs to the new user. This means the previous owner can still use the expired domain until the new owner explicitly callsset_nameThis is a unintended behaviour of the protocol. Re-registering a domain should immediately transfer all rights to the new owner, but the system retains stale mappings, which breaks the functionality of
get_address_from_namefunction. This creates a time gap where the previous owner can still use the expired domain.Here, “can still use the expired domain” means the previous owner retains access to the domain(for sometime) as if it were active, even after expiration.
Example scenario to describe the impact:
- Alice buys
abc.initdomain and callsset_name(Alice gave this address to John for transactions).- John entered
abc.initand sends a transaction to Alice.- Alice domain got expired; now when John tries to do (2), When John entered
abc.initit will returnNonebecause it expired.- Now another user, Bob, already has
def.initas primary also want to buyabc.initand callsregister_domainwithabc.init. There is no successive call toset_nameafter callingregister_domain. Afterward, Bob continues to usedef.initas his primary domain. Meanwhile, Bob’sregister_domaincall extends the expiration ofabc.init.Note : Since Bob did not call
set_nameforabc.init, he would not share it with anyone for transactions. As of now, only John hasabc.init, which was shared by Alice in step (1) .
- Now, when John tries to send transaction to (Alice)
abc.init, the system returns Alice’s address instead of None in (3).The issue was downgraded because loss of funds requires multiple steps to occur. However, this example scenario shows another significant impact that unintended behaviour of the protocol, which allows the previous owner to still use the expired domain for some time. This breaks the expected functionality of the protocol.
Severity stays at Medium.
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 register_domain function does not clear the name_to_addr and addr_to_name mappings when re-registering an expired domain, leaving stale address associations.
Impact
Funds sent to the domain name could be transferred to the previous owner instead of the new owner, because the domain resolves to the old address until set_name is called.
What the attacker needed
A domain expires; a new user registers the expired domain; the new user does not call set_name; someone sends funds to the domain name
The fix
The register_domain function should clear the previous name_to_addr and addr_to_name mappings when registering an expired domain; the project confirmed and made changes.
How it was found
- User1 registers domain 'abc' and calls set_name, linking the domain to User1's address.
- The domain expires, but the old mappings remain.
- User2 registers the expired domain 'abc' without calling set_name.
- The domain still resolves to User1's address via get_address_from_name.
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 domain name service lets people register names like 'abc.init' and link them to a wallet address. When a name expires and someone else registers it, the old link to the previous owner's address is not removed. So if someone sends money to that name, it may still go to the old owner instead of the new one.
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.