
























Imagine a global map simulation, a distributed land registry, or a radio frequency allocator. They all share one unbreakable rule: two people cannot own the exact same space. Polygons must not overlap.
Traditional GIS solved this decades ago. But doing it on-chain—inside a strictly consensus-driven network without external servers—has long been considered impossible. Compute limits were simply too strict.
I wrote Mercator, an open-source spatial indexing library for Sui. It lets you register polygons of any shape directly in a smart contract, mathematically guaranteeing zero overlap.
Registering a 4-vertex polygon in Mercator costs about $0.0065. Registering twenty polygons costs exactly the same. The system scales logarithmically, not linearly. To achieve this, I didn't invent anything new. I just borrowed algorithms from 1990s game engines: the Separating Axis Theorem (SAT) for collision detection, and the Morton Z-curve for indexing.
Why are these classic tools only becoming smart contract primitives now? The answer lies in data model architecture. This code simply will not run on EVM, Solana, or Aptos. Here is why.
The obvious question: why not just use Postgres and PostGIS?
If you trust a central authority to arbitrate boundaries, you absolutely should. A centralized database will always be faster. But if you are building a system that requires trustless ownership—like a decentralized frequency allocator, an autonomous world, or a censorship-resistant registry—the spatial guarantee must share the same security model as the ledger.
If your ownership record is on-chain, but your collision detection runs on a central server, the server administrator is the actual owner of the network. They can arbitrarily approve overlapping claims, destroying the asset's value.
Bringing the index on-chain also unlocks atomic composability. A third-party smart contract can dictate: "Execute this complex financial trade only if this exact 50-vertex polygon is successfully registered without overlapping existing claims." If the spatial check fails, the entire transaction rolls back. You cannot do that if the spatial state lives outside the virtual machine.
When math gets too heavy, smart contracts usually offload it to external servers (oracles). This works for many tasks, but for spatial rights, it destroys atomicity.
Here is the state vulnerability:
This is an inevitable flaw of asynchronous architecture. "Fast" oracles don't exist: a time gap of even a fraction of a second leaves a window for a race condition.
The only fix is to check for collisions and save the result in the exact same transaction, entirely on-chain. The geometry must be calculated inside the network's virtual machine.
I ported three classic physics engine algorithms to the Move language. Together, they form a fast pipeline: filter out the noise for pennies, leaving heavy math only for actual collisions.
Crucial detail: All arithmetic in Mercator is integer-based. The Move VM does not support floating-point numbers. While painful for game physics, this is a salvation for distributed consensus. We get strictly deterministic results across all nodes. The on-chain math and the client-side math match bit-for-bit.
The innovation isn't the algorithms themselves; it's the pipeline. A new registration passes through four filters:
occupied_depths) tracks which tree levels actually contain registered plots. The search skips empty space entirely.For 99% of registrations, step 4 never executes. The AABB and quadtree filter out irrelevant plots instantly, saving compute resources.
If oracles are out, why not just write a quadtree in Solidity or Rust? Because every major platform kills this idea in its own way:
The root problem: none of these platforms support dynamic runtime access to independent objects without state conflicts.
Sui solves this at the object model level. There are no "accounts with tables." Every quadtree node is a separate, independent object.
When a transaction calculates a Morton key, it accesses the required object on the fly—just like a program working with pointers in RAM. Parallelism follows automatically: plots in different quadrants touch different objects. Nodes process them in parallel with zero locks.
The collision check and database write happen in one transaction. Finality takes less than a second. Attackers have no time gap to exploit.
Tests ran on the Sui Testnet. The minimum compute cost for any transaction on the platform is floored at 1,000,000 MIST.
| Vertices | Cost (MIST) | In USD (at $0.93/SUI) |
|---|---|---|
| 4 | 7,045,496 | ~$0.0065 |
| 8 | 7,531,896 | ~$0.0070 |
| 16 | 8,504,696 | ~$0.0079 |
| 32 | 11,120,296 | ~$0.0103 |
| 64 | 20,481,496 | ~$0.0190 |
Up to 16 vertices, the algorithm runs so fast it simply hits the platform's minimum compute threshold. Costs only rise for complex shapes (32–64 vertices) because SAT scales quadratically. The bulk of the total cost (about 6–7 million MIST) is actually storage, not math.
Fun fact: Register 20 square plots in different locations sequentially, and each transaction costs exactly 7,045,496 MIST. The tree does not degrade as it fills. A million objects on the other side of the continent won't slow down your transaction.
As a bonus, deleting a polygon triggers a storage rebate, refunding part of the gas. The net cost of a "register and delete" cycle is about $0.0019.
This is not a silver bullet. The architecture dictates strict limits:
ECellOccupancyExceeded.Mercator is open-source. Use it as an out-of-the-box spatial registry, or extract the standalone geometry modules (polygon, sat, aabb) to use independently of the quadtree.
Questions, bug reports, and PRs are welcome in the repository.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。