Manuscript Offprint
arXiv:2611.03415O2N2: Efficient Doubly Oblivious Approximate Nearest Neighbor Search
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Zhechen Li
Peking University
Zimai Guo
Peking University
Mingxun Zhou
The Hong Kong University of Science and Technology
Chang Shi
The Hong Kong University of Science and Technology
Cheng Hong
Ant Group
Abstract—Privacy-preserving approximate nearest neighbor (ANN) search allows clients to search from an untrusted server without revealing sensitive queries, and is useful in scenarios like medical diagnostics and credit scoring. Among the various privacy-preserving primitives, trusted execution environments (TEEs) have much lower overhead than heavy cryptographic ones, yet they leak memory access patterns, enabling adversaries to infer query contents.
Oblivious RAM (ORAM) can be used to hide those access patterns at asymptotic cost, but existing high-performance ANN search algorithms (e.g., IVF or HNSW) exhibit complex, data-dependent access patterns that are unfriendly for ORAM. Furthermore, standard ORAM constructions typically assume there exists a small amount of trusted storage, which weakens the security guarantees and is not always feasible. Solutions that eliminate such trusted storage (known as double obliviousness) typically degrade performance further to .
We introduce O2N2, a doubly oblivious ANN framework built around single-path search in randomly rotated k-d tree forests. A pointer-based Circuit ORAM stores the search structure, with separate storage for compact internal nodes and vector-bearing leaves. Each visited leaf is processed by an oblivious selection network, and fixed-schedule duplicate removal and selection combine the local results into the final top-k.
We evaluate O2N2 on real-world datasets and further test its scalability on 100 million vectors. For 10-NN and 100-NN search at the specified high-recall targets, it achieves a 9.8–125.9× speedup over the fastest doubly oblivious baselines.
1. Introduction
Approximate nearest neighbor (ANN) search is a core primitive for modern data-intensive applications, including embedding search and retrieval-augmented generation [24, 28]. Given a query vector, ANN search retrieves its (approximately) top-k closest vectors from a vector database, typically using specialized indexes such as IVF [20], HNSW [21], and DiskANN [19] to avoid exhaustive scans. With the growth of database size, ANN search relies more and more on external memory, which is often untrusted. This creates a need for private ANN search schemes that protect both sensitive queries and database contents. Trusted Execution Environments (TEEs) [22, 27, 53] provide an attractive foundation for this goal by offering low-overhead protected execution on untrusted platforms [13, 34], where the enclave plays the role of trusted client in conventional outsourced storage systems.
However, TEEs alone do not solve the private ANN search problem. Although TEEs protect the confidentiality of code and data, they do not hide memory access traces. Prior attacks show that such traces can leak sensitive information [7, 15, 18, 49]. A standard defense against these attacks is to achieve obliviousness [14], which requires the access patterns to be data-independent. Traditional schemes treat the client-side storage as trusted and do not hide accesses to it. In TEEs, however, the enclave plays this client's role, and its internal accesses may be exposed through page-fault or cache-timing attacks [42, 44, 48]. We therefore require double obliviousness [29, 42, 50], which requires both external and enclave memory access patterns to be independent of the sensitive input.
To achieve this guarantee, a natural black-box approach is running a non-private ANN index under a fixed, padded schedule, with all memory accesses routed through a doubly oblivious memory layer, such as doubly oblivious RAMs [29, 50] or doubly oblivious maps [8, 29, 42]. This black-box route mitigates the access pattern leakage, but most of existing constructions typically pay cost per logical access. Since mainstream ANN indexes perform many fine-grained, adaptive probes, this per-access overhead is repeatedly incurred and leads to impractical latency in our evaluation. This gap raises the following question.
How can we design a doubly-oblivious ANN search scheme that achieves both strong privacy guarantees and practical efficiency?
We answer this question with O2N2, a doubly oblivious ANN search system built around structural alignment
TABLE 1. COMPARISON OF PRIVATE ANN SEARCH SOLUTIONS, WHERE single (external) obliviousness hides storage access patterns, while double obliviousness also hides access patterns inside the TEE.
| Work | Data model | Core primitive | Privacy guarantee | Underlying ANN scheme |
|---|---|---|---|---|
| Panther [25] | Server-owned | PIR | Query privacy + database privacy | Cluster-based |
| Pacmann [51] | Public | PIR | Query privacy | Graph-based |
| Tiptoe [16] | Public | PIR | Query privacy | Cluster-based |
| Compass [52] | Client-owned | ORAM | Query privacySingle (external) obliviousness | Graph-based |
| BiSON [12] | Client-owned | ORAM | Query privacy + database privacySingle (external) obliviousness | Graph-based |
| Onyx [32] | Client-owned | ORAM | Query privacy + database privacySingle (external) obliviousness | Graph-based |
| O2N2 (Ours) | Any | ORAM | Query privacy + database privacyDouble obliviousness | Tree-based |
between the search algorithm and the oblivious primitive. Defeatist search in a randomly rotated k-d tree forest follows one root-to-leaf path per tree [31]. O2N2 combines pointer-based Circuit ORAM access [46, 47], a heterogeneous layout for internal and leaf nodes, and oblivious selection networks over the complete leaf candidates. Independent tree queries expose multiple candidate sets, while the selection stage retains their best distinct neighbors.
Using the combined network by Cong et al. [11], O2N2 answers 10-NN queries on SIFT1M at 90.01% recall in 1.37 ms. We evaluate latency, recall, and distance error across workloads, and use a paired ablation to isolate the effect of the candidate selector.
Theorem 1 (Main result, informal). For a dataset of points in and a query for top- neighbors, O2N2 provides a doubly oblivious ANN search scheme using a forest of trees, achieving a worst-case time complexity of , where is the size of k-d tree leaves.
When , the complexity is roughly . Comparing with the theoretical lower bound of oblivious ANN search [23], the overhead of O2N2 is , as the factor is a tunable parameter for accuracy.
Our contributions are summarized as follows:
-
We formulate the problem of doubly oblivious ANN search and design O2N2, a practical construction that aligns randomized k-d tree defeatist search with tree-based ORAM. This design avoids black-box doubly oblivious compilation of adaptive ANN probes and achieves log-arithmetic structural overhead relative to the underlying root-to-leaf search pattern.
-
We design and implement two doubly oblivious ANN baselines, OIVF and OHNSW, by adapting IVF and HNSW to doubly oblivious storage and replacing data-dependent components with oblivious operations. These constructions may be of independent interest for secure
vector search, with OHNSW achieving latency comparable to Compass-in-TEE [32] while also protecting internal memory accesses.
Our code base is open-sourced .
2. Related work and discussions
Private ANN with cryptographic primitives. Early private ANN systems often relied on fully homomorphic encryption [36, 54], which protects computation but tends to require expensive distance evaluation over large candidate sets. Another line of work improves efficiency under a two-server non-collusion assumption [35, 40], trading performance for an additional trust assumption. In the single-server setting, SANNS [9] and Panther [25] target stronger data-privacy settings using cryptographic primitives such as PIR, while Tiptoe [16] and Pacmann [51] assume a public database and focus on query privacy. Table 1 summarizes these differences.
TEE- and ORAM-based private ANN. ORAM is a natural complement to TEEs because it hides which encrypted records are accessed while allowing the computation itself to run efficiently inside protected execution. The closest system to ours is Compass [52], which adapts HNSW [21] using Ring ORAM [33]. Compass provides single external obliviousness and is therefore effective against an adversary observing outsourced storage, but it does not protect all enclave-internal access behavior. O2N2 instead targets double obliviousness, which is needed when the adversary can observe both external memory and internal memory-access side channels.
Doubly oblivious RAM and black-box compilation. Doubly oblivious RAM removes the trusted-storage assumption by making all memory accesses, including the accesses to ORAM metadata, oblivious [29, 50]. This stronger guarantee is expensive when used as a black-box compiler: every logical access of an ANN index incurs doubly oblivious memory overhead, while modern non-private ANN methods such as IVF [20], HNSW [21], and DiskANN [19] rely on adaptive, data-dependent probing. O2N2 follows a different route: it chooses a tree-based ANN algorithm whose query path can
- https://anonymous.4open.science/r/O2N2-B448 be made to coincide with a tree-based ORAM access pattern, reducing the mismatch between efficiency and obliviousness.
3. Preliminaries
In this section, we formally define the problem of approximate nearest neighbor search and introduce the key cryptographic and algorithmic primitives that form the basis of our scheme.
3.1. Approximate nearest neighbor search
Let be a metric space, where the distance between is denoted by . Let be a dataset of points in . Given , the -nearest neighbor (-NN for short) search problem is defined as follows.
Definition 1 (k-NN search). Given an integer , a dataset , and a query point , the (exact) k-NN search problem is to find a point set containing exactly k points, satisfying that for any and , . The set is called the k-NN of q in , denoted by .
While the k-NN can be defined for any metric space, in the paper, we only focus on the d-dimensional Euclidean space . The distance between any two points is . Accordingly, the k-NN of point in is defined as
In practice, exact k-NN search is often too expensive for large, high-dimensional datasets, so practical systems typically use approximate nearest neighbor (ANN) search. We model an ANN search algorithm as a possibly randomized mapping that maps each tuple to a set of points in . We measure its effectiveness using the following metrics.
- Recall measures the expected fraction of the true k-NN retrieved by the algorithm. Formally, given dataset D and a probability distribution Q of queries, the recall of f is
• Distance-sum ratio (DSR) is the ratio of the distance sums between the approximate k-NN and the true k-NN, i.e.,
- Relative distance error (RDE) measures the per-neighbor relative distance error. Let and , both ordered ascendingly w.r.t. . Then
For any ANN search index and input instance, the ranges of recall, DSR, and RDE are , , and

Figure 1. A visualization of RR k-d tree forest. Different rotations make the same query point q fall into different leaves.
, respectively. Higher recall and lower DSR/RDE values indicate better performance.
3.2. Randomly rotated k-d tree
Our scheme is built upon the randomly rotated (RR) k-d tree [31], a randomized variant of the classic k-d tree [5]. An RR k-d tree first applies a random rotation matrix to the dataset, and applies the same rotation to each query. It then recursively partitions the rotated points along cycling coordinates, using a random split quantile from at each internal node. During query processing, it performs a defeatist search, i.e., the query follows a single root-to-leaf path without backtracking. Figure 1 illustrates how different rotations send the same query to different leaf cells across trees.
The defeatist search is the structural feature we rely on. Because every split leaves at most a 3/4 fraction of the points in either child, the tree has depth . Hence, each query follows a fixed-length root-to-leaf traversal, up to padding. This fixed traversal is naturally compatible with tree-based ORAM [47] and is the reason we can avoid a black-box oblivious compilation of adaptive ANN probes. Although defeatist search is approximate, its accuracy is supported by its connection to randomized partition trees.
Lemma 1 ([31]). Given any query , the Recall@1 of an RR k-d tree is identical to that of a randomized partition tree.
This theoretical equivalence places RR k-d trees within the broader class of ANN indexes based on randomized partitions. Prior work shows that randomized partition trees provide a competitive and often better query time and recall tradeoff than locality sensitive hashing for nearest neighbor search [39]. Thus, RR k-d trees inherit the accuracy support of randomized partition trees while exposing the fixed path from root to leaf needed by our tree based ORAM design. Using a forest of RR k-d trees with independent rotations then gives multiple independent chances to retrieve true neighbors while preserving the same single path structure per tree.
3.3. Obliviousness and ORAM
Let be an algorithm expressed as a random access machine (RAM) program, denote the access pattern produced when runs on input . This pattern records the sequence of memory locations touched by the program and may reveal information about the input even when the stored data are encrypted. Goldreich [14] formalized protection against such leakage through the notion of obliviousness, formally defined as follows.
Definition 2 (Obliviousness [14]). Given a security parameter , a RAM program is oblivious if for any two inputs , the access pattern distributions and are statistically indistinguishable. That is, there exists a negligible function such that
where is the statistical distance.
ORAM. A standard way to achieve obliviousness is to use an oblivious RAM (ORAM). An ORAM stores an array of data blocks and supports logical read and write operations while hiding which logical addresses are accessed. In the classical client-server model, however, the ORAM may keep trusted client side states such as a position map or a stash, and accesses to this state are not required to be oblivious. The stronger notion of double obliviousness [29] removes this trusted storage assumption by requiring all memory accesses, including accesses to auxiliary state, to be oblivious.
Circuit ORAM. Our construction uses Circuit ORAM [46], a tree based ORAM whose server side storage is a binary tree of buckets. Each logical access reads two root to leaf paths and then performs an oblivious eviction. We use the following standard bound.
Lemma 2 ([46]). Let be a Circuit ORAM storing blocks of size with capacity and bucket size . Then supports read and write operations obliviously, each with worst case complexity .
A standard Circuit ORAM is not doubly oblivious because its position map and stash are client side auxiliary structures. A generic recursive construction can make these structures oblivious, but it incurs an additional logarithmic factor and yields cost per logical access. Our construction avoids this black box recursion for the ORAMs used by O2N2.
Oblivious sort. We also use oblivious sorting as a basic primitive. Throughout the paper, OSort denotes a bitonic sorting network [4], which sorts items obliviously in (item-level) time.
4. Threat model and security goals
We consider a server equipped with a TEE that owns a database and provides a private ANN search service to multiple clients. A client's query must remain protected against a server-side adversary capable of observing all memory access patterns. These patterns reveal which memory regions are read or written and the exact sequence of those operations between the TEE-enabled processor and RAM.
To achieve strong security in our setting, O2N2 provides double obliviousness [8]. This property ensures that the memory access patterns remains computationally indistinguishable for any two inputs of the same size. This holds both inside the TEE's protected memory (the enclave) and outside it, including all interactions between the CPU and memory. Consequently, after processing a query, the server learns nothing beyond publicly known hyperparameters, and the client learns nothing beyond the ANN search result itself.
Trusted computing base (TCB). Our Trusted Computing Base consists solely of the TEE-enabled processor. We trust this hardware to correctly enforce confidentiality (preventing unauthorized reading of enclave contents) and integrity (preventing unauthorized modifications). We do not, however, assume that it automatically hides access patterns within enclave memory. We also rely on its remote attestation mechanism, which enables clients to verify that the enclave is genuine and executes the intended code. For instance, we assume the adversary cannot extract the hardware encryption keys used by the TEE. In other words, we do not defend against attacks that exploit hardware design flaws of the TEE implementation, such as Foreshadow [43], SGAxe [45] or TEE.fail [10]. These attacks are orthogonal to the application-level access-pattern leakage addressed in this work. Such hardware vulnerabilities can only be mitigated through microcode patches or processor redesign.
Note that our threat model differs fundamentally from some prior TEE-based works that assume memory accesses inside the enclave are oblivious [30]. While both models utilize TEEs and ORAM, they typically assume an outsourced setting, where the server places the client-encrypted database outside the enclave, and achieve only single (external) obliviousness for accesses between the enclave and external storage. In contrast, our design achieves double obliviousness, delivering stronger protection overall. In fact, our techniques can be readily adapted to support this classic outsourced setting with a higher security guarantee.
5. Technical overview
The cornerstone of our approach is the compatibility between defeatist search in a randomly rotated -d tree and pointer-based oblivious traversal. Each tree query follows one root-to-leaf path without backtracking. A parent node can therefore supply both the identifier and the ORAM position of the next node, avoiding a recursive position-map lookup [47].
Figure 2 illustrates a single tree in O2N2, where small internal nodes and large leaf buckets are placed in two ORAM trees separately. Within our scheme O2N2, a forest of such trees is stored in external memory. A query visits one leaf per tree and computes distances to all points in each visited leaf. An oblivious selection network then selects the points closest to the query from each visited leaf. Oblivious aggregation across trees produces the final answer. Candidate ranking does not alter the navigation path, so both stages have a fixed public schedule.

Figure 2. The structure of a single oblivious k-d tree, which first randomly rotate the original dataset, then build a conceptual k-d tree on it, and finally map the tree to two distinct circuit ORAMs. Each ORAM contains a stash and a binary tree, where a “O” represents a slot occupied by a REAL node and a “●” represents an empty slot (padded with a dummy node).
For a single tree, a query visits O(log N) internal nodes and exactly one leaf. The internal-node accesses cost O(log² N) in total, while fetching the leaf costs O(dn₀ log N). The forest repeats these accesses for all m trees, with additional local selection and cross-tree aggregation costs as stated in Theorem 1.
6. O2N2: Doubly oblivious randomly rotated k-d tree forest
This section provides a detailed technical description of O2N2, building upon the high-level architecture presented in Section 5. Our two fundamental building blocks are a doubly oblivious Circuit ORAM in Section 6.1 and a top-k selection scheme in Section 6.2. We then describe single-tree queries over a doubly oblivious RR k-d tree in Section 6.3. Finally, Section 6.4 gives the full query phase of O2N2. Table 2 summarizes the costs of these building blocks with constant ORAM bucket size and k ≥ 2.
TABLE 2. COSTS OF ORAM AND SELECTION.
| Component | Operation | Time complexity |
|---|---|---|
| Internal ORAM | Read/Write | O(log N) per access |
| Leaf ORAM | Read/Write | O(dn₀ log N) per access |
| Top-k selection | Select top-k | O(n₀ log² k) per leaf |
6.1. Building block: Doubly oblivious circuit ORAM
Circuit ORAM is a natural starting point for O2N2, since a query in a randomly rotated k-d tree already follows a root to leaf path. However, standard Circuit ORAM is not doubly oblivious, as its stash and position map are visited in a data-dependent manner. In our model, these structures reside inside the TEE enclave, so their access patterns must also be hidden.
One generic conversion is to scan the entire stash on every logical access and store the position map recursively in roughly O(log N) smaller ORAMs. This supports arbitrary logical addresses, but it raises the cost of a single logical ORAM access from O(log N) to O(log² N). Since O2N2
accesses tree nodes through this ORAM interface, the extra logarithmic factor would propagate to the costs.
We instead use position embedding [47], i.e., let each parent node in the conceptual k-d tree store the identifiers and ORAM positions of its children. Reaching a child through its parent provides the required position directly. Stash operations scan a fixed-size array, using masked moves to select or update entries. The eviction follows the oblivious Circuit ORAM schedule [46]. With a stash of O(log N) blocks configured for the desired failure probability, the pointer-based interface costs O(BZ log N) per access, where B is the data block size and Z is the ORAM bucket size.
Let be a Circuit ORAM of O(N) capacity. We address each block by a pointer ptr = (idx, pos) containing its identifier and ORAM position. The ORAM provides the following interfaces.
-
.ReadRm(ptr) scans the stash and the ORAM path identified by ptr.pos, returns the block with key ptr.idx, and replaces it by a dummy block .
-
.Add(ptr, x) scans the stash and places block x with pointer ptr in a dummy slot using masked updates.
-
.Evict() runs the public, data-independent Circuit ORAM eviction procedure [46].
We write Write for Add followed by Evict. The query schedule explicitly alternates removal and reinsertion, so a block can be updated between its ReadRm and Write calls without an intermediate dummy reinsertion. In O2N2, the read/write schedule is fixed independently of the query, so distinguishing reads from writes reveals no query-dependent information.
6.2. Building block: Selection network
Our second building block selects the k closest candidates to a query q from an array of n₀ candidates stored in a single k-d tree leaf. Here, each candidate is represented by a constant-size record (, idx) containing its distance to q and its identifier. We order records first by distance and then by identifier, with dummy records placed after all valid records. This order preserves Euclidean distance ranking and resolves ties consistently throughout the query.
We use the combined selection network of Cong et al. [11]. It combines truncated odd-even merging with Yao's recursive selection. The former merges sorted candidate lists while omitting comparisons unnecessary for the top-. The latter compares disjoint pairs and recursively retains the best records from the larger members. It then selects the top- from these records, the smaller members, and any unpaired record. The combined construction chooses between these approaches according to their comparator counts for the public subproblem sizes. It returns the best records without requiring them to be sorted.
We generate the comparator schedule before querying. All comparisons and exchanges use fixed record addresses and masked moves, so the access schedule depends only on leaf size and output size . The combined network uses no more comparisons than truncated selection alone, giving time for . For , a minimum tournament takes linear time.
Remark 1. A max heap of capacity is a standard way to retain the best candidates, with the worst retained candidate at the root. A doubly oblivious max heap is therefore an alternative for this building block. We construct a restricted DO heap based on circuit ORAM, incurring cost for Insert and ExtractMin operations. Within our scope, it is slightly faster than Shi's path oblivious heap [37]. We describe its construction in Appendix A and compare it with a selection network in the ablation in Figure 8.
6.3. Doubly oblivious randomly rotated k-d tree
We represent a single conceptual randomly rotated (RR) k-d tree by a tuple . Here is the tree's random transform, root is its root pointer, and is the public number of internal levels, with shorter paths padded to this depth. The internal-node ORAM stores blocks , where is the splitting coordinate in the transformed space, is the split threshold, and and are the left and right child pointers, with form (idx, pos) defined in Section 6.1. Each block in the leaf ORAM stores a bundle of points from a single -d tree leaf, padded with dummies to slots. Points retain their original coordinate representation for distance evaluation.
Separating the two node types avoids padding every tiny block to size. A query visits internal nodes and one leaf. A unified ORAM would charge per internal access. Separate ORAMs reduce the ORAM access cost to per internal node and pay the large-block cost only for the leaf.
For a query , Algorithm 1 computes and follows one root-to-leaf path in the conceptual -d tree. At each internal node, selects lptr when true and rptr otherwise, yielding . The access to is implemented by scanning all coordinates with masked moves to keep oblivious. Pointer selection and replacement likewise access both child fields on a fixed schedule, changing only the selected field during replacement.
At the start of each iteration, ptr identifies the current block at its existing ORAM position, while is its fresh
reinsertion position, already recorded in root or its parent. After removing with ReadRm(ptr), the algorithm samples for the selected child and records in . It then reinserts at using Write. Retaining the child's existing pointer in allows the next iteration to read that child before reinserting it at . Each fresh position is sampled uniformly from the public position range of the ORAM storing the corresponding node. After exactly internal iterations, the algorithm reads the leaf block in containing and reinserts it unchanged at its reserved position. In other words, every query performs internal-node read/write pairs and one leaf read/write pair. Finally, it calls the selector from Section 6.2 (denoted by ) to retain the leaf's top- closest candidates and returns them as .
Algorithm 1: Query of oblivious k-d tree
Input: Index , Query
Output: Top- candidates from the visited leaf, padded with dummies if necessary
1 ;
2 ptr root;
3 Sample uniformly at random and update root ;
4 for to do
5
6 the child pointer selected by ;
7 Sample uniformly at random;
8 In , replace the selected child pointer by ;
9 ;
10 ;
11 ;
12 ;
13 ;
14 ;
15 return
6.4. Query phase of O2N2
We now describe the full query phase of O2N2, which composes the single-tree query procedure with oblivious candidate aggregation. The input is a forest of doubly oblivious RR -d trees with independent rotations. For a query , the algorithm queries every tree using Algorithm 1. Each tree returns candidate slots selected from its visited leaf.
The candidates returned by all trees are appended to an array A. After oblivious duplicate removal, a final selection network produces the best k distinct candidates as . The duplicate-removal procedure sorts A by identifier and replaces repeated identifiers by dummies in a fixed scan, preserving the array length.
Algorithm 2: Approximate k-NN query of O2N2
Input: Index , Query
Output: Approximate k-NN set
1 ;
2 for to do
3
4 Append to ;
5
6 ;
7 Replace all duplicate items in with ;
8 ;
9 return
7. Correctness and obliviousness
This section proves the guarantees behind Theorem 1. We first establish correctness and double obliviousness for the single-tree query, then compose these facts to obtain the guarantee for O2N2. The running-time bound follows from the public loop bounds in Algorithm 2 and the costs in Table 2.
Correctness. We show that Algorithm 1 simulates plaintext defeatist search followed by top- selection in the visited leaf.
Claim 1 (Correctness of single-tree query). Let be a plaintext RR -d tree with transform and padded depth . Suppose that stores the same logical tree as in the following sense.
-
The root pointer root identifies the root node of at its current ORAM position.
-
Each internal block stores the same split coordinate, threshold, and logical child identifiers as the corresponding node of , with valid ORAM positions in both child pointers.
-
Each leaf block stores the points in the corresponding leaf of , padded with dummies to slots.
Then, for every query , Algorithm 1 returns the top- points from the leaf reached by plaintext defeatist search on , using the distance-ID order from Section 6.2 and dummy padding when necessary. The logical tree and pointer consistency are preserved.
Proof. Let . We use a loop invariant over the internal-node rounds. At the beginning of each round, ptr locates the same logical node as the plaintext query, while is the fresh position reserved for in its root or parent pointer. All other stored pointers remain valid, and the logical tree is unchanged. The invariant holds initially after the algorithm reserves the root's new position.
Consider one round at . The block read from contains the same splitting coordinate , threshold , and child identifiers as in . The coordinate scan returns , so selects the same child as the plaintext query. The algorithm retains that child's current pointer in and records its fresh position in the parent block. Writing
the parent at restores its incoming pointer's validity. Advancing to with reserved position therefore preserves the invariant.
After rounds, ptr identifies the same leaf as the plaintext query. Its ReadRm returns the same point set, and its Write restores the last pending pointer without changing the leaf contents. By the correctness of the selection network of Cong et al. [11], the final returns that leaf's top- according to distances to the original query , padded with dummies if necessary.
Double obliviousness. A single-tree query hides both the selected traversal path and the subsequent candidate selection.
Claim 2 (Double obliviousness of single-tree query). Let be an RR -d tree stored using the pointer-based ORAM interface in Section 6.1. For fixed public parameters, the query procedure in Algorithm 1 is doubly oblivious under the security guarantee of that interface.
Proof. Fix the public parameters and consider any two valid query-index states sharing these parameters. In both executions, the algorithm performs exactly internal rounds on , each with one ReadRm and one Write, followed by one leaf round on with the same operation types. The resulting logical access sequences have length and agree in their ORAM instances and operation types at every position. Their logical pointers may differ adaptively. Fresh positions are sampled independently, and the doubly oblivious ORAM interface hides these logical choices, including accesses to the stash. Its sequential security guarantee therefore gives indistinguishable physical traces for the two access sequences.
Outside the ORAM calls, the transform, coordinate scans, and masked pointer updates follow fixed schedules. Distance evaluation scans all point slots, and the selection network uses public comparator addresses with masked exchanges and returns exactly slots. These local traces depend only on public parameters. Composing them with the ORAM accesses preserves indistinguishability of the complete traces, proving double obliviousness.
Main guarantee. We now combine the two claims to obtain the formal version of Theorem 1.
Theorem 2 (Guarantee of O2N2). For points in with , trees and leaf capacity , Algorithm 2 correctly simulates the plaintext RR -d tree forest query with the same trees, transforms, and distance-ID order, returning the best distinct points in the visited leaves and satisfying double obliviousness. Using constant ORAM bucket size, its worst-case query time is
Proof. For correctness, Claim 1 shows that each single-tree query returns the top- of the same leaf as plaintext defeatist search. Retaining only these points is lossless for global top- selection. Every discarded point has at least distinct points preceding it in the same leaf under the common distance-ID order, so it cannot belong to the top- of the union of visited leaves. Sorting the retained candidates by identifier makes duplicates adjacent, and the fixed scan replaces repeated occurrences by dummies. The final Select therefore returns the best distinct candidates, exactly matching the plaintext forest query.
For double obliviousness, Algorithm 2 makes a public number of single-tree queries, each doubly oblivious by Claim 2, and appends exactly candidate records per tree. Aggregation uses oblivious sorting, a fixed scan for duplicate marking, and a selection network on the resulting slots. Their access schedules depend only on public parameters, so their composition with the tree queries is doubly oblivious.
For running time, Table 2 gives for the internal-node accesses per tree and for the leaf access. The local selector costs for . Since , the transform, coordinate scans, and distance evaluation are bounded by the leaf-access cost, as is the linear selector for . Multiplying the per-tree costs by gives the first two terms. Aggregation over the retained candidates takes time for , and constant time otherwise, giving the last term.
8. Experiments
In this section, we evaluate the performance of our proposed scheme, O2N2, and compare it against several doubly oblivious baselines. We implement all algorithms in C++20 and evaluate them on the benchmark datasets summarized in Table 3. We additionally report O2N2 scalability results on SIFT100M, the first 100 million base vectors of BIGANN, using its public queries and 100M ground truth [38].
Workload difficulty. To summarize workload difficulty, we use two metrics, local intrinsic dimensionality (LID) and relative contrast (RC). Given dataset and query , LID and RC are defined as
where denotes the probability that a database point lies within distance of query , and denotes the distance between and the -th NN. Following Aumüller and Ceccarello [2], we use the same 100-NN maximum-likelihood estimator for LID, and estimate RC by a sample average on with size .
Table 3 reports averages over all queries. Higher LID values and lower RC values generally indicate more challenging workloads. Among these datasets, DEEP10M has the highest LID, while MS MARCO has the lowest RC.
Our experiments are conducted on a confidential machine protected by Intel® Trust Domain Extensions (TDX) [17]. The underlying physical host is powered by an Intel Xeon Platinum 8469C processor (codenamed Sapphire Rapids).
TABLE 3. DATASETS AND WORKLOAD STATISTICS.
| Dataset | N | d | LID | RC | ||
|---|---|---|---|---|---|---|
| mean | median | mean | median | |||
| DEEP10M [1] | 9,990,000 | 96 | 25.22 | 25.20 | 3.41 | 2.40 |
| SIFT1M [1] | 1,000,000 | 128 | 21.70 | 21.67 | 3.19 | 2.75 |
| MSONG [6] | 994,185 | 420 | 23.83 | 23.46 | 3.98 | 3.48 |
| MS MARCO [3, 26] | 8,841,823 | 768 | 6.40 | 6.23 | 1.84 | 1.81 |
Algorithm 3: Approximate -NN query of OIVF
Input: Index , Query
Output: Approximate -NN set
1 ;
2 ascendingly by distance between centroids and ;
3 for to do
4
5
6 by the distance to in ascending order;
7 elements of ;
8 return
The guest VM is configured with 192 vCPUs operating at 2.6 GHz, and allocated 3TiB of RAM. All experiments are performed over a local network with 5Gbps bandwidth and sub-millisecond round-trip latency.
8.1. Baselines
Since no prior work addresses doubly oblivious ANN, our only viable baselines are strengthening popular plaintext ANN algorithms with existing doubly oblivious RAMs. We construct baselines from two standard ANN indexes, Inverted File Index (IVF) and Hierarchical Navigable Small World (HNSW).
Doubly oblivious IVF index (OIVF). A typical IVF index consists of a cluster collection and point storage. Here contains clusters, and each cluster contains its centroid and a point list assigned to that centroid. OIVF stores point records in a doubly ORAM and pads every point list to the public capacity . Given a query point , it sorts by centroid distance to , fetches points from each of the first clusters, and returns the best candidates after an oblivious sort. The query details are shown in Algorithm 3, of which the complexity is , where we assume each access of incurs runtime. In our experiments, we set target cluster size to 25, which is a public constant. Since a cluster can exceed its target after clustering, we pad each point list to .
- Since our protocol requires only a single round trip with tens of kilobytes of communication between the client and server, readers can directly add their wide-area network RTT to estimate performance in geographically distributed settings.
O2N2 OIVF (H2O2RAM) OHNSW (H2O2RAM) OIVF (Circuit ORAM) OHNSW (Circuit ORAM)

Figure 3. Query time and quality for 10-NN search.
Doubly oblivious HNSW index (OHNSW). A typical HNSW index consists of an entry point , a layered graph , and point storage . OHNSW stores point records in and graph adjacency arrays in . The graph has top layer and public degree bounds . Given a query point , query processing starts from , uses fixed greedy rounds on each upper layer, and then runs a base layer beam search with public beam width and fixed visit budget . The query details are shown in Algorithm 4, which returns the final approximate nearest neighbors. Its ORAM-dominated query complexity is , where we assume each backed ORAM access incurs runtime and let . In our experiments, DEEP10M and MS MARCO use upper-layer degree bounds and base-layer degree bound , while the other datasets use upper-layer degree bounds and base-layer degree bound .
Double obliviousness of the baselines. In Algorithms 3 and 4, we implement minimum/maximum selection and membership tests using full scans, conditionals and set operations using masked updates on fixed-capacity arrays, and sorting using oblivious networks. Loop bounds and array lengths are public, and each query returns exactly slots. Dummy accesses use reserved ORAM records with padded
empty adjacency lists where needed. Intuitively, the doubly ORAMs hide the logical addresses accessed during search, while the fixed query schedule and oblivious local operations hide data-dependent choices. Formally, we have the following proposition.
Proposition 1 (Double obliviousness of Baselines). Given OIVF and OHNSW indexes, Algorithms 3 and 4 are doubly oblivious.
Proof. Throughout the proof, we assume that all public parameters are fixed.
For OIVF, centroid distance evaluation and oblivious sorting process all fixed-width cluster records, each containing a centroid and its padded identifier list. The algorithm then scans the first records at fixed offsets and reads all point slots per cluster, including dummies. It therefore issues exactly ORAM reads, whose logical addresses depend on the selected clusters. Distance evaluation, final oblivious sorting, and output of the first slots follow fixed local access schedules.
For OHNSW, the algorithm executes rounds per upper layer and base-layer rounds. Each round processes the full padded neighbor list. These fixed rounds and list lengths, together with the scheduled entry-point reads, determine the number and order of graph and point ORAM accesses.

Figure 4. Query time and quality for 100-NN search.
Candidate selection, membership tests, and updates scan the fixed-capacity arrays using masked operations, even for dummy, visited, or rejected candidates. Final oblivious sorting and output of the first slots also follow fixed schedules.
Thus, each algorithm is a fixed-schedule composition of local oblivious computations and doubly ORAM calls. Query-dependent choices affect the logical addresses supplied to ORAM, but not the call counts, operation types, or local access schedules. By the security of the underlying doubly ORAMs against adaptive logical accesses, these calls have indistinguishable internal and external access traces for any two valid inputs sharing the public parameters. Their composition with the local oblivious computations therefore proves double obliviousness of both algorithms.
Choosing ORAM backend. We instantiate two baselines using different doubly oblivious RAM backends. The first is built on our own implementation of recursive Circuit ORAM [46]. This serves as a natural reference point in the doubly oblivious setting: when client-side computation must itself be oblivious, its eviction circuit avoids the additional log log factor incurred by other state-of-the-art ORAMs such as Path ORAM [41]. The second baseline uses the open-source implementation of H2O2RAM [50], which
was reported to significantly outperform EnigMap [42] and GraphOS [8].
8.2. Experimental results
The main baseline comparisons cover four datasets: DEEP10M, SIFT1M, MSONG, and MS MARCO (Table 3). We additionally evaluate O2N2 on SIFT100M in Figure 5 and Table 4. For O2N2, we set the leaf size to and the ORAM bucket size to across all datasets. The number of trees is varied to trace the time-recall tradeoff curves. Our primary metrics are query time, recall accuracy (Recall@k), distance sum ratio (DSR@k), and RDE (RDE@k) for and .
Overall performance tradeoffs. Figures 3 and 4 report the query time versus recall, DSR, and RDE for the 10-NN and 100-NN results. In the reported regimes, O2N2 generally gives the best latency. The performance gap comes from how each index maps to oblivious execution. To reach
- Interestingly, Circuit ORAM baselines outperform H2O2RAM baselines in many settings, we observe that this is because H2O2RAM's efficiency depends heavily on cache locality across long sequences of consecutive accesses, while the memory-intensive ANN computations interleaved with ORAM accesses inevitably break this locality and pollute the cache.
Algorithm 4: Approximate k-NN query of OHNSW
Input: Index , query
Output: Approximate k-NN set
1 ;
2 for to 1 do
3
4
5
6
7 ;
8 Initialize arrays , and :
-
Fill and with and copies of ;
-
Fill with and copies of ;
for to do
;
;
;
for do
;
if and then
Add to by a linear scan;
;
if then
in ascending distance order;
;
return
high recall, OIVF scans many candidate points from the selected clusters, while OHNSW performs a fixed-budget graph traversal that still follows a sequential dependency chain. Each step depends on the previous step, creating serialized ORAM accesses that are difficult to parallelize. In contrast, O2N2 queries independent -d trees. These tree queries can run concurrently, allowing O2N2 to turn additional parallel resources into better accuracy.
Scalability on SIFT100M. Figure 5 compares the time-recall tradeoffs on SIFT1M and SIFT100M as the dataset size increases by a factor of 100. With the forest size fixed at , measured query latency increases by factors of 2.17 and 1.67 for and , respectively. The same forest size also yields lower recall on SIFT100M for both values of . Scaling to the larger dataset therefore increases the cost at a fixed tree count and requires more trees to attain comparable recall.

Figure 5. Query time versus recall of O2N2 on SIFT1M and SIFT100M for and .
Breakdown of query time. Figures 6 and 7 separate query latency on SIFT1M and MSONG into forest search and cross-tree aggregation for and . The search time includes the query transform, ORAM navigation and leaf access, distance computation, and local selection, with the trees queried in parallel. Aggregation time consolidates the returned candidates. The overlaid line reports the search-to-aggregation ratio. On SIFT1M, for , aggregation accounts for less than 3% of total query time. For , its share increases from 8.7% at to 24.2% at , as aggregation processes the candidates returned by the trees.
Besides , the dimension parameter also impacts the search-to-aggregation ratio. SIFT1M and MSONG both contain approximately one million points and use nearly identical leaf occupancies, while their dimensions are 128 and 420, respectively. At and , search takes 2.52 ms on SIFT1M and 7.88 ms on MSONG, whereas aggregation takes approximately 0.80 ms on both. Its share of total query time consequently falls from 24.2% to 9.2%. Higher dimensionality increases leaf-access and distance-computation costs, whereas aggregation operates only on IDs and distances.
Ablation of selection network. The DO max heap discussed in Section 6.2 is a viable selector that, like a selection network, retains the exact top- of a visited leaf. We compare their query costs on SIFT1M for and to evaluate the benefit of network-based selection. Both versions use the same random seed, with all other experimental conditions held constant.
Figure 8 shows query latency for to 64. The network achieves a speedup at and a speedup at , reducing latency by 34.8–47.8% and 70.7–87.3%, respectively. At , latency falls from 2.31 to 1.45 ms for and from 8.19 to 1.90 ms for .
The benefit is concentrated in forest search. At , this stage accounts for 0.846 ms of the 0.855 ms total reduction at and 6.276 ms of the 6.298 ms reduction at . Appendix A provides the heap construction, its comparison with Shi's Path Oblivious Heap [37], and the complete ablation results.

(a) Breakdown for 10-NN on SIFT1M

(b) Breakdown for 100-NN on SIFT1M
Figure 6. Query-time breakdown of O2N2 on SIFT1M for 10-NN and 100-NN. For both panels, the right axes show the search-to-aggregation ratio.

(a) Breakdown for 10-NN on MSONG

(b) Breakdown for 100-NN on MSONG
Figure 7. Query-time breakdown of O2N2 on MSONG for 10-NN and 100-NN. For both panels, the right axes show the search-to-aggregation ratio.
Quantitative analysis at high recall. Table 4 reports operating points at a target recall of 90%, with an 80% target for MS MARCO and for SIFT100M at . We select the fastest measured O2N2 configuration meeting the target. For DEEP10M, reaches 90.09% Recall@10 in 4.36 ms. The SIFT100M experiment has no completed baseline. OHNSW exhausted available memory, while OIVF did not finish the indexing process.
Storage overhead. As shown in Table 4, O2N2 has clear storage advantage than the baselines for low-dimension

Figure 8. Leaf-selector ablation on SIFT1M.
TABLE 4. Comparison for 10-NN and 100-NN at the specified target recall, where N/A denotes an unavailable result.
| Dataset‡ | O2N2* | Baseline† | Speedup | ||||
|---|---|---|---|---|---|---|---|
| Storage | Time | Storage | Time | ||||
| DEEP10M | 10100 | 128208 | 256415 | 4.46.9 | 1165 | 333.8497.1 | 76.6×72.3× |
| SIFT1M | 10100 | 5696 | 1526 | 1.32.5 | 40 | 161.3260.5 | 125.9×102.9× |
| SIFT100M‡ | 10100 | 88104 | 23252748 | 3.54 | N/A | N/A | N/A |
| MSONG | 10100 | 64112 | 5585 | 4.38.1 | 49 | 253.1322.1 | 58.4×39.6× |
| MS MARCO | 10 | 184 | 2540 | 53.4 | 1526 | 522.2 | 9.8× |
- Storage and Time denote storage requirement (GB) and latency (ms), and denotes the number of trees. Storage values are based on the heap-based index measurements. The target recall is 90%, except for SIFT100M at and MS MARCO at , where it is 80%. We report the fastest measured O2N2 configuration meeting the target and the baseline point with recall closest to the target.
† We use the fastest baseline OHNSW (Circuit ORAM) here.
‡ Our machine with 3TB storage can only support up to 200 trees for MS MARCO dataset, so only is stated here.
‡ SIFT100M baseline results are unavailable because OHNSW exhausts the available storage, while OIVF's index construction was prohibitively slow at this scale and did not finish in our experiments.
datasets (SIFT and DEEP). However, on high-dimensional datasets (MSONG and MS MARCO), the limitation of tree-based methods becomes apparent. To fetch more candidates and achieve higher recall, the number of trees (and hence the total storage) must increase, causing O2N2 to exceed the baselines in storage. In contrast, OHNSW can maintain a fixed storage size: adjusting the query parameter only affects the computation time, not the storage. Our 3 TB storage limit prevents O2N2 from reaching 90% Recall@100 on SIFT100M and higher-recall operating points on MS MARCO. Within the feasible parameter regime of MS MARCO, O2N2 is still 9.8× faster than OHNSW, albeit at a higher storage cost (2540 GB vs. 1526 GB).
TABLE 5. Query latency of private ANN systems for .
| System† | Privacy | SIFT1M | MS MARCO | ||
|---|---|---|---|---|---|
| Recall | Time | Recall | Time | ||
| O2N2 | Double O | 90.09 | 1.28 | 85.26 | 55.53 |
| OHNSW | Double O | 90 | 161.3 | 90.24 | 1,210.4 |
| Compass [52] | (Single) O | ≥ 90 | 40 | ≥ 90 | 470 |
| BiSON [12] | (Single) O | 90.24 | 9 | 91.43 | 40 |
| TEE Compass [32] | (Single) O | ≈ 90 | 42.5 | ≈ 90 | 827 |
| Onyx [32]‡ | (Single) O | ≈ 90 | 18.8 | ≈ 90 | 67.1 |
† Compass results use the semi-honest fast-network setting (3 Gbps, 1 ms RTT), and BiSON results use the LAN setting (10 Gbps, 0.3 ms RTT). We select these low-latency network settings to limit communication overhead in comparison with our local query execution. For both systems, we report full latency including deferred ORAM eviction, since our query timings also include eviction.
‡ Onyx results use the 1-SSD setting.
8.3. Comparison with existing private ANN systems
We compare O2N2 with Compass [52], Onyx [32], and BiSON [12]. Table 5 places our measurements alongside their published results for and includes Circuit OHNSW. For O2N2 on MS MARCO, we report the point with the highest measured recall. The table records the privacy guarantee, recall, and query latency of each reported operating point.
On SIFT1M, the results in Table 5 show that O2N2 is , , and faster than Compass, BiSON, and Onyx, respectively. This advantage does not carry over uniformly to the higher-dimensional MS MARCO workload, where the forest requires more trees for high recall. Although O2N2 remains faster than Compass and Compass-in-TEE, its highest-recall operating point has latency between BiSON and Onyx and lower recall than both. In addition, note that at approximately 90% recall on MS MARCO, our circuit OHNSW takes only about as long as Compass-in-TEE while additionally protecting internal memory accesses, demonstrating the competitiveness of our baseline.
The different privacy guarantees help explain these results. Compass and BiSON keep quantized vector hints, position maps, ORAM metadata, and graph caches in trusted client memory [12, 52]. Candidate node IDs directly index local hints and cached nodes without hiding these accesses. Their reported client memory on MS MARCO is approximately 500 MB and 827 MB, respectively. Onyx similarly keeps compressed traversal hints and ORAM client state in TEE memory, with DRAM access patterns explicitly excluded from its threat model [32]. These designs benefit from query-dependent local lookups whose access patterns are assumed hidden. In contrast, O2N2 protects both external and internal accesses, retaining competitive latency under this additional requirement.
Comparison with Panther. Panther [25] is a PIR-based private ANN search system that protects query privacy and database privacy in a single-server model. Under its reported SIFT1M setting, Panther takes 1.49 s, whereas O2N2 meeting 90% Recall@10 takes 1.28 ms, a reported-latency ratio of . Panther provides a cryptographic comparison point alongside the ORAM-based systems above.
Comparison with plaintext search. To quantify the performance overhead of O2N2, we compare it against two plaintext schemes, HNSWlib and FAISS-IVF, via ann-benchmark [1]. At approximately 90% Recall@10 on SIFT1M, HNSWlib and FAISS-IVF take 0.08 ms and 0.4 ms, respectively. O2N2 is slower than FAISS-IVF and slower than HNSWlib. We argue that this overhead remains acceptable for remote services, where the round-trip latency constitute the major cost of ANN search.
9. Conclusion and future work
We presented O2N2, a doubly oblivious ANN system for TEEs. By aligning RR -d tree traversals with tree-based ORAM, O2N2 reduces the overhead per block access from for generic recursive doubly oblivious storage to . Experiments across datasets and query parameters show that O2N2 achieves speedup over doubly oblivious baselines at the evaluated high-recall operating points.
Nevertheless, O2N2 inherits limitations from its tree-based design. While it is more space- and time-efficient on low-dimensional datasets, achieving high recall on high-dimensional data requires more trees and substantially increases storage costs. Improving this space-latency tradeoff, for example through hybrid index structures, is an interesting direction for future work.
AI assistance disclosure
We used GPT-5.6 and GPT-6 to optimize the implementation, prepare experiment scripts, process benchmark logs, and review the proofs. GPT and Grok also assisted with checking grammar and revising the manuscript. The authors take responsibility for the implementation, analysis, and conclusions.
References
[1] Martin Aumüller, Erik Bernhardsson, and Alexander Faithfull. 2020. ANN-Benchmarks: A benchmarking tool for approximate nearest neighbor algorithms. Information Systems 87 (2020), 101374. [2] Martin Aumüller and Matteo Ceccarello. 2019. The role of local intrinsic dimensionality in benchmarking nearest neighbor search. In Proceedings of the International Conference on Similarity Search and Applications. Springer, 113–127. [3] Payal Bajaj, Daniel Campos, Nick Craswell, Li Deng, Jianfeng Gao, Xiaodong Liu, Rangan Majumder, Andrew McNamara, Bhaskar Mitra, Tri Nguyen, Mir Rosenberg, Xia Song, Alina Stoica, Saurabh Tiwary, and Tong Wang. 2016. MS MARCO: A Human Generated Machine Reading Comprehension Dataset. arXiv preprint arXiv:1611.09268 (2016).
[4] Kenneth E Batcher. 1968. Sorting networks and their applications. In Proceedings of the Spring Joint Computer Conference. 307–314.
[5] Jon Louis Bentley. 1975. Multidimensional binary search trees used for associative searching. Commun. ACM 18, 9 (1975), 509–517.
[6] Thierry Bertin-Mahieux, Daniel P. W. Ellis, Brian Whitman, and Paul Lamere. 2011. The Million Song Dataset. In Proceedings of ISMIR. 591–596.
[7] David Cash, Paul Grubbs, Jason Perry, and Thomas Ristenpart. 2015. Leakage-abuse attacks against searchable encryption. In Proceedings of CCS. 668–679.
[8] Javad Ghareh Chamani, Ioannis Demertzis, Dimitrios Papadopoulos, Charalampos Papamanthou, and Rasool Jalili. 2023. GraphOS: Towards oblivious graph processing. Proceedings of the VLDB Endowment 16, 13 (2023), 4324–4338.
[9] Hao Chen, Ilaria Chillotti, Yihe Dong, Oxana Poburinnaya, Ilya Razenshteyn, and M Sadegh Riazi. 2020. SANNS: Scaling up secure approximate k-nearest neighbors search. In Proceedings of USENIX Security. 2111–2128.
[10] J Chuang, A Seto, N Berrios, S van Schaik, C Garman, and D Genkin. 2026. Tee. fail: Breaking trusted execution environments via ddr5 memory bus interposition. In Proceedings of SP. 1894–1912.
[11] Kelong Cong, Robin Geelen, Jiayi Kang, and Jeongeun Park. 2025. Revisiting Oblivious Top-k Selection with Applications to Secure k-NN Classification. In Selected Areas in Cryptography – SAC 2024 (Lecture Notes in Computer Science, Vol. 15516). Springer, 3–25. https://doi.org/10.1007/978-3-031-82852-2_1
[12] Sankha Das, Rohan Ravi, Nishanth Chandran, and Divya Gupta. 2026. BiSON: Billion-Scale Oblivious Nearest-Neighbor Search in Milliseconds. In 2026 IEEE 11th European Symposium on Security and Privacy (EuroS&P). IEEE, 160–172. https://doi.org/10.1109/EuroSP68448.2026.00021
[13] Dengguo Feng, Yu Qin, Wei Feng, Wei Li, Ketong Shang, and Hongzhan Ma. 2024. Survey of research on confidential computing. IET Communications 18, 9 (2024), 535–556.
[14] Oded Goldreich. 1987. Towards a theory of software protection and simulation by oblivious RAMs. In Proceedings of STOC. 182–194.
[15] Paul Grubbs, Richard McPherson, Muhammad Naveed, Thomas Ristenpart, and Vitaly Shmatikov. 2016. Breaking web applications built on top of encrypted data. In Proceedings of CCS. 1353–1364.
[16] Alexandra Henzinger, Emma Dauterman, Henry Corrigan-Gibbs, and Nickolai Zeldovich. 2023. Private web search with Tiptoe. In Proceedings of SOSP. 396–416.
[17] Intel Corporation. 2022. Intel® trust domain extensions. Technical Report. Intel Corporation. https://cdrdv2-public.intel.com/690419/TDX-Whitepaper-February2022.pdf White Paper.
[18] Mohammad Saiful Islam, Mehmet Kuzu, and Murat
Kantarcioglu. 2012. Access pattern disclosure on searchable encryption: Ramification, attack and mitigation. In Proceedings of NDSS, Vol. 20. 12.
[19] Suhas Jayaram Subramanya, Fnu Devvrit, Harsha Vardhan Simhadri, Ravishankar Krishnawamy, and Rohan Kadekodi. 2019. DiskANN: Fast accurate billion-point nearest neighbor search on a single node. Advances in Neural Information Processing Systems 32 (2019).
[20] Herve Jegou, Matthijs Douze, and Cordelia Schmid. 2010. Product quantization for nearest neighbor search. IEEE Transactions on Pattern Analysis and Machine Intelligence 33, 1 (2010), 117–128.
[21] Jeff Johnson, Matthijs Douze, and Hervé Jégou. 2019. Billion-scale similarity search with GPUs. IEEE Transactions on Big Data 7, 3 (2019), 535–547.
[22] David Kaplan, Jeremy Powell, and Tom Woller. 2016. AMD Memory Encryption. Technical Report. Advanced Micro Devices, Inc. White Paper.
[23] Kasper Green Larsen, Tal Malkin, Omri Weinstein, and Kevin Yeo. 2020. Lower bounds for oblivious near-neighbor search. In Proceedings of SODA. 1116–1134.
[24] Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, et al. 2020. Retrieval-augmented generation for knowledge-intensive nlp tasks. Advances in Neural Information Processing Systems 33 (2020), 9459–9474.
[25] Jingyu Li, Zhicong Huang, Min Zhang, Cheng Hong, Jian Liu, Tao Wei, and Wenguang Chen. 2025. Panther: Private approximate nearest neighbor search in the single server setting. In Proceedings of CCS. 365–379.
[26] Jimmy Lin, Xueguang Ma, Sheng-Chieh Lin, Jheng-Hong Yang, Ronak Pradeep, and Rodrigo Nogueira. 2021. Pyserini: A Python Toolkit for Reproducible Information Retrieval Research with Sparse and Dense Representations. In Proceedings of SIGIR. 2356–2362.
[27] Frank McKeen, Ilya Alexandrovich, Alex Berenzon, Carlos V. Rozas, Hisham Shafi, Vedyas Shanbhogue, and Uday R. Savagaonkar. 2013. Innovative instructions and software model for isolated execution. In HASP@ISCA. 10.
[28] Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean. 2013. Distributed representations of words and phrases and their compositionality. Advances in Neural Information Processing Systems 26 (2013).
[29] Pratyush Mishra, Rishabh Poddar, Jerry Chen, Alessandro Chiesa, and Raluca Ada Popa. 2018. Oblix: An efficient oblivious search index. In Proceedings of SP. 279–296.
[30] Maan Haj Rachid, Ryan D. Riley, and Qutaibah M. Malluhi. 2020. Enclave-based oblivious RAM using Intel's SGX. Computers & Security 91 (2020), 101711.
[31] Parikshit Ram and Kaushik Sinha. 2019. Revisiting kd-tree for nearest neighbor search. In Proceedings of SIGKDD. 1378–1388.
[32] Deevashwer Rathee, Jean-Luc Watson, Zirui Neil Zhao, G. Edward Suh, and Raluca Ada Popa. 2026. Onyx:
Cost-Efficient Disk-Oblivious ANN Search. arXiv preprint arXiv:2604.20401 (2026).
[33] Ling Ren, Christopher Fletcher, Albert Kwon, Emil Stefanov, Elaine Shi, Marten Van Dijk, and Srinivas Devadas. 2015. Constants count: Practical improvements to oblivious RAM. In Proceedings of USENIX Security. 415–430.
[34] Muhammad Usama Sardar and Christof Fetzer. 2023. Confidential computing and related technologies: a critical review. Cybersecurity 6, 1 (2023), 10.
[35] Sacha Servan-Schreiber, Simon Langowski, and Srinivas Devadas. 2022. Private approximate nearest neighbor search with sublinear communication. In Proceedings of SP. 911–929.
[36] Hayim Shaul, Dan Feldman, and Daniela Rus. 2020. Secure k-ish nearest neighbors classifier. In Proceedings on PETS, Vol. 3, 42–61.
[37] Elaine Shi. 2020. Path oblivious heap: Optimal and practical oblivious priority queue. In Proceedings of SP. 842–858.
[38] Harsha Vardhan Simhadri, George Williams, Martin Aumüller, Matthijs Douze, Artem Babenko, Dmitry Baranchuk, Qi Chen, Lucas Hosseini, Ravishankar Krishnaswamy, Gopal Srinivasa, Suhas Jayaram Subramanya, and Jingdong Wang. 2022. Results of the NeurIPS'21 Challenge on Billion-Scale Approximate Nearest Neighbor Search. In Proceedings of the NeurIPS 2021 Competitions and Demonstrations Track, Vol. 176. 177–189.
[39] Kaushik Sinha. 2014. LSH vs randomized partition trees: Which one to use for nearest neighbor search?. In International Conference on Machine Learning and Applications. 41–46.
[40] Shang Song, Lin Liu, Rongmao Chen, Wei Peng, and Yi Wang. 2023. Secure approximate nearest neighbor search with locality-sensitive hashing. In Proceedings of ESORICS. 411–430.
[41] Emil Stefanov, Marten van Dijk, Elaine Shi, T.-H. Hubert Chan, Christopher W. Fletcher, Ling Ren, Xiangyao Yu, and Srinivas Devadas. 2018. Path ORAM: An extremely simple oblivious RAM protocol. Journal of ACM 65, 4 (2018), 18:1–18:26.
[42] Afonso Tinoco, Sixiang Gao, and Elaine Shi. 2023. EnigMap: External-Memory oblivious map for secure enclaves. In Proceedings of USENIX Security. 4033–4050.
[43] Jo Van Bulck, Marina Minkin, Ofir Weisse, Daniel Genkin, Baris Kasikci, Frank Piessens, Mark Silberstein, Thomas F Wenisch, Yuval Yarom, and Raoul Strackx. 2018. Foreshadow: Extracting the keys to the intel SGX kingdom with transient Out-of-Order execution. In Proceedings of USENIX Security. 991–1008.
[44] Jo Van Bulck, Nico Weichbrodt, Rüdiger Kapitza, Frank Piessens, and Raoul Strackx. 2017. Telling your secrets without page faults: Stealthy page Table-Based attacks on enclaved execution. In Proceedings of USENIX Security. 1041–1056.
[45] Stephan Van Schaik, Andrew Kwong, Daniel Genkin,
and Yuval Yarom. 2020. SGAxé: How SGX fails in practice.
[46] Xiao Wang, Hubert Chan, and Elaine Shi. 2015. Circuit ORAM: On tightness of the Goldreich-Ostrovsky lower bound. In Proceedings of CCS. 850–861.
[47] Xiao Shaun Wang, Kartik Nayak, Chang Liu, T.-H. Hubert Chan, Elaine Shi, Emil Stefanov, and Yan Huang. 2014. Oblivious data structures. In Proceedings of CCS. 215–226.
[48] Yuanzhong Xu, Weidong Cui, and Marcus Peinado. 2015. Controlled-channel attacks: Deterministic side channels for untrusted operating systems. In Proceedings of SP. 640–656.
[49] Yupeng Zhang, Jonathan Katz, and Charalampos Papamanthou. 2016. All your queries are belong to us: the power of File-Injection attacks on searchable encryption. In Proceedings of USENIX Security. 707–720.
[50] Leqian Zheng, Zheng Zhang, Wentao Dong, Yao Zhang, Ye Wu, and Cong Wang. 2025. H2O2RAM: A High-Performance hierarchical doubly oblivious RAM. In Proceedings of USENIX Security. 8501–8520.
[51] Mingxun Zhou, Elaine Shi, and Giulia Fanti. 2025. Pacmann: Efficient private approximate nearest neighbor search. In Proceedings of ICLR.
[52] Jinhao Zhu, Liana Patel, Matei Zaharia, and Raluca Ada Popa. 2025. Compass: Encrypted semantic search with high accuracy. In Proceedings of OSDI. 915–938.
[53] Jianwei Zhu, Hang Yin, Peng Deng, Aline Almeida, and Shunfan Zhou. 2024. Confidential Computing on NVIDIA Hopper GPUs: A Performance Benchmark Study. arXiv preprint arXiv:2409.03992 (2024).
[54] Martin Zuber and Renaud Sirdey. 2021. Efficient homomorphic evaluation of k-NN classifiers. In Proceedings of PETS, Vol. 2021. 111–129.
Appendix
The main construction uses an oblivious selection network to obtain the top- candidates from each visited leaf. This appendix describes the doubly oblivious (DO) heap used as the alternative selector in the ablation. We first report the heap-operation comparison with Shi's Path OHeap [37], then describe the heap and compare its query latency with the network version.
1. Comparison with Path OHeap
The DO heap supports fixed-capacity top- updates: a new candidate replaces the current maximum only when its distance is smaller. We compare it with the official Path OHeap implementation by filling both structures with blocks of the same size and performing the same number of extract-maximum/insert update pairs. Table 6 retains the measured operation times. Relative to the fastest reported Path OHeap configuration at each capacity, our heap is , , and faster for , respectively. Thus this implementation is competitive at small capacities, although the measured advantage narrows as grows.
TABLE 6. HEAP UPDATE LATENCY (s PER EXTRACT/INSERT PAIR). IS THE PATH OHEAP BUCKET SIZE.
| k | Z = 1 | Z = 2 | Z = 4 | DO heap | Speedup |
|---|---|---|---|---|---|
| 10 | 3.902 | 4.641 | 4.572 | 1.400 | 2.79 |
| 100 | 6.211 | 6.181 | 7.123 | 3.493 | 1.77 |
| 1000 | 10.464 | 8.553 | 10.116 | 7.284 | 1.17 |
2. DO heap construction
The heap is a pointer-based binary tree stored in a DO Circuit ORAM [46]. Its capacity is public. Set and pad the tree to nodes. The first nodes are active slots; the remaining nodes are inactive padding. A node stores an item-distance pair and pointers to its children. Each pointer contains both a logical identifier and its ORAM position. Child positions are embedded in parent blocks following the pointer-based access technique of Wang et al. [47]. The stash is scanned on a fixed schedule, and local comparisons and record moves use masked operations.
For top- selection, set . Initially, the active slots contain dummy candidates with value ; inactive slots have value . For each of the public number of leaf slots, compute its distance and execute a fixed-capacity update. A valid candidate replaces the root exactly when it is better than the current maximum. A padded leaf slot is represented by an invalid candidate with value . After the scan, exactly extractions return the retained candidates. The forest uses the same cross-tree duplicate removal and final selection as the network version.
The basic interface consists of Insert, ExtractMax(), and a fixed-height OSift operation. Insert conditionally replaces the root and always runs OSift. ExtractMax saves the root record, replaces it with , runs OSift, and returns the saved record. After all inputs have been offered, this yields the best leaf candidates; reversing the extraction order produces ascending distances.
Algorithm 5: Doubly oblivious max heap
Input: Doubly oblivious max heap
1 Function Insert : 2 4 Assign new pos to root and call ; 6 Call ;
7 Function ExtractMax(): 8 9 10 Assign new pos to root and call ; 11 Call ; 12 return
13 Function OSift (ptr): 14 for to do 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Algorithm 5 gives the three operations. OSift executes rounds, each with three ReadRm calls followed by three Write calls. Conditional updates and swaps denote masked operations on fixed local records. If no swap is needed, the algorithm continues into a randomly chosen child and completes the same number of rounds.
Position reassignment uses a future-position convention. For a child revisited in the next round, its parent records a reserved final position, while the child is temporarily written at an independent fresh position retained by the traversal. The next round reads from this temporary position and writes the current node at its reserved position, without resampling that position. Other children, including both children in the final round, are written directly to the positions recorded by their parent. Only the current read pointer and reserved output position need to be carried between rounds. The heap's root pointer is updated to the root's final output position.
For , an ORAM access to a -word block costs for bucket size . OSift makes accesses, so Insert and ExtractMax each cost . A leaf scan and final extraction therefore cost . In the compact implementation, is a point identifier, while the vector itself remains in the leaf buffer. Root handling is fused with the update and the workspace is reused between queries. These choices are enabled in the heap endpoint of the ablation.
3. Correctness and obliviousness
Claim 3. If the two subtrees below the root satisfy the max-heap property, a complete OSift restores that property throughout the heap without changing its multiset of records.
Proof. At the beginning of each real sift step, only an edge from the current node to one of its children can violate the heap property. Moving the largest of the three values to the current node repairs both outgoing edges. Only the selected child's outgoing edges can then require repair. If the current node already holds the maximum, the entire remaining subtree is ordered and the dummy continuation leaves it unchanged. The fixed rounds reach the bottom level. Masked swaps preserve the multiset. For a revisited child, the traversal uses its temporary read position and then writes it at the reserved position recorded by its parent. All other child pointers name their immediate write positions. Thus every parent-child link is valid when OSift completes.
Insert leaves the retained multiset unchanged or replaces its maximum with a better candidate. Induction over the leaf scan shows that the active slots retain the best records seen so far, counting initial dummies when necessary. ExtractMax returns the current maximum and replaces it with , so exactly extractions enumerate the retained records. The tie convention can be fixed by ordering distance-ID pairs; the measured older heap endpoint used distance-only comparisons.
Claim 4. Assuming the DO Circuit ORAM interface and fixed-schedule local operations, the fixed-capacity heap updates and extractions are doubly oblivious.
Proof. For public height , OSift issues exactly ORAM calls; Insert and ExtractMax each add one ReadRm and one Write. Position samples use fixed-size local buffers
and a fixed schedule. Candidate values affect only masked record contents and logical pointers, not local addresses or operation types. Adaptive doubly ORAM security hides the resulting logical access sequence, and fixed local scans hide internal record selection. Sequential composition over the public number of updates and extractions establishes the claim.
4. Heap versus selection network
The query-level ablation uses SIFT1M, , seed 1, 1000 queries, and 32 query workers. Each endpoint builds 64 trees with the same forest seed and varies the queried prefix. Both use FP16 leaf payloads, disable initial random candidates, and retain the same tree-search and final aggregation routines. The heap endpoint enables compact distance-ID records, fused root handling, and workspace reuse. The network endpoint uses our blockwise bitonic selector, replacing the per-leaf heap by block sorting and truncated merges over the complete leaf.
Table 7 gives the 11 measured prefixes for each value of . The network achieves speedup at and at . Recall agrees at the printed precision except at , , where it is 90.00% for the heap and 90.01% for the network. Distance-sum ratio and RDE agree at all reported points for both values of . The network evaluates the full leaf candidate set and avoids the heap's per-candidate ORAM updates and final extraction phase.
TABLE 7. PAIRED SIFT1M QUERY LATENCY FOR AND . TIMES ARE MILLISECONDS.
| m | ||||||
|---|---|---|---|---|---|---|
| DO heap | Network | Speedup | DO heap | Network | Speedup | |
| 1 | 0.780 | 0.407 | 1.92 | 3.434 | 0.436 | 7.88 |
| 2 | 0.786 | 0.421 | 1.87 | 3.535 | 0.450 | 7.86 |
| 4 | 0.881 | 0.479 | 1.84 | 3.583 | 0.513 | 6.99 |
| 8 | 0.995 | 0.561 | 1.77 | 3.720 | 0.617 | 6.03 |
| 16 | 1.225 | 0.687 | 1.78 | 4.906 | 0.849 | 5.78 |
| 24 | 1.268 | 0.757 | 1.68 | 4.508 | 1.049 | 4.30 |
| 32 | 1.489 | 0.971 | 1.53 | 4.343 | 1.274 | 3.41 |
| 40 | 1.695 | 1.016 | 1.67 | 7.236 | 1.220 | 5.93 |
| 48 | 1.831 | 1.151 | 1.59 | 7.658 | 1.403 | 5.46 |
| 56 | 2.051 | 1.292 | 1.59 | 7.962 | 1.753 | 4.54 |
| 64 | 2.306 | 1.451 | 1.59 | 8.194 | 1.896 | 4.32 |
These two experiments measure different workloads: Table 6 compares heap operations, whereas Table 7 measures full forest queries with alternative local selectors. Together they explain the design choice: the DO heap is effective among the tested small-capacity heap implementations, while the fixed leaf-selection workload is served more efficiently by the network.