Algorithmadvanced
Spatial cloaking
Also called location k-anonymity.
Replaces a user's location by a region that holds at least k users before it goes to a location-based service, by quadtree subdivision.
- Time
- O(n h) worst
- Space
- O(n) extra
- Where
- h = the depth of the finest quadrant; k = the anonymity parameter; n = the number of users known to the anonymizer
- Model
- Word RAM
- Properties
- deterministicnot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Marco Gruteser, Dirk Grunwald, 2003
Spatial cloaking hides who sent a request to a location-based service. A trusted anonymity server sits between the users and the service. It knows the current position of every user. When a user asks a question such as "where is the nearest fuel station", the server replaces the exact position by a region that also holds at least other users, removes the network address, and sends the region to the service. Gruteser and Grunwald (MobiSys 2003) called this k-anonymous location information and gave the adaptive-interval cloaking algorithm. It goes down a quadtree from the whole area towards the user's quadrant and stops just before the quadrant would hold fewer than users. Dense areas get small regions and sparse areas get large ones. For users and a finest level the descent takes time in the word-RAM model, or with a tree of counts. The value of is a policy choice. The guarantee holds against an attacker who sees only one region; Kalnis et al. (2007) showed that an attacker who knows the positions and the algorithm can sometimes still find the user.
In plain words
A driver asks a map service for nearby hotels. The service does not need the exact spot to answer. A helper server that the driver trusts takes the request and swaps the exact spot for an area.
The helper starts with the whole map. It cuts the current area into four equal squares and keeps the square that holds the driver. It does this again and again. Before each cut it counts the people in the current square. When the square holds fewer than people, the helper stops and sends the previous square, which still held at least .
The service then sees a square with at least people in it. From that square alone, it cannot tell which of them asked. In a city centre the square is small, so the answer stays useful. In the country the square must be large.
The problem
The input is a snapshot of user positions in the square with integer coordinates, the position of the requester, and an integer . The quadrants of a square are its four half-open squares of side . A cell is or a quadrant of a cell; the cells of side 1 are at depth .
The output is the smallest cell that holds and at least users of , counting the requester, or NONE if . Gruteser and Grunwald define a location as k-anonymous when it cannot be told apart from the location of at least other subjects (Section 5.1); a cell with users meets this for one request. They also allow the region to carry a time interval, which gives temporal cloaking below.
The algorithm
CLOAK(p, U, k, h) ▷ U holds the requester at p; all points lie in [0, 2^h)^2- 1
q ← [0, 2^h)^2, q_prev ← q, d ← 0 - 2
V ← U - 3
if |V| < k then return NONE - 4
loop - 5
if |V| < k then return q_prev - 6
if d = h then return q - 7
q_prev ← q - 8
q ← the quadrant of q that holds p - 9
V ← the users of V that lie in q - 10
d ← d + 1
Line L1 starts at the whole area that the server covers, and line L2 takes all known users. Line L5 is step 4 of Table 2 in the paper: when the current cell holds fewer than users, the previous cell, which held at least , is the answer. Lines L7 to L9 are steps 5 to 8: cut the cell into four, remember the old cell, keep the quadrant of and drop the users outside it. Table 2 does not have lines L3 and L6. Line L3 refuses a request that no region can cloak; without it, the first pass of the loop returns the whole area with fewer than users. Line L6 stops at cells of side 1, because users at the same point would make the loop run for ever.
Example
The area is , so , and . Eight synthetic users stand at , , , , , , and . User sends a request.
| pass | action | ||||
|---|---|---|---|---|---|
| 1 | 0 | 8 | : , | ||
| 2 | 1 | 4 | : , | ||
| 3 | 2 | 1 | : return |
The service receives the square , which holds four users. For this snapshot, , and also get , and to get the whole area , because each of their quadrants , and holds fewer than 3 users. Each region is sent by at least 3 users, so here an attacker who knows the positions still has at least 3 candidates. That is not always so; see Pitfalls.
Correctness
The cells that hold form a chain , with of side , and the number of users in does not grow with . Before each test of line L5, , is the set of users in , and, if , holds at least users. Line L8 keeps the quadrant that holds , so stays in the chain, and line L9 keeps exactly the users of the new cell. So line L5 returns for the first with fewer than users, and line L6 returns if all the cells have at least . In both cases the result is the deepest cell of the chain with at least users, which is the smallest cell that holds and users. Line L3 makes sure that line L5 never returns at . The full proof is in proofs/correctness.md.
The privacy claim is weaker than it looks. For one request seen alone, the region holds at least users who could have sent it. The claim says nothing about an attacker who knows the positions of all users and the algorithm, about a series of requests from the same user, or about the anonymity server itself, which sees everything.
Proof: CLOAK returns the smallest quadtree cell that holds the requester and at least k usersfull
Let , let be a finite multiset of integer points in , let and let . For let be the cell of side that holds , that is with , and . Let be the number of users of in .
Claim 1 (the chain). , each is the quadrant of that holds , and .
Proof. The four quadrants of are the cells of side inside it, and they partition it, so exactly one holds , and it is . Since , . Every holds , which is in , so .
The cells that hold are exactly , and they are nested. So the smallest cell that holds and at least users is for the largest with , if .
Claim 2 (invariant). Each time line L5 runs, , is the multiset of users of in , and if then and .
Proof. At the first test, lines L1 and L2 give , and . Suppose the claim holds at a test that neither line L5 nor line L6 ends. Then and . Line L7 sets , line L8 sets to the quadrant of that holds , which is by Claim 1, line L9 keeps the users of in , which are all the users of in since , and line L10 adds 1 to . So the claim holds at the next test, with for the old .
Claim 3 (the result). CLOAK returns NONE if , and otherwise .
Proof. If , line L3 returns NONE. Otherwise , so line L5 does not return at . The loop stops by at the latest, since grows by one per pass. By Claim 2 and Claim 1, the tests at line L5 see in turn. If line L5 returns at some , then , and by Claim 1 every later is also below , so and the result is correct. If instead line L6 returns at , then , so and the result is .
Reciprocity is not implied. The result depends on through line L8. The four users , , and with and give for the first three and for the last, so the region is returned for only one user. The test file checks this case and compares the reciprocity check with an oracle.
Cost. By Claim 3 the loop makes at most passes, and each pass scans , which has at most users, once. The time is , and needs extra space.
Complexity
- Each pass of lines L5 to L10 scans once, and there are at most passes, so a request takes time in the worst case, when the users are packed near . If the number of users halves at each level, the total is .
- With a region quadtree of the positions that stores the number of users in each node, lines L8 and L9 become one step down the tree and one read of a count, so a request takes time. Keeping the counts up to date costs per position update.
- The extra space is for , or for the tree in the worst case.
Properties
- Adaptive. The region size follows the density of users, so the same gives small regions in dense areas and large ones in sparse areas.
- Coarse steps. The region area changes by a factor of 4 at each level, so the region often holds many more than users. In the paper's simulation with , the mean number of users in a region was about 10 (a measurement, Section 7).
- Deterministic. The region depends only on , the snapshot and .
- Not reciprocal. Different users in the same region may get different regions; this is the weak point of the method.
Variants and improvements
- Temporal cloaking. Gruteser and Grunwald also give a version that fixes a spatial resolution, waits until different users have visited the chosen area, and returns the area with a time interval that ends at the current time and starts a random amount before the request (Section 5.2). It trades delay for spatial accuracy.
- Reciprocal cloaking. Kalnis et al. require that every user inside a region would get the same region. Then an attacker who knows the positions and the algorithm still has at least candidates. Their Hilbert Cloak orders the users along a Hilbert curve, cuts the order into groups of users, and returns the bounding rectangle of the requester's group, so every member of a group gets the same region.
- Personal and minimum area. Later systems let each user choose and a minimum region size, since a region with users inside one building can still reveal the building.
- Without a trusted server. Geo-indistinguishability adds planar Laplace noise on the user's device and gives a local differential privacy style guarantee that does not depend on where the other users are. Private information retrieval hides the query from the service by cryptography.
When to use it
Use spatial cloaking when a trusted party already knows all positions, such as a network operator, and the service only needs a coarse location, for example points of interest or local traffic. The paper's simulation gives an idea of the cost: with , the median region side was 30 and 65 metres in two areas with many expressways and 125 and 250 metres in two areas with mostly collector streets (a measurement, Section 7). Do not use it when the attacker can learn the positions of the other users, or when one user sends many requests along a route. Use a reciprocal variant in the first case and a local, noise-based method in the second.
Pitfalls
- Returning instead of at line L5. The current cell has just been found to hold fewer than users. Returning it reveals a region with as few as one user, the requester.
- No depth limit at line L6. If users stand at the same point, every quadrant that holds holds all of them, and the loop never stops. Real coordinates have a finite resolution; stop there.
- No check at line L3. Table 2 of the paper returns the previous quadrant when the count is too small, and on the first pass the previous quadrant is the whole area. If fewer than users are known in total, the result is a region with fewer than users. Refuse the request instead.
- Choosing the quadrant by at line L8 lets the region identify . Take with , , three users at , and , and one user at . The three users each get . The user is alone in , so gets the whole area. The whole area holds four users, but only would ever send it. An attacker who knows the positions and the algorithm learns that sent the request. Kalnis et al. call the missing property reciprocity, and the code has a check for it.
- Tracking across requests. Each request is cloaked against a fresh snapshot at line L2. A user who sends requests while driving gives a series of regions; the intersection with a road map and with the next region can shrink the candidate set below . The paper names location tracking as a threat (Section 4.1) but the algorithm does not stop it.
- A region that is all one place. A region with users inside one hospital tells the service that the requester is in the hospital. k-anonymity of identity is not privacy of location.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/spatial-cloaking/. The authors are listed in prov/JKVDFZ.jsonl.
from collections.abc import Sequence
Point = tuple[int, int]
Cell = tuple[int, int, int] # (x, y, side): the half-open square [x, x + side) x [y, y + side)
def cloak(p: Point, users: Sequence[Point], k: int, h: int) -> Cell | None:
"""Return the smallest quadtree cell that holds p and at least k users, or None.
users lists every known position, the requester included, with integer
coordinates in [0, 2^h). Precondition: k >= 1, h >= 0 and p is in users.
Cost: O(n h) time and O(n) extra space for n users.
"""
q: Cell = (0, 0, 1 << h) # @line L1
q_prev = q
d = 0
v = list(users) # @line L2
if len(v) < k: # @line L3
return None
while True: # @line L4
if len(v) < k: # @line L5
return q_prev
if d == h: # @line L6
return q
q_prev = q # @line L7
x, y, side = q
half = side // 2
q = (x + half if p[0] >= x + half else x, y + half if p[1] >= y + half else y, half) # @line L8
v = [u for u in v if q[0] <= u[0] < q[0] + half and q[1] <= u[1] < q[1] + half] # @line L9
d += 1 # @line L10
def reciprocity_holds(users: Sequence[Point], k: int, h: int) -> bool:
"""Return True if every region that CLOAK returns for some user is returned for at least k users.
Precondition: as for cloak, and at least k users. Cost: O(n^2 h).
"""
senders: dict[Cell | None, int] = {}
for u in users:
r = cloak(u, users, k, h)
senders[r] = senders.get(r, 0) + 1
return all(c >= k for c in senders.values())
test_spatial_cloaking.py 74 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/spatial-cloaking/. The authors are listed in prov/JKVDFZ.jsonl.
import random
from spatial_cloaking import cloak, reciprocity_holds
USERS = [(1, 1), (3, 2), (2, 3), (0, 3), (5, 1), (6, 6), (7, 5), (2, 6)]
def test_example() -> None:
assert cloak((1, 1), USERS, 3, 3) == (0, 0, 4)
for u in USERS[:4]:
assert cloak(u, USERS, 3, 3) == (0, 0, 4)
for u in USERS[4:]:
assert cloak(u, USERS, 3, 3) == (0, 0, 8)
assert reciprocity_holds(USERS, 3, 3)
def test_not_reciprocal() -> None:
users = [(0, 0), (1, 0), (0, 1), (3, 3)]
assert cloak((0, 0), users, 3, 2) == (0, 0, 2)
assert cloak((3, 3), users, 3, 2) == (0, 0, 4)
assert not reciprocity_holds(users, 3, 2)
def test_edges() -> None:
assert cloak((0, 0), [(0, 0)], 2, 3) is None
assert cloak((0, 0), [(0, 0)], 1, 3) == (0, 0, 1)
assert cloak((5, 5), [(5, 5)] * 4, 3, 3) == (5, 5, 1)
assert cloak((0, 0), [(0, 0), (0, 0)], 2, 0) == (0, 0, 1)
# with k = 1 the requester alone is enough, so the cell of side 1 comes back
assert cloak((6, 2), USERS + [(6, 2)], 1, 3) == (6, 2, 1)
def oracle(p: tuple[int, int], users: list[tuple[int, int]], k: int, h: int) -> tuple[int, int, int] | None:
best = None
for d in range(h + 1):
side = 1 << (h - d)
x, y = p[0] // side * side, p[1] // side * side
inside = sum(1 for u in users if u[0] // side * side == x and u[1] // side * side == y)
if inside >= k:
best = (x, y, side)
return best
def test_against_oracle() -> None:
rng = random.Random(11)
for _ in range(600):
h = rng.randint(0, 5)
size = 1 << h
n = rng.randint(1, 30)
users = [(rng.randrange(size), rng.randrange(size)) for _ in range(n)]
k = rng.randint(1, 8)
p = rng.choice(users)
got = cloak(p, users, k, h)
assert got == oracle(p, users, k, h)
if got is not None:
x, y, side = got
assert x <= p[0] < x + side and y <= p[1] < y + side
assert sum(1 for u in users if x <= u[0] < x + side and y <= u[1] < y + side) >= k
def test_reciprocity_against_oracle() -> None:
rng = random.Random(12)
for _ in range(500):
h = rng.randint(1, 4)
size = 1 << h
k = rng.randint(1, 4)
n = rng.randint(k, 12)
users = [(rng.randrange(size), rng.randrange(size)) for _ in range(n)]
regions = [oracle(u, users, k, h) for u in users]
want = all(regions.count(r) >= k for r in regions)
assert reciprocity_holds(users, k, h) == want
History
Gruteser and Grunwald presented the anonymity server, k-anonymous location information and the adaptive-interval and temporal cloaking algorithms at MobiSys 2003, borrowing the idea of k-anonymity from published tables. Their evaluation used simulated traffic on road maps of Denver. In 2007 Kalnis, Ghinita, Mouratidis and Papadias showed that the quadtree cloak can reveal the requester when the attacker knows the positions, and defined reciprocity. Later work moved towards methods that need no trusted server, such as geo-indistinguishability.
References
- Marco Gruteser and Dirk Grunwald, Anonymous usage of location-based services through spatial and temporal cloaking, MobiSys 2003, pages 31-42, Section 4.1 (restricted space identification, observation identification and location tracking), Section 5 (the trusted anonymity server), Section 5.1 (k-anonymous location information), Section 5.2 (Table 2, the adaptive-interval cloaking algorithm, and temporal cloaking), Sections 6 and 7 (k_min = 5 and the measured resolutions)
- Panos Kalnis, Gabriel Ghinita, Kyriakos Mouratidis and Dimitris Papadias, Preventing location-based identity inference in anonymous spatial queries, IEEE Transactions on Knowledge and Data Engineering 19(12), 2007, pages 1719-1733, the reciprocity property as a sufficient condition for spatial k-anonymity, the attack on cloaking regions that do not have it, and the Nearest Neighbor Cloak and Hilbert Cloak algorithms
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag JKVDFZ Edit this page History Report an error Markdown