ERC-2390 Geohash-based location ENS (Geo-ENS)
Stagnant · Names & metadata · created 2019-11-15
A standard that stores location-specific addresses in an ENS resolver using geohashes, enabling lookups of resources corresponding to a specific point or region, similar to GeoDNS.
Why it is needed
The existing ENS registers and looks up one resource per human readable name (node), so it has no way to find resources based on location. Traditional GeoDNS estimates location by looking up the querier's IP address in a GeoIP database, but if the database is outdated the estimated location can differ significantly from the actual one, and it can only look up the querier's own location, not other regions. Commercial GeoDNS services such as Amazon Route 53 usually can only distinguish regions at the country or US state level, making fine grained control difficult, and they have no feature to return a list of all resources within a given radius. Because of these limitations, there has been no way to implement CDN style proximity routing on top of ENS, smart contract discovery tied to physical locations, or location based tokenization.
What to implement
function setGeoAddr(bytes32 node, string calldata geohash, address addr) external authorised(node): Sets a resource (address) for a node and an exactly 8 character geohash. Using address(0) removes the resource at that location.function geoAddr(bytes32 node, string calldata geohash) external view returns (address[] memory ret): Returns all resource addresses matching a node and a geohash (or a shorter prefix of it).event GeoENSRecordChanged(bytes32 indexed node, bytes8 geohash, address addr);: An event emitted when a record registered at a geohash for a specific node changes.
In depth
What is a geohash
A geohash is a location representation that interleaves latitude and longitude bits into a single string, usually written in base32 characters. The longer the string, the higher the precision, and the 8 character geohash used in this standard corresponds to an accuracy of about plus or minus 20 meters.
setGeoAddr / geoAddr interface
setGeoAddr(node, geohash, addr) registers a resource (contract address, IP, ABI, TEXT record, etc.) for a node and geohash. The geohash must be unique per address and exactly 8 characters, and leaving addr at its default of address(0) removes that record. geoAddr(node, geohash) returns all resources matching the node and geohash; passing the full 8 character geohash returns the resource at that exact point, while passing a prefix shorter than 8 characters returns all resources within the geographic bounding box that geohash represents.
Quadtree storage structure
The implementation uses a sparse quadtree to index geohashes. The tree depth is 8, the maximum geohash precision, and the fanout is 32, the base of a single geohash character. Leaf nodes hold the actual resource records, and non leaf nodes each represent one geohash character. Since 71% of the Earth's surface is covered by water, the tree stays sparse, and this structure is well suited to retrieving the list of records within a given bounding box using standard tree traversals such as DFS/BFS.
Base32 decoding and tree traversal in the implementation
The example implementation (Solidity) takes the geohash as bytes8 and converts each character to a 5 bit integer via the chartobase32 function. Base32 uses digits 0-9 and letters of the alphabet excluding a, i, l, and o, so those excluded characters are rejected with a require. geomap stores, per node, an array of Node structs (each Node holding a data address, a parent index, and 32 children indices). geoAddr descends the tree by the given precision, then traverses the subtree using a queue of size TREE_VISITATION_QUEUESZ (64), collecting up to MAX_ADDR_RETURNS (64) leaf addresses. setGeoAddr lazily creates the root node, creates any missing nodes along the path on demand, writes addr at the leaf, and then emits GeoENSRecordChanged.
Can be extended to other resolver interfaces
The specification is described in terms of the address resolver from EIP-137, but the same geohash based interface can equally be applied to other ENS resolver record types, such as the DNS resolver defined by EIP-1185, the IPFS content hash storage defined by EIP-1062, the ABI resolver, and the TEXT resolver.
Standard status
This proposal was written in November 2019 and its status is marked Stagnant, meaning it has stalled and seen no further progress.
Things to watch out for
- Exposure of queried location information: The geohash passed when calling geoAddr (the queried region, if shorter than 8 characters) is exposed to that node if the user is using a light client or is connected to a full node operated by a third party such as Infura.
- Possibility that the queried region overlaps the actual location: Given the nature of location services, the queried region is likely to include the user's actual location, so this can lead not only to exposure of the lookup range but also to inference of the actual location.
- No exposure when running your own full node: If a user runs their own full node or has access to a trusted full node, location information is not exposed externally.
- General ENS resolver security considerations apply: Since this contract is functionally similar to a general ENS resolver, the security considerations that apply to ENS resolvers apply here as well.