Skip to content

Commit

Permalink
fix: crash on reverse resolving post subdomain transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Jul 13, 2024
1 parent d9020ab commit af6ed6d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ mod Naming {
fn domain_to_address(
self: @ContractState, domain: Span<felt252>, hint: Span<felt252>
) -> ContractAddress {
if domain.len() == 0 {
return ContractAddressZeroable::zero();
}
let (resolver, parent_length) = self.domain_to_resolver(domain);
// if there is a resolver starting from the top
if (resolver != ContractAddressZeroable::zero()) {
Expand Down Expand Up @@ -305,9 +308,11 @@ mod Naming {
// self.domain_to_address(domain, array![].span()) == address,
// 'domain not pointing back'
// );
println!("echo: {:?}", domain);
if self.domain_to_address(domain, array![].span()) != address {
return array![].span();
}
println!("hey");
domain
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,54 @@ fn test_buy_empty_domain() {
0
);
}


#[test]
#[available_gas(2000000000)]
fn test_subdomain_reverse() {
// setup
let (eth, pricing, identity, naming) = deploy();
let alpha = contract_address_const::<0x123>();
let bravo = contract_address_const::<0x456>();
let charlie = contract_address_const::<0x789>();

// we mint the ids
set_contract_address(alpha);
identity.mint(1);
set_contract_address(bravo);
identity.mint(2);
set_contract_address(charlie);
identity.mint(3);

set_contract_address(alpha);
let aller: felt252 = 35683102;

// we check how much a domain costs
let (_, price) = pricing.compute_buy_price(5, 365);

// we allow the naming to take our money
eth.approve(naming.contract_address, price);

// we buy with no resolver, no sponsor, no discount and empty metadata
naming
.buy(1, aller, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0, 0);

let subdomain = array![aller, aller].span();

// we transfer aller.aller.stark to id2
naming.transfer_domain(subdomain, 2);

// and make sure the owner has been updated
assert(naming.domain_to_id(subdomain) == 2, 'owner not updated correctly');
set_contract_address(bravo);
let result = naming.address_to_domain(bravo, array![].span());
assert(result == array![].span(), 'unexpected result');
// we then set this subdomain as main domain and ensures reverse resolving works
identity.set_main_id(2);
let result = naming.address_to_domain(bravo, array![].span());
assert(result == subdomain, 'unexpected result');
// before transfering this subdomain
naming.transfer_domain(subdomain, 3);
let result = naming.address_to_domain(bravo, array![].span());
assert(result == array![].span(), 'unexpected result');
}

0 comments on commit af6ed6d

Please sign in to comment.