Skip to content

Commit

Permalink
Validate forward resolution for reverse resolution by default
Browse files Browse the repository at this point in the history
- As outlined in the warning in the ENS docs, for the reverse resolution of a name for an address to be accurate, the forward resolution address must also match. Source at the time of this commit is here: https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution.
  • Loading branch information
fselmo committed Apr 8, 2022
1 parent cde7a06 commit 1197256
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 1197256

Please sign in to comment.