Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate forward resolution for reverse resolution by default #2420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ def name(self, address: ChecksumAddress) -> Optional[str]:
:type address: hex-string
"""
reversed_domain = address_to_reverse_domain(address)
return self.resolve(reversed_domain, get='name')
name = self.resolve(reversed_domain, get='name')

# To be absolutely certain of the name, via reverse resolution, the address must match in
# the forward resolution
return name if to_checksum_address(address) == self.address(name) else None

def setup_address(
self,
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2420.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For ``ENS.name()``, validate that the forward resolution returns the same address as provided by the user as per the ENS documentation recommendation for Reverse Resolution.
11 changes: 11 additions & 0 deletions tests/ens/test_setup_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def test_setup_name(ens, name, normalized_name, namehash_hex):
# check that the correct owner is set:
assert ens.owner(name) == owner

# setup name to point to new address
new_address = ens.w3.eth.accounts[4]
ens.setup_address(name, None)
ens.setup_name(name, new_address)

# validate that ens.name() only returns a name if the forward resolution also returns the
# address
assert ens.name(new_address) == normalized_name # reverse resolution
assert ens.address(name) == new_address # forward resolution
assert not ens.name(address)

ens.setup_name(None, address)
ens.setup_address(name, None)
assert not ens.name(address)
Expand Down