From 1641be7395631e2f8395172d7a641b84cda824ed Mon Sep 17 00:00:00 2001 From: Simon Bihel Date: Tue, 8 Mar 2022 14:45:45 +0000 Subject: [PATCH] Enforce commutativity of reverse resolution (#996) As specified in https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution --- CHANGELOG.md | 2 ++ ethers-providers/src/provider.rs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa750c8..c44561a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ - Add a getter to `ProjectCompileOutput` that returns a mapping of compiler versions to a vector of name + contract struct tuples [#908](https://github.com/gakonst/ethers-rs/pull/908) +- Enforce commutativity of ENS reverse resolution + [#996](https://github.com/gakonst/ethers-rs/pull/996) ## ethers-contract-abigen diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index c5192ced..dee01796 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -112,6 +112,10 @@ pub enum ProviderError { #[error("ens name not found: {0}")] EnsError(String), + /// Invalid reverse ENS name + #[error("reverse ens name not pointing to itself: {0}")] + EnsNotOwned(String), + #[error(transparent)] SerdeJson(#[from] serde_json::Error), @@ -794,7 +798,14 @@ impl Middleware for Provider

{ /// a string. This should theoretically never happen. async fn lookup_address(&self, address: Address) -> Result { let ens_name = ens::reverse_address(address); - self.query_resolver(ParamType::String, &ens_name, ens::NAME_SELECTOR).await + let domain: String = + self.query_resolver(ParamType::String, &ens_name, ens::NAME_SELECTOR).await?; + let reverse_address = self.resolve_name(&domain).await?; + if address != reverse_address { + Err(ProviderError::EnsNotOwned(domain)) + } else { + Ok(domain) + } } /// Returns the avatar HTTP link of the avatar that the `ens_name` resolves to (or None