Enforce commutativity of reverse resolution (#996)

As specified in https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution
This commit is contained in:
Simon Bihel 2022-03-08 14:45:45 +00:00 committed by GitHub
parent 4f1a2352f7
commit 1641be7395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -47,6 +47,8 @@
- Add a getter to `ProjectCompileOutput` that returns a mapping of compiler - Add a getter to `ProjectCompileOutput` that returns a mapping of compiler
versions to a vector of name + contract struct tuples versions to a vector of name + contract struct tuples
[#908](https://github.com/gakonst/ethers-rs/pull/908) [#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 ## ethers-contract-abigen

View File

@ -112,6 +112,10 @@ pub enum ProviderError {
#[error("ens name not found: {0}")] #[error("ens name not found: {0}")]
EnsError(String), EnsError(String),
/// Invalid reverse ENS name
#[error("reverse ens name not pointing to itself: {0}")]
EnsNotOwned(String),
#[error(transparent)] #[error(transparent)]
SerdeJson(#[from] serde_json::Error), SerdeJson(#[from] serde_json::Error),
@ -794,7 +798,14 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
/// a string. This should theoretically never happen. /// a string. This should theoretically never happen.
async fn lookup_address(&self, address: Address) -> Result<String, ProviderError> { async fn lookup_address(&self, address: Address) -> Result<String, ProviderError> {
let ens_name = ens::reverse_address(address); 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 /// Returns the avatar HTTP link of the avatar that the `ens_name` resolves to (or None