On Best-Possible One-Time Programs Aparna Gupte, Jiahui Liu, Luowen Qian, Justin Raizes, Bhaskar Roberts, Mark Zhandry Abstract One-time programs (OTPs) aim to let a user evaluate a program on a single input while revealing nothing else. Classical OTPs require hardware assumptions, and even with quantum information, deterministic functionalities remain impossible due to gentle-measurement attacks (Broadbent, Gutoski and Stebila, 2013). While recent works achieve positive results for randomized functionalities with high-entropy outputs, the fundamental limits and the strongest achievable security notions remain poorly understood. Inspired by analogous successes in the classical obfuscation setting, we ask for a “best-possible” analogue of obfuscation for OTPs: a generic transformation that, for any functionality, achieves the strongest one-time security achievable by any construction. Our first result is negative. We show that a generic best-possible one-time compiler cannot exist even for classical randomized functionalities. We prove this under the assumption that lossy encryption schemes exist (e.g. from either the Learning with Errors or weakly pseudorandom group actions). Our proof identifies computationally indistinguishable families for which any best-possible transformation would be forced to behave incompatibly. Given this impossibility, we introduce a natural subclass of one-time compilers called “testable one-time program” compilers, which output quantum states augmented with reflection oracles for themselves. We show that best-possible security for this subclass, i.e. best-possible testable one-time compilers, are most likely achievable. For this, we give two results. (1) We formulate a simplified, generalized Single-Effective-Query (SEQ) simulation security notion for quantum channels and show that SEQ security implies best-possible testable one-time security. (2) We construct SEQ-secure OTPs for all quantum functionalities in the classical oracle model, yielding the first positive results for arbitrary quantum channels beyond classical randomized functionalities. Thus, SEQ security could serve as a testable one-time analogue of virtual black-box (VBB) security in the many-time obfuscation setting. Finally, we propose stateful quantum indistinguishability obfuscation (stateful quantum iO) — quantum state obfuscation for stateful quantum programs. We show that (1) stateful quantum iO implies best-possible testable OTPs and (2) stateful quantum iO is also achievable in the classical oracle model. These results identify stateful quantum iO as a promising approach towards best-possible testable OTPs. 1 Introduction The notion of one-time programs (OTPs) was introduced by Goldwasser, Kalai, and Rothblum [ 20 ] . An OTP allows a user to evaluate the program on a single input of their choice, while preventing them from learning anything else about the program. OTPs can be thought of as a strengthening of obfuscation where the only information revealed is the output on a single input. If realized, OTPs would have many applications throughout cryptography such as software protection. It is not hard to see that OTPs cannot be achieved in the plain model, as a user can always copy the program and evaluate it on multiple inputs. Thus the original work of Goldwasser et al. [ 20 ] considered constructing OTPs in the hardware token model. Subsequently, Broadbent, Gutoski, and Stebila [ 12 ] ruled out constructing OTPs with the aid of quantum information for any deterministic classical functionality. Although quantum mechanics forbids cloning, [ 12 ] showed that multiple evaluations can still be achieved generically via gentle measurements. Therefore, hardware assumptions remain necessary for secure OTPs even with quantum information. By contrast, a work by Ben-David and Sattath [ 11 ] constructed “quantum one-time signature tokens,” which can be viewed as a quantum one-time program for the signing functionality. This result circumvents the impossibility of [ 12 ] by implicitly leveraging the fact that the signing functionality is a randomized (classical) functionality with high entropy outputs. More recently, two works [ 24 , 23 ] revisited the definitions of quantum OTPs. Specifically, they proposed and proved the security for a quantum construction of OTPs for general randomized (classical) functionalities with entropic outputs, the first general positive result without hardware assumptions 1 1 1 From this point onwards, we will exclusively focus on OTPs without hardware assumptions. . Despite these exciting new results, if we look more closely at the intuitive ideal security goal of only “revealing information about a single input”, we see that even randomized functionalities do not completely circumvent the impossibility of [ 12 ] . In particular, as pointed out in [ 24 ] , if it were possible to deterministically extract some piece of information from the probabilistic output (say, all possible outputs for a given input had the same parity), then this information can be extracted from multiple inputs by a generalization of [ 12 ] . This seemingly violates the intuition for what a one-time program should be. The prior works [ 24 , 23 ] do give some one-time security guarantee but it is unclear what this actually means for the one-time security of general programs, and whether their notions are the strongest security one could hope for. In particular, [ 24 ] propose a strong simulation security notion of one-time security, but leave open the question whether it is the strongest notion of one-time security one could hope for. For example, it would be ideal to have a security guarantee that says that the program protected is one-time except for certain classes of attacks such as the one above. We further discuss the security definition from prior works in Section 1.5 . Given the discussion, the following fundamental question naturally arises. For a given family of functionalities, what is the strongest achievable one-time security notion for quantum OTPs? For inspiration, let us momentarily turn our attention to an analogous problem but for classical obfuscation, the goal of hiding the implementation of a program while maintaining its input-output behaviors. Here, a similar issue arises. Virtual black-box (VBB) obfuscation is the natural ideal notion for obfuscation: the behavior of any adversary receiving the obfuscated program cannot be distinguished from that of a simulator with black-box access to an oracle computing the functionality. But it is provably impossible [ 7 ] for certain functionalities. Due to this general impossibility, two approaches have been taken. First, [ 7 ] propose a weaker notion of indistinguishability obfuscation (iO), which roughly states that the obfuscations of two equivalent programs are indistinguishable. This notion avoids the impossibility, and is even potentially achievable (e.g. [ 19 , 28 ] in the pre-quantum setting, or [ 9 , 26 ] ). On the other hand, it is a priori unclear what sorts of guarantees iO provides, as we usually care about the security of a single program, and it is not clear we gain an insights into the security of a particular program by looking at equivalent programs. The other direction is to stick with VBB, but show that it is achievable for some very specific functionalities [ 16 , 29 , 34 , 22 ] . Unfortunately, there is a wide gulf between what is known to be VBB obfuscatable and what is known to be un-obfuscatable. These two directions both have major limitations. Fortunately, the work of Goldwasser and Rothblum [ 21 ] provides a satisfying way to unify both approaches through the lens of “best possible” obfuscation. Instead of trying to determine whether a given functionality can be obfuscated, they instead just try to give an obfuscator which is “best possible”, in the intuitive sense that if a functionality can be obfuscated security by any obfuscator, then the given obfuscator also obfuscates that functionality securely. Surprisingly, they show that such best-possible obfuscation is actually equivalent to iO. With the subsequent emergence of iO constructions, we now have best-possible obfuscation for all programs. Now, in order to VBB obfuscate some functionality for which VBB obfuscation is possible, all that is necessary is to show that some obfuscator exists, which then implies that any iO scheme is in particular a VBB obfuscator for that functionality. Inspired by the success of best-possible obfuscation and iO, it is natural to ask if there is also an analog of a best-possible obfuscator for quantum OTPs, i.e. whether there exists a generic quantum OTP transformation that always achieves the strongest possible one-time security for any possible functionality. More succinctly, Is there a best-possible one-time compiler? 1.1 Our Results on Best-Possible One-Time Programs The results in this work on best-possible one-time programs are three-fold. First, our work gives convincing evidence that perhaps surprisingly, there is rather no generic way to achieve best-possible one-time programs (with or without oracles). Second, we also show that best-possible security is achievable via a simulation security for a very natural class of quantum one-time compilers called “testable one-time programs” in the oracle model. Finally, we point to a plausible approach for constructing best-possible testable quantum one-time programs in the plain model. Impossibility of Best-Possible One-Time Programs. First, we introduce the definition of best-possible one-time programs, à la “best-possible obfuscation” of [ 21 ] . For this result, we state impossibility for randomized classical functionalities. This already rules out generic best-possible compilers for all quantum functionalities, since randomized classical functionalities are a special case. Definition 1 (Informal; Definition 12 ) . A one-time compiler \mathsf{OTP}^{*} is best-possible for a family \mathcal{F} of sampling functionalities if there exists a simulator \mathsf{Sim} such that for any sampling functionality f\in\mathcal{F} , and for any quantum program P that one-time implements f , \mathsf{OTP}^{*}(f,1^{|P|}) is computationally indistinguishable from \mathsf{Sim}(P,1^{|f|}) . Intuitively, this definition captures the idea that among all the programs P that implement the sampling functionality f , \mathsf{OTP}^{*}(f) leaks the minimum amount. The length of the program is also unavoidably leaked similar to indistinguishability obfuscation and best-possible obfuscation [ 21 ] . Our main theorem rules out best-possible one-time program compilers that work for any program, even if restricted to randomized classical functionalities. Theorem 1 (Informal; Theorem 8 ) . Best-possible one-time compilers do not exist unless lossy encryptions do not exist. This holds relative to all oracles. Corollary 1 (Informal; Theorem 7 ) . Assuming either Learning with Errors (LWE) is hard or weak pseudorandom effective group actions 2 2 2 The impossibility from LWE is slightly weaker: in that case, we only rule out best-possible one-time programs among those that one-time implements the same functionality up to a negligible statistical distance; the reason is basically that the lossiness of the LWE-based construction is only statistically close. The impossibility from group actions rules out the weaker notion of best-possible one-time programs among those that one-time implements the exact same functionality (with no error). , best-possible one-time compilers do not exist. Even though we state our theorem as the impossibility of the best-possible one-time compiler as we defined above, our proof does not actually rely on the subtleties in defining best-possible one-time programs. In particular, we prove this by identifying two classes of randomized programs that are computationally indistinguishable yet the best-possible one-time compilers must work very differently, leading to a contradiction. We elaborate on this in the technical overview and even further in Section 1.4 . Best-Possible Testable One-Time Programs. We now turn to a positive direction. Instead of comparing against all one-time implementations, we compare within a natural restricted class and ask for best-possible security among what we call “testable one-time compilers”. Definition 2 (Informal; Definition 13 ) . A one-time compiler \mathsf{OTP}(P) is testable if it (possibly randomly) outputs two programs (\ket{\tilde{P}},R) such that \ket{\tilde{P}} is the one-time program that one-time implements P and R implements the reflection unitary I-2\ket{\tilde{P}}\bra{\tilde{P}} . Intuitively, this is the class of one-time compilers whose outputs are well-defined pure states: the pure state \ket{\tilde{P}} that one-time implements the functionality is “defined” by the reflection program R . We emphasize that the obfuscator’s output can still be a mixed state, in which case the mixed state should be entirely supported on testable pure state programs. Crucially, this definition disallows a mixed state program that on average one-time implements P . Looking ahead, this restriction is exactly what breaks the counterexample construction in the impossibility proof: that construction uses mixed implementations that are only correct on average, which testability excludes. We further expand on this subtlety later in Section 1.4 . The main motivation for this definition is that there are concrete and recurring ways to modify most existing one-time compiler constructions to become testable 3 3 3 The only counterexample that we are aware of is given in this work in the impossibility result, which is arguably contrived. . For starters, a trivial case is the classical-state case: if \ket{\tilde{P}} is always a computational-basis string, then one can first read out that string (equivalently, measure in the computational basis) and then efficiently implement the exact reflection I-2\ket{\tilde{P}}\bra{\tilde{P}} coherently via an equality check and phase kickback. The most common pattern for designing a one-time compiler is to issue an uncloneable token that collapses upon use, along with an obfuscated classical program that only works when the two-basis measurement outcome on the token is correct; implementing the reflection in this case is also straightforward by simply making use of the obfuscated classical program to check if the token is undisturbed. More generally, the reflection oracle can usually be implemented by simply gently measuring if the one-time program is still functional. In fact, we conjecture that the program implicitly having a reflection oracle might be an unavoidable property for many natural function classes, since an approximate version of this test is always possible if the output of the functionality is verifiable, such as a signature token or a one-time NIZK. Our next contribution shows that best-possible testable one-time programs, i.e. one-time programs that are best-possible among testable ones, are achievable in the oracular setting via a simulation-based security, which is a revised and generalized version of Single Effective Query (SEQ) security from [ 24 ] . We further elaborate on this in Section 1.2 . Theorem 2 (Informal; Corollary 2 ) . There exists a classical oracle relative to which there exists an SEQ-secure one-time compiler for all quantum non-oracular functionalities. 4 4 4 The oracle here is simply used to obfuscate and evaluate programs. Here we disallow the functionalities being obfuscated to access the oracle to avoid the VBB-style impossibility [ 5 , 24 ] . In comparison with our impossibility for best-possible one-time programs (instead of testable ones), the functionalities considered by Corollary 1 are nonoracular and still hold in our oracle model assuming LWE/group action assumptions. Theorem 3 (Informal; Theorem 9 ) . Relative to all oracles, any one-time compiler that achieves SEQ security is best-possible among testable one-time compilers. Theorem 4 (Informal; Theorem 15 ) . For every non-trivial randomized classical functionality f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} with |\mathcal{X}|>1 , there is a quantum channel \Phi_{f} such that the classical query interface O_{f}^{\mathsf{CSEQ}} and the generalized query interface O^{\mathsf{SEQ}}_{\Phi_{f}} are efficiently inter-simulatable. Consequently, the classical \mathsf{CSEQ} security is a special case of the generalized \mathsf{SEQ} security. Best-Possible Testable OTP in the Plain Model? Towards achieving best possible testable one-time programs in the plain model, we give a new notion of obfuscation which is sufficient, and seemingly necessary, for constructing these. Our new notion of stateful quantum obfuscation allows obfuscation of quantum programs which maintain an internal state that may evolve as the program is queried. Since one-time programs inherently change their behavior over subsequent queries, allowing for evolution seems necessary. However, accounting for it requires some care. If two programs may behave similarly on the first evaluation, but degrade in a way that subsequent evaluations are distinguishable, then it should be hard to obfuscate them into programs that are indistinguishable. In fact, our impossibility for best-possible one-time programs formalizes this intuition: it is in general impossible to indistinguishably obfuscate two programs that are equivalent only on a single query. Instead, we ask to indistinguishably obfuscate two circuits only if they produce the same output distributions over many sequential evaluations. We call this notion stateful quantum iO. Theorem 5 (Informal; Theorems 10 and 11 ) . Assuming stateful quantum iO, there exists a best possible testable one-time compiler for all quantum functionalities. Furthermore, stateful quantum iO exists in the classical oracle model. 1.2 One-Time Security for Quantum Functionalities Along the lines of investigating best-possible one-time programs, we also extend the study of one-time security from randomized classical functionalities to all quantum (channel) functionalities. As far as we are aware, our Theorems 2 and 5 are also the first positive results for constructing one-time programs for arbitrary quantum channels without hardware assumptions. As mentioned earlier, we revise and generalize the Single Effective Query (SEQ) security defined by Gupte et al. [ 24 ] from randomized classical functionalities to all quantum functionalities. In this work, we call our new generalized notion simply SEQ and refer to the older version from [ 24 ] as classical SEQ (CSEQ). As the prior work [ 24 ] has already shown, SEQ as a simulation-based security is unachievable for certain randomized circuits in the plain model by generalizing the impossibility of VBB [ 6 ] . Despite this VBB-style impossibility, we believe that SEQ on its own is still a very useful notion for the topic of one-time programs. Of course, the VBB-style impossibility does not rule out SEQ for all interesting functionalities; but more importantly, similar to the role VBB plays today, SEQ provides a relatively simple yet realistic ceiling on the one-time security that one could hope for in the plain model for a given functionality using testable OTP obfuscators. Indeed, it will turn out that SEQ is also capable of capturing the fact (from the gentle-measurement impossibility [ 12 ] ) that any one-time correct implementation of a deterministic/unitary program will inevitably allow an unbounded number of evaluations. Additionally, if one aims to construct a one-time compiler that achieves security unachievable by even SEQ, the OTP construction must actively prevent its output program from being testable. In order for SEQ security to provide this useful role, we point out that our revised version of SEQ is in fact much simpler than the original formulation, despite being a generalization. We hope that our simplification would help downstream applications of one-time programs in future work. For completeness, we give a self-contained presentation of SEQ below. To motivate the definition, let us briefly recall the intuition for SEQ security from [ 24 ] . SEQ security states that the information extractable from a SEQ-secure OTP of a functionality \Psi can be reduced to that extractable from an ideal query interface of \Psi . This interface allows for a one-time evaluation of \Psi but refuses to cooperate with any other query as much as possible. This is in contrast to older simulation-based one-time security notions such as in [ 20 , 12 ] where the interface allows literally one physical query, regardless what has been learned in the query. Without hardware assumptions, an adversary could always compute and uncompute the unitary implementation of the interface. This motivates the following definition of a “self-adjoint implementation” of a quantum channel. Definition 3 (Informal; Definition 14 ) . Consider a quantum channel \Psi using input/output register \mathcal{X} which is implemented by some unitary U_{\Psi} which might use a private auxiliary register \mathcal{A} that is initialized to 0. Let \mathcal{C} be a qubit register acting as a counter. Let the self-adjoint implementation S(U_{\Psi}) of \Psi be the unitary that swaps \ket{x}_{\mathcal{X}}\ket{0}_{\mathcal{A}}\otimes\ket{0}_{\mathcal{C}}\leftrightarrow(U_{\Psi}\ket{x}_{\mathcal{X}}\ket{0}_{\mathcal{A}})\otimes\ket{1}_{\mathcal{C}} and acts as identity everywhere else. Fact 1 . S(U_{\Psi}) is a well-defined self-adjoint unitary and can be efficiently implemented given controlled query access to U_{\Psi} . Definition 4 (Informal; Definition 15 ) . A one-time compiler is SEQ-secure if \mathsf{OTP}(P) can be efficiently (computationally indistinguishably) simulated by a simulator that only gets access to P via querying the self-adjoint implementation for P without having access to its \mathcal{A},\mathcal{C} registers. It is so called “Single Effective Query” because (1) to compute \Psi a second time, you must first return to the state \ket{x}_{\mathcal{X}}\ket{0}_{\mathcal{A}}\otimes\ket{0}_{\mathcal{C}} by uncomputing it; but more importantly, (2) if the output is “meaningfully” disturbed, then further evaluations become effectively impossible because the evaluator cannot return to the initial state \ket{x}_{\mathcal{X}}\ket{0}_{\mathcal{A}}\otimes\ket{0}_{\mathcal{C}} . A helpful example to illustrate SEQ would be to consider a channel that ignores the input and outputs some random coins. In this example, the simulator could invoke the interface and obtain the random coins and possibly uncompute it subsequently; however, if it decides to completely measure the output, this breaks up the entanglement between \mathcal{A} and \mathcal{X} registers, and the SEQ interface would subsequently reject (acting very close to identity) if queried again. Security notion Impossibilities Constructions Single physical query, simulation-based, OTP for quantum functionalities [ 13 ] Strong impossibility for most functionalities relative to all oracles For single physical-query learnable (trivial) functions only [ 13 ] ; For constant-distribution functionalities (implicit in this work) Classical SEQ, simulation-based, OTP for classical functionalities [ 24 ] VBB-style impossibility for contrived functionalities in the plain model [ 24 ] For all classical functions, relative to a classical oracle [ 24 ] Generalized SEQ, simulation-based, OTP for quantum functionalities ( this work ) For all quantum functionalities relative to a classical oracle ( this work ) Best-possible OTP compiler ( this work ) Impossibility for generic compilers relative to all oracles that admit secure lossy encryptions ( this work ) Best-possible OTP compiler among only testable programs ( this work ) From either SEQ security or quantum stateful iO ( this work ) Figure 1: One-time program security notions with impossibilities and constructions. 1.3 Technical Overview Best-possible impossibility. The main idea of proving the impossibility of best-possible one-time compilers is identifying two families of functionalities D and E such that: 1. The one-time compilers for D and E must behave very differently to achieve the strongest one-time security; 2. Yet it is impossible to efficiently distinguish D from E . As a first step, we consider D to be a randomized functionality that can be information-theoretically one-time protected. Such a functionality can be constructed by simply defining D(x) to be sampling from a fixed distribution C independent of x . Then, note that the ideal one-time security could actually be achieved as follows: • The one-time compiler simply samples C by evaluating on a fixed input such as D(0) to get a sample y ; the compiler then outputs y as the description of the one-time program. • The evaluator simply ignores the input x and outputs y . It is clear that this one-time program can be perfectly simulated with just one query to D , thus it achieves the strongest possible one-time security of being simulatable via one “physical” query. This example is interesting since on one hand, it can be perfectly one-time protected; but on the other hand, the one-time compiler above in general is correct only if the functionality in question samples the same distribution for every input. However, intuitively whether a circuit’s output depends on the input should not be a property that can be efficiently learned (by the obfuscator). Therefore, the idea is that we should start by considering E to be a sampling circuit that samples a different distribution for every input, yet all of those distributions look indistinguishable to C , the distribution that D samples. It turns out that we can find such D and E by leverging lossy encryptions. A lossy encryption scheme has two modes, an injective mode and a lossy mode. The injective mode corresponds to a regular encryption scheme; the lossy mode corresponds to a scheme where the encryptions of any two different messages are statistically indistinguishable. More importantly, the public encryption keys sampled in these two modes are computationally indistinguishable. We can construct a post-quantum lossy encryption scheme from LWE or effective group actions using folklore techniques. We remark that our first construction in fact only needs lossy trapdoor functions rather than the full power of LWE. Now, we can consider the previously proposed function E to be an injective encryption algorithm \mathsf{Enc}_{\mathsf{inj}} for input x , whereas D will be a lossy encryption algorithm \mathsf{Enc}_{\mathsf{lossy}} whose ciphertext produced is statistically independent of x (this ciphertext distribution would be the distribution C mentioned before). More concretely, we consider the following families of classical circuits. \mathsf{Enc}(\mathsf{\vphantom{p}pk},x;r) is the encryption algorithm of a lossy encryption with inputs public key \mathsf{\vphantom{p}pk} , message x and randomness r . 1. D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}(x;r):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},x;r) 2. E_{\mathsf{\vphantom{p}pk}_{\mathsf{inj}}}(x;r):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{inj}},x;r) To finish the proof, we must show how we can use a best-possible one-time protector \mathsf{OTP}^{*} to efficiently distinguish the lossy key from the injective key. A priori, the best-possible \mathsf{OTP}^{*}(D) need not output a fixed sample from C even though C achieves the best one-time security for D . Nevertheless, we argue that \mathsf{OTP}^{*}(D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}) must still necessarily be effectively a constant function whereas \mathsf{OTP}^{*}(E_{\mathsf{\vphantom{p}pk}_{\mathsf{inj}}}) cannot possibly be (or correctness would be violated). Then, to distinguish, a QPT algorithm can simply run the program on a uniform superposition over input x and measure the output. Then if \mathsf{OTP}^{*}(D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}) is run, the superposition would not collapse since the output is constant and thus deterministic; on the other hand, if \mathsf{OTP}^{*}(E_{\mathsf{\vphantom{p}pk}_{\mathsf{inj}}}) is run, then the superposition must collapse by injectivity. In the end, we can distinguish D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}} from E_{\mathsf{\vphantom{p}pk}_{\mathsf{inj}}} by simply measuring whether the pre-image superposition collapses or not. Finally, to show that \mathsf{OTP}^{*}(D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}) must act like constant function, we use the following observation: D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}} is in fact one-time equivalent to an ensemble of constant functions. This is because we can just map each ciphertext (image) \mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},x;r^{*}) in the output of D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}} to a constant function C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}}(\cdot):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*}) outputting the fixed \mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*}) on any input x , where randomness r^{*} is pre-sampled uniformly at random and then fixed for the circuit. By the property of the lossy encryption key, C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}}(\cdot) ’s output distribution is statistically indistinguishable from sampling from the output distribution of D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}} on input x , i.e. all ciphertexts \mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},x;r) for r is sampled uniformly at random upon evaluation. By the correctness of \mathsf{OTP}^{*} , \mathsf{OTP}^{*}(C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}}) must always output \mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*}) regardless of the input. However, by best-possible security, \mathsf{OTP}^{*}(D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}) must be computationally indistinguishable from applying \mathsf{OTP}^{*} to the distribution over C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}} where the fixed output \mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*}) is sampled by r^{*}\leftarrow\{0,1\}^{|r|} . Therefore, we can conclude a contradiction here. We conclude by noting that this impossibility relativizes even in the presence of unitary oracles. Remark 1 . We note that our impossibility can be dequantized to state that best-possible one-time programs are also impossible with classical obfuscators assuming the existence of the same (but classically secure) lossy encryptions. The only step that needs to be changed is that rather using a quantum distinguisher that tests if the input superposition collapses, we can simply rewind the classical program to test if it is a constant function. Best possible testable one time programs. Having ruled out best-possible OTPs, we next turn to testable OTPs. Here, we show that a one-time program achieving SEQ security is as secure as any testable one-time program. To show that SEQ security is best-possible for testable one-time programs, we must show how to simulate \mathsf{SEQ}(f) using an alternative quantum program g which is equivalent to f for one query and has a reflection oracle R . The idea of the simulator is straightforward: we simply implement \mathsf{SEQ}(f) by implementing \mathsf{SEQ}(g) instead. The intuition is that the \mathsf{SEQ} interface would hide the implementation details of whether f or g is being queried since they are one-time equivalent. Towards that goal, it is helpful to first see how \mathsf{SEQ} interface can be efficiently implemented. In particular, let U_{f} be a purified unitary of f , \mathsf{SEQ}(f) is implemented by the following quantum circuit S(U_{f}) : 1. Controlled on \ket{1}_{\mathcal{C}} , compute U_{f}^{\dagger} . 2. Controlled on the auxiliary register \mathcal{A} being all zeroes, flip \mathcal{C} register. 3. Controlled on \ket{1}_{\mathcal{C}} , compute U_{f} . To formalize our intuition above, we establish the following lemma showing that self-adjoint implementations hide the implementation details of the channel, which could be of independent interest. Lemma 1 (Informal; Lemma 11 ) . For any two unitary implementations U_{\Psi},U^{\prime}_{\Psi} of the same channel \Psi , S(U_{\Psi}) and S(U^{\prime}_{\Psi}) are perfectly indistinguishable given unbounded query access to only the input/output register \mathcal{X} . This already suffices to prove the statement if f and g are classically described programs. However, there is one subtlety we need to address, which is that g may be a quantum state describing a program \ket{g} . After evaluating it once, the program state may be disturbed. Unlike classically, we cannot say that the program state is readonly due to no cloning. This is where the reflection oracle R plays a crucial role: the reflection oracle R well defines the quantum program \ket{g} . In particular, the way we fix this is by modifying the step 2 of \mathsf{SEQ}(g) to in addition also control on the quantum program register being \ket{g} , which can be efficiently implemented using the reflection oracle. The intuitive reason that this works is that this way, we are effectively implementing the following quantum program that does not involve a quantum auxiliary input \ket{g} and yet is perfectly equivalent to g : 1. Perform a swap \ket{0}\leftrightarrow\ket{g} in the program register. 2. Carry out the original computation. Observe that the \mathsf{SEQ} for this program would reflect around all zeroes on both the auxiliary register and the program register, which is equivalent to reflecting around all zeroes on the auxiliary register and \ket{g} on the program register if we do not do the first step. Achieving SEQ Security with Oracles. Note that our Lemma 1 gives a straightforward way for instantiating SEQ-secure one-time programs with stateful unitary ideal obfuscation. In such an obfuscation scheme, the obfuscator takes as input a unitary U that acts on a public register \mathcal{X} and an internal auxiliary register \mathcal{A} that is initialized to some state that is given; and it outputs \tilde{U} which can only be queried in either the forward or backward direction where the internal register is inaccessible. Then to one-time protect f , we can simply use the ideal obfuscation to obfuscate and give out \mathsf{SEQ}(f) . Intuitively, such a stateful unitary ideal obfuscation scheme can be implemented in a (stateless) unitary oracle model, or by ideal unitary obfuscation. The idea is that we can use a quantum authentication scheme to protect the internal state so that we can delegate the internal state management to the adversary without compromising security. Furthermore, such a scheme can be ported to the classical oracle model using the compiler of [ 27 ] . While this compiler introduces quantum states into the program, this does not matter for our application since our obfuscated programs are allowed to have quantum states. Towards the Plain Model via Stateful Quantum Obfuscation. Even though SEQ security is achievable using ideal obfuscation or classical oracles, we already know that there are randomized classical functionalities that cannot be SEQ-securely one-time protected in the plain model [ 24 ] . A natural question then is whether we can nevertheless achieve best-possible testable one-time programs in the plain model. Perhaps this is achievable through an alternative notion of obfuscation which plausibly exists in the plain model, similar to how for many-time security, iO and best-possible obfuscation are equivalent. Previous works propose natural definitions for indistinguishability obfuscation of quantum circuits that compute either pseudodeterministic functions [ 8 , 17 ] or unitaries [ 27 ] — for every two quantum programs that compute the same pseudodeterministic function (or unitary), their obfuscations should be indistinguishable. A natural attempt at generalizing this to arbitrary quantum channels would be to ask that if two quantum programs output similar mixed states, their obfuscations should look indistinguishable. However, if two programs produce similar outputs for the first evaluation, but then degrade so that subsequent evaluations are distinguishable, it should be hard to obfuscate them into programs that are indistinguishable. In fact, our previously discussed impossibility result formalizes this intuition. This is a uniquely quantum issue for two reasons. First, quantum programs with auxiliary quantum states inherently maintain state over evaluations that involve non-gentle measurements. Second, quantum circuits have the ability to self-produce randomness, and there is no general way to “de-randomize” them, like in the classical case. Classical descriptions of circuits do not degrade with evaluations, and it is always possible to de-randomize a probabilistic circuit C(x;r) and obfuscate C(x;F_{k}(x)) , so that the obfuscations of two equivalent classical probabilistic circuits C_{1},C_{2} will always produce the same output across evaluations. To avoid the impossibility, we explicitly consider obfuscating programs whose state may change over time. Definition 5 (Stateful iO, Informal; Definition 20 ) . Stateful indistinguishability obfuscation allows two stateful quantum programs to be indistinguishably obfuscated if and only if they produce the same output distributions over any sequence of evaluations. To show that stateful iO evades our impossibility result, we show that it is implied by ideal unitary obfuscation. Intuitively, a unitary program can authenticate a private register to itself in order to maintain state across multiple queries. Using ideal obfuscation, the authentication key is protected, so the register remains private from the evaluator. Similarly as before, we can further port this to the classical oracle model using the compiler of [ 27 ] . Furthermore, unlike ideal obfuscation, there does not seem to be an inherent barrier to constructing stateful iO in the plain model. Because the output distributions are required to be close even for query sequences that can depend on the programs being obfuscated, stateful iO avoids the self-referential techniques used to rule out ideal obfuscation [ 5 ] . Finally, we show that stateful iO implies best-possible testable one-time programs. Thus, if one could construct stateful iO in the plain model, they would also construct best-possible testable one-time programs in the plain model. This again uses Lemma 1 , which when combined with the security guarantee of stateful iO, shows that whatever could be learned from the stateful obfuscation of \mathsf{SEQ}(f) could also be learned from g by statefully obfuscating \mathsf{SEQ}(g) . 1.4 Discussions Should Best-Possible OTPs Consider Mixed Programs? One possible concern regarding our definition of best-possible one-time programs (and the resulting impossibility) is that it differs from best-possible obfuscation in one technical respect. Namely, we require the simulator \mathsf{Sim} to work for any mixed-state implementation that one-time implements the same functionality on average, rather than only for fixed pure-state implementations. This choice is intentional. Interpreting “best-possible” literally, i.e. as secure as any one-time implementation, naturally leads to a comparison class that includes all efficient implementations, including mixed ones. For comparison, let us also briefly look at why best-possible obfuscation is traditionally defined with respect to (effectively) pure-state implementations only [ 21 ] . The reason is simply that for obfuscation of deterministic functionalities, this distinction collapses: if a mixed state implements a deterministic functionality on average, then every pure state in its support implements the same functionality, so quantifying over mixed states only makes the definition conceptually more involved. Turning back to one-time programs of randomized functionalities, the distinction need not collapse: a mixed implementation can be correct only in aggregate while its pure components are not individually correct. This gap is exactly what drives our impossibility for unrestricted best-possible OTPs, and also why restricting to testable programs avoids that counterexample. A pure-only best-possible notion is arguably still meaningful, but it should be interpreted as a weaker security guarantee: best among pure-state implementations only. Our definition of testable OTP can exactly be seen as a formal approach for capturing pure-state implementations. However, if the goal is the absolute strongest benchmark in the usual English sense of best-possible, then quantifying over mixed-state implementations is the more appropriate definition. Scope of the Impossibility. Our impossibility result considers one-time protection of a classical sampling channel: the input is classical (or measured in the standard basis if not) and the output is one classical sample. This is the natural interface for one-time protection of randomized functionalities. For example, for one-time signatures, one naturally asks that the adversary can obtain at most one classical signature on one classical message. With that said, one could also consider one-time protection of different quantum channels that wrap a classical functionality. Whether our impossibility extends to every such restricted coherent extension is unclear. We leave this setting to future work for the reasons below. • Our goal is to rule out generic best-possible compilers for the broadest functionality classes (all quantum channels); ruling out the classical sampling channel already suffices for this purpose. By contrast, restricting the protected class can evade impossibility, one example of which being restricting the class to be the constant-distribution functionalities. • It is unclear what is the right/meaningful coherent extension channel of a randomized functionality. Should the randomness be sampled once and used for every input, or should the randomness be sampled fresh for every input (such as by querying a random oracle/pairwise independent hash on the input)? • Relatedly, it is unclear which coherent extension channel is useful for downstream applications, such as one-time signatures. Prevalence of Our Best-Possible OTP Impossibility. In our best-possible impossibility, we only identify two classes of functionalities for which best-possible OTPs cannot exist. One possible loophole of our impossibility is that perhaps once you exclude one class from consideration, then best-possible OTPs may indeed be possible. Inspecting our impossibility further, the lossy class is probably unlikely to be of interest for one-time programs, where the randomized program samples the same distribution for every input. While this is true, we argue that the impossibility could creep up even in unsuspecting functionalities. For starters, consider the randomized functionality f(x;r)\to(y_{1},y_{2}) where y_{1} is sampled from a fixed distribution independent of x . Then, this is a functionality that is not lossy yet (a suitably adapted version of) our impossibility still applies. One could even further consider more involved variants of this where the lossy structure is even less apparent, such as applying a pseudorandom permutation to the output. Given these examples, we suspect that it is unlikely to identify a meaningful and large class of functionalities where best-possible OTPs are possible, since any class that is closed under augmentation of such structures is also susceptible to our impossibility. Implications for Defining Obfuscation of Quantum Programs. Previous work propose natural definitions for indistinguishability obfuscation for quantum circuits that compute pseudodeterministic classical functions [ 8 , 17 ] and unitaries [ 27 ] — for every two quantum programs that compute the same pseudodeterministic function (or unitary), their obfuscations should be indistinguishable. A natural attempt at generalizing this to quantum channels would be to ask that if two quantum programs output (approximately) the same mixed state, their obfuscations should look indistinguishable. Note that this natural attempt only asks the two programs to produce samples from same mixed state for the first evaluation. This is because for (approximately) classical functions or more generally unitaries, one-time equivalence is equivalent to many-time equivalence by gentle measurement. However, when the functionality is not unitary and the program is described by a program state, the program state itself may evolve after the first query. Crucially, we can rule out this one-time security notion by invoking our best-possible OTP impossibility, since intuitively if such an object exists, then it would give a best-possible OTP similar to how iO is equivalent to best-possible obfuscation. We formalize this in Appendix C . Our definition of stateful iO gets around this problem by considering many-time equivalence of two programs rather than one-time equivalence. Thus, when defining obfuscation for quantum sampling programs, a notion which takes into account behavior on sequential queries, like stateful iO, seems necessary. Future Directions. Are there any interesting examples of one-time programs that are not testable? Less interesting examples appear in our impossibility where lossy-mode encryptors or constant-distribution samplers are considered. It would be interesting to identify other examples that can be one-time protected yet is different from the one considered in our impossibility. To further motivate one-time program security beyond SEQ, we sketch a generic efficient attack against any testable one-time program f . The attack aims to estimate multiple (efficient) observables O_{1},...,O_{t} on different input states x_{1},...,x_{n} ; in other words, we aim to estimate \mathsf{Tr}(O_{i}f(x_{j})) for all i,j up to a small inverse polynomial error. (For example, we can estimate how often each bit of the output is 0 for x_{1},...,x_{n} .) While this attack is not always useful (say for forging multiple signatures against a one-shot signature), it is a clear separation between SEQ and a single physical query (or even any polynomial number of physical queries) for almost all functionalities. For a single observable and a single input, this can be estimated using Marriott–Watrous style rewinding [ 30 ] : one simply alternates the measurement of the observable and the projection back to the original state using the reflection oracle. To extend this to multiple observables on multiple inputs, it suffices to make each estimation measurement gentle: this can be done via the Laplace noise measurement [ 1 , Corollary 6] . We formalize this generic attack in Appendix D . On the (many-time) obfuscation front, does unitary indistinguishability obfuscation imply stateful iO? The main difficulty in lifting our proof from ideal obfuscation is to adapt the argument that the obfuscator protects the authentication key. Furthermore, does classical indistinguishability obfuscation imply unitary iO? 1.5 One-Time Security in Previous Works For completeness, we survey one-time security notions studied in prior works in this section. • The work by Gupte et al. [ 24 ] propose a notion called “single effective query (SEQ) simulation-based one-time security” that circumvents the impossibility results (without hardware assumptions) of the simulation-based one-time security defined in preceding works [ 20 , 14 ] . In this work, we revise and generalize their SEQ definition to all functionalities and, to distinguish, we refer to their original (classical) version as CSEQ. More concretely, the CSEQ one-time security notion requires that the adversary’s view after maliciously utilizing the one-time program of f can be simulated by only querying a restricted stateful query interface to f . Such an interface attempts to record prior queries made to f and only answers the query if no prior queries are recorded. They show that this notion is achievable for all functionalities in the classical oracle model, which is both good and also unsatisfactory. It is good because it is a single notion that captures all functionalities. It is however unsatisfactory because it delegates the problem of identifying what security their construction achieves to the problem of what can be learned through the CSEQ interface. For example, the CSEQ interface would allow an unlimited number of evaluations for a deterministic functionality thus keeping consistency with the impossibility result [ 12 ] . However, for a general randomized functionality, it is not clear what can be learned through the CSEQ interface since the interface is somewhat complicated. Our SEQ notion somewhat mitigates this issue since our SEQ security is much simpler. • Apart from CSEQ security, [ 24 ] has presented several security notions in the plain model, but are relatively restricted to a specific setting or targeting a specific application. These notions can be viewed as extensions of the security requirement for one-time signature tokens in [ 11 ] to more functionalities. [ 11 ] states that it is impossible to produce two valid outputs signatures for two distinct inputs (messages) with respect to the signature verification algorithm. This security can be generalized to any unforgeable functionalities such as one-time NIZKs [ 24 ] . Similarly, the security of one-time PRFs (where part of the PRF input is sampled randomly) [ 24 ] only states that it is impossible to simultaneously distinguish the outputs on two different inputs from random. • The work by Gunn and Movassagh [ 23 ] showed that for their construction, a somewhat natural class of attackers (including the attack in [ 12 ] ) cannot even produce a second output as long as the functionality samples a high min entropy output on every input. However, it is possible that a more malicious attacker can still produce multiple outputs: an example of this can be seen from the plain-model impossibility in [ 24 , Theorem 7.7] . We conclude by pointing out that all the constructions in these works can be straightforwardly modified so that they are testable (using ideas discussed before). Therefore, these security notions are all achievable by using a best-possible testable one-time compiler. 2 Preliminaries 2.1 Quantum Computation We fix canonical description formats for all objects. For a classical randomized function f , we write |f| for the bit-length of its canonical description (excluding any oracle access it might carry). For a quantum sampling program P=(\rho,C) , we write |P| for the length of a canonical description consisting of a description of the state \rho together with the description of the (possibly oracle-aided) circuit C ; oracle access is not counted toward length. For a stateful quantum program (U,\ket{\psi}) , we similarly write |(U,\ket{\psi})| for the length of a canonical description of U together with a description of \ket{\psi} . When comparing programs by length (e.g., in indistinguishability obfuscation), we allow padding to equalize lengths without changing behavior: padding may add ancilla qubits initialized to \ket{0} and insert no-op gates that leave the program’s input–output behavior unchanged. When we say a result relativizes to any unitary oracle, we mean that it holds in the model where all parties receive query access to a family of unitaries including inverse and control as is standard [ 35 ] . We will need a few facts about the trace distance of two pure states whose amplitudes are defined by classical probability distributions. Definition 6 (Hellinger Distance) . For two probability density functions f,g over a finite domain \mathcal{X} , the squared Hellinger distance between f and g is defined as \displaystyle H^{2}(f,g)=\frac{1}{2}\sum_{x\in\mathcal{X}}\left(\sqrt{f(x)}-\sqrt{g(x)}\right)^{2}=1-\sum_{x\in\mathcal{X}}\sqrt{f(x)g(x)}. Lemma 2 . Let D_{1},D_{2} be two probability density functions over a finite domain \mathcal{X} , then \displaystyle\frac{1}{2}H^{2}(D_{1},D_{2})\leq\mathrm{TV}(D_{1},D_{2})\leq H(D_{1},D_{2}). Lemma 3 . Let \mathcal{X} be a finite set and let D_{1},D_{2} be probability densities on \mathcal{X} . Let \displaystyle\ket{\psi_{1}}=\sum_{x\in\mathcal{X}}\sqrt{D_{1}(x)}\ket{x}\quad\text{ and }\quad\ket{\psi_{2}}=\sum_{x\in\mathcal{X}}\sqrt{D_{2}(x)}\ket{x}\;. Then, the trace distance between the pure states \ket{\psi_{1}},\ket{\psi_{2}} is \displaystyle T(\ket{\psi_{1}}\bra{\psi_{1}},\ket{\psi_{2}}\bra{\psi_{2}})=\sqrt{1-(1-H^{2}(D_{1},D_{2}))^{2}}. 2.2 Quantum Authentication Schemes Definition 7 (Quantum Authentication Scheme) . A quantum authentication scheme is a tuple of QPT algorithms (\mathsf{KeyGen},\mathsf{Enc},\mathsf{Dec},\mathsf{Ver}) with the following behavior. • k\leftarrow\mathsf{KeyGen}(1^{\lambda},n) takes as input the security parameter \lambda and a length n\in\mathbb{N} , then outputs a key k . Here, n is the length of the state to be authenticated. • \ket{\psi^{\prime}}\leftarrow\mathsf{Enc}_{k}(\ket{\psi}) takes as input a key k and an n -qubit state \ket{\psi} , then outputs another state \ket{\psi^{\prime}} . • \ket{\psi^{\prime\prime}}/\bot\leftarrow\mathsf{Dec}_{k}(\ket{\psi^{\prime}}) takes as input a key k and a state \ket{\psi^{\prime}} , then outputs another state \ket{\psi^{\prime\prime}} or \bot . • \mathsf{Acc}/\mathsf{Rej}\leftarrow\mathsf{Ver}_{k}(\ket{\psi^{\prime}}) takes as input a key k and a state \ket{\psi^{\prime}} , then outputs \mathsf{Acc} (accept) or \mathsf{Rej} (reject). \mathsf{Ver}_{k} ’s behavior is identical to \mathsf{Dec}_{k} ’s, except \mathsf{Ver}_{k} outputs \mathsf{Acc} whenever \mathsf{Dec}_{k} would output \ket{\psi} and outputs \mathsf{Rej} whenever \mathsf{Dec}_{k} would output \bot . A quantum authentication scheme must satisfy correctness and security properties. • Correctness. For every k in the support of \mathsf{KeyGen} and every state \ket{\psi} , \mathsf{Dec}_{k}(\mathsf{Enc}_{k}(\ket{\psi}))=\ket{\psi} • Security. For every QPT adversary \mathcal{A} , there exists an \varepsilon(\lambda)\in[0,1] such that for every \ket{\psi} , \left\{\mathsf{Dec}_{k}(\rho)\,\middle|\begin{array}[]{c}k\leftarrow\mathsf{KeyGen}(1^{\lambda})\\ \rho\leftarrow\mathcal{A}(\mathsf{Enc}_{k}(\ket{\psi}))\end{array}\right\}\approx(1-\varepsilon)\{\ket{\psi}\}+\varepsilon\{\bot\} If this holds given oracle access to \mathsf{Ver}_{k} (or if there is a public key \mathsf{vk} that allows implementing \mathsf{Ver}_{k} and it holds given access to \mathsf{vk} , we say that the scheme is publicly verifiable. [ 8 ] shows how to construct publicly verifiable quantum authentication using coset states. 2.3 Ideal Obfuscation of Unitaries In this section, we will deal with quantum programs (\ket{\psi},Q) that approximately implement a unitary transform \rho\mapsto U\rho U^{\dagger} . Definition 8 . A quantum program (\ket{\psi},Q) is an \varepsilon -approximation of a unitary transformation U if \displaystyle\|Q(\cdot\otimes\ket{\psi})-U(\cdot)\|_{\diamond}\leq\varepsilon. Definition 9 (Quantum State Obfuscation for Unitaries) . A quantum state ideal obfuscation for the class of approximately-unitary quantum programs in the classical oracle model is a pair of QPT algorithms (\mathsf{QObf},\mathsf{QEval}) with the following syntax: • \mathsf{QObf}(1^{\lambda},(\ket{\psi},Q))\to(\ket{\widetilde{\psi}},\mathsf{F}) : The obfuscator takes as input the security parameter 1^{\lambda} and a quantum program (\ket{\psi},Q) in the plain model 5 5 5 To circumvent impossibility results of [ 5 ] , we say that Q does not make use oracles. , and outputs an obfuscated program specified by a state \ket{\widetilde{\psi}} and a classical function \mathsf{F} . • \mathsf{QEval}^{\mathsf{F}}(\rho_{\mathsf{in}},\ket{\widetilde{\psi}})\to\rho_{\mathsf{out}} : The evaluation algorithm executes the obfuscated program on quantum input \rho_{\mathsf{in}} by making use of the state \ket{\widetilde{\psi}} and making superposition queries to the classical oracle \mathsf{F} , and produces the quantum output \rho_{\mathsf{out}} . These algorithms have to satisfy the following properties. • Functionality-Preserving: For every quantum program (\ket{\psi},Q) which is an \mathsf{negl}\left(\lambda\right) -approximation of some unitary U , the quantum program \mathbb{E}_{(\ket{\widetilde{\psi}},\mathsf{F})\leftarrow\mathsf{QObf}(1^{\lambda},(\ket{\psi},Q))}\big(\ket{\widetilde{\psi}},\mathsf{QEval}^{\mathsf{F}}\big) is also a \mathsf{negl}\left(\lambda\right) -approximation of \mathcal{U} . • Ideal Obfuscation: There exists a QPT simulator \mathsf{Sim} such that for every QPT adversary \mathcal{A} and quantum program (\ket{\psi},Q) that \mathsf{negl}\left(\lambda\right) -approximates some unitary {U} , and every QPT distinguisher D , \left|\Pr\left[1\leftarrow D(\mathcal{A}(\mathsf{QObf}(1^{\lambda},(\ket{\psi},Q)))\right]-\Pr\left[1\leftarrow D(\mathsf{Sim}^{U,U^{\dagger}}(1^{\lambda},\mathcal{A},n(\lambda),m(\lambda))\right]\right|=\mathsf{negl}\left(\lambda\right) Here, n is the input length of the quantum program, m is the size of the quantum program. Theorem 6 (Theorem 7.2 of [ 27 ] ) . There exists a quantum state ideal obfuscation for the class of approximately unitary programs with quantum inputs and outputs in the classical oracle model, assuming post-quantum one-way functions. 6 6 6 Alternatively, the one-way functions can be replaced with a random oracle, in which case the classical oracle becomes inefficient. 3 Impossibility of Best-Possible One-Time Compilers 3.1 Definition of a Best-Possible One-Time Program Compiler A one-time program compiler \mathsf{OTP} takes a randomized function f and outputs a sampling program P that one-time implements f . This means that for any input x\in\mathcal{X} , the distribution of P(x) is statistically close to f(x) . Finally \mathsf{OTP} is best-possible if \mathsf{OTP}(f) can be simulated by any program implementing f for which |f|=|P| . Randomized Functions. A randomized function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} takes an input x\in\mathcal{X} , samples randomness r\overset{\$}{\leftarrow}\mathcal{R} and outputs y=f(x;r)\in\mathcal{Y} . Let f(x) be the distribution over y -values that results from this procedure. By considering f as a circuit description of itself, f is computable in time \mathsf{poly}\left(|f|\right) , where |f| is its description length. Let \mathcal{F} be a set of randomized functions, and for each \lambda\in\mathbb{N} , let \mathcal{F}_{\lambda} be the set of all functions in \mathcal{F} with description length \lambda . Sampling Programs. Given a randomized function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} , a sampling program P that implements f is a quantum program P=(\rho,\mathsf{Eval}) comprising a (possibly mixed) quantum state \rho and a (possibly oracle-aided) quantum unitary circuit \mathsf{Eval} . We write |P| for its description length. P can be evaluated on any x\in\mathcal{X} by computing \mathsf{Eval}(\ket{x}\bra{x}_{\mathscr{X}}\otimes\ket{0}\bra{0}_{\mathscr{Y}}\otimes\rho_{\mathscr{P}}) and measuring the \mathscr{Y} register to obtain output y . Let P(x) refer to the distribution over y -values that results from this evaluation procedure. Definition 10 (Correctness of Sampling Programs) . Let \mu(\lambda) be a negligible function. Given a randomized function f\in\mathcal{F}_{\lambda} and a sampling program P , we say that P implements f with error \mu if for every x\in\mathcal{X} , the statistical distance between P(x) and f(x) is \leq\mu(\lambda) . Our notion of correctness is really a notion of one-time correctness. It says that the first time the program is evaluated, it will sample from approximately the desired distribution. However, measuring the output of the program may destroy the program state \rho , so there is no guarantee that the second evaluation of the program will be correct. One-Time Program Compilers. A one-time program compiler \mathsf{OTP} takes a randomized function f and outputs a sampling program P that implements f . The compiler is best-possible if \mathsf{OTP}(f) can be simulated by any program implementing f for which |f|=|P| . Definition 11 (One-Time Program Compiler) . Let \mathcal{F} be a family of randomized functions. A one-time program compiler for \mathcal{F} is a QPT machine \mathsf{OTP} that takes as input the description of a function f\in\mathcal{F} and outputs a sampling program P=\mathsf{OTP}(f) . For correctness, we require that there is a negligible function \mu(\lambda) such that for any \lambda\in\mathbb{N} and any f\in\mathcal{F}_{\lambda} , \mathsf{OTP}(f) implements f with error \mu(\lambda) . The following definition says that a one-time program compiler is best-possible if \mathsf{OTP}(f) can be simulated given any program P that implements f with low error. We consider two notions of equivalence: perfect equivalence requires P to implement f with 0 error, and statistical equivalence allows P to implement f with a non-zero, but still negligible, error. Definition 12 (Best-Possible One-Time Program Compiler) . Let \mathcal{F} be a family of randomized functions, and let \mathsf{OTP}^{*} be a one-time program compiler for \cal{F} . \mathsf{OTP}^{*} is a best-possible one-time program compiler for \cal{F} with statistical/perfect equivalence if for every QPT adversary \mathcal{A} and any function \mu(\lambda) that is (respectively) negligible/identically zero, there is a QPT simulator \mathsf{Sim} and a negligible function \nu(\lambda) such that for any \lambda\in\mathbb{N} , any f\in\mathcal{F}_{\lambda} , any sampling program P that implements f with error \mu(\lambda) and satisfies |P|=|f| , and any QPT distinguisher D , \displaystyle\left|\Pr\left[1\leftarrow D(1^{\lambda},\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f)))\right]-\Pr\left[1\leftarrow D(1^{\lambda},\mathsf{Sim}(1^{\lambda},P))\right]\right|\leq\nu(\lambda). Note that the distinguisher D can implicitly depend on f because D is chosen after f . In the study of best-possible obfuscation, [ 21 ] requires perfect equivalence. In other words, the simulator only needs to work correctly when P implements f with 0 error. Statistical equivalence allows \mu to be a non-zero, but negligible, function. Requiring statistical equivalence yields a stronger notion of security. Now the simulator must work correctly even if P does not perfectly implement f . We can rule out both notions of best-possible OTP compilers. Ruling out the notion that requires statistical equivalence ( definition 12 ) is impossible assumes the hardness of LWE; ruling out the notion that requires perfect equivalence is impossible assumes the pseudorandomness of group actions. 3.2 Impossibility Result We show that there exists a family of functions for which there is no best-possible one-time program compiler. Theorem 7 . Assuming the post-quantum hardness of LWE for the parameter choices given in Theorem 12 , there exists a function family \mathcal{F} for which there is no best-possible one-time program compiler with statistical equivalence ( Definition 12 ). Assuming the weak pseudorandomness of group actions ( 1 ), there exists a function family \mathcal{F} for which there is no best-possible one-time program compiler with perfect equivalence ( Definition 12 ). Proof. We can construct statistically lossy PKE from LWE ( Theorem 13 ). Then Theorem 8 below says that statistically lossy PKE rules out a best-possible one-time program compiler with statistical equivalence. Next, we can construct perfectly lossy PKE from group actions ( Theorem 14 ). Theorem 8 below says that perfectly lossy PKE rules out a best-possible one-time program compiler with perfect equivalence. ∎ Theorem 8 . Assuming the existence of statistically/perfectly lossy PKE scheme ( Definition 22 ), there exists a function family \mathcal{F} for which there is no best-possible one-time program compiler with statistical/perfect equivalence ( Definition 12 ). This relativizes to all unitary oracles. The rest of Section 3.2 is devoted to proving Theorem 8 . The proof has the following roadmap. The function family \mathcal{F} is the union of three other families \mathcal{C},\mathcal{D},\mathcal{E} . \mathcal{C} contains constant functions; \mathcal{E} mostly contains injective functions; \mathcal{D} contains functions that are, in certain settings, indistinguishable from both \mathcal{C} and \mathcal{E} . Then we show that there exists a QPT adversary \mathcal{A} that can easily distinguish OTPs for functions in \mathcal{E} from OTPs for functions in \mathcal{C} . Essentially, \mathcal{A} checks whether evaluating the program entangles the input and output registers. Injective functions do create entanglement, whereas constant functions do not. For functions in \mathcal{D} , \mathcal{A} has contradictory behavior. Functions sampled from \mathcal{D} should be computationally indistinguishable from those in \mathcal{E} . However, we also show that a mixture over functions in \mathcal{C} actually implements a function in \mathcal{D} . This will imply our contradiction. The function family \mathcal{F} Assuming the post-quantum hardness of LWE, Theorem 13 says that there exists a statistically lossy PKE scheme ( Definition 22 ) comprising the functions (\mathsf{Gen},\mathsf{GenPK},\mathsf{Enc},\mathsf{Dec}) with message space \mathcal{M}=\{0,1\}^{\lambda} . Let \mathcal{X}=\mathcal{M} and \mathcal{R}=\mathcal{R}_{\mathsf{Enc}} . For a given \lambda\in\mathbb{N} , let us define three function families \mathcal{C}_{\lambda},\mathcal{D}_{\lambda},\mathcal{E}_{\lambda} as follows. Any differences among the families are highlighted in red or blue . • \mathcal{C}_{\lambda} : Each function c\in\mathcal{C}_{\lambda} is a constant function described by a \mathsf{\vphantom{p}pk} in the support of \mathsf{GenPK}(1^{\lambda},{\color[rgb]{0,0,1}\mathsf{lossy}}) and a string r_{\mathsf{Enc}}\in\mathcal{R}_{\mathsf{Enc}} . The function ignores its inputs (x,r) and outputs y=\mathsf{Enc}(\mathsf{\vphantom{p}pk},{\color[rgb]{1,0,0}0^{\lambda}};{\color[rgb]{1,0,0}r_{\mathsf{Enc}}}) . • \mathcal{D}_{\lambda} : Each function d\in\mathcal{D}_{\lambda} is described by a \mathsf{\vphantom{p}pk} in the support of \mathsf{GenPK}(1^{\lambda},{\color[rgb]{0,0,1}\mathsf{lossy}}) . The function takes inputs (x,r) and computes y=\mathsf{Enc}(\mathsf{\vphantom{p}pk},{\color[rgb]{0,0,1}x};{\color[rgb]{0,0,1}r}) . • \mathcal{E}_{\lambda} : Each function e\in\mathcal{E}_{\lambda} is described by a \mathsf{\vphantom{p}pk} in the support of \mathsf{GenPK}(1^{\lambda},{\color[rgb]{1,0,0}\mathsf{inj}}) . The function takes inputs (x,r) and computes y=\mathsf{Enc}(\mathsf{\vphantom{p}pk},{\color[rgb]{0,0,1}x};{\color[rgb]{0,0,1}r}) . Let \mathcal{F}_{\lambda}=\mathcal{C}_{\lambda}\cup\mathcal{D}_{\lambda}\cup\mathcal{E}_{\lambda} , and let \mathcal{F}=\bigcup_{\lambda\in\mathbb{N}}\mathcal{F}_{\lambda} . Let \mathcal{C},\mathcal{D},\mathcal{E} be defined analogously to \mathcal{F} . Next, let us require that all functions in \mathcal{F}_{\lambda} have the same description length as each other. We can pad the descriptions with 0 s to ensure this is the case. Finally, assume toward contradiction that there exists a one-time program compiler \mathsf{OTP}^{*} that is best-possible for \mathcal{F} with statistical/perfect equivalence. The adversary \mathcal{A} Next, let us define a quantum algorithm \mathcal{A} that tests whether querying a given sampling program P=(\rho,\mathsf{Eval}) will entangle the input and output registers. \mathcal{A} acts on the query register \mathscr{Q}=\mathscr{X}\times\mathscr{Y} , the program register \mathscr{P} , and two ancilla registers \mathscr{X}^{\prime} and \mathscr{Y}^{\prime} , which will store inputs and outputs respectively. 1. Initialization: \mathcal{A} prepares an EPR pair of input values on the \mathscr{X} and \mathscr{X}^{\prime} registers. Let us call this state \ket{++} . \ket{++}:=\frac{1}{\sqrt{2^{\lambda}}}\sum_{x\in\{0,1\}^{\lambda}}\ket{x}_{\mathscr{X}}\otimes\ket{x}_{\mathscr{X}^{\prime}} The \mathscr{P} register contains the program state \rho , and \mathscr{Y}\times\mathscr{Y}^{\prime} contains \ket{0}\otimes\ket{0} . 2. \mathcal{A} evaluates the program by applying \mathsf{Eval} to the \mathscr{X}\times\mathscr{Y}\times\mathscr{P} registers. 3. \mathcal{A} CNOTs the value on the \mathscr{Y} register onto the \mathscr{Y}^{\prime} register. 4. \mathcal{A} uncomputes step 2 by applying \mathsf{Eval}^{\dagger} to the \mathscr{X}\times\mathscr{Y}\times\mathscr{P} registers. 5. \mathcal{A} checks whether the \mathscr{X}\times\mathscr{X}^{\prime} registers are still in the original state \ket{++} . If so, \mathcal{A} outputs 0 . If not, \mathcal{A} outputs 1 . Intuitively, if P outputs the same value for every input, then the \mathscr{X}\times\mathscr{X}^{\prime} registers are returned to their original state by the end of \mathcal{A} ’s execution, so \mathcal{A} outputs 0 . If P is injective, then \mathscr{X}^{\prime} is entangled with \mathscr{Y}^{\prime} , so the \mathscr{X}^{\prime}\times\mathscr{X} registers will be far from the state \ket{++} . Then \mathcal{A} will output 1 with high probability. \mathcal{A} usually outputs 0 for family \mathcal{C} . With overwhelming probability, \mathcal{A} outputs 0 for function sequences in \mathcal{C} ( Lemma 4 ). This is because they describe constant function, which do not entangle the input with the output. Lemma 4 . There is a negligible function \mathsf{negl}\left(\lambda\right) such that for any \lambda\in\mathbb{N} and any c\in\mathcal{C}_{\lambda} , \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(c))\to 1]\leq\mathsf{negl}\left(\lambda\right) Proof. c is described by (\mathsf{\vphantom{p}pk},r_{\mathsf{Enc}}) , and for any input x\in\{0,1\}^{\lambda} , c outputs y_{c}:=\mathsf{Enc}(\mathsf{\vphantom{p}pk},0^{\lambda};r_{\mathsf{Enc}}) . Next, since \mathsf{OTP}^{*} is a one-time program compiler for \mathcal{F} ( definition 11 ), \mathsf{OTP}^{*}(c) implements c with negligible error. Formally, we say there is a negligible function \mu(\lambda) such that for any \lambda\in\mathbb{N} , any c\in\mathcal{C}_{\lambda} , and any x\in\{0,1\}^{\lambda} , when \mathsf{OTP}^{*}(c) is evaluated on x , it outputs y_{c} with probability \geq 1-\mu(\lambda) . After step 2 of \mathcal{A} (which evaluates the program), let us condition on the event that \mathscr{Y} contains y_{c} . This event occurs with overwhelming probability, so conditioning on this event changes the state of the system and the probability that \mathcal{A} outputs 1 by negligible amounts. Then step 3 copies the value y_{c} over to the \mathscr{Y}^{\prime} register. Now we can trace out (forget about) the \mathscr{Y}^{\prime} register. Step 3 does not change the state on the remaining registers \mathscr{X}^{\prime}\times\mathscr{X}\times\mathscr{Y}\times\mathscr{P} because the value copied to \mathscr{Y}^{\prime} is deterministic. Step 4 uncomputes step 2 and returns the state of \mathscr{X}^{\prime}\times\mathscr{X}\times\mathscr{Y}\times\mathscr{P} to be negligibly close to their initial state. Step 5 checks whether the state on \mathscr{X}^{\prime}\times\mathscr{X} is the same as the initial state \ket{++} . This check will accept with overwhelming probability because the state on \mathscr{X}^{\prime}\times\mathscr{X} is negligibly close to the initial state. Then \mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(c)) outputs 0 with overwhelming probability and 1 with negligible probability. ∎ \mathcal{A} usually outputs 1 for family \mathcal{E} . With overwhelming probability, \mathcal{A} outputs 1 for functions sampled from \mathcal{E} ( Lemma 5 ). This is because with overwhelming probability, the function we sample is injective, so it will entangle the input with the output. Lemma 5 . For any given \lambda\in\mathbb{N} , let e\in\mathcal{E}_{\lambda} be chosen by sampling a key \mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{inj}) and setting e=\mathsf{Enc}(\mathsf{\vphantom{p}pk},\cdot;\cdot) . Next, there is a negligible function \mathsf{negl}\left(\lambda\right) such that over the randomness of sampling e and the randomness of \mathcal{A} and \mathsf{OTP}^{*} , \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(e))\to 1]\geq 1-\mathsf{negl}\left(\lambda\right) Proof. For any x\in\{0,1\}^{\lambda} , let \mathcal{Y}_{x} comprise all y -values in the support of e(x) . With overwhelming probability over the sampling of \mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{inj}) , e is injective, meaning the sets \{\mathcal{Y}_{x}\}_{x\in\{0,1\}^{\lambda}} are disjoint. This follows from the correctness property of lossy PKE ( Definition 22 ). Next, since \mathsf{OTP}^{*} is a one-time program compiler for \mathcal{F} ( definition 11 ), \mathsf{OTP}^{*}(e) implements e with negligible error. That means there exists a negligible function \mu(\lambda) such that for any \lambda\in\mathbb{N} , any injective e\in\mathcal{E}_{\lambda} , and any x\in\{0,1\}^{\lambda} , when \mathsf{OTP}^{*}(e) is evaluated on x , it outputs a value in \mathcal{Y}_{x} with probability \geq 1-\mu(\lambda) . Let us step through the execution of \mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(e)) and condition on the event that e is injective. After step 2 of \mathcal{A} (which evaluates the program), let us condition on the event that the \mathscr{X}^{\prime}\times\mathscr{Y} registers contain values (x,y) such that y\in\mathcal{Y}_{x} . This event occurs with overwhelming probability because \mathcal{X}^{\prime} contains the value x that was inputted to \mathsf{OTP}^{*}(e) , and \mathcal{Y} contains the output of \mathsf{OTP}^{*}(e) . When we condition on this event, we change the state of the system and the probability that \mathcal{A} outputs 1 by negligible amounts. Step 3 CNOTs the value on the \mathscr{Y} register onto the \mathscr{Y}^{\prime} register. At the end of this step, the \mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} registers contain values (x,y) such that y\in\mathcal{Y}_{x} . Step 4 acts only on the \mathscr{X}\times\mathscr{Y}\times\mathscr{P} registers and does not touch the \mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} registers. After this step, it is still true that \mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} contain values (x,y) such that y\in\mathcal{Y}_{x} . Step 5 checks whether the \mathscr{X}\times\mathscr{X}^{\prime} registers are in the state \ket{++} . Let \Pi_{++} be the corresponding projector acting on \mathscr{X}\times\mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} : \displaystyle\Pi_{++} \displaystyle:=\ket{++}\bra{++}_{\mathscr{X}\times\mathscr{X}^{\prime}}\otimes\mathbb{I}_{\mathscr{Y}^{\prime}} \displaystyle=\frac{1}{2^{\lambda}}\sum_{x,x^{\prime}}\ket{x}\bra{x^{\prime}}_{\mathscr{X}}\otimes\ket{x}\bra{x^{\prime}}_{\mathscr{X}^{\prime}}\otimes\mathbb{I}_{\mathscr{Y}^{\prime}} Next, let \Pi_{\mathsf{inj}} be a projector that acts on \mathscr{X}\times\mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} and projects onto all states in which \mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} contain values (x,y) such that y\in\mathcal{Y}_{x} : \Pi_{\mathsf{inj}}=\sum_{x}\sum_{y\in\mathcal{Y}_{x}}\mathbb{I}_{\mathscr{X}}\otimes\ket{x}\bra{x}_{\mathscr{X}^{\prime}}\otimes\ket{y}\bra{y}_{\mathscr{Y}^{\prime}} Let \rho be the state of the system at the start of step 5 on the \mathscr{X}\times\mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} registers. We know that \displaystyle\rho \displaystyle=\Pi_{\mathsf{inj}}\rho\Pi_{\mathsf{inj}} because the \mathscr{X}^{\prime}\times\mathscr{Y}^{\prime} registers of \rho only contain values (x,y) such that y\in\mathcal{Y}_{x} . Next, \displaystyle\Pr[\mathcal{A}\to 0] \displaystyle=\mathsf{Tr}\left[\Pi_{++}\rho\right] \displaystyle=\mathsf{Tr}\left[\Pi_{++}\left(\Pi_{\mathsf{inj}}\rho\Pi_{\mathsf{inj}}\right)\right] \displaystyle=\mathsf{Tr}\left[\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}}\cdot\rho\right] \displaystyle\leq\|\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}}\| Next, \displaystyle\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}} \displaystyle=\left(\sum_{x}\sum_{y\in\mathcal{Y}_{x}}\mathbb{I}\otimes\ket{x}\bra{x}\otimes\ket{y}\bra{y}\right)\cdot\left(\frac{1}{2^{\lambda}}\sum_{x^{\prime\prime},x^{\prime\prime\prime}}\ket{x^{\prime\prime}}\bra{x^{\prime\prime\prime}}\otimes\ket{x^{\prime\prime}}\bra{x^{\prime\prime\prime}}\otimes\mathbb{I}\right) \displaystyle\quad\quad\quad\cdot\left(\sum_{x^{\prime}}\sum_{y^{\prime}\in\mathcal{Y}_{x^{\prime}}}\mathbb{I}\otimes\ket{x^{\prime}}\bra{x^{\prime}}\otimes\ket{y^{\prime}}\bra{y^{\prime}}\right) \displaystyle=\frac{1}{2^{\lambda}}\cdot\sum_{x,x^{\prime},x^{\prime\prime},x^{\prime\prime\prime}}\sum_{y\in\mathcal{Y}_{x}}\sum_{y^{\prime}\in\mathcal{Y}_{x^{\prime}}}\left(\mathbb{I}\cdot\ket{x^{\prime\prime}}\bra{x^{\prime\prime\prime}}\cdot\mathbb{I}\right)_{\mathscr{X}} \displaystyle\quad\quad\quad\otimes\left(\ket{x}\bra{x}\ket{x^{\prime\prime}}\bra{x^{\prime\prime\prime}}\ket{x^{\prime}}\bra{x^{\prime}}\right)_{\mathscr{X}^{\prime}}\otimes\left(\ket{y}\bra{y}\cdot\mathbb{I}\cdot\ket{y^{\prime}}\bra{y^{\prime}}\right)_{\mathscr{Y}^{\prime}} \displaystyle=\frac{1}{2^{\lambda}}\cdot\sum_{x,x^{\prime}}\sum_{y\in\mathcal{Y}_{x}\cap\mathcal{Y}_{x^{\prime}}}\ket{x}\bra{x^{\prime}}\otimes\ket{x}\bra{x^{\prime}}\otimes\ket{y}\bra{y} \displaystyle=\frac{1}{2^{\lambda}}\cdot\sum_{x}\sum_{y\in\mathcal{Y}_{x}}\ket{x}\bra{x}\otimes\ket{x}\bra{x}\otimes\ket{y}\bra{y} We used the fact that \mathcal{Y}_{x}\cap\mathcal{Y}_{x^{\prime}}=\emptyset if x\neq x^{\prime} . Continuing on, \displaystyle\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}} \displaystyle=\frac{1}{2^{\lambda}}\cdot\sum_{x}\sum_{y\in\mathcal{Y}_{x}}\ket{x,x,y}\bra{x,x,y} \displaystyle\|\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}}\| \displaystyle=\frac{1}{2^{\lambda}} \displaystyle=\mathsf{negl}\left(\lambda\right) \displaystyle\Pr[\mathcal{A}\to 0] \displaystyle\leq\|\Pi_{\mathsf{inj}}\cdot\Pi_{++}\cdot\Pi_{\mathsf{inj}}\| \displaystyle=\mathsf{negl}\left(\lambda\right) \displaystyle\Pr[\mathcal{A}\to 1] \displaystyle\geq 1-\mathsf{negl}\left(\lambda\right) ∎ \mathcal{A} has contradictory behavior for family \mathcal{D} . How likely is \mathcal{A} to output 1 for functions sampled from \mathcal{D} ? On one hand, we can show that \mathcal{A} will output 1 with overwhelming probability ( Lemma 6 ). This is because functions sampled from \mathcal{D} are indistinguishable from functions sampled from \mathcal{E} , so \mathcal{A} ’s behavior should be similar for these two families. On the other hand, we can show that \mathcal{A} outputs 0 with overwhelming probability ( Lemma 7 ). This is because d can be implemented by a mixture over functions in \mathcal{C} . The simulator, given this mixture, will output 0 with overwhelming probability. That implies that \mathcal{A} , given \mathsf{OTP}^{*}(d) , will also output 0 with overwhelming probability. We’ve reached a contradiction, so in fact, the family \mathcal{F} does not have a best-possible one-time program compiler. For any given \lambda\in\mathbb{N} , let d\in\mathcal{D}_{\lambda} be chosen by sampling a key \mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{lossy}) and setting d=\mathsf{Enc}(\mathsf{\vphantom{p}pk},\cdot;\cdot) . Lemma 6 . There is a negligible function \mathsf{negl}\left(\lambda\right) such that over the randomness of sampling d and the randomness of \mathcal{A} and \mathsf{OTP}^{*} , \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(d))\to 1]\geq 1-\mathsf{negl}\left(\lambda\right) Proof. Otherwise, we could use \mathcal{A} and \mathsf{OTP}^{*} to break the indistinguishability of modes property of lossy PKE ( Definition 22 ). This property says that the output distributions of \mathsf{GenPK}(1^{\lambda},\mathsf{inj}) and \mathsf{GenPK}(1^{\lambda},\mathsf{lossy}) are indistinguishable to any QPT adversary. Let us construct a QPT adversary that tries to distinguish these two distributions. Given a \mathsf{\vphantom{p}pk} sampled from either \mathsf{GenPK}(1^{\lambda},\mathsf{inj}) or \mathsf{GenPK}(1^{\lambda},\mathsf{lossy}) , let us define the function f_{\mathsf{\vphantom{p}pk}}(x;r)=\mathsf{Enc}(\mathsf{\vphantom{p}pk},x;r) . If \mathsf{\vphantom{p}pk} is lossy, then f_{\mathsf{\vphantom{p}pk}}\in\mathcal{D}_{\lambda} , and if \mathsf{\vphantom{p}pk} is injective, then f_{\mathsf{\vphantom{p}pk}}\in\mathcal{E}_{\lambda} . Next, let our distinguisher compute \mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}})) and output the result. Since \mathcal{A} and \mathsf{OTP}^{*} are QPT, our distinguisher is QPT as well. For each \mathsf{mode}\in\{\mathsf{inj},\mathsf{lossy}\} , the probability that the distinguisher outputs 1 is: \displaystyle\Pr_{\mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{mode})}[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}}))\to 1] By the indistinguishability of modes, \displaystyle\Big|\Pr_{\mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{inj})}[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}}))\to 1]-\Pr_{\mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{lossy})}[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}}))\to 1]\Big|\leq\mathsf{negl}\left(\lambda\right) Lemma 5 implies that in injective mode, the distinguisher will output 1 with probability \geq 1-\mathsf{negl}\left(\lambda\right)^{\prime} : \displaystyle\Pr_{\mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{inj})}[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}}))\to 1]\geq 1-\mathsf{negl}\left(\lambda\right)^{\prime} Therefore, \displaystyle\Pr_{\mathsf{\vphantom{p}pk}\leftarrow\mathsf{GenPK}(1^{\lambda},\mathsf{lossy})}[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f_{\mathsf{\vphantom{p}pk}}))\to 1]\geq 1-\mathsf{negl}\left(\lambda\right)^{\prime\prime} ∎ Lemma 7 . There is a negligible function \mathsf{negl}\left(\lambda\right) such that over the randomness of sampling d and the randomness of \mathcal{A} and \mathsf{OTP}^{*} , \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(d))\to 1]\leq\mathsf{negl}\left(\lambda\right) Proof. d is described by a \mathsf{\vphantom{p}pk} in the support of \mathsf{GenPK}(1^{\lambda},\mathsf{lossy}) . Note that d(x)=\mathsf{Enc}(\mathsf{\vphantom{p}pk},x;r) for a random r . The statistical/perfect lossiness property of the encryption scheme ( Definition 22 ) implies that there is a negligible/identically zero function \mu(\lambda) such that with overwhelming probability over the sampling of \mathsf{\vphantom{p}pk} , the following is true for every x\in\{0,1\}^{\lambda} : the distributions of \mathsf{Enc}(\mathsf{\vphantom{p}pk},x) and \mathsf{Enc}(\mathsf{\vphantom{p}pk},0^{\lambda}) (over the randomness of \mathsf{Enc} ) are \mu(\lambda) -close in statistical distance. Let us assume from now on that this is the case. Furthermore, for any r\in\mathcal{R}_{\mathsf{Enc}} , (\mathsf{\vphantom{p}pk},r) describe a function in \mathcal{C}_{\lambda} . Let us define some sampling programs that compute functions in \mathcal{C}_{\lambda} and \mathcal{D}_{\lambda} . \displaystyle\text{Let }\rho_{r} \displaystyle=\ket{r}\bra{r} \displaystyle\rho \displaystyle=\frac{1}{\left\lvert\mathcal{R}_{\mathsf{Enc}}\right\rvert}\sum_{r\in\mathcal{R}_{\mathsf{Enc}}}\rho_{r} Next, let \mathsf{Eval}_{\mathsf{\vphantom{p}pk}} be a circuit that maps \ket{x,0,r}\overset{\mathsf{Eval}_{\mathsf{\vphantom{p}pk}}}{\longrightarrow}\ket{x,\mathsf{Enc}(\mathsf{\vphantom{p}pk},0^{\lambda};r),r} Finally, let us define the sampling programs: \displaystyle\text{Let }P_{r} \displaystyle=(\rho_{r},\mathsf{Eval}_{\mathsf{\vphantom{p}pk}}) \displaystyle P \displaystyle=(\rho,\mathsf{Eval}_{\mathsf{\vphantom{p}pk}}) Let the descriptions of P_{r} and P be padded so that |P_{r}| and |P| equal the description length |f| of any function f\in\mathcal{F}_{\lambda} . Claim 1 . For any r\in\mathcal{R}_{\mathsf{Enc}} , P_{r} implements a function in \mathcal{C}_{\lambda} with 0 error. Proof. If we evaluate P_{r} on any input x , the output will be \mathsf{Enc}(\mathsf{\vphantom{p}pk},0^{\lambda};r) . This is exactly the same output distribution as a function c\in\mathcal{C}_{\lambda} . ∎ Claim 2 . P implements d with error \mu . Proof. The program state \rho is a uniform mixture over the values r\in\mathcal{R}_{\mathsf{Enc}} . For any input x , P(x) is distributed as \mathsf{Enc}(\mathsf{\vphantom{p}pk},0^{\lambda};r) for a random r\overset{\$}{\leftarrow}\mathcal{R}_{\mathsf{Enc}} . Additionally, d(x) is distributed as \mathsf{Enc}(\mathsf{\vphantom{p}pk},x;r) for a random r\overset{\$}{\leftarrow}\mathcal{R}_{\mathsf{Enc}} . By the lossiness of the encryption scheme, the distributions of P(x) and d(x) are \mu(\lambda) -close in statistical distance. Therefore, P implements d with error \mu . ∎ Since \mathsf{OTP}^{*} is best-possible for \mathcal{F} with statistical/perfect equivalence ( definition 12 ), there is a QPT simulator \mathsf{Sim} and there is a negligible function \nu(\lambda) such that for any \lambda\in\mathbb{N} , any function f\in\mathcal{F}_{\lambda} , and any sampling program P that implements f with error \mu(\lambda) and satisfies |P|=|f| , the outputs of \mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f)) and \mathsf{Sim}(1^{\lambda},P) are computationally indistinguishable, and in particular: \left\lvert\Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(f))\to 1]-\Pr[\mathsf{Sim}(1^{\lambda},P)\to 1]\right\rvert\leq\nu(\lambda) Lemma 4 says that for any c\in\mathcal{C}_{\lambda} , \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(c))\to 1]=\mathsf{negl}\left(\lambda\right) Then since P_{r} implements c with 0 error, \Pr[\mathsf{Sim}(1^{\lambda},P_{r})\to 1]\leq\mathsf{negl}^{\prime}(\lambda) Next, the quantum part of P is \rho , and it is a mixture over states \{\rho_{r}\}_{r\in\mathcal{R}_{\mathsf{Enc}}} . Then \displaystyle\Pr[\mathsf{Sim}(1^{\lambda},P)\to 1] \displaystyle=\frac{1}{\left\lvert\mathcal{R}_{\mathsf{Enc}}\right\rvert}\sum_{r\in\mathcal{R}_{\mathsf{Enc}}}\Pr[\mathsf{Sim}(1^{\lambda},P_{r})\to 1] \displaystyle\leq\mathsf{negl}^{\prime}(\lambda) Finally, since P implements d with error \mu , \displaystyle\Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(d))\to 1] \displaystyle\leq\Pr[\mathsf{Sim}(1^{\lambda},P)\to 1]+\mathsf{negl}^{\prime\prime}(\lambda) \displaystyle\leq\mathsf{negl}^{\prime\prime\prime}(\lambda) ∎ We have now reached a contradiction. Lemma 7 says that \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(d))\to 1]\leq\mathsf{negl}\left(\lambda\right) but Lemma 6 says that \Pr[\mathcal{A}(1^{\lambda},\mathsf{OTP}^{*}(d))\to 1]\geq 1-\mathsf{negl}\left(\lambda\right) Therefore, the initial assumption must be false, and in fact, there does not exist a one-time program compiler that is best-possible for \mathcal{F} with statistical/perfect equivalence. Relativization The relativization follows from the fact that if we replace the steps in the above proof with steps with access to an (arbitrary unitary) oracle machine where the lossy encryption remains post-quantum secure, the argument still goes through. All the steps are information-theoretic except invoking the computational security of lossy encryption. As shown in the preliminaries, lossy encryption can also be derived from LWE/weak pseudorandomness of group actions in a black-box way where each step can be replaced with an oracle-assisted step as long as the oracle does not help solve LWE/weak pseudorandomness of group actions. 4 SEQ Implies Best-Possible Testable One-Time Security Definition 13 (Testable quantum program) . A quantum program P=(\ket{\psi},\mathsf{Eval}) specified by a pure state \ket{\psi} and a unitary \mathsf{Eval} can be augmented with a reflection unitary 7 7 7 Typically, the reflection oracle is defined as R^{\prime}=I-2|\psi\rangle\langle\psi| , but we adopt a different (but equivalent) definition for convenience. To see why R and R^{\prime} are equivalent, note that R^{\prime} can be implemented by first applying R to \ket{0}\ket{\phi} , applying a \mathsf{Z} gate to the first register, and then applying R again to uncompute the first register. R\ket{b}\ket{\phi} can be implemented as follows: apply H to the first register, then controlled on the first register containing 1 , apply R^{\prime} to the state \ket{\phi} , and finally apply H to the first register again. \displaystyle R=\mathsf{X}\otimes\ket{\psi}\bra{\psi}+I\otimes(I-\ket{\psi}\bra{\psi}) We say that the resulting program P^{\prime}=(\ket{\psi},\mathsf{Eval},R) is testable. A testable one-time program compiler is a one-time program compiler that outputs testable quantum programs. Note that it makes sense only to define a reflection oracle (the test oracle) about a pure state \ket{\psi} . For simplicity, we assume that the reflection unitary R is provided in the form of an oracle, or the classical description of a unitary; rather than a quantum program itself with a quantum auxiliary input, so that it does not degrade over uses. Next we revise and generalize the SEQ definition of [ 24 ] to all quantum functionalities and adopt the name SEQ for this generalized notion. To distinguish from the prior work, we refer to their original, classical version as CSEQ. Intuitively, the SEQ oracle embeds a single effective application of the purified channel into a globally unitary, repeatable interface. Stinespring form and notation. Let \Phi:\mathsf{L}(\mathcal{H}_{Q})\to\mathsf{L}(\mathcal{H}_{Q}) be a quantum channel. Without loss of generality (by padding with dummy qubits if needed), assume the Stinespring dilation has matching input/output dimensions, so we fix a Stinespring unitary U_{\Phi}:\mathcal{H}_{Q}\otimes\mathcal{H}_{P}\to\mathcal{H}_{Q}\otimes\mathcal{H}_{P} with the private register P initialized to \ket{0^{m}}_{P} as expected by the purification. Tracing out the private register yields \Phi on the query register. Definition 14 (The Single Effective Query Oracle (SEQ)) . For a channel \Phi with fixed purification U_{\Phi} as above, the single effective query oracle O^{\mathsf{SEQ}}_{\Phi} acts on a query register \mathcal{Q} and maintains a private register \mathcal{P} and a one-qubit computed flag \mathcal{C} . The registers are initialized to \ket{0^{m}}_{\mathcal{P}}\otimes\ket{0}_{\mathcal{C}} . On each query, the oracle applies the following unitary on (\mathcal{Q},\mathcal{P},\mathcal{C}) : 1. Controlled on \mathcal{C}{=}1 , apply U_{\Phi}^{\dagger} to (\mathcal{Q},\mathcal{P}) . 2. Apply the swap on the subspace spanned by \ket{0}_{\mathcal{C}}\otimes\ket{0^{m}}_{\mathcal{P}} and \ket{1}_{\mathcal{C}}\otimes\ket{0^{m}}_{\mathcal{P}} (and act as the identity on the orthogonal subspace). Equivalently, flip \mathcal{C} controlled on \mathcal{P}{=}\ket{0^{m}} . 3. Controlled on \mathcal{C}{=}1 , apply U_{\Phi} to (\mathcal{Q},\mathcal{P}) . O^{\mathsf{SEQ}}_{\Phi} may also be called O^{\mathsf{SEQ}}_{U_{\Phi}} to make the particular Stinespring dilation U_{\Phi} explicit. It is often unnecessary to write O^{\mathsf{SEQ}}_{U_{\Phi}} , which makes the particular dilation U_{\Phi} explicit, and instead O^{\mathsf{SEQ}}_{\Phi} suffices. Lemma 11 says that any two Stinespring dilations U,U^{\prime} of \Phi will produce indistinguishable oracles O^{\mathsf{SEQ}}_{U} and O^{\mathsf{SEQ}}_{U^{\prime}} . The above makes the SEQ interface unitary-by-construction. Intuitively, the first time we query, Step 1 is inactive, Step 2 flips the computed flag, and Step 3 applies U_{\Phi} . On subsequent queries, Steps 1 and 3 cancel on (\mathcal{Q},\mathcal{P}) , and Step 2 flips the flag only in the \mathcal{P}{=}\ket{0^{m}} subspace; the overall interface remains unitary and well-defined. In fact, we can verify that this unitary exactly maps the well-initialized input to its output and vice versa, while acting as identity on everything else. Definition 15 ( \mathsf{SEQ} -based simulation security for one-time programs) . A one-time program compiler \mathsf{OTP} satisfies \mathsf{SEQ} -based simulation security for a class \mathcal{C} of quantum channels if there exists a q.p.t. simulator \mathsf{Sim} such that for every \Phi\in\mathcal{C} and for every q.p.t. distinguisher D , there exists a negligible function \mathsf{negl}\left(\lambda\right) with \displaystyle\bigl|\Pr\bigl[1\leftarrow D(1^{\lambda},\Phi,\mathsf{OTP}(1^{\lambda},\Phi))\bigr]-\Pr\bigl[1\leftarrow D(1^{\lambda},\Phi,\mathsf{Sim}^{O_{\Phi}^{\mathsf{SEQ}}}(1^{\lambda}))\bigr]\bigr|\leq\mathsf{negl}\left(\lambda\right). As before, giving \Phi to D means that D may depend on \Phi (e.g., via a classical description or black-box evaluation access); this redundancy matches the order of quantifiers. We now define the notion of a best-possible one-time program compiler, which produces one-time programs that are “best-possible” among all programs that implement the same sampling task and are testable. Definition 16 (Best-possible OTP among testable programs) . Let \mathcal{C} be a family of quantum channels. A testable one-time program compiler \mathsf{OTP}^{*} is best-possible among testable programs for \mathcal{C} if there exists a q.p.t. simulator \mathsf{Sim} such that for every \Phi\in\mathcal{C} , for every testable quantum program P that implements \Phi , and for every q.p.t. distinguisher D , \displaystyle\bigl|\Pr\bigl[1\leftarrow D(1^{\lambda},\Phi,\mathsf{OTP}^{*}(1^{\lambda},\Phi))\bigr]-\Pr\bigl[1\leftarrow D(1^{\lambda},\Phi,\mathsf{Sim}(1^{\lambda},P))\bigr]\bigr|\leq\mathsf{negl}\left(\lambda\right). Here, “ P implements \Phi ” means that tracing out P ’s private register after applying \mathsf{Eval} to the program state \ket{\psi} realizes the channel \Phi on the external interface. Theorem 9 . Any one-time program compiler \mathsf{OTP}^{*} satisfying \mathsf{SEQ} security for a class of quantum channels ( Definition 15 ) is a best-possible one-time program compiler among testable programs for that class ( Definition 16 ). Moreover, this implication relativizes to all unitary oracles. Proof. Since \mathsf{OTP}^{*} satisfies \mathsf{SEQ} security, there exists a q.p.t. simulator \mathsf{Sim} such that for every channel \Phi and every q.p.t. distinguisher D , \displaystyle\bigl|\Pr[1\leftarrow D(1^{\lambda},\Phi,\mathsf{OTP}^{*}(1^{\lambda},\Phi))]-\Pr[1\leftarrow D(1^{\lambda},\Phi,\mathsf{Sim}^{O^{\mathsf{SEQ}}_{\Phi}}(1^{\lambda}))]\bigr|\leq\mathsf{negl}\left(\lambda\right). It therefore suffices to show that given any testable implementation P of \Phi , we can simulate oracle access to O^{\mathsf{SEQ}}_{\Phi} using P . Composing \mathsf{Sim} with this wrapper yields the simulator required by Definition 16 . Let P=(\ket{\psi},\mathsf{Eval},R) be a testable quantum program that implements \Phi , where R=\mathsf{X}\otimes\ket{\psi}\bra{\psi}+I\otimes(I-\ket{\psi}\bra{\psi}) acts on a one-qubit flag and the program register. Without loss of generality, we can think about \ket{\psi} padded with zero qubits which are used for the auxiliary wires, and the reflection unitary is extended to also reflect around zeroes for those qubits. The following simulator \mathsf{Sim}^{\prime} takes any such testable program P that implements \Phi and simulates O^{\mathsf{SEQ}}_{\Phi} . Definition 17 (Simulator \mathsf{Sim}^{\prime}(P) for O^{\mathsf{SEQ}}_{\Phi} from a testable program.) . The oracle \mathsf{Sim}^{\prime}(P) maintains internally the program register \mathcal{P} initialized to \ket{\psi} and a one-qubit computed flag \mathcal{C} initialized to \ket{0} . On each query on register \mathcal{Q} , \mathsf{Sim}^{\prime}(P) applies the following unitary on (\mathcal{Q},\mathcal{P},\mathcal{C}) : 1. Controlled on \mathcal{C}{=}1 , apply \mathsf{Eval}^{\dagger} to (\mathcal{Q},\mathcal{P}) , mapping back to the input space of \mathsf{Eval} . 2. Apply the reflection-controlled flip R to (\mathcal{C},\mathcal{P}) , i.e., flip \mathcal{C} iff the program register equals \ket{\psi} . 3. Controlled on \mathcal{C}{=}1 , apply \mathsf{Eval} to (\mathcal{Q},\mathcal{P}) . We now argue that \mathsf{Sim}^{\prime}(P) is perfectly indistinguishable from O^{\mathsf{SEQ}}_{\Phi} . We write \mathcal{A} for the adversary’s private workspace register, which the adversary may initialize and act upon arbitrarily; the oracle’s hidden registers (\mathcal{C},\mathcal{P}) remain inaccessible. Lemma 8 . Let P be any (potentially oracle-aided) 8 8 8 P may query an oracle that maintains a quantum state as long as the reflection oracle correctly reflects around the initial state of the oracle. testable quantum program that implements \Phi . Then oracles for \mathsf{Sim}^{\prime}(P) ( definition 17 ) and O^{\mathsf{SEQ}}_{\Phi} are perfectly indistinguishable after any number of quantum queries. Proof. Let U_{\Phi} be the canonical Stinespring dilation unitary for \Phi . O^{\mathsf{SEQ}}_{\Phi} involves applying U_{\Phi} . We will refer to O^{\mathsf{SEQ}}_{\Phi} as O^{\mathsf{SEQ}}_{U_{\Phi}} to distinguish it from a similar oracle that applies a different unitary. We will show that \mathsf{Sim}^{\prime}(P) is equivalent to O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} , for a particular Stinespring dilation U^{\prime}_{\Phi} of the channel \Phi . Note that the Stinespring dilation needs \mathcal{P} to be initialized to \ket{0^{m}} , whereas \mathsf{Sim}^{\prime}(P) initializes it to \ket{\psi} . We handle this discrepancy by conjugating each step of \mathsf{Sim}^{\prime}(P) with a swap operation that swaps the states \ket{0^{m}} and \ket{\psi} . Let U^{\prime}_{\Phi} be the following unitary: 1. Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . 2. Apply \mathsf{Eval} to (\mathcal{Q},\mathcal{P}) . 3. Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . Lemma 9 . U^{\prime}_{\Phi} is a valid Stinespring dilation of \Phi . Proof. Given a state \rho on the query register \mathcal{Q} , consider the following three procedures for handling the query: 1. Apply channel \Phi to \rho_{\mathcal{Q}} . 2. Apply \mathsf{Eval} to \rho_{\mathcal{Q}}\otimes\ket{\psi}_{\mathcal{P}} and then trace out \mathcal{P} . 3. Apply U^{\prime}_{\Phi} to \rho_{\mathcal{Q}}\otimes\ket{0^{m}}_{\mathcal{P}} and then trace out \mathcal{P} . Procedure 1 is equivalent to procedure 2 because P implements \Phi . Next, procedure 2 is equivalent to procedure 3 because U^{\prime}_{\Phi} maps \ket{0^{m}}_{\mathcal{P}}\to\ket{\psi}_{\mathcal{P}} before applying \mathsf{Eval} . This shows that U^{\prime}_{\Phi} is a Stinespring dilation of \Phi . ∎ Let O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} be the SEQ oracle ( definition 14 ) that uses unitary U^{\prime}_{\Phi} instead of U_{\Phi} . Lemma 10 . O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} and \mathsf{Sim}^{\prime}(P) are perfectly indistinguishable after any number of quantum queries. Proof. Let’s consider the following hybrids, which transform O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} to \mathsf{Sim}^{\prime}(P) : Hybrid 1 – O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} – Start with state \ket{0}_{\mathcal{C}}\ket{0^{m}}_{\mathcal{P}} and handle each query as follows: 1. Controlled on \mathcal{C}{=}1 , apply {U^{\prime}_{\Phi}}^{\dagger} as follows: (a) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . (b) Apply \mathsf{Eval}^{\dagger} to (\mathcal{Q},\mathcal{P}) . (c) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . 2. Controlled on \mathcal{P}{=}\ket{0^{m}} , flip \mathcal{C} . 3. Controlled on \mathcal{C}{=}1 , apply U^{\prime}_{\Phi} as follows: (a) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . (b) Apply \mathsf{Eval} to (\mathcal{Q},\mathcal{P}) . (c) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . Hybrid 2 : Start with state \ket{0}_{\mathcal{C}}\ket{0^{m}}_{\mathcal{P}} and handle each query as follows: 1. Controlled on \mathcal{C}{=}1 : (a) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . (b) Apply \mathsf{Eval}^{\dagger} to (\mathcal{Q},\mathcal{P}) . (c) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . 2. (a) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . (b) Controlled on \mathcal{P}{=}{\color[rgb]{1,0,0}\ket{\psi}} , flip \mathcal{C} . (c) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . 3. Controlled on \mathcal{C}{=}1 : (a) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . (b) Apply \mathsf{Eval} to (\mathcal{Q},\mathcal{P}) . (c) Swap \ket{0^{m}}_{\mathcal{P}} and \ket{\psi}_{\mathcal{P}} . Hybrids 1 and 2 are equivalent. The only difference is step 2 . In hybrid 1, we control on \mathcal{P}=\ket{0^{m}} . In hybrid 2, we swap \ket{0^{m}} with \ket{\psi} and control on \mathcal{P}=\ket{\psi} . These procedures implement the same operation. Hybrid 3 – \mathsf{Sim}^{\prime}(P) – Start with state \ket{0}_{\mathcal{C}}{\color[rgb]{1,0,0}\ket{\psi}_{\mathcal{P}}} and handle each query as follows: 1. Controlled on \mathcal{C}{=}1 , apply \mathsf{Eval}^{\dagger} to (\mathcal{Q},\mathcal{P}) . 2. Controlled on \mathcal{P}{=}\ket{\psi} , flip \mathcal{C} . 3. Controlled on \mathcal{C}{=}1 , apply \mathsf{Eval} to (\mathcal{Q},\mathcal{P}) . The difference between hybrids 2 and 3 is that in hybrid 3, we have omitted all the swap operations (the steps that swap \ket{0^{m}} and \ket{\psi} ), and the initial state of \mathcal{P} is \ket{\psi} , not \ket{0^{m}} . We will argue that hybrids 2 and 3 are perfectly indistinguishable. Given any user that submits a sequence of queries to the oracle in hybrids 2 or 3, we can view their sequence of queries as a sequence of invocations of steps 1 , 2 , and 3 . We will prove the following invariant: at the start or end of any step in the sequence, the current state of the system in hybrid 2 can be mapped to the current state of the system in hybrid 3 by applying the swap operation to \mathcal{P} , which swaps \ket{0^{m}} and \ket{\psi} . First, before the first step of the first query, the state of the oracle’s registers are \ket{0}_{\mathcal{C}}\ket{0^{m}}_{\mathcal{P}} in hybrid 2 and \ket{0}_{\mathcal{C}}\ket{\psi}_{\mathcal{P}} in hybrid 3, so the invariant is satisfied at this point. Second, let us assume the invariant is satisfied at the start of some invocation of step 1 , and let’s step through the execution of step 1 to show that the invariant is satisfied at the end. If \mathcal{C}=0 , then step 1 acts as the identity in both hybrids, so the invarinat will be satisfied at the end. Next, let’s consider the case where \mathcal{C}=1 . In hybrid 2, step 1 applies the swap operation, which transforms the state to match the initial state of hybrid 3. Then it applies \mathsf{Eval}^{\dagger} , as is done in hybrid 3. At this point, the state is the same in the two hybrids. Finally, in hybrid 2, we apply the swap operation again so the final state in hybrid 2 could be transformed into the final state in hybrid 3 by another swap operation. Therefore the invariant is satisfied at the end of step 1. Third, let us assume the invariant is satisfied at the start of some invocation of step 2 or 3 . We can show that the invariant is still satisfied at the end of this step using similar reasoning to our argument for step 1. In conclusion, before or after any step of any query, the current state of the system in hybrid 2 can be mapped to the current state of the system in hybrid 3 by applying a swap operation to \mathcal{P} . The swap operation is applied to an internal register of the oracle, which is not part of the user’s view. If a computationally unbounded user makes an unbounded number of queries to either the hybrid 2 or hybrid 3 oracle and outputs a final state on their registers, this state will be the same once we trace out \mathcal{P} . Therefore, hybrids 2 and 3 are perfectly indistinguishable. In total, we have shown that O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} and \mathsf{Sim}^{\prime}(P) are perfectly indistinguishable after any number of queries. ∎ It just remains to show that O^{\mathsf{SEQ}}_{U_{\Phi}} and O^{\mathsf{SEQ}}_{U^{\prime}_{\Phi}} are perfectly indistinguishable. This is implied by the following lemma. Lemma 11 (Self-adjoint implementations hide dilation differences) . Let U,U^{\prime} be two Stinespring dilations of \Phi with the same ancilla register \mathcal{P} initialized to \ket{0^{m}}_{\mathcal{P}} . Then the oracles O^{\mathsf{SEQ}}_{U} and O^{\mathsf{SEQ}}_{U^{\prime}} ( definition 14 ) are perfectly indistinguishable after any number of queries. Proof. Let P_{0}:=I_{\mathcal{Q}}\otimes\ket{0^{m}}\bra{0^{m}}_{\mathcal{P}} and P_{\perp}:=I-P_{0} . Writing O^{\mathsf{SEQ}}_{U} in 2\times 2 block form on \mathcal{C} using the identities \displaystyle\mathrm{C}_{\mathcal{C}}\!U=\begin{pmatrix}I&0\\ 0&U\end{pmatrix},\quad\mathrm{C}_{\mathcal{C}}\!U^{\dagger}=\begin{pmatrix}I&0\\ 0&U^{\dagger}\end{pmatrix},\quad\mathrm{C}_{\mathcal{P}{=}\ket{0^{m}}}\!\mathrm{NOT}_{\mathcal{C}}=\begin{pmatrix}P_{\perp}&P_{0}\\ P_{0}&P_{\perp}\end{pmatrix}, where we use the shorthand \mathrm{C}_{\mathcal{P}{=}\ket{0^{m}}}\!\mathrm{NOT}_{\mathcal{C}} to denote the controlled-NOT on target \mathcal{C} with control projector P_{0} on \mathcal{P} , namely \mathrm{C}_{\mathcal{P}{=}\ket{0^{m}}}\!\mathrm{NOT}_{\mathcal{C}}:=\mathsf{X}_{\mathcal{C}}\otimes P_{0}+I_{\mathcal{C}}\otimes P_{\perp} . Writing \mathsf{X}_{\mathcal{C}}=\ket{0}\bra{0}{1}_{\mathcal{C}}+\ket{1}\bra{1}{0}_{\mathcal{C}} and I_{\mathcal{C}}=\ket{0}\bra{0}{0}_{\mathcal{C}}+\ket{1}\bra{1}{1}_{\mathcal{C}} , the resulting 2\times 2 block form on \mathcal{C} is precisely \begin{pmatrix}P_{\perp}&P_{0}\\ P_{0}&P_{\perp}\end{pmatrix} . We obtain \displaystyle O^{\mathsf{SEQ}}_{U}=\begin{pmatrix}P_{\perp}&P_{0}U^{\dagger}\\ UP_{0}&UP_{\perp}U^{\dagger}\end{pmatrix}_{\mathcal{C};(\mathcal{P},\mathcal{Q})}. (1) By Stinespring uniqueness (for equal-dimension ancillae), there exists a unitary V_{\mathcal{P}} on \mathcal{P} such that U^{\prime}=(I_{\mathcal{Q}}\otimes V_{\mathcal{P}})\cdot U . Let W:=I_{\mathcal{Q}}\otimes V_{\mathcal{P}} and define a unitary on (\mathcal{C},\mathcal{P},\mathcal{Q}) that is controlled by \mathcal{C} : \displaystyle S:=\ket{0}\bra{0}_{\mathcal{C}}\otimes I_{\mathcal{P}\mathcal{Q}}+\ket{1}\bra{1}_{\mathcal{C}}\otimes W\,. Then, using the block form from ( 1 ), \displaystyle S\,O^{\mathsf{SEQ}}_{U}\,S^{\dagger} \displaystyle=\begin{pmatrix}I&0\\ 0&W\end{pmatrix}\begin{pmatrix}P_{\perp}&P_{0}U^{\dagger}\\ UP_{0}&UP_{\perp}U^{\dagger}\end{pmatrix}\begin{pmatrix}I&0\\ 0&W^{\dagger}\end{pmatrix} \displaystyle=\begin{pmatrix}P_{\perp}&P_{0}U^{\dagger}W^{\dagger}\\ WUP_{0}&WUP_{\perp}U^{\dagger}W^{\dagger}\end{pmatrix} \displaystyle=\begin{pmatrix}P_{\perp}&P_{0}(U^{\prime})^{\dagger}\\ U^{\prime}P_{0}&U^{\prime}P_{\perp}(U^{\prime})^{\dagger}\end{pmatrix}=O^{\mathsf{SEQ}}_{U^{\prime}}\,. Thus O^{\mathsf{SEQ}}_{U^{\prime}}=SO^{\mathsf{SEQ}}_{U}S^{\dagger} with S acting only on the hidden registers (\mathcal{C},\mathcal{P}) and trivially on (\mathcal{A},\mathcal{Q}) . Consider any t -query adversary that interleaves local operations V_{i} on (\mathcal{A},\mathcal{Q}) with oracle calls. Writing O_{U}^{\mathrm{op}}:=O^{\mathsf{SEQ}}_{U}\otimes I_{\mathcal{A}} and similarly for O^{\mathsf{SEQ}}_{U^{\prime}} , we have \displaystyle\mathcal{U}_{U^{\prime}} \displaystyle=V_{t}O_{U^{\prime}}^{\mathrm{op}}\cdots V_{1}O_{U^{\prime}}^{\mathrm{op}}=V_{t}(SO_{U}^{\mathrm{op}}S^{\dagger})\cdots V_{1}(SO_{U}^{\mathrm{op}}S^{\dagger}) \displaystyle=S\,\bigl(V_{t}O_{U}^{\mathrm{op}}\cdots V_{1}O_{U}^{\mathrm{op}}\bigr)\,S^{\dagger}=S\,\mathcal{U}_{U}\,S^{\dagger}, since S acts only on (\mathcal{C},\mathcal{P}) and commutes with each V_{i} (which acts on (\mathcal{A},\mathcal{Q}) ). The joint initial state is \ket{\psi}_{\mathcal{A}}\ket{0}_{\mathcal{C}}\ket{0^{m}}_{\mathcal{P}}\ket{\phi}_{\mathcal{Q}} , and S fixes it because S acts as identity on the \mathcal{C}{=}0 subspace. Therefore \mathcal{U}_{U^{\prime}}\ket{\mathrm{init}}=S\,\mathcal{U}_{U}\ket{\mathrm{init}} . Tracing out the inaccessible registers (\mathcal{C},\mathcal{P}) yields identical reduced states on (\mathcal{A},\mathcal{Q}) in the two worlds (partial trace is invariant under local conjugation on the traced-out subsystem). Hence no test on (\mathcal{A},\mathcal{Q}) can distinguish O^{\mathsf{SEQ}}_{U} from O^{\mathsf{SEQ}}_{U^{\prime}} , even across multiple queries. ∎ Lemmas 9 , 10 and 11 imply that oracle access to \mathsf{Sim}^{\prime}(P) and O^{\mathsf{SEQ}}_{\Phi} are perfectly indistinguishable. ∎ Giving the \mathsf{SEQ} -security simulator \mathsf{Sim} query access to \mathsf{Sim}^{\prime}(P) , instead of O^{\mathsf{SEQ}}_{\Phi} , completes the proof of the theorem. Relativization to unitary oracles. The construction of \mathsf{Sim}^{\prime}(P) and the indistinguishability argument are black-box. Consequently, if a fixed family of unitary oracles \mathcal{O} is given to all parties, each hybrid and equality above holds verbatim with all machines making identical relative use of \mathcal{O} . The theorem therefore holds relative to \mathcal{O} . ∎ 5 Stateful Quantum State Obfuscation: Towards a Plain Model Construction Now that we have a strong definition for OTPs which makes sense in the plain model, we would like to actually construct it there. For a moment, let us suppose that we had a candidate construction. How would we show that any functionally equivalent program reveals no more information than the candidate? In the classical setting, we can prove that iO is best-possible by using iO to obfuscate the other, allegedly “better” program. However, in the quantum setting, the other program may use a quantum state - so at a minimum we need quantum state iO [ 8 , 17 ] . Further than that, the other program might change its behavior as it is queried – for example by refusing to answer a second query. So it seems that any security proof would need the ability to obfuscate such programs. In this section, we define and investigate the feasibility of quantum state obfuscation for programs which may modify their behavior as they are queried. Definition 18 (Stateful Quantum Programs) . A stateful quantum program is specified by a tuple (U,\ket{\psi}) consisting of a unitary U and an initial state \ket{\psi} contained in register \mathcal{R} . To evaluate a stateful quantum program on a state contained in register \mathcal{Q} , apply U to register (\mathcal{Q},\mathcal{R}) and output register \mathcal{Q} . We define oracle access to P as follows. We initialize an internal register \mathcal{R} with the state \ket{\psi} . A query can be either a forward or inverse query. On a forward query in register \mathcal{Q} , the operation U is performed on registers (\mathcal{Q},\mathcal{R}) , and the query register \mathcal{Q} is returned. On an inverse query in register \mathcal{Q} , the operation U^{-1} is performed on registers (\mathcal{Q},\mathcal{R}) and \mathcal{Q} is returned. For a quantum oracle algorithm A , we denote oracle access to program P as A^{P} . Definition 19 (Functional Equivalence Between Stateful Programs) . Two stateful quantum programs P_{1}=(U_{1},\ket{\psi_{1}}) and P_{2}=(U_{2},\ket{\psi_{2}}) are (s,\varepsilon) -functionally equivalent if for every quantum oracle algorithm A_{s} making at most s oracle queries, the trace distance between the state of A_{s} given P_{1} and its state when its given P_{2} is at most \varepsilon , that is, 9 9 9 Note that the order of quantifiers permits A_{s} to depend on the programs. For example, A_{s} could evaluate P_{1} on a description of U_{1} . \frac{1}{2}\left\|A_{s}^{P_{1}}-A_{s}^{P_{2}}\right\|_{1}\leq\varepsilon If this holds for every s=\mathsf{poly}\left(\lambda\right) , we say they are (\mathsf{poly}\left(\lambda\right),\varepsilon) -functionally equivalent. A stateful quantum program essentially implements a quantum channel with memory . As the program is queried, the state on register \mathcal{R} may evolve, changing the behavior on future queries. As an example, imagine the “counting program” given by \ket{\psi}=\ket{0^{n}} and U which increments the contents of \mathcal{R} by 1 modulo 2^{n} , then classical-copies the result to register \mathcal{Q} . If one were to query this program twice on \ket{0} , the program would return \ket{1} the first time and \ket{2} the second time. 5.1 Stateful Quantum Indistinguishability Obfuscation Using the notion of stateful functional equivalence, the definition of stateful iO is quite natural: if two programs have stateful functional equivalence, they can be indistinguishably obfuscated. Definition 20 (Stateful Quantum Indistinguishability Obfuscation) . A stateful quantum state indistinguishability obfuscator is a QPT compiler \mathsf{Obfs} which takes in a stateful quantum program (U,\ket{\psi}) , then outputs another stateful quantum program (\widetilde{U},\ket{\widetilde{\psi}}) : (\widetilde{U},\ket{\widetilde{\psi}})\leftarrow\mathsf{Obfs}(1^{\lambda},(U,\ket{\psi})) It must satisfy the following two properties. • Correctness: There exists some negligible function \mu such that for every stateful program (U,\ket{\psi}) , the obfuscation (\widetilde{U},\ket{\widetilde{\psi}})\leftarrow\mathsf{Obfs}(1^{\lambda},(U,\ket{\psi})) is (\mathsf{poly}\left(\lambda\right),\mu(\lambda)) -functionally equivalent to (U,\ket{\psi}) with probability 1-\mathsf{negl}\left(\lambda\right) . • Security: For every pair of stateful programs (U_{1},\ket{\psi_{1}}) and (U_{2},\ket{\psi_{2}}) which are (\mathsf{poly}\left(\lambda\right),\mathsf{negl}\left(\lambda\right)) -functionally equivalent and satisfy |(U_{1},\ket{\psi_{1}})|=|(U_{2},\ket{\psi_{2}})| , \{\mathsf{Obfs}(1^{\lambda},(U_{1},\ket{\psi_{1}}))\}\approx\{\mathsf{Obfs}(1^{\lambda},(U_{2},\ket{\psi_{2}}))\} It is useful to compare this to the classical notion of indistinguishability obfuscation. In the classical setting, two programs P_{1} and P_{2} are considered to be functionally equivalent if P_{1}(x)=P_{2}(x) for every x . In the quantum setting, the functional equivalence requirement is usually relaxed to allow negligible error in implementing the program [ 15 , 27 ] , because it is generally quite difficult to exactly implement a quantum program. This behavior can be seen as requiring that once P_{1} and P_{2} are fixed, no possible query x exists that would allow distinguishing black-box access to P_{1} from access to P_{2} . We emphasize that in this view, x is still allowed to depend on the code of the two program even though the adversary otherwise can only make black-box queries to the selected program. As a sanity check, allowing the adversary to depend on the code ensures that this view still avoids impossibility results like [ 6 , 3 ] which are based on “feeding the program to itself”. In the stateful setting, the definition needs to account for the ability of the program to change over the course of several queries. We allow this by considering an adversary which may submit a polynomial number of queries in sequence. If the program did not update its state, then this would be equivalent to quantifying over all single queries, since sequential queries would have the same effect as single queries (up to negligible error due to allowing imperfect implementations). On the other hand, it might be the case that two stateful programs have identical outputs for, say, 10 queries, before suddenly changing behavior on the 11’th. Since even an adversary with black-box access could perform 11 queries and notice the difference on the last query, it does not make sense to claim that the two programs can be indistinguishably obfuscated. The restriction to a polynomial number of queries is also quite natural. Although any polynomial-time adversary could certainly reach a polynomially-late program state by simply performing that many queries, to reach a superpolynomially-late program state they would need to interact with the program in a non-black-box manner. Thus, we argue that the ability to skip to a superpolynomially-late program state should be considered as a major break in the security of the scheme. At that point, we should simply consider obfuscating a state less program which allows anyone to skip to any point in the future. Nonetheless, we do note that strengthening the functional equivalence requirement to a superpolynomial number of queries also makes sense as a (weaker) definition, if obfuscation for polynomial functional equivalence turns out to be impossible. We provide evidence in Section 5.3 that obfuscation is possible for programs which are only polynomially-equivalent by constructing such a scheme in an idealized model. 5.2 Stateful Quantum iO Implies Best-Possible Testable One-Time Programs We show that such stateful quantum iO is actually sufficient to achieve best-possible testable quantum one-time programs. Thus, if one were to construct stateful quantum indistinguishability obfuscation in the plain model, they would also obtain good one-time programs. Theorem 10 . Assuming stateful quantum indistinguishability obfuscation, there exists a best-possible testable quantum one-time program compiler for quantum channels ( Definition 16 ). Proof. Let \Phi:L(\mathcal{H}_{\mathcal{Q}})\rightarrow L(\mathcal{H}_{\mathcal{Q}}) be a quantum channel and let P=(\ket{0^{m}},\mathsf{Eval}) be a canonical Stinespring dilation of \Phi . Without loss of generality, we can equip P with a reflection oracle by reflecting around \ket{0^{m}} . The construction is \mathsf{sqiO}(\mathsf{SEQ}(P)) , where \mathsf{SEQ}(P) is a program implementing the \mathsf{SEQ} oracle on P (see Section 4 ). To show best-possible security among testable programs, we must show a simulator that is indistinguishable from \mathsf{sqiO}(\mathsf{SEQ}(P)) . Given a program P^{\prime} that implements \Phi , the simulator is \mathsf{sqiO}(\mathsf{SEQ}(P^{\prime})) . By Lemma 11 , \mathsf{SEQ}(P) and \mathsf{SEQ}(P^{\prime}) are (s,\varepsilon) -functionally equivalent for all s\in\mathbb{N} and \varepsilon=0 . Therefore stateful iO security implies that \mathsf{sqiO}(\mathsf{SEQ}(P)) is computationally indistinguishable from \mathsf{sqiO}(\mathsf{SEQ}(P^{\prime})) . ∎ 5.3 Stateful Oracles in the Classical Oracle Model Next, we provide evidence that stateful obfuscation is possible by constructing it in the classical oracle model. Unfortunately, we do not yet know how to construct stateful quantum state indistinguishability obfuscation in the plain model. Even giving a plausible candidate would resolve a major open question since it implies weaker notions of obfuscation which have not yet been constructed, such as iO for pseudodeterministic circuits or for unitaries. Another interpretation of our construction is that oracle models with memory are just as good as stateless oracle models. For example, our Single Effective Query (SEQ) security is a query interface that maintains internal state across queries. Although it might seem somewhat odd to allow an oracle to maintain state, our result shows that this behavior can be achieved in the more standard classical oracle model. Definition 21 (Ideal Stateful Quantum State Obfuscation) . A ideal stateful quantum state obfuscator is a QPT compiler \mathsf{Obfs} which takes as input a stateful quantum program (U,\ket{\psi}) and outputs another stateful quantum program (\widetilde{U},\ket{\widetilde{\psi}}) . (\widetilde{U},\ket{\widetilde{\psi}})\leftarrow\mathsf{Obfs}(1^{\lambda},(U,\ket{\psi})) In an oracle model, \mathsf{Obfs} may also output a description of an efficient algorithm matching the oracle model (e.g. a unitary for the unitary oracle model) and all parties are given oracle access to that unitary. It must satisfy the following two properties. • Correctness: There exists some \varepsilon=\mathsf{negl}\left(\lambda\right) such that for every stateful program (U,\ket{\psi}) , the obfuscation (\widetilde{U},\ket{\widetilde{\psi}})\leftarrow\mathsf{Obfs}(1^{\lambda},(U,\ket{\psi})) is (\mathsf{poly}\left(\lambda\right),\varepsilon) -functionally equivalent to (U,\ket{\psi}) with probability 1-\mathsf{negl}\left(\lambda\right) . • Security: There exists a simulator \mathsf{Sim} such that for every stateful program P=(U,\ket{\psi}) , every QPT adversary \mathcal{A} , and every QPT distinguisher D , \left|\Pr[1\leftarrow D(\mathcal{A}(\mathsf{Obfs}(1^{\lambda},P)]-\Pr[D(\mathsf{Sim}^{P}(1^{\lambda},\mathcal{A},n(\lambda),m(\lambda))]\right|=\mathsf{negl}\left(\lambda\right) where U has at most n(\lambda) gates, \ket{\psi} has at most n(\lambda) qubits, and P takes as input an m(\lambda) -sized register. A straightforward hybrid argument shows that ideal stateful obfuscator is also a stateful indistinguishability obfuscator. First, ideal obfuscation allows replacing an obfuscation of P_{1} by a simulator who only has oracle access to P_{1} . Then, since the simulator makes only a polynomial number of queries, it cannot distinguish between oracle access to P_{1} or P_{2} . Finally, ideal obfuscation allows switching back from the simulator with oracle access to P_{2} to an obfuscation of P_{2} . Claim 3 . Any ideal stateful quantum state obfuscator is also a stateful quantum state indistinguishability obfuscator. We now show how to construct ideal stateful obfuscation in the unitary oracle model. As a corollary of [ 27 ] , it can also be constructed in the classical oracle model. Construction 1 . The construction uses a publicly verifiable quantum authentication scheme \mathsf{QAS} (e.g. the coset authentication scheme from [ 8 ] ) and an ideal unitary obfuscation \mathsf{Obfs}^{\prime} (e.g. Theorem 6 [ 27 ] ). Without loss of generality, the QAS scheme supports Pauli key updates since we can always attach a Pauli correction to the key. [ 8 ] ’s authentication scheme also supports Pauli key updates natively. We implement \mathsf{QAS}.\mathsf{Dec}_{k} and \mathsf{QAS}.\mathsf{Enc}_{k} as reversible circuits that act unitarily on an enlarged work space and return all ancillas to \ket{0} (i.e., they are coherently implemented isometries), so the following overall procedure is unitary. Assume that U does not make any use of oracles. On input P=(U,\ket{\psi}) and security parameter 1^{\lambda} : 1. Sample an authentication key k\leftarrow\mathsf{QAS}.\mathsf{KeyGen}(1^{\lambda}) . 2. Compute \ket{\widetilde{\psi}}\coloneqq\mathsf{QAS}.\mathsf{Enc}_{k}(\ket{\psi}) on register \mathcal{R} . 3. Let \widetilde{U} be the following unitary: (a) Take as input two registers (\mathcal{Q},\ \mathcal{R}) (b) Apply \mathsf{QAS}.\mathsf{Dec}_{k} to register \mathcal{R} . If the result is \bot , uncompute \mathsf{QAS}.\mathsf{Dec}_{k} and return the input registers immediately. (c) Otherwise, apply U to (\mathcal{Q},\mathcal{R}) . (d) Apply \mathsf{QAS}.\mathsf{Enc}_{k} to register \mathcal{R} . (e) Return (\mathcal{Q},\mathcal{R}) . 4. Compute the unitary obfuscation (\ket{\widetilde{\phi}},C)\leftarrow\mathsf{Obfs}^{\prime}(\widetilde{U}) . 5. Output \ket{\widetilde{\psi}},\mathsf{Obfs}^{\prime}(\widetilde{U}) . Theorem 11 . Ideal stateful quantum obfuscation exists in the classical oracle model. Proof. Let n be the size of the internal state register \mathcal{R} , in qubits. Let \mathsf{Adv} be the adversary. Let \mathsf{Sim}^{\prime} be the simulator of the ideal unitary obfuscation scheme \mathsf{Obfs}^{\prime} . Let \mathsf{Adv}^{\prime} be the adversary obtained as \mathsf{Adv}^{\prime}=\mathsf{Sim}^{\prime}(\mathsf{Adv},\cdot) . The simulator \mathsf{Sim}^{P}(\mathsf{Adv}^{\prime}) initializes itself by sampling k\leftarrow\mathsf{Auth}.\mathsf{KeyGen}(1^{\lambda}) . Prepare n EPR pairs in registers (\mathcal{A}_{1},\mathcal{B}_{1}),\ \dots,\ (\mathcal{A}_{n},\mathcal{B}_{n}) and apply \mathsf{Auth}.\mathsf{Enc}_{k} to register \mathcal{B}=(\mathcal{B}_{1},\dots,\mathcal{B}_{n}) , expanding the register as necessary, to obtain \propto\sum_{x\in\{0,1\}^{n}}\ket{x}_{\mathcal{A}}\otimes\mathsf{Auth}.\mathsf{Enc}_{k}(\ket{x})_{\mathcal{B}} It runs {\mathsf{Adv}^{\prime}}^{(\cdot)}(\mathcal{B}) , answering its oracle queries as follows. 1. Parse the query register as (\mathcal{Q},\mathcal{B}^{\prime}) . 2. Run \mathsf{Auth}.\mathsf{Ver}_{k}(\mathcal{B}^{\prime}) . If the result is \bot , uncompute \mathsf{Auth}.\mathsf{Ver}_{k} and return immediately. Otherwise continue. 3. Query P on \mathcal{Q} . Return the result. We show that \mathsf{Sim}^{P}(\mathsf{Adv}) is indistinguishable from \mathsf{Adv}^{\widetilde{U}}(\ket{\widetilde{\psi}}) for any q=\mathsf{poly}\left(\lambda\right) queries via a series of hybrid experiments. • \mathsf{Hyb}_{-1}=\mathsf{Adv}(\ket{\widetilde{\psi}},\mathsf{Obfs}^{\prime}(\widetilde{U})) . • \mathsf{Hyb}_{0}={\mathsf{Sim}^{\prime}}^{\widetilde{U},\widetilde{U}^{\dagger}}(\mathsf{Adv},\ket{\widetilde{\psi}})={\mathsf{Adv}^{\prime}}^{\widetilde{U},\widetilde{U}^{\dagger}}(\ket{\widetilde{\psi}}) . • \mathsf{Hyb}_{1} : Prepare the half-authenticated EPR pairs \propto\sum_{x\in\{0,1\}^{n}}\ket{x}_{\mathcal{A}}\otimes\mathsf{Auth}.\mathsf{Enc}_{k}(\ket{x})_{\mathcal{B}} as in the simulator. Teleport \ket{\psi} into the authenticated register \mathcal{B} using the EPR halves in register \mathcal{A} . Run {\mathsf{Sim}^{\prime}}^{\widetilde{U}_{k^{\prime}},\widetilde{U}_{k^{\prime}}^{\dagger}}(\mathsf{Adv},\mathcal{B})={\mathsf{Adv}^{\prime}}^{\widetilde{U}_{k^{\prime}},\widetilde{U}_{k^{\prime}}^{\dagger}}(\mathcal{B}) . Here, \widetilde{U}_{k^{\prime}} denotes that the oracle uses key k^{\prime} . • \mathsf{Hyb}_{2} : Instead of performing the teleportation and key update k\mapsto k^{\prime} immediately after the teleportation, perform it when \mathsf{Sim}^{\prime} submits its first query (before answering the query). Until that point, store the internal state, which is initialized to \ket{\psi} , in register \mathcal{R} . • \mathsf{Hyb}_{2+i} for i=1 to q : Initialize \mathsf{Sim}^{\prime} as in \mathsf{Hyb}_{2} . For the first i queries, answer the query as in \mathsf{Sim} . To do this, perform P internally using register \mathcal{R} . Then, upon receiving query i+1 , teleport the state of register \mathcal{R} into register \mathcal{B} and update the key k\mapsto k^{\prime} . Then continue answering queries as in the real scheme. • \mathsf{Sim}=\mathsf{Hyb}_{2+q} . \mathsf{Hyb}_{-1}\approx\mathsf{Hyb}_{0} by the security of the ideal obfuscation of unitary \widetilde{U} (see Definition 9 ). \mathsf{Hyb}_{0}=\mathsf{Hyb}_{1} by the correctness of teleportation and the ability to perform Pauli key updates on the authentication scheme. \mathsf{Hyb}_{1}=\mathsf{Hyb}_{2} since the teleportation and key updates are performed on disjoint registers from those hold by \mathsf{Adv} . The main step is to show that \mathsf{Hyb}_{2+i}\approx\mathsf{Hyb}_{2+i+1} . Claim 4 . For every i1 , there is a channel \Phi_{f} such that the classical SEQ oracle O^{\mathsf{CSEQ}}_{f} reveals the same information as the (channel) SEQ oracle O^{\mathsf{SEQ}}_{\Phi_{f}} . The channel \Phi_{f} computes f on any input x and uses a (compressed) random oracle H to sample r . Given a function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} and a random oracle H:\mathcal{X}\to\mathcal{R} , \Phi_{f} maps x\to f(x;H(x)) and also flips a bit b to indicate that it has executed. \Phi_{f} is essentially the same as the classical SEQ oracle O^{\mathsf{CSEQ}}_{f} , except without step 1 of O^{\mathsf{CSEQ}}_{f} . Definition 27 (Channel \Phi_{f} ) . Given a randomized classical function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} , let \Phi_{f} be the following quantum channel. • The channel’s internal register has two parts \mathcal{P}=\mathcal{D}\times\mathcal{W} . \mathcal{D} is a database register for the compressed random oracle, and \mathcal{W} is a workspace register to perform intermediate computations. \mathcal{D} is initialized to \ket{\emptyset}_{\mathcal{D}} , and we maintain the invariant that \mathcal{W} is in the state \ket{0,0}_{\mathcal{W}} at the start of each query. • The channel’s Stinespring unitary U_{\Phi_{f}} acts as follows on each basis state \ket{x,u,b}_{\mathcal{Q}}\otimes\ket{D}_{\mathcal{D}}\otimes\ket{0,0}_{\mathcal{W}} : 1. Copy x into the workspace register: \ket{x,u,b}_{\mathcal{Q}}\otimes\ket{D}_{\mathcal{D}}\otimes\ket{0,0}_{\mathcal{W}}\mapsto\ket{x,u,b}_{\mathcal{Q}}\otimes\ket{D}_{\mathcal{D}}\otimes\ket{x,0}_{\mathcal{W}} 2. Apply the query operation of the compressed oracle with \mathcal{W} as the query register and \mathcal{D} as the database register. 3. Apply the unitary that acts as follows on the basis states: \displaystyle\ket{x,u,b}_{\mathcal{Q}}\otimes\ket{D}_{\mathcal{D}}\otimes\ket{x,r}_{\mathcal{W}}\mapsto\ket{x,u\oplus f(x;r),b\oplus 1}_{\mathcal{Q}}\otimes\ket{D}_{\mathcal{D}}\otimes\ket{x,r}_{\mathcal{W}} 4. Uncompute step 2 and then step 1 . Note that f and \Phi_{f} provide no one-time guarantee. They never reject queries, so the user may make many effective queries. There are two ways to limit the user’s queries: we can implement f with the classical SEQ oracle O^{\mathsf{CSEQ}}_{f} and implement \Phi_{f} with the SEQ oracle O^{\mathsf{SEQ}}_{\Phi_{f}} . The purpose of both oracles is to restrict the user to just one effective query. Which oracle reveals more information about f ? In fact, they reveal the same information. We formalize this by showing that O^{\mathsf{CSEQ}}_{f} can be used to simulate O^{\mathsf{SEQ}}_{\Phi_{f}} , and vice versa as long as |\mathcal{X}|>1 ( theorem 15 ). To prove the first simulation indistinguishability in theorem 15 , we first define the CSEQ-wrapper simulator \mathsf{Sim}^{\prime} . The simulator \mathsf{Sim}^{\prime} below has the following internal registers. Let \mathcal{P} store the program state of P , which is initialized to \ket{\psi} . Let \mathcal{D} be an internal database register that stores a query x\in\mathcal{X}\cup\{\emptyset\} and is initialized to \ket{\emptyset} . Let \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} be work registers that store values (x,y,b)\in(\cal{X}\cup\{\emptyset\})\times(\mathcal{Y}\cup\{\emptyset\})\times\text{$\{0,1\}$} . \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} are initialized to \ket{\emptyset,\emptyset,0} . We represent elements of \mathcal{X}\cup\{\emptyset\} as the following binary strings. Each x\in\mathcal{X} becomes x\|1 and \emptyset becomes 0^{n}\|0 . In particular, x=0^{n} is represented as 0^{n}\|1 , which is different from the representation 0^{n}\|0 of \emptyset . Therefore, we have that \emptyset+x=x , and x+x=\emptyset . The same kind of representation is used for \mathcal{Y}\cup\{\emptyset\} . \mathsf{Sim}^{\prime}(P) works as follows. First, it uses the \mathsf{EvalAndCopy} operation to evaluate P(x) . Rather than evaluating the program on registers \mathcal{Q}_{x}\times\mathcal{Q}_{u} directly, \mathsf{EvalAndCopy} evaluates it on work registers \mathcal{W}_{x}\times\mathcal{W}_{y} instead, and copies the inputs and outputs between \mathcal{Q}_{x}\times\mathcal{Q}_{u} and \mathcal{W}_{x}\times\mathcal{W}_{y} . This provides insulation from any pathological behavior of \mathsf{Eval} . Even if \mathsf{Eval} modifies or reads from its query register arbitrarily, we are guaranteed that \mathsf{EvalAndCopy} only reads from \mathcal{Q}_{x} and only writes to \mathcal{Q}_{y} . Next, \mathsf{Sim}^{\prime}(P) stores a query x^{\prime} in the database \mathcal{D} and rejects any new query x if x^{\prime}\notin\{x,\emptyset\} . This is analogous O^{\mathsf{CSEQ}}_{f} ’s database. The \mathsf{ReflectAndCopy} operation updates \mathsf{Sim}^{\prime}(P) ’s database by copying x from \mathcal{Q}_{x} to \mathcal{D} if and only if the remaining internal registers \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} are in their initial state ( lemma 18 ). Definition 28 (Simulator \mathsf{Sim}^{\prime} for O_{f}^{\mathsf{CSEQ}} ) . • \mathsf{Sim}^{\prime} takes as input a testable quantum program P=(\ket{\psi},\mathsf{Eval},R) . • Initialize the internal state to \ket{\psi}_{\mathcal{P}}\otimes\ket{\emptyset}_{\mathcal{D}}\otimes\ket{\emptyset}_{\mathcal{W}_{x}}\otimes\ket{\emptyset}_{\mathcal{W}_{y}}\otimes\ket{0}_{\mathcal{W}_{b}} . • Given a query \ket{x,u,b}_{\mathcal{Q}} and database \ket{x^{\prime}}_{\mathcal{D}} , \mathsf{Sim}^{\prime} acts as follows. 1. If x^{\prime}\notin\{x,\emptyset\} , do nothing and ignore the remaining steps. 2. \mathsf{ReflectAndCopy} : If \mathcal{W}_{x}\times\mathcal{W}_{y} contains (\emptyset,\emptyset) , then do the following: (a) Apply the reflection oracle R to registers (\mathcal{W}_{b},\mathcal{P}) . (b) If \mathcal{W}_{b} contains 1 , then \mathsf{CNOT} the value x from \mathcal{Q}_{x} onto \mathcal{D} . (c) Apply the reflection oracle R to registers (\mathcal{W}_{b},\mathcal{P}) . 3. \mathsf{EvalAndCopy} : (a) \mathsf{CNOT} the value x from \mathcal{Q}_{x} to \mathcal{W}_{x} . (b) Apply \mathsf{Eval} to registers (\mathcal{W}_{x},\mathcal{W}_{y},\mathcal{P}) . (c) \mathsf{CopyOutput} : \mathsf{CNOT} the contents of \mathcal{W}_{y} onto \mathcal{Q}_{u} . (d) Apply \mathsf{Eval}^{\dagger} to registers (\mathcal{W}_{x},\mathcal{W}_{y},\mathcal{P}) . (e) \mathsf{CNOT} the value x from \mathcal{Q}_{x} to \mathcal{W}_{x} . 4. Apply \mathsf{ReflectAndCopy} (step 2 ) again. 5. \mathsf{Bitflip} : Apply \mathsf{X} to the \mathcal{Q}_{b} register. In summary, the simulator acts as follows: it acts as the identity on states \ket{x,u,b}\ket{D}\ket{\cdots} if x^{\prime}\in D for some x^{\prime}\neq x , and on the rest of the state space it acts as the unitary \displaystyle\mathsf{Bitflip}\circ\mathsf{ReflectAndCopy}\circ\mathsf{EvalAndCopy}\circ\mathsf{ReflectAndCopy}. The next lemma says that \mathsf{ReflectAndCopy} acts similarly to a reflection oracle on registers \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} . It CNOTS x from \mathcal{Q}_{x} to \mathcal{D} if and only if \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} is in its initial state. Lemma 18 . If P is a testable quantum program, then \mathsf{ReflectAndCopy} (step 2 of \mathsf{Sim}^{\prime}(P) ) is equivalent to the operation that applies \mathsf{CNOT} from \mathcal{Q}_{x} to \mathcal{D} controlled on \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} being in their initial state \ket{\psi,\emptyset,\emptyset,0} . Additionally, after any number of queries to \mathsf{Sim}^{\prime}(P) , \mathcal{W}_{b} is in state \ket{0} . Proof. First, \mathcal{W}_{b} is initialized to \ket{0} . Next, note that \mathcal{W}_{b} is only modified during the \mathsf{ReflectAndCopy} operation. Let us assume that at the start of a given \mathsf{ReflectAndCopy} operation, \mathcal{W}_{b} contains \ket{0} . We will show that at the end of this operation, \mathcal{W}_{b} still contains \ket{0} . This establishes that \mathcal{W}_{b}=\ket{0} after every query to \mathsf{Sim}^{\prime}(P) . Let us consider how \mathsf{ReflectAndCopy} acts on the following basis states. Case 1: \mathcal{W}_{x}\times\mathcal{W}_{y} contains a state orthogonal to \ket{\emptyset,\emptyset} . Then \mathsf{ReflectAndCopy} acts as the identity, so at the end of \mathsf{ReflectAndCopy} , \mathcal{W}_{b}=\ket{0} , and \mathcal{Q}_{x}\times\mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} are unchanged. Case 2: \mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\emptyset,\emptyset} , but \mathcal{P} contains a state that is orthogonal to \ket{\psi} . \mathsf{ReflectAndCopy} first applies R to (\mathcal{W}_{b},\mathcal{P}) , resulting in \mathcal{W}_{b}=\ket{0} . Then the \mathsf{CNOT} operation from \mathcal{Q}_{x} to \mathcal{D} is controlled on 0 , so we do not copy x to \mathcal{D} , and we can replace this operation with the identity. Finally, the second application of R also leaves the \mathcal{W}_{b}=\ket{0} . At the end of \mathsf{ReflectAndCopy} , \mathcal{W}_{b}=\ket{0} , and \mathcal{Q}_{x}\times\mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} are unchanged. Case 3: \mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\emptyset,\emptyset} , and \mathcal{P}=\ket{\psi} . \mathsf{ReflectAndCopy} first applies R to (\mathcal{W}_{b},\mathcal{P}) , resulting in \mathcal{W}_{b}=\ket{1} . Then, the \mathsf{CNOT} operation copies x from \mathcal{Q}_{x} to \mathcal{D} . Since the \mathsf{CNOT} step acts only on \mathcal{W}_{b}\times\mathcal{Q}_{x}\times\mathcal{D} , this does not affect the \mathcal{P} register, which will still be in the state \ket{\psi} . Finally, the second application of the reflection oracle R will XOR the \mathcal{W}_{b} register with 1 , returning it to \ket{0} . At the end of \mathsf{ReflectAndCopy} , \mathcal{W}_{b}=\ket{0} , and \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} are unchanged. In summary, we’ve shown that for each type of basis state listed above, \mathsf{ReflectAndCopy} keeps \mathcal{W}_{b}=\ket{0} , and it performs a \mathsf{CNOT} from \mathcal{Q}_{x}\to\mathcal{D} controlled on \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\psi,\emptyset,\emptyset} . Any state on registers \mathcal{Q}_{x}\times\mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is in the span of the basis states above, so we have completely characterized the behvaior of \mathsf{ReflectAndCopy} . ∎ Next, let us define a testable quantum program P_{f}=(\ket{+},\mathsf{Eval}_{f},R_{+}) as follows: • \ket{+}=\frac{1}{\sqrt{\left\lvert\mathcal{R}\right\rvert}}\cdot\sum_{r\in\mathcal{R}}\ket{r} • \mathsf{Eval}_{f} is a unitary that maps \ket{x,u}\otimes\ket{r}\mapsto\ket{x,u\oplus f(x;r)}\otimes\ket{r} • R_{+} is the reflection about \ket{+} Note that P_{f} is a testable quantum program that implements f with 0 error. Lemma 19 . Oracles for \mathsf{Sim}^{\prime}(P_{f}) and O^{\mathsf{CSEQ}}_{f} are perfectly indistinguishable to any adversary making an unbounded number of quantum queries. Proof. The following hybrids transform O^{\mathsf{CSEQ}}_{f} into \mathsf{Sim}^{\prime}(P_{f}) . Hybrid 0. This is the CSEQ oracle, except that the size of the compressed oracle database is fixed to record at most 1 query. This is equivalent to the CSEQ oracle because the CSEQ oracle holds at most one entry in the database at any point in time, by Claim 4.7 of [ 24 ] . Recall that \mathsf{StdDecomp} applied to \mathcal{W}\times\mathcal{D} swaps the states \ket{x,r}_{\mathcal{W}}\otimes\ket{\emptyset,\emptyset}_{\mathcal{D}} and \ket{x,r}_{\mathcal{W}}\otimes\ket{x,+}_{\mathcal{D}} , and acts as the identity on the rest of the space. Additionally, \mathsf{CStO}^{\prime} applied to \mathcal{W}\times\mathcal{D} maps \ket{x,r}_{\mathcal{W}}\otimes\ket{D}_{\mathcal{D}}\mapsto\ket{x,r\oplus D(x)}\otimes\ket{D} . The oracle initializes its internal registers \mathcal{W}\times\mathcal{D}=\ket{0}\times\ket{\emptyset} . On query \ket{x,u,b}_{\mathcal{Q}} , the oracle acts as follows: 1. If there exists some x^{\prime}\neq x such that (x^{\prime},r)\in D for some r\in\mathcal{R} , skip the following steps. 2. Copy x into the workspace register \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{0}_{\mathcal{W}}\mapsto\ket{x}_{\mathcal{Q}_{x}}\otimes\ket{x,0}_{\mathcal{W}}. 3. Apply the compressed random oracle to registers \mathcal{W}\times\mathcal{D} by executing the following unitaries: \mathsf{StdDecomp}\circ\mathsf{CStO}^{\prime}\circ\mathsf{StdDecomp} 4. Apply the following unitary map: \displaystyle\ket{u,b}_{\mathcal{Q}_{u}\times\mathcal{Q}_{b}}\otimes\ket{x,r}_{\mathcal{W}}\mapsto\ket{u\oplus f(x;r),b\oplus 1}_{\mathcal{Q}_{u}\times\mathcal{Q}_{b}}\otimes\ket{x,r}_{\mathcal{W}} 5. Query the compressed oracle again: \mathsf{StdDecomp}\circ\mathsf{CStO}^{\prime}\circ\mathsf{StdDecomp} 6. Copy x into the workspace register \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{x,0}_{\mathcal{W}}\mapsto\ket{x}_{\mathcal{Q}_{x}}\otimes\ket{0}_{\mathcal{W}} Hybrid 1. We’ve canceled out operations with their inverse whereever possible. We have also moved the bitflip on \mathcal{Q}_{b} to the final step. The oracle initializes its internal registers \mathcal{W}\times\mathcal{D}=\ket{0}\times\ket{\emptyset} . On query \ket{x,u,b}_{\mathcal{Q}} , the oracle acts as follows: 1. If there exists some x^{\prime}\neq x such that (x^{\prime},r)\in D for some r\in\mathcal{R} , skip the following steps. 2. Apply \mathsf{StdDecomp} to registers \mathcal{Q}_{x}\times\mathcal{D} . 3. Apply the following unitary map: \displaystyle\ket{x,u,b}_{\mathcal{Q}}\otimes\ket{x,r}_{\mathcal{D}}\mapsto\ket{x,u\oplus f(x;r),b}_{\mathcal{Q}}\otimes\ket{x,r}_{\mathcal{D}} 4. Apply \mathsf{StdDecomp} to registers \mathcal{Q}_{x}\times\mathcal{D} . 5. Apply \mathsf{X} (bitflip) to \mathcal{Q}_{b} . Claim 5 . The oracles in hybrids 0 and 1 are perfectly indistinguishable after any number of queries. Proof. First, in hybrid 0, \mathsf{StdDecomp} applies \mathsf{StdDecomp}_{x} to \mathcal{D} controlled on the value of x written on \mathcal{W} . In hybrid 1, \mathsf{StdDecomp} applies \mathsf{StdDecomp}_{x} to \mathcal{D} controlled on the value of x written on \mathcal{Q}_{x} . These operations are equivalent because during any query in hybrid 0, the value of x written on \mathcal{Q}_{x} matches the value written on \mathcal{W} whenever \mathsf{StdDecomp} is called. Let us modify hybrid 0 so that \mathsf{StdDecomp} is controlled on \mathcal{Q}_{x} instead of \mathcal{W} . Second, \mathsf{StdDecomp} now commutes with items 2 , 4 and 6 of hybrid 0. This is because \mathsf{StdDecomp} applies \mathsf{StdDecomp}_{x} to \mathcal{D} controlled on the computational-basis value of \mathcal{Q}_{x} . Step 2 applies a unitary to \mathcal{W} controlled on the computational-basis value of \mathcal{Q}_{x} . \mathsf{StdDecomp} and step 2 commute because they are controlled by the computational-basis value of the same register \mathcal{Q}_{x} , and they apply a controlled unitary to disjoint registers, \mathcal{D} and \mathcal{W} respectively. The same reasoning shows that \mathsf{StdDecomp} commutes with step 6 . Step 4 does not act on \mathcal{Q}_{x} or D , so it commutes with \mathsf{StdDecomp} because they act on disjoint registers. Let us switch the order of step 2 and the first \mathsf{StdDecomp} in step 3 . Let us also switch the order of step 6 and the last \mathsf{StdDecomp} in step 5 . Third, the final application of \mathsf{StdDecomp} in step 3 cancels out with the first application of \mathsf{StdDecomp} in step 5 . This is because \mathsf{StdDecomp}^{-1}=\mathsf{StdDecomp} , and the only operation that occurs in between these two applications of \mathsf{StdDecomp} is step 4 , which commutes with \mathsf{StdDecomp} . Fourth, after making the changes above, we have that hybrid 0 is equivalent to the following operations: 1. If there exists some x^{\prime}\neq x such that (x^{\prime},r)\in D for some r\in\mathcal{R} , skip the following steps. 2. Apply \mathsf{StdDecomp} to \mathcal{Q}_{x}\times\mathcal{D} . 3. Step 2 : \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{0}_{\mathcal{W}}\to\ket{x}_{\mathcal{Q}_{x}}\otimes\ket{x,0}_{\mathcal{W}} 4. \mathsf{CStO}^{\prime} : \ket{x,0}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}}\to\ket{x,r}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}} 5. Step 4 : \ket{u,b}_{\mathcal{Q}_{u}\times\mathcal{Q}_{b}}\otimes\ket{x,r}_{\mathcal{W}}\mapsto\ket{u\oplus f(x;r),b\oplus 1}_{\mathcal{Q}_{u}\times\mathcal{Q}_{b}}\otimes\ket{x,r}_{\mathcal{W}} 6. \mathsf{CStO}^{\prime} : \ket{x,r}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}}\to\ket{x,0}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}} 7. Step 6 : \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{x,0}_{\mathcal{W}}\to\ket{x}_{\mathcal{Q}_{x}}\otimes\ket{0}_{\mathcal{W}} 8. Apply \mathsf{StdDecomp} to \mathcal{Q}_{x}\times\mathcal{D} . Note that the middle steps, \text{Step \ref{step:hyb-0-copy-input-2}}\circ\mathsf{CStO}^{\prime}\circ\text{Step \ref{step:hyb-0-copy-output}}\circ\mathsf{CStO}^{\prime}\circ\text{Step \ref{step:hyb-0-copy-input-1}} , are all classical operations, and they are equivalent to the following operation: \ket{x,u,b}_{\mathcal{Q}}\otimes\ket{0}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}}\to\ket{x,u\oplus f(x;r),b\oplus 1}_{\mathcal{Q}}\otimes\ket{0}_{\mathcal{W}}\otimes\ket{x,r}_{\mathcal{D}} Note that \mathcal{W} is returned to the \ket{0} state by the end of this sequence of operations, so we can ignore it. Fifth, let us delay applying the bitflip to \mathcal{Q}_{b} until after all the other steps have finished. This is equivalent to the steps above because the bitflip commutes with all other steps. Now we have that hybrid 0 is equivalent to the following steps: 1. If there exists some x^{\prime}\neq x such that (x^{\prime},r)\in D for some r\in\mathcal{R} , skip the following steps. 2. Apply \mathsf{StdDecomp} to \mathcal{Q}_{x}\times\mathcal{D} . 3. Apply the following unitary map: \ket{x,u,b}_{\mathcal{Q}}\otimes\ket{x,r}_{\mathcal{D}}\to\ket{x,u\oplus f(x;r),b}_{\mathcal{Q}}\otimes\ket{x,r}_{\mathcal{D}} 4. Apply \mathsf{StdDecomp} to \mathcal{Q}_{x}\times\mathcal{D} . 5. Apply \mathsf{X} (bitflip) to \mathcal{Q}_{b} . This is exactly hybrid 1, so we’ve shown that hybrids 0 and 1 are perfectly indistinguishable. ∎ Hybrid 2. Let us split the database register \mathcal{D} into two registers, called \mathcal{D}\times\mathcal{P} to match the eventual notation of \mathsf{Sim}^{\prime}(P_{f}) . \mathcal{D} will store the database’s x -value, and \mathcal{P} will store its r -value. Let \mathsf{Record} be the unitary that swaps the states \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{\emptyset}_{\mathcal{D}}\ket{+}_{\mathcal{P}} and \ket{x}_{\mathcal{Q}_{x}}\otimes\ket{x}_{\mathcal{D}}\ket{+}_{\mathcal{P}} , and acts as the identity on the rest of the space. Additionally, let \mathsf{Decomp} be the unitary that swaps \ket{\emptyset}_{\mathcal{P}} and \ket{+}_{\mathcal{P}} . In this hybrid, the oracle initializes database registers \mathcal{D}\times\mathcal{P}=\ket{\emptyset,\emptyset} and work registers \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b}=\ket{\emptyset,\emptyset,0} , although the oracle never operates on \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} . Next, the oracle answers queries on \ket{x,u,b}_{\mathcal{Q}}\otimes\ket{x^{\prime}}_{\mathcal{D}} as follows: 1. If x^{\prime}\notin\{x,\emptyset\} , then skip the following steps. 2. Apply {\color[rgb]{1,0,0}\mathsf{Record}\circ\mathsf{Decomp}} to the (\mathcal{Q}_{x},\mathcal{D},\mathcal{P}) registers. 3. Apply \mathsf{Eval}_{f} on the (\mathcal{Q}_{x},\mathcal{Q}_{u},\mathcal{P}) registers: \ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{r}_{\mathcal{P}}\to\ket{x,u\oplus f(x;r)}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{r}_{\mathcal{P}} 4. Apply {\color[rgb]{1,0,0}\mathsf{Decomp}\circ\mathsf{Record}} on the (\mathcal{Q}_{x},\mathcal{D},\mathcal{P}) registers. 5. Apply \mathsf{X} (bitflip) to \mathcal{Q}_{b} . Claim 6 . The oracles in hybrids 1 and 2 are perfectly indistinguishable after any number of quantum queries. Proof. We claim that the unitaries defined in hybrids 1 and 2 are identical. We argue this by choosing a suitable basis for states on registers \mathcal{Q}_{x}\times\mathcal{D} (hybrid 1) or \mathcal{Q}\times\mathcal{P}\times\mathcal{D} (hybrid 2) and then tracing how the unitaries \mathsf{StdDecomp} , \mathsf{Eval}_{f} , \mathsf{Record}\circ\mathsf{Decomp} and \mathsf{Decomp}\circ\mathsf{Record} transform these basis states. The unitaries in hybrids 1 and 2 both act as the identity on basis states of the form \ket{x}_{\mathcal{Q}_{x}}\ket{x^{\prime}}_{\mathcal{D}}\ket{\cdots} for x^{\prime}\notin\{x,\emptyset\} , so we will restrict our attention to states supported on \ket{x}_{\mathcal{Q}_{x}}\ket{x}_{\mathcal{D}} and \ket{x}_{\mathcal{Q}_{x}}\ket{\emptyset}_{\mathcal{D}} . For the \mathcal{P} register, our orthogonal “basis” will be \ket{\emptyset} , \ket{+} and \ket{-} , where, in an abuse of notation, we write \ket{-} to denote any state in the span of \{\frac{1}{\sqrt{\left\lvert\mathcal{R}\right\rvert}}\cdot\sum_{r\in\mathcal{R}}(-1)^{r\cdot u}\ket{r}\}_{u\neq 0} . • The starting state of the first query is \ket{x}_{\mathcal{Q}_{x}}\ket{\emptyset}_{\mathcal{D}}\ket{\emptyset}_{\mathcal{P}} , and both \mathsf{StdDecomp} and \mathsf{Record}\circ\mathsf{Decomp} map it to \ket{x}\ket{x}\ket{+} . • \mathsf{Eval}_{f} maps \ket{x}\ket{x}\ket{+} and \ket{x}\ket{x}\ket{-} to superpositions of \ket{x}\ket{x}\ket{+} and \ket{x}\ket{x}\ket{-} (where \ket{-} does not necessarily refer to the same state as before the application of \mathsf{Eval}_{f} ). • Both \mathsf{StdDecomp} and \mathsf{Decomp}\circ\mathsf{Record} map these states as follows: \displaystyle\ket{x}\ket{x}\ket{+} \displaystyle\mapsto\ket{x}\ket{\emptyset}\ket{\emptyset},\text{ and} \displaystyle\ket{x}\ket{x}\ket{-} \displaystyle\mapsto\ket{x}\ket{x}\ket{-}. • Note that \mathsf{StdDecomp} , \mathsf{Record}\circ\mathsf{Decomp} , and \mathsf{Decomp}\circ\mathsf{Record} each leave \ket{x}\ket{x}\ket{-} invariant. Let us define the set of reachable states to be states whose database is supported on eigenstates of the form: \ket{x,-},\ket{\emptyset,\emptyset} . We claim that the database is in a reachable state at the start of any query. First, the state of the database at the start of the first query is reachable. Second, the observations above imply that if the database is in a reachable state at the start of a query, then it will end the query in a reachable state. The only difference in the operations applied by hybrids 1 and 2 is that hybrid 1 uses \mathsf{StdDecomp} twice, and hybrid 2 uses \mathsf{Record}\circ\mathsf{Decomp} and \mathsf{Decomp}\circ\mathsf{Record} instead. Let us step through a query in hybrids 1 or 2 when the starting state is reachable. The first time that \mathsf{StdDecomp} or \mathsf{Record}\circ\mathsf{Decomp} is called during the query, the database is supported on states of the form \ket{\emptyset,\emptyset},\ket{x,-} . We’ve already argued that \mathsf{StdDecomp} , \mathsf{Record}\circ\mathsf{Decomp} act equivalently on such states. After this operation, the database is supported on states of the form \ket{x,+},\ket{x,-} . Then \mathsf{Eval}_{f} maps these states to superpositions of \ket{x,+},\ket{x,-} . Next, \mathsf{StdDecomp} or \mathsf{Decomp}\circ\mathsf{Record} is called. We’ve argued that \mathsf{StdDecomp} and \mathsf{Decomp}\circ\mathsf{Record} act equivalently on database states of the form \ket{x,+},\ket{x,-} . This shows that the unitaries in hybrids 1 and 2 act equivalently on any reachable state, so hybrids 1 and 2 are perfectly indistinguishable. ∎ Hybrid 3. This is \mathsf{Sim}^{\prime}(P_{f}) . In this hybrid, the oracle initializes internal registers \mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b}=\ket{\emptyset}\otimes{\color[rgb]{1,0,0}\ket{+}}\otimes\ket{\emptyset,\emptyset,0} , and answers queries on \ket{x,u,b}\otimes\ket{x^{\prime}}_{\mathcal{D}} as follows: 1. If x^{\prime}\notin\{x,\emptyset\} , do nothing and ignore the remaining steps. 2. Apply {\color[rgb]{1,0,0}\mathsf{ReflectAndCopy}} to the (\mathcal{Q}_{x},\mathcal{D},\mathcal{P},{\color[rgb]{1,0,0}\mathcal{W}_{x},\mathcal{W}_{y},\mathcal{W}_{b}}) registers. 3. Apply {\color[rgb]{1,0,0}\mathsf{EvalAndCopy}} on the (\mathcal{Q}_{x},\mathcal{Q}_{u},\mathcal{P},{\color[rgb]{1,0,0}\mathcal{W}_{x},\mathcal{W}_{y}}) registers. 4. Apply {\color[rgb]{1,0,0}\mathsf{ReflectAndCopy}} to the (\mathcal{Q}_{x},\mathcal{D},\mathcal{P},{\color[rgb]{1,0,0}\mathcal{W}_{x},\mathcal{W}_{y},\mathcal{W}_{b}}) registers. 5. Apply \mathsf{Bitflip} to \mathcal{Q}_{b} . Claim 7 . The oracles in hybrids 2 and 3 are perfectly indistinguishable after any number of quantum queries. Proof. First, \mathsf{Record} is equivalent to \mathsf{ReflectAndCopy} for program P_{f} . \mathsf{ReflectAndCopy} copies x from \mathcal{Q}_{x} to \mathcal{D} controlled on \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} being in the initial state ( lemma 18 ). \mathsf{Record} copies x from \mathcal{Q}_{x} to \mathcal{D} controlled on \mathcal{P} being in its initial state \ket{+} . Furthermore, every time that \mathsf{Record} is called in hybrid 2, the \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} registers are in their initial state because hybrid 2 does not operate on these registers after initializing them. Therefore, we can replace \mathsf{Record} with \mathsf{ReflectAndCopy} . Second, \mathsf{Eval}_{f} is equivalent to \mathsf{EvalAndCopy} for program P_{f} . If \mathcal{W}_{x}\times\mathcal{W}_{y} are in the state \ket{\emptyset,\emptyset} at the start of \mathsf{EvalAndCopy} , then \mathsf{EvalAndCopy} acts as follows: \displaystyle\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\emptyset,\emptyset}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} \displaystyle\to\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{x,\emptyset}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} \displaystyle\to\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{x,f(x;r)}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} \displaystyle\to\ket{x,u\oplus f(x;r)}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{x,f(x;r)}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} \displaystyle\to\ket{x,u\oplus f(x;r)}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{x,\emptyset}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} \displaystyle\to\ket{x,u\oplus f(x;r)}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\emptyset,\emptyset}_{\mathcal{W}_{x}\times\mathcal{W}_{y}}\otimes\ket{r}_{\mathcal{P}} We claim that \mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\emptyset,\emptyset} at the start of every \mathsf{EvalAndCopy} query. Before any queries have been made, \mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\emptyset,\emptyset} . Next, the computational-basis values of \mathcal{W}_{x}\times\mathcal{W}_{y} are only modified during \mathsf{EvalAndCopy} . We showed above that \mathsf{EvalAndCopy} returns \mathcal{W}_{x}\times\mathcal{W}_{y} to \ket{\emptyset,\emptyset} , so \mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\emptyset,\emptyset} at the start of every \mathsf{EvalAndCopy} query. We also showed that \mathsf{EvalAndCopy} is equivalent to \ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{r}_{\mathcal{P}}\to\ket{x,u\oplus f(x;r)}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{r}_{\mathcal{P}} which is the application of \mathsf{Eval}_{f} to \mathcal{Q}_{x}\times\mathcal{Q}_{u}\times\mathcal{P} . Third, let us remove all the \mathsf{Decomp} operations from hybrid 2 as follows. The \mathsf{Decomp} operation at the end of one query cancels with the \mathsf{Decomp} operation at the start of the next one. This is because \mathsf{Decomp}\circ\mathsf{Decomp}=I , and \mathsf{Decomp} operates only on the internal registers of the oracle. Next, we can remove the first \mathsf{Decomp} from the first query. This \mathsf{Decomp} operation acts on \ket{\emptyset}_{\mathcal{P}} to produce the state \ket{+}_{\mathcal{P}} . In hybrid 3, we remove this \mathsf{Decomp} operation and instead have the oracle start with state \ket{+}_{\mathcal{P}} . Finally, we can remove the final \mathsf{Decomp} from the final query. \mathsf{Decomp} acts only on the internal registers of the oracle, so the view of a distinguisher that has query access to the oracle is unchanged. In summary, we have transformed hybrid 2 into hybrid 3 and shown that the two hybrids are equivalent. ∎ ∎ Lemma 20 . If P_{1} and P_{2} are testable quantum programs that implement the same functionality with 0 error, then oracles for \mathsf{Sim}^{\prime}(P_{1}) and \mathsf{Sim}^{\prime}(P_{2}) are perfectly indistinguishable to any adversary making an unbounded number of quantum queries. The intuition for this proof is that given two program states \ket{\psi^{1}},\ket{\psi^{2}} that implement the same sampling functionality, for each x , we can decompose each program state into a superposition over an orthonormal basis of programs that give deterministic output values. Since the two programs implement the same functionality, these bases are equivalent up to a rotation/labeling. This nice picture breaks down when you consider querying the program on multiple x values, but the database that \mathsf{Sim}^{\prime} uses to record queries allows us to get around this issue and still make the argument go through. Proof. First, for any program P and any (x,y)\in\mathcal{X}\times\mathcal{Y} , let \alpha_{x,y}=\sqrt{\Pr[P(x)\to y]} . In \mathsf{Sim}^{\prime}(P) , the initial state of \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is \ket{\psi,\emptyset,\emptyset} . The following claim says that we can decompose \ket{\psi,\emptyset,\emptyset} into a basis defined by the y -values that the program outputs. For each y -value, \ket{\psi_{x,y}} is the component of \ket{\psi,\emptyset,\emptyset} that produces output y when \mathsf{EvalAndCopy} is called. Claim 8 . For any x\in\mathcal{X} , there exists a set of orthonormal states \{\ket{\psi_{x,y}}\}_{y\in\mathcal{Y}} on registers \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} such that for any u\in\mathcal{Y}\cup\{\emptyset\} and any y in the support of P(x) , \displaystyle\mathsf{EvalAndCopy}\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}} \displaystyle=\ket{x,u+y}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}} Additionally, \ket{\psi,\emptyset,\emptyset} is in the span of \{\ket{\psi_{x,y}}\}_{y} : \ket{\psi,\emptyset,\emptyset}=\sum_{y\in\mathcal{Y}}\alpha_{x,y}\ket{\psi_{x,y}} Proof. First, note that \mathsf{EvalAndCopy} does not modify the computational-basis value of \mathcal{Q}_{x} . It just applies an operation that is controlled by \mathcal{Q}_{x} . When \mathcal{Q}_{x} contains value x , the \mathsf{EvalAndCopy} step acts as follows on registers \mathcal{Q}_{u}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{P} : \mathsf{Eval}_{x}^{\dagger}\circ\mathsf{CopyOutput}\circ\mathsf{Eval}_{x} where we define \mathsf{Eval}_{x} to be the operation that \mathsf{CNOT} s x onto register \mathcal{W}_{x} and then applies \mathsf{Eval} to \mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{P} . Second, for each x\in\mathcal{X} and each y in the support of P(x) , let \ket{\psi_{x,y}} be the component of \ket{\psi,\emptyset,\emptyset} that produces output y when the program is queried on x . Formally, for each x\in\mathcal{X} and each y in the support of P(x) , \text{let }\ket{\psi_{x,y}}=\frac{1}{\alpha_{x,y}}\cdot\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot(\ket{\psi,\emptyset,\emptyset}_{\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}}) This state is well-defined because for all y in the support of P(x) , \alpha_{x,y}\neq 0 . The state \ket{\psi_{x,y}} defined above has unit norm. We know that when P is evaluated on x , the value written to \mathcal{W}_{y} will be y with probability \alpha_{x,y}^{2}=\Pr[P(x)\to y] . That means \displaystyle\left\|(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right\| \displaystyle=\alpha_{x,y} Next, since \mathsf{Eval}_{x} is a unitary, \displaystyle\left\|\ket{\psi_{x,y}}\right\| \displaystyle=\left\|\frac{1}{\alpha_{x,y}}\cdot\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right\| \displaystyle=\frac{1}{\alpha_{x,y}}\cdot\left\|(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right\| \displaystyle=\frac{1}{\alpha_{x,y}}\cdot\alpha_{x,y}=1 Third, let us define \ket{\psi_{x,y}} for any y not in the support of P(x) . The definition above will not suffice here because \alpha_{x,y}=0 . \text{Let }\ket{\psi_{x,y}}=\mathsf{Eval}_{x}^{\dagger}\cdot(\ket{\psi}_{\mathcal{P}}\ket{\emptyset}_{\mathcal{W}_{x}}\ket{y}_{\mathcal{W}_{y}}) This state is well-defined and has unit norm because \mathsf{Eval}_{x}^{\dagger} is a unitary. Now we will prove some properties of \{\ket{\psi_{x,y}}\}_{y\in\mathcal{Y}} . Fourth, for any x\in\mathcal{X} , the states \{\ket{\psi_{x,y}}\}_{y\in\mathcal{Y}} are orthogonal. This is because for any y\in\mathcal{Y} , \mathsf{Eval}_{x}\ket{\psi_{x,y}} is in the span of \mathbb{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}} . For any two distinct values y,y^{\prime}\in\mathcal{Y} , \mathbb{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}} and \mathbb{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y^{\prime}}\bra{y^{\prime}}_{\mathcal{W}_{y}} project onto orthogonal subspaces, so \mathsf{Eval}_{x}\ket{\psi_{x,y}} and \mathsf{Eval}_{x}\ket{\psi_{x,y^{\prime}}} are orthogonal. Finally, \mathsf{Eval}_{x} is a unitary, so it preserves inner products, and \ket{\psi_{x,y}} and \ket{\psi_{x,y^{\prime}}} are orthogonal as well. Fifth, \ket{\psi,\emptyset,\emptyset} is in the span of \{\ket{\psi_{x,y}}\}_{y\in\mathcal{Y}} . \displaystyle\ket{\psi,\emptyset,\emptyset} \displaystyle=\mathsf{Eval}_{x}^{\dagger}\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset} \displaystyle=\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\mathbbm{I}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset} \displaystyle=\mathsf{Eval}_{x}^{\dagger}\cdot\left(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\sum_{y\in\mathcal{Y}\cup\{\emptyset\}}\ket{y}\bra{y}\right)\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset} \displaystyle=\sum_{y\in\mathcal{Y}\cup\{\emptyset\}}\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset} \displaystyle=\sum_{y\in\mathcal{Y}}\alpha_{x,y}\ket{\psi_{x,y}} We used the fact that \mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\left(\sum_{y\in\mathcal{Y}\cup\{\emptyset\}}\ket{y}\bra{y}\right)=\sum_{y\in\mathcal{Y}\cup\{\emptyset\}}\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y} We also used the fact that (\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{\emptyset}\bra{\emptyset})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}=\mathbf{0} because P(x) never outputs \emptyset . Likewise, for any y not in the support of P(x) , (\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}=\mathbf{0} . Sixth, let us show that for any y in the support of P(x) , \mathsf{EvalAndCopy}\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}}=\ket{x,u+y}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}} \mathsf{EvalAndCopy} does not modify the computational basis value of \mathcal{Q}_{x} and acts as \mathsf{Eval}_{x}^{\dagger}\circ\mathsf{CopyOutput}\circ\mathsf{Eval}_{x} on the remaining registers. Let us apply \mathsf{Eval}_{x} : \displaystyle\mathsf{Eval}_{x}(\ket{u}_{\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}}) \displaystyle=\ket{u}_{\mathcal{Q}_{u}}\otimes\mathsf{Eval}_{x}\cdot\left(\frac{1}{\alpha_{x,y}}\cdot\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right) \displaystyle=\frac{1}{\alpha_{x,y}}\cdot\ket{u}_{\mathcal{Q}_{u}}\otimes\left((\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right) Next, if we apply \mathsf{CopyOutput} , this copies y from \mathcal{W}_{y} to \mathcal{Q}_{u} : \displaystyle\mathsf{CopyOutput}\cdot\mathsf{Eval}_{x}\cdot\left(\ket{u}\otimes\ket{\psi_{x,y}}\right) \displaystyle=\frac{1}{\alpha_{x,y}}\cdot\ket{u+y}\otimes\left((\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right) Finally, let us apply \mathsf{Eval}_{x}^{\dagger} : \displaystyle\mathsf{Eval}_{x}^{\dagger}\cdot\mathsf{CopyOutput}\cdot\mathsf{Eval}_{x}\cdot\left(\ket{u}\otimes\ket{\psi_{x,y}}\right) \displaystyle=\frac{1}{\alpha_{x,y}}\cdot\ket{u+y}\otimes\left(\mathsf{Eval}_{x}^{\dagger}\cdot(\mathbbm{I}_{\mathcal{P}\times\mathcal{W}_{x}}\otimes\ket{y}\bra{y}_{\mathcal{W}_{y}})\cdot\mathsf{Eval}_{x}\cdot\ket{\psi,\emptyset,\emptyset}\right) \displaystyle=\ket{u+y}\otimes\ket{\psi_{x,y}} In summary, \mathsf{EvalAndCopy}\ket{x,u}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}}=\ket{x,u+y}_{\mathcal{Q}_{x}\times\mathcal{Q}_{u}}\otimes\ket{\psi_{x,y}} ∎ Let S_{x} be the span of \{\ket{\psi_{x,y}}\}_{y\in\mathcal{Y}} , and let S_{\perp,x} be the subspace of S_{x} that is orthogonal to \ket{\psi,\emptyset,\emptyset} . Since \ket{\psi_{x,y}}\in S_{x} , \ket{\psi_{x,y}} can be written as a superposition of \ket{\psi,\emptyset,\emptyset} and a state \ket{\psi^{\perp}_{x,y}}\in S_{\perp,x} . For programs P_{1}=(\ket{\psi^{1}},\mathsf{Eval}_{1},R_{1}) and P_{2}=(\ket{\psi^{2}},\mathsf{Eval}_{2},R_{2}) , let us use superscripts or subscripts for the variables defined above. For example, let \ket{\psi^{1}_{x,y}} and \ket{\psi^{2}_{x,y}} be the state \ket{\psi_{x,y}} defined for programs P_{1} and P_{2} , respectively. Let \mathsf{ReflectAndCopy}_{1},\mathsf{EvalAndCopy}_{1},\mathsf{ReflectAndCopy}_{2},\mathsf{EvalAndCopy}_{2} be defined analogously. For each x , let us define a unitary U_{x} that maps \displaystyle U_{x}:\ket{\psi^{1}_{x,y}}\mapsto\ket{\psi^{2}_{x,y}} for all y\in\mathcal{Y} . Such a unitary exists because \{\ket{\psi^{1}_{x,y}}\}_{y} and \{\ket{\psi^{2}_{x,y}}\}_{y} are each orthonormal. Next, let us define \mathsf{CU} to be a controlled version of U_{x} that reads the value of x from \mathcal{Q}_{x} and applies U_{x} to \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} . Claim 9 . For any x\in\mathcal{X} , U_{x}\cdot\ket{\psi^{1},\emptyset,\emptyset}=\ket{\psi^{2},\emptyset,\emptyset} . Proof. First, for any (x,y) , \alpha^{1}_{x,y}=\sqrt{\Pr[P_{1}(x)\to y]}=\sqrt{\Pr[P_{2}(x)\to y]}=\alpha^{2}_{x,y} . Second, \displaystyle U_{x}\cdot\ket{\psi^{1},\emptyset,\emptyset} \displaystyle=U_{x}\cdot\sum_{y}\alpha^{1}_{x,y}\ket{\psi^{1}_{x,y}} \displaystyle=\sum_{y}\alpha^{1}_{x,y}\cdot U_{x}\cdot\ket{\psi^{1}_{x,y}} \displaystyle=\sum_{y}\alpha^{1}_{x,y}\cdot\ket{\psi^{2}_{x,y}} \displaystyle=\sum_{y}\alpha^{2}_{x,y}\ket{\psi^{2}_{x,y}} \displaystyle=\ket{\psi^{2},\emptyset,\emptyset} ∎ Now let us define some hybrids to transform \mathsf{Sim}^{\prime}(P_{1}) into \mathsf{Sim}^{\prime}(P_{2}) . Hybrid 1. \mathsf{Sim}^{\prime}(P_{1}) Hybrid 2. At a high level, in this hybrid we operate on initial state \ket{\psi^{1}} but on each query it transforms the state into \ket{\psi^{2}} and acts with the P_{2} evaluation unitary. An important detail is that transforming from \ket{\psi^{1}} to \ket{\psi^{2}} can only be done with respect to some x – the x -value given as input to the query. • Initialize the program register with \ket{\psi^{1}} . • On queries of the form \ket{x,u,b}\ket{D} with x^{\prime}\in D such that x^{\prime}\neq x , act as the identity and skip the following steps. • Apply \mathsf{CU} , which applies U_{x} to \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} controlled on the value x written on \mathcal{Q}_{x} . • Apply the unitary \displaystyle\mathsf{Bitflip}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}}\circ\mathsf{EvalAndCopy}_{{\color[rgb]{1,0,0}2}}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}} • Apply \mathsf{CU}^{\dagger} . Hybrid 3. \mathsf{Sim}^{\prime}(P_{2}) Before showing the indistinguishability of these hybrids, we make the following claim. Claim 10 . At the end of any query in hybrids 1 and 2, the database and program registers maintain the following invariant: D=\emptyset if and only if \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} contain the initial program state \ket{\psi^{1},\emptyset,\emptyset} , and D=x if and only if \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} are in some state \ket{\phi}\in S^{1}_{\perp,x} . Proof. We first prove this invariant for hybrid 1 using induction. For the base case: the oracle is initialized in the state \ket{\emptyset}_{\mathcal{D}}\ket{\psi^{1},\emptyset,\emptyset}_{\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}} , so the invariant is satisfied to begin with. For the inductive case, let us assume that at the start of a query, the invariant is satisfied. We will show that the invariant is still satisfied at the end of the query. First, if \mathcal{Q}_{x}=\ket{x} , \mathcal{D}=\ket{x^{\prime}} , and x^{\prime}\notin\{\emptyset,x\} , then this query aborts, and the state on \mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} still satisfy the invariant. Next, let us consider the case where \mathcal{Q}_{x}=\ket{x} , and \mathcal{D} contains either x or \emptyset . Let us also assume that the state satisfies the invariant at the start of the query. First, by lemma 18 , \mathsf{ReflectAndCopy} acts as follows. \displaystyle\mathsf{ReflectAndCopy}: \displaystyle\ket{\emptyset}\ket{\psi^{1},\emptyset,\emptyset}\mapsto\ket{x}\ket{\psi^{1},\emptyset,\emptyset} \displaystyle\ket{x}\ket{\phi}\mapsto\ket{x}\ket{\phi} where \ket{\phi}\in S^{1}_{\perp,x} . Therefore, at the end of \mathsf{ReflectAndCopy} , \mathcal{D}=\ket{x} , and \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} are in S^{1}_{x} . Second, \mathsf{EvalAndCopy} is applied. When \mathsf{EvalAndCopy} is applied to \ket{x}_{\mathcal{D}}\ket{\psi^{1}_{x,y}}_{\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}} , it does not change the state on the \mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} registers (by 8 ). This implies that \mathsf{EvalAndCopy} maps states in S^{1}_{x} to states in S^{1}_{x} . Additionally, \mathsf{EvalAndCopy} does not touch \mathcal{D} . Therefore, at the end of \mathsf{EvalAndCopy} , \mathcal{D} still contains x , and \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} still lies in S^{1}_{x} . Third, we apply \mathsf{ReflectAndCopy} again. At the start of this operation, \mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is in the span of \ket{x}\ket{\psi^{1},\emptyset,\emptyset} and \ket{x}\ket{\phi} for states \ket{\phi}\in S^{1}_{\perp,x} . \mathsf{ReflectAndCopy} acts on these basis states as follows: \displaystyle\mathsf{ReflectAndCopy}: \displaystyle\ket{x}\ket{\psi^{1},\emptyset,\emptyset}\mapsto\ket{\emptyset}\ket{\psi^{1},\emptyset,\emptyset} \displaystyle\ket{x}\ket{\phi}\mapsto\ket{x}\ket{\phi} Therefore, the state at the end of this operation is in the span of states that satisfy the invariant. Fourth, we apply \mathsf{Bitflip} . This operation acts only on \mathcal{Q}_{b} , so the state at the end of this operation will still satisfy the invariant. A very similar argument also shows that this invariant holds for hybrid 2. ∎ Claim 11 . At the start of any invocation of \mathsf{EvalAndCopy}_{1} in hybrid 1, the state of \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is in S^{1}_{x} , where x is the value written on \mathcal{Q}_{x} . Proof. 10 says that at the start of any query, the state of \mathcal{D}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is in \ket{\emptyset}\ket{\psi^{1},\emptyset,\emptyset} or \ket{x^{\prime}}\ket{\phi} for some \ket{\phi}\in S^{1}_{\perp,x^{\prime}} . In the second case, we can assume that x^{\prime}=x because otherwise, the query will immediately abort, and \mathsf{EvalAndCopy}_{1} will not be executed. Next, the query to \mathsf{Sim}^{\prime}(P) applies \mathsf{ReflectAndCopy}_{1} , which acts as follows ( lemma 18 ): \displaystyle\mathsf{ReflectAndCopy}_{1}: \displaystyle\ket{\emptyset}\ket{\psi^{1},\emptyset,\emptyset}\mapsto\ket{x}\ket{\psi^{1},\emptyset,\emptyset} \displaystyle\ket{x}\ket{\phi}\mapsto\ket{x}\ket{\phi} for any \ket{\phi}\in S^{1}_{\perp,x} . In either case, \mathsf{ReflectAndCopy}_{1} maps states in S^{1}_{x} to states in S^{1}_{x} . Next, the only time that \mathsf{EvalAndCopy}_{1} is invoked is right after the first invocation of \mathsf{ReflectAndCopy} . We’ve shown that at the start of \mathsf{EvalAndCopy}_{1} , the state of \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} is in S^{1}_{x} . ∎ Claim 12 . Hybrids 1 and 2 are perfectly indistinguishable. Proof. First, we make the following observations: 1. \mathsf{CU}^{\dagger}\circ\mathsf{Bitflip}\circ\mathsf{CU}=\mathsf{Bitflip} . This is because \mathsf{Bitflip} acts only on \mathcal{Q}_{b} , and \mathsf{CU} acts only on \mathcal{Q}_{x}\times\mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} . Since they act on disjoint registers, they commute, so \mathsf{CU}^{\dagger}\circ\mathsf{Bitflip}\circ\mathsf{CU}=\mathsf{CU}^{\dagger}\circ\mathsf{CU}\circ\mathsf{Bitflip}=\mathsf{Bitflip} . 2. \mathsf{CU}^{\dagger}\circ\mathsf{ReflectAndCopy}_{2}\circ\mathsf{CU}=\mathsf{ReflectAndCopy}_{1} . First, \mathsf{ReflectAndCopy}_{2} is equivalent to the operation that applies \mathsf{CNOT} from \mathcal{Q}_{x} to \mathcal{D} controlled on \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}\times\mathcal{W}_{b} being in the state \ket{\psi^{2},\emptyset,\emptyset,0} ( lemma 18 ). Second, \mathsf{CU} acts as follows ( 9 ): \ket{x}_{\mathcal{Q}_{x}}\ket{\psi^{1},\emptyset,\emptyset,0}\to\ket{x}_{\mathcal{Q}_{x}}\ket{\psi^{2},\emptyset,\emptyset,0} That implies that \mathsf{CU}^{\dagger}\circ\mathsf{ReflectAndCopy}_{2}\circ\mathsf{CU} applies \mathsf{CNOT} from \mathcal{Q}_{x} to \mathcal{D} controlled on the state \ket{\psi^{1},\emptyset,\emptyset,0} . This is the same as \mathsf{ReflectAndCopy}_{1} . 3. For every x,y , \displaystyle\mathsf{EvalAndCopy}_{1}(\ket{x,u}\ket{\psi^{1}_{x,y}}) \displaystyle=\ket{x,u+y}\ket{\psi^{1}_{x,y}} \displaystyle=\mathsf{CU}^{\dagger}\circ\mathsf{EvalAndCopy}_{2}(\ket{x,u}\ket{\psi^{2}_{x,y}}) \displaystyle=\mathsf{CU}^{\dagger}\circ\mathsf{EvalAndCopy}_{2}\circ\mathsf{CU}(\ket{x,u}\ket{\psi^{1}_{x,y}}) 4. For every x,y , and every state \ket{\phi}\in S^{1}_{x} , we have that \displaystyle\mathsf{EvalAndCopy}_{1}(\ket{x,u}\ket{\phi})=\mathsf{CU}^{\dagger}\circ\mathsf{EvalAndCopy}_{2}\circ\mathsf{CU}(\ket{x,u}\ket{\phi}) This follows from the previous observation ( Item 3 ). By 11 , in hybrid 1, \mathsf{EvalAndCopy}_{1} is only invoked on states in S^{1}_{x} , and on these states, \mathsf{EvalAndCopy}_{1} acts the same as \mathsf{CU}^{\dagger}\circ\mathsf{EvalAndCopy}_{2}\circ\mathsf{CU} . Therefore, in hybrid 1, we can replace \mathsf{EvalAndCopy}_{1} with \mathsf{CU}^{\dagger}\circ\mathsf{EvalAndCopy}_{2}\circ\mathsf{CU} , and the change will be perfectly indistinguishable. Let us put everything together. We can replace \mathsf{Bitflip}\circ\mathsf{ReflectAndCopy}_{1}\circ\mathsf{EvalAndCopy}_{1}\circ\mathsf{ReflectAndCopy}_{1} from hybrid 1 with {\color[rgb]{1,0,0}\mathsf{CU}^{\dagger}}\circ\mathsf{Bitflip}\circ{\color[rgb]{1,0,0}\mathsf{CU}}\circ{\color[rgb]{1,0,0}\mathsf{CU}^{\dagger}}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}}\circ{\color[rgb]{1,0,0}\mathsf{CU}}\circ{\color[rgb]{1,0,0}\mathsf{CU}^{\dagger}}\circ\mathsf{EvalAndCopy}_{{\color[rgb]{1,0,0}2}}\circ{\color[rgb]{1,0,0}\mathsf{CU}}\circ{\color[rgb]{1,0,0}\mathsf{CU}^{\dagger}}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}}\circ{\color[rgb]{1,0,0}\mathsf{CU}} Then when we cancel out adjacent applications of \mathsf{CU} and \mathsf{CU}^{\dagger} , the operation becomes: {\color[rgb]{1,0,0}\mathsf{CU}^{\dagger}}\circ\mathsf{Bitflip}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}}\circ\mathsf{EvalAndCopy}_{{\color[rgb]{1,0,0}2}}\circ\mathsf{ReflectAndCopy}_{{\color[rgb]{1,0,0}2}}\circ{\color[rgb]{1,0,0}\mathsf{CU}} This is the sequence of operations found in hybrid 2. Therefore, hybrids 1 and 2 are perfectly indistinguishable. ∎ Claim 13 . Hybrids 2 and 3 are perfectly indistinguishable. Proof. In hybrid 2, the first application of \mathsf{CU} during the first query to the simulator converts \ket{\psi^{1},\emptyset,\emptyset} into \ket{\psi^{2},\emptyset,\emptyset} , which is consistent with the initial state of \ket{\psi^{2},\emptyset,\emptyset} in hybrid 3. We would now like to argue that the applications of \mathsf{CU} and \mathsf{CU}^{\dagger} cancel each other, but this is not true in general: in between queries, the adversary can act on the input query register, so that we are effectively applying a U_{x^{\prime}}\circ U^{\dagger}_{x} operation on the internal state of the oracle, which is not the identity operation in general. We make use of the invariant from 10 : In every branch of the superposition of hybrid 2, after the end of a query, either D=\emptyset and \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y}=\ket{\psi^{1},\emptyset,\emptyset} , or D contains x , and \mathcal{P}\times\mathcal{W}_{x}\times\mathcal{W}_{y} contains \ket{\phi}\in S^{1}_{\bot,x} . In the branch with \ket{\psi^{1},\emptyset,\emptyset} , \mathsf{CU} acts the same no matter what the control register is, and always transforms \ket{\psi^{1},\emptyset,\emptyset} to \ket{\psi^{2},\emptyset,\emptyset} , In this branch, the applications of \mathsf{CU} and \mathsf{CU}^{\dagger} cancel each other. In the branch with \ket{\phi}\ket{x} , where \ket{\phi}\in S^{1}_{\bot,x} , if x^{\prime}\neq x , the next query acts as the identity on this branch, so we can ignore it. ∎ This shows that \mathsf{Sim}^{\prime}(P_{1}) and \mathsf{Sim}^{\prime}(P_{2}) are perfectly indistinguishable and completes the proof of Lemma 20 . ∎ Lemma 21 (Simulation of the CSEQ oracle) . Given any (possibly oracle-aided) testable quantum program P that implements f with 0 error, an oracle for \mathsf{Sim}^{\prime}(P) ( definition 28 ) is perfectly indistinguishable from O_{f}^{\mathsf{CSEQ}} to any adversary making an unbounded number of quantum queries. Proof. First, \mathsf{Sim}^{\prime} only needs black-box access to the \mathsf{Eval} and R operations of P . It does not access \ket{\psi} directly. P may even be oracle-aided, and the oracle may maintain an internal pure state, which is considered part of \ket{\psi} . Second, P_{f} (defined in lemma 19 ) and P are testable quantum programs. P_{f} implements f with 0 error. Lemma 19 says that \mathsf{Sim}^{\prime}(P_{f}) and O_{f}^{\mathsf{CSEQ}} are perfectly indistinguishable after an unbounded number of quantum queries. Third, since P also implements f with 0 error, lemma 20 implies that oracles for \mathsf{Sim}^{\prime}(P_{f}) and \mathsf{Sim}^{\prime}(P) are perfectly indistinguishable after an unbounded number of quantum queries. Therefore, \mathsf{Sim}^{\prime}(P) and O_{f}^{\mathsf{CSEQ}} are also perfectly indistinguishable after an unbounded number of quantum queries. ∎ Remark 2 . For classical functionalities, any testable OTP compiler that satisfies CSEQ security is best-possible among testable programs, in the sense of definition 16 . This follows from Lemma 21 . Theorem 15 . 1. For any sets of bitstrings \mathcal{X},\mathcal{R},\mathcal{Y} , there exists a Q.P.T. simulator \mathsf{Sim}_{1} such that for every randomized function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} , O^{\mathsf{CSEQ}}_{f} and \mathsf{Sim}_{1}^{O^{\mathsf{SEQ}}_{\Phi_{f}}} are perfectly indistinguishable. 2. For any sets of bitstrings \mathcal{X},\mathcal{R},\mathcal{Y} , for which |\mathcal{X}|>1 , there exists a Q.P.T. simulator \mathsf{Sim}_{2} such that for every randomized function f:\mathcal{X}\times\mathcal{R}\to\mathcal{Y} , \mathsf{Sim}_{2}^{O^{\mathsf{CSEQ}}_{f}} and O^{\mathsf{SEQ}}_{\Phi_{f}} are perfectly indistinguishable. Proof. Simulating O_{f}^{\mathsf{CSEQ}} with \mathsf{Sim}_{1} : Let \mathsf{Sim}^{\prime} be the simulator from definition 28 . By lemma 21 , if \mathsf{Sim}^{\prime} is given black-box access to any testable quantum program P that implements f with 0 error, then \mathsf{Sim}^{\prime}(P) is perfectly indistinguishable from O^{\mathsf{CSEQ}}_{f} . The program P may be oracle-aided, and the oracle may maintain an internal pure state. Next, O^{\mathsf{SEQ}}_{\Phi_{f}} can be used to construct such a testable quantum program that implements f with 0 error ( lemma 22 ). Composing these two procedures yields \mathsf{Sim}_{1} . Simulating O_{\Phi_{f}}^{\mathsf{SEQ}} with \mathsf{Sim}_{2} : \mathsf{Sim}_{2} mainly uses the simulator \mathsf{Sim}^{\prime} from definition 17 (this is a different \mathsf{Sim}^{\prime} than the one used to construct \mathsf{Sim}_{1} ). This \mathsf{Sim}^{\prime} takes any testable quantum program that implements \Phi_{f} and perfectly simulates O^{\mathsf{SEQ}}_{\Phi_{f}} ( lemma 8 ). The program can be oracle-aided, and the oracle can even maintain an internal state. \mathsf{Sim}^{\prime} only needs black-box access to the program’s \mathsf{Eval} and R operations. Next, we can use O^{\mathsf{CSEQ}}_{f} to construct an (oracle-aided) testable quantum program that implements \Phi_{f} as long as |\mathcal{X}|>1 ( lemma 23 ). Then if we run \mathsf{Sim}^{\prime} on this program, it will perfectly simulate O^{\mathsf{SEQ}}_{\Phi_{f}} . ∎ Lemma 22 . O^{\mathsf{SEQ}}_{\Phi_{f}} can be used to construct an (oracle-aided) testable quantum program that implements f with 0 error. The program is oracle-aided since it makes queries to O^{\mathsf{SEQ}}_{\Phi_{f}} , and the program state includes the internal state of the oracle. Proof. Let us construct a testable quantum program P=(\ket{\psi},\mathsf{Eval},\mathsf{R}) that implements f . • Program State \ket{\psi} : Let the program state be the internal state of O^{\mathsf{SEQ}}_{\Phi_{f}} concatenated with a cache register \mathcal{B} that is initialized to \ket{0} . Note that the internal state of O^{\mathsf{SEQ}}_{\Phi_{f}} is defined as a pure state, so the initial program state \ket{\psi} is indeed pure. • \mathsf{Eval} : The program’s \mathsf{Eval} operation simply queries O^{\mathsf{SEQ}}_{\Phi_{f}} . \mathsf{Eval} takes an external query register \mathcal{Q} with basis states of the form \ket{x,u} where (x,u)\in\mathcal{X}\times\mathcal{Y} . Then \mathsf{Eval} queries O^{\mathsf{SEQ}}_{\Phi_{f}} on \mathcal{Q}\times\mathcal{B} : \ket{x,u}_{\mathcal{Q}}\otimes\ket{b}_{\mathcal{B}}\to\ket{x,u\oplus y}_{\mathcal{Q}}\otimes\ket{b\oplus b^{\prime}}_{\mathcal{B}} Finally, \mathsf{Eval} outputs \mathcal{Q} . • R : The reflection operation R takes an external register \mathcal{E} . If \mathcal{B} stores 0 , then R applies \mathsf{X} to \mathcal{E} . Claim 14 . The program P defined above implements f with 0 error ( definition 10 ). Proof. Given a query of the form \ket{x,0} , the program’s \mathsf{Eval} operation queries O^{\mathsf{SEQ}}_{\Phi_{f}} on \ket{x,0,b} . The first time O^{\mathsf{SEQ}}_{\Phi_{f}} is queried, it applies the unitary U_{\Phi_{f}} , which uses a compressed oracle to compute y=f(x;r) for a uniformly random r\overset{\$}{\leftarrow}\mathcal{R} . This is exactly the output distribution of f(x) . ∎ The following claim shows that P is indeed testable. Claim 15 . After any number of \mathsf{Eval} and R operations, applying R is equivalent to applying the function \mathsf{X}\otimes\ket{\psi}\bra{\psi}+I\otimes(I-\ket{\psi}\bra{\psi}) to \mathcal{E} and the current program state. Proof. Here is some intuition for why R works as the reflection oracle. First, O^{\mathsf{SEQ}}_{\Phi_{f}} ’s internal state includes a register \mathcal{C} that is \ket{0} if and only if O^{\mathsf{SEQ}}_{\Phi_{f}} is in its initial state. Second, any time that \mathcal{C} is changed, O^{\mathsf{SEQ}}_{\Phi_{f}} flips the output bit b . This implies that \mathcal{C} and \mathcal{B} always store the same value after any query, and that \mathcal{B}=\ket{0} if and only if the program state is in its initial state. Next, we will make this argument formal. The program state comprises three registers: \mathcal{C} and \mathcal{P} , which contain O^{\mathsf{SEQ}}_{\Phi_{f}} ’s state, and \mathcal{B} . The initial state of \mathcal{B}\times\mathcal{C}\times\mathcal{P} is \ket{\psi}:=\ket{0}\otimes\ket{0}\otimes\ket{0^{m}} . We will show that after any number of \mathsf{Eval} and R operations, \mathcal{B}=\ket{0} if and only if \mathcal{B}\times\mathcal{C}\times\mathcal{P}=\ket{\psi} . After any number of \mathsf{Eval} and R operations, \mathcal{B} and \mathcal{C} store the same computational-basis value. First, \mathcal{B}\times\mathcal{C} are initialized to \ket{0}\otimes\ket{0} . Next, the only time that \mathcal{C} ’s computational-basis value changes is potentially during an \mathsf{Eval} operation, specifically during step 2 of the query to O^{\mathsf{SEQ}}_{\Phi_{f}} . If \mathcal{C} is not flipped in step 2 , then this call to O^{\mathsf{SEQ}}_{\Phi_{f}} acts as the identity, and \mathcal{B} is not flipped either. On the other hand, if \mathcal{C} is flipped in step 2 , then this call to O^{\mathsf{SEQ}}_{\Phi_{f}} applies U_{\Phi_{f}} or U_{\Phi_{f}}^{\dagger} , which are equal according to 16 . U_{\Phi_{f}} flips the value of b . Since the program records the value of b on register \mathcal{B} , that means that \mathcal{B} is flipped on any query that flips \mathcal{C} . Therefore, after any number of \mathsf{Eval} or R operations, \mathcal{B}\times\mathcal{C} store (0,0) or (1,1) . After any number of \mathsf{Eval} and R operations, if \mathcal{C}=\ket{0} then \mathcal{P}=\ket{0^{m}} . First, \mathcal{C}\times\mathcal{P} are initialized to \ket{0}\otimes\ket{0^{m}} , so the invariant is initially true. Second, R does not change the state of \mathcal{C}\times\mathcal{P} . Third, the first \mathsf{Eval} query flips \mathcal{C} to \ket{1} with certainty. If any future \mathsf{Eval} query flips \mathcal{C} back to \ket{0} , then the check in step 2 of O^{\mathsf{SEQ}}_{\Phi_{f}} must have found that \mathcal{P}=\ket{0^{m}} and flipped \mathcal{C} to \ket{0} . Then step 3 would have acted as the identity because \mathcal{C}=\ket{0} , so at the end of the query, it is still true that \mathcal{P}=\ket{0^{m}} . This argument extends to show that after any number of queries, either \mathcal{C}=\ket{1} or \mathcal{C}\times\mathcal{P}=\ket{0}\otimes\ket{0^{m}} . The previous discussion implies that after any number of \mathsf{Eval} and R operations, if \mathcal{B}=\ket{0} , then \mathcal{C}=\ket{0} , and \mathcal{P}=\ket{0^{m}} , so \mathcal{B}\times\mathcal{C}\times\mathcal{P}=\ket{\psi} . Next, if \mathcal{B}=\ket{1} , then \mathcal{B}\times\mathcal{C}\times\mathcal{P}\neq\ket{\psi} . Therefore, \mathcal{B}=\ket{0} if and only if \mathcal{B}\times\mathcal{C}\times\mathcal{P}=\ket{\psi} . Finally, R applies \mathsf{X} to \mathcal{E} if \mathcal{B}=\ket{0} . This is equivalent to applying \mathsf{X} to \mathcal{E} if \mathcal{B}\times\mathcal{C}\times\mathcal{P} is in state \ket{\psi} . ∎ Claim 16 . For the unitary U_{\Phi_{f}} defined in definition 27 , U^{\dagger}_{\Phi_{f}}=U_{\Phi_{f}} . Proof. First, steps 1 - 3 of U_{\Phi_{f}} are each their own inverses. Step 1 CNOTs x from \mathcal{Q} to \mathcal{W} , which can be uncomputed by applying step 1 a second time. Step 2 queries the compressed oracle. The compressed oracle is perfectly indistinguishable from a random oracle when queried as a black box, and any query to a random oracle can be uncomputed by querying the random oracle a second time. Therefore, step 2 can be uncomputed by computing step 2 a second time. Step 3 CNOTs some values that are computed from \mathcal{W} onto \mathcal{Q} . This can be uncomputed by applying step 3 a second time. Second, U_{\Phi_{f}} and U_{\Phi_{f}}^{\dagger} apply the following sequences of operations: \displaystyle U_{\Phi_{f}} \displaystyle=\text{step \ref{step:copy-x}}^{\dagger}\cdot\text{step \ref{step:query-CO}}^{\dagger}\cdot\text{step \ref{step:answer-query}}\cdot\text{step \ref{step:query-CO}}\cdot\text{step \ref{step:copy-x}} \displaystyle U_{\Phi_{f}}^{\dagger} \displaystyle=\left(\text{step \ref{step:copy-x}}^{\dagger}\cdot\text{step \ref{step:query-CO}}^{\dagger}\cdot\text{step \ref{step:answer-query}}\cdot\text{step \ref{step:query-CO}}\cdot\text{step \ref{step:copy-x}}\right)^{\dagger} \displaystyle=\text{step \ref{step:copy-x}}^{\dagger}\cdot\text{step \ref{step:query-CO}}^{\dagger}\cdot\text{step \ref{step:answer-query}}^{\dagger}\cdot\left(\text{step \ref{step:query-CO}}^{\dagger}\right)^{\dagger}\cdot\left(\text{step \ref{step:copy-x}}^{\dagger}\right)^{\dagger} \displaystyle=\text{step \ref{step:copy-x}}^{\dagger}\cdot\text{step \ref{step:query-CO}}^{\dagger}\cdot\text{step \ref{step:answer-query}}\cdot\text{step \ref{step:query-CO}}\cdot\text{step \ref{step:copy-x}} \displaystyle=U_{\Phi_{f}} ∎ ∎ Lemma 23 . If |\mathcal{X}|>1 , then O^{\mathsf{CSEQ}}_{f} can be used to construct an (oracle-aided) testable quantum program that implements \Phi_{f} . Proof. Let us construct a testable quantum program P=(\ket{\psi},\mathsf{Eval},\mathsf{R}) that implements \Phi_{f} . • Program State \ket{\psi} : Let the program state \ket{\psi} be the internal state of O^{\mathsf{CSEQ}}_{f} concatenated with several work registers. Let x_{0},x_{1}\in\mathcal{X} be two distinct values, and then initialize the work registers as follows: \mathcal{Q}_{0}=\ket{x_{0},0,0},\mathcal{Q}_{1}=\ket{x_{1},0,0},\mathcal{B}_{0}=\ket{0},\mathcal{B}_{1}=\ket{0} Note that the internal state of O^{\mathsf{CSEQ}}_{f} is defined as a pure state, so \ket{\psi} is indeed pure. • \mathsf{Eval} : The program’s \mathsf{Eval} operation simply queries O^{\mathsf{CSEQ}}_{f} . • R : The reflection operation R should test whether the program state is in its initial state. Part of the program state is contained in the oracle O^{\mathsf{CSEQ}}_{f} , so our construction cannot access it directly. Instead, we can make queries to O^{\mathsf{CSEQ}}_{f} to test if its internal state is in its initial state. Our strategy is to query O^{\mathsf{CSEQ}}_{f} on two different inputs, while uncomputing between queries. If the oracle answers both queries, then its state began in the initial state. If it rejects at least one query, then its database must already record a query. Formally, R takes as input a single-qubit register \mathcal{E} and acts as follows. 1. Query O^{\mathsf{CSEQ}}_{f} on \mathcal{Q}_{0} . The resulting state is \ket{x_{0},y_{0},b_{0}}_{\mathcal{Q}_{0}} for some y_{0}\in\mathcal{Y} and b_{0}\in\{0,1\} . 2. Copy b_{0} onto \mathcal{B}_{0} . 3. Uncompute item 1 . 4. Query O^{\mathsf{CSEQ}}_{f} on \mathcal{Q}_{1} . The resulting state is \ket{x_{1},y_{1},b_{1}}_{\mathcal{Q}_{1}} for some y_{1}\in\mathcal{Y} and b_{1}\in\{0,1\} . 5. Copy b_{1} onto \mathcal{B}_{1} . 6. Uncompute item 4 . 7. If \ket{b_{0},b_{1}}_{\mathcal{B}_{0}\times\mathcal{B}_{1}}=\ket{1,1} , then apply \mathsf{X} (bitflip) to register \mathcal{E} . 8. Uncompute steps 1 - 6 . Claim 17 . P implements \Phi_{f} (with 0 error). Proof. When we apply \mathsf{Eval} to the user’s query register \mathcal{Q} and the initial program state \ket{\psi} , it queries O^{\mathsf{CSEQ}}_{f} . Since the database of O^{\mathsf{CSEQ}}_{f} is initialized to \ket{\emptyset} , step 1 of O^{\mathsf{CSEQ}}_{f} does nothing during this query. If we omit step 1 of O^{\mathsf{CSEQ}}_{f} , then the remaining steps are exactly the same as U_{\Phi_{f}} . Therefore, applying \mathsf{Eval} with program state \ket{\psi} computes the same operation as \Phi_{f} . ∎ The following claim shows that P is indeed testable. Claim 18 . After any number of \mathsf{Eval} and R operations, applying R is equivalent to applying the function \mathsf{X}\otimes\ket{\psi}\bra{\psi}+I\otimes(I-\ket{\psi}\bra{\psi}) to \mathcal{E} and the current program state. Proof. Let us consider the case where P ’s program state is in its initial state \ket{\psi} . We will show that in this case, R applies \mathsf{X} to \mathcal{E} and restores the program state to its initial state. Step 1 of R queries O^{\mathsf{CSEQ}}_{f} on input \ket{x_{0},0,0} . Since we are in the initial state, O^{\mathsf{CSEQ}}_{f} responds to the query and flips b_{0} to 1 with certainty. Step 2 copies b_{0} to another register \mathcal{B}_{0} , but this step does not change the joint state on \mathcal{Q}_{0} and the internal registers of O^{\mathsf{CSEQ}}_{f} because the value b_{0}=1 is deterministic. Step 3 uncomputes step 1 . Steps 1 and 3 act only on \mathcal{Q}_{0} and the internal state of O^{\mathsf{CSEQ}}_{f} , and the state on these registers is unchanged by step 2 . Therefore the state of \mathcal{Q}_{0} and the internal state of O^{\mathsf{CSEQ}}_{f} is the same at the end of step 3 as it was at the start of step 1 . The only difference in the program’s state is that at the end of step 3 , \mathcal{B}_{0} contains \ket{1} . Next, steps 4 - 6 are the same as steps 1 - 3 except the query register is \mathcal{Q}_{1}=\ket{x_{1},0,0} . By the same argument as before, the state at the end of step 6 is the same as the state at the start of step 1 except that \mathcal{B}_{0}=\ket{1} and \mathcal{B}_{1}=\ket{1} . Next, step 7 applies \mathsf{X} to \mathcal{E} with certainty. This step does not change the state on the program’s registers because the application of \mathsf{X} occurs with probability 1 . Finally, step 8 uncomputes all steps except for the application of \mathsf{X} . At the end of R , the program state is the initial state \ket{\psi} , and the only change from the beginning of R is the application of \mathsf{X} to \mathcal{E} . Next, let us consider the case where the program state is orthogonal to \ket{\psi} . We only need to consider states that are reachable from a sequence of \mathsf{Eval} and R operations. We will show that in this case, R acts as the identity. If the program state is orthogonal to \ket{\psi} , then the database register \mathcal{D} must contain a non-empty database D . The program state comprises the registers: \mathcal{W}\times\mathcal{D} , which are the internal state of O^{\mathsf{CSEQ}}_{f} , as well as \mathcal{Q}_{0}\times\mathcal{Q}_{1}\times\mathcal{B}_{0}\times\mathcal{B}_{1} . After any query to O^{\mathsf{CSEQ}}_{f} , the \mathcal{W} register is in the \ket{0} state because any values written to it have been uncomputed during the query. Likewise, the state of \mathcal{Q}_{0}\times\mathcal{Q}_{1}\times\mathcal{B}_{0}\times\mathcal{B}_{1} at the start of any R operation is the same as its initial state ( 19 ). After any number of queries to \mathsf{Eval} and R , the only register that might not be in its initial state is \mathcal{D} . If the program state is orthogonal to \ket{\psi} , then \mathcal{D} must contain a non-empty database. We will consider two types of non-empty databases: (1) every entry of D (the only entry, really) is of the form (x_{0},r) for some r\in\mathcal{R} , and (2) D contains (x^{\prime},r) for some x^{\prime}\neq x_{0} and some r\in\mathcal{R} . Now let us step through R in the first case, where every entry of D is of the form (x_{0},r) for some r\in\mathcal{R} . Step 1 queries O^{\mathsf{CSEQ}}_{f} on input \ket{x_{0},0,0} , and the query is answered ( b_{0}=1 ). Step 2 copies b_{0} to \mathcal{B}_{0} , and step 3 uncomputes step 1 . The state of the program at the end of step 3 is the same as the state at the beginning of step 1 except that \mathcal{B}_{0}=\ket{1} . Next, step 4 queries O^{\mathsf{CSEQ}}_{f} on x_{1} . This query is rejected ( b_{1}=0 ) because D contains (x_{0},r) . By step 7 , \mathcal{B}_{0}\times\mathcal{B}_{1}=\ket{1,0} , so step 7 acts as the identity. Finally, step 8 uncomputes steps 1 - 6 , so R acts as the identity on the program state. Finally, let us step through R in the second case, where D contains (x^{\prime},r) for some x^{\prime}\neq x_{0} and some r\in\mathcal{R} . Then the query to O^{\mathsf{CSEQ}}_{f} in step 1 will be rejected ( b_{0}=0 ). Skipping ahead, at the start of step 7 , \mathcal{B}_{0}=\ket{0} , so this step acts as the identity. Finally, step 8 uncomputes steps 1 - 6 , so R acts as the identity on the program state. In summary, we’ve shown that for every program state that is reachable by a sequence of \mathsf{Eval} and R operations, if the program state is orthogonal to \ket{\psi} , then R acts as the identity on the program state. ∎ Claim 19 . After any number of \mathsf{Eval} and R operations, the work registers are in their initial state: \mathcal{Q}_{0}=\ket{x_{0},0,0},\mathcal{Q}_{1}=\ket{x_{1},0,0},\mathcal{B}_{0}=\ket{0},\mathcal{B}_{1}=\ket{0} Proof. Before any \mathsf{Eval} and R operations have been executed, the work registers \mathcal{Q}_{0}\times\mathcal{Q}_{1}\times\mathcal{B}_{0}\times\mathcal{B}_{1} are in their initial state. Next, \mathsf{Eval} does not modify the work registers. Finally, it suffices to analyze an R operation and show that if the work registers are in their initial state at the start of the operation, then they will return to their initial state at the end of the operation. Let us split up the program’s registers into two groups. Let register \mathcal{R} comprise all components of the work registers \mathcal{Q}_{0}\times\mathcal{Q}_{1}\times\mathcal{B}_{0}\times\mathcal{B}_{1} except the values x_{0} and x_{1} written on \mathcal{Q}_{0} and \mathcal{Q}_{1} respectively. Let \mathcal{S} comprise the internal registers of O^{\mathsf{CSEQ}}_{f} and the values x_{0} and x_{1} written on \mathcal{Q}_{0} and \mathcal{Q}_{1} . Next, no step of R or O^{\mathsf{CSEQ}}_{f} modifies the computational basis value of x_{0} and x_{1} written on \mathcal{Q}_{0} and \mathcal{Q}_{1} . Therefore these values remain in unchanged by R . Steps 1 - 6 of R may modify register \mathcal{R} , but they only do so by CNOT-ing a value onto \mathcal{R} that was computed from the state on register \mathcal{S} . Next, step 7 applies an \mathsf{X} operation to \mathcal{E} controlled on the value of \mathcal{R} . However, step 7 does not change the state of \mathcal{S} . Finally, step 8 uncomputes steps 1 - 6 . Again, this entails CNOT-ing a value onto \mathcal{R} that is computed from the state on \mathcal{S} . The value that is CNOT-ed in step 8 is the same as the value that was CNOT-ed during steps 1 - 6 because the state on \mathcal{S} is unchanged. Therefore step 8 returns the state of \mathcal{R} to its initial state. In summary, all components of \mathcal{Q}_{0}\times\mathcal{Q}_{1}\times\mathcal{B}_{0}\times\mathcal{B}_{1} are returned to their initial state at the end of R . ∎ ∎ Appendix C Impossibility of one-time correct sampling QSIO In this section, we show that our impossibility for a best-possible one-time compiler in Section 3 rules out the existence of obfuscation schemes that satisfy a natural definition of quantum state indistinguishability obfuscation for sampling programs. Previously, quantum state indistinguishability obfuscation has been studied only in the setting where the quantum program implements a deterministic classical functionality with negligible error [ 10 , 23 ] . A natural generalization of the definition of quantum state IO to quantum programs designed for sampling tasks is the following. It requires obfuscations of any two programs that implement the same sampling task to be indistinguishable. Crucially, for two programs to be equal in this sense, they need to evaluate the same distributions on the first query, but there are no guarantees on their equivalence on subsequent queries. A priori, one can image that it might be possible to indistinguishably obfuscate such a pair of programs by enforcing some kind of one-time guarantee, so both obfuscations stop working after one evaluation. The impossibility in this section ( Corollary 3 ) says that this is not possible. Indeed, if it was possible, then it would be a best-possible one-time program. This is formalized in Lemma 24 . We also give a more direct proof of this impossibility, without going through the intermediate primitive of best-possible one-time programs. This proof is simpler to describe and will hopefully shed light on the core idea of the impossibility. We leave open the question of coming up with a feasible notion of quantum state IO for sampling programs. Our notion of stateful obfuscation in Section 5.3 (a notion of quantum state IO where the two programs must have the same behavior on polynomially many (forward and inverse) queries, instead of just the first one) can be seen as an attempt to make progress in this direction. Definition 29 (Quantum State Obfuscation for Quantum Sampling Programs) . A quantum state obfuscator for quantum sampling programs is a q.p.t. algorithm \mathsf{QObf} with the following syntax: \mathsf{QObf}(1^{\lambda},\rho,C)\rightarrow(\ket{\tilde{\psi}},\tilde{C}). The obfuscator takes as input a security parameter 1^{\lambda} and a quantum program (\ket{\psi},C) and outputs an obfuscated circuit (\ket{\tilde{\psi}},\tilde{C}) . • Correctness: Suppose a family of quantum sampling programs \{\ket{\psi_{\lambda}},C_{\lambda}\}_{\lambda\in\mathbb{N}} implements a family of sampling functionalities \{D_{\lambda}:\{0,1\}^{n(\lambda)}\rightarrow\{0,1\}^{m(\lambda)}\}_{\lambda\in\mathbb{N}} for every x\in\{0,1\}^{n(\lambda)} up to negligible error \mathsf{negl}\left(\lambda\right) . Then, the family of quantum sampling programs \{\ket{\tilde{\psi}_{\lambda}},\tilde{C}_{\lambda}\} where (\ket{\tilde{\psi}_{\lambda}},\tilde{C}_{\lambda})\leftarrow\mathsf{QObf}(1^{\lambda},\ket{\psi_{\lambda}},C_{\lambda}) also implements the same sampling functionality up to negligible error. • Indistinguishability Obfuscation: For every pair of families of quantum sampling programs \{\ket{\psi_{\lambda,0}},C_{\lambda,0}\}_{\lambda\in\mathbb{N}} and \{\ket{\psi_{\lambda,1}},C_{\lambda,1}\}_{\lambda\in\mathbb{N}} that both implement the same sampling functionality \{D_{\lambda}:\{0,1\}^{n(\lambda)}\rightarrow\{0,1\}^{m(\lambda)}\}_{\lambda\in\mathbb{N}} up to negligible error in \lambda , and furthermore satisfy that the program descriptions have the same length |\ket{\psi_{\lambda,0}},C_{\lambda,0}|=|\ket{\psi_{\lambda,1}},C_{\lambda,1}| for every \lambda , for every q.p.t. adversary \{A_{\lambda}\}_{\lambda\in\mathbb{N}} , \displaystyle\left|\Pr\left[1\leftarrow A_{\lambda}\left(1^{\lambda},\mathsf{QObf}(1^{\lambda},\ket{\psi_{\lambda,0}},C_{\lambda,0})\right)\right]-\Pr\left[1\leftarrow A_{\lambda}\left(1^{\lambda},\mathsf{QObf}(1^{\lambda},\ket{\psi_{\lambda,1}},C_{\lambda,1})\right)\right]\right|\leq\mathsf{negl}\left(\lambda\right). Lemma 24 . Suppose there exists a quantum state indistinguishability obfuscator for quantum sampling programs for a class of classical functionalities randomized \mathcal{F} . Then, there must exist a one-time compiler that satisfies the best-possible one-time security guarantee of Definition 12 for \mathcal{F} . Proof. By assumption, let \mathsf{QObf} be an obfuscator that satisfies quantum state indistinguishability obfuscation for quantum sampling programs for \mathcal{F} . Consider the following quantum sampling program P_{f}=(\ket{\psi_{f}},C_{f}) that implements classical randomized functions f:\mathcal{X}\times\mathcal{R}\rightarrow\mathcal{Y} for f\in\mathcal{F} : the program state is a description of f , along with a uniform superposition over \mathcal{R} , \displaystyle\ket{\psi_{f}}=\ket{f}\otimes\sum_{r\in\mathcal{R}}\ket{r}. The circuit C_{f} maps \displaystyle\ket{x,u}_{\mathcal{Q}}\otimes\ket{r,f}_{\mathcal{P}}\mapsto\ket{x\oplus f(x;r)}_{\mathcal{Q}}\otimes\ket{r,f}_{\mathcal{P}}. Without loss of generality, we assume that all functionalities in \mathcal{F} are padded to the same length. Define \mathsf{OTP}^{*}(1^{\lambda},f):=\mathsf{QObf}(1^{\lambda},P_{f}) for f\in\mathcal{F} . We claim that \mathsf{OTP}^{*} satisfies the best-possible one-time security guarantee of Definition 12 . For every q.p.t. adversary \mathcal{A} , define a corresponding \mathsf{Sim}(1^{\lambda},P)\rightarrow\mathcal{A}(1^{\lambda},\mathsf{QObf}(P)) . Then, for every f\in\mathcal{F} , for every program P that implements f , by the security of quantum state indistinguishability obfuscation, it must hold that for all q.p.t. distinguishers D , \displaystyle\left|\Pr[1\leftarrow D(1^{\lambda},f,\mathcal{A}(\mathsf{OTP}^{*}(1^{\lambda},f)))]-\Pr[1\leftarrow D(1^{\lambda},f,\mathsf{Sim}(1^{\lambda},P))]\right| Otherwise, there exists some f\in\mathcal{F} and some program P that implements f such that the following two distributions are distinguishable: \displaystyle\mathcal{A}(\mathsf{OTP}^{*}(1^{\lambda},f)) \displaystyle=\mathcal{A}(\mathsf{QObf}(1^{\lambda},P_{f}))\text{ and} \displaystyle\mathsf{Sim}(1^{\lambda},P) \displaystyle=\mathcal{A}(1^{\lambda},\mathsf{QObf}(P)), even though P_{f} and P implement the same classical randomized functionality f . ∎ Corollary 3 . There exists a class of sampling functionalities \mathcal{D} such that there is no quantum state indistinguishability obfuscator (as defined in Definition 29 ) for \mathcal{D} . Alternate proof of Corollary 3 . Consider the following families of classical circuits. 1. C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}}(x;r):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*}) , where \mathsf{\vphantom{p}pk}_{\mathsf{lossy}} is sampled as a lossy encryption key. 2. D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}}(x;r):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},x;r) 3. E_{\mathsf{\vphantom{p}pk}_{\mathsf{inj}}}(x;r):=\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{inj}},x;r) We assume that the obfuscator preserves functionality, so in the case of the C circuits (which are deterministic and constant), evaluation does not entangle the input and output registers. We can test entanglement between the input and output registers by evaluating on the uniform superposition of inputs \ket{+}:=\sum_{x}\ket{x} , measuring the output registers, and then checking that the input register is still in the \ket{+} state. In the E programs, however, by the correctness of the encryption scheme, evaluation must create entanglement the input and output registers. Since the only difference in the D and E circuits is that the public key is sampled from the lossy and injective modes respectively, they are indistinguishable, and therefore evaluation of D must also entangle the input and output registers. However, consider the following two programs: • Program description contains the mixed state \sum_{r^{*}}\ket{\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*})}\bra{\mathsf{Enc}(\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},0;r^{*})} , and the evaluation algorithm simply copies the contents of the program register onto the output register. • Program description is simple the classical circuit D_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}}} and evaluation algorithm is to evaluate this classical circuit on fresh randomness by producing \ket{+}_{\mathcal{R}} . For every input x , these programs have the same output distributions. By padding, we can ensure their descriptions have the same length. So if we had IO for sampling quantum circuits (as in Definition 29 ), the obfuscations should be indistinguishable. However, they are not: The obfuscation of the first program is going to be a mixture of obfuscations over C_{\mathsf{\vphantom{p}pk}_{\mathsf{lossy}},r^{*}} , where the mixture is taken over r^{*} . Since each element of the mixture does not entangle the input and output registers, so does the overall mixture. But as we have already seen, the obfuscation of D must be entangling the input and output registers. ∎ Appendix D A Generic Multi-Observable Attack against Testable Programs This section formalizes the attack sketched in the discussion section: a testable program can always be used to estimate arbitrarily many output observables on many inputs. Theorem 16 (Marriott–Watrous Empirical Estimator [ 30 , proof of Theorem 4, Fig. 2] ) . Fix a verifier unitary A and projectors \Pi_{1},\Delta_{1} as in the proof of [ 30 , Theorem 4] , and define Q\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}(I\otimes\bra{0^{k}})A^{\dagger}\Pi_{1}A(I\otimes\ket{0^{k}}). For any integer N\geq 1 , the Marriott–Watrous procedure B (proof of [ 30 , Theorem 4] ) outputs bits z_{1},\ldots,z_{N}\in\{0,1\} . If the input witness is an eigenvector of Q with eigenvalue p\in[0,1] , then \Pr[(z_{1},\ldots,z_{N})=z]=p^{w(z)}(1-p)^{N-w(z)} for every z\in\{0,1\}^{N} (see the analysis around Fig. 2 in the proof of [ 30 , Theorem 4] ). Consequently, for \widetilde{p}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\frac{1}{N}\sum_{\ell=1}^{N}z_{\ell}, we have \Pr\!\left[\left|\widetilde{p}-p\right|>\alpha\right]\leq 2e^{-2N\alpha^{2}} for every \alpha>0 . In particular, for N=\Theta(\alpha^{-2}\log(1/\beta)) , \widetilde{p} is an (\alpha,\beta) additive estimator of p . Corollary 4 (Gentleness of Laplace Noise Measurement [ 1 , Corollary 6] ) . Let L_{\sigma} denote the Laplace-noise measurement applied to n registers. Then L_{\sigma} is O(\sqrt{n}/\sigma) -gentle on product states. We use the following finite-outcome wrapper abstracted from the camera-ready theorem statement [ 1 , Theorem 7] and the full-version derivation [ 2 , Proposition 55, Theorem 56, and §7.3 (proof of Theorem 7)] . Theorem 17 (Safe-Use Wrapper for Finite-Outcome Estimation) . Fix a finite outcome set \mathcal{Y} and a classical post-processing rule \mathcal{C}:\mathcal{Y}\to\{\mathrm{pass},\mathrm{fail}\} . Suppose \mathcal{A} is an estimation subroutine whose output lies in \mathcal{Y} . Then there is a compiled subroutine \widetilde{\mathcal{A}} with two guarantees: 1. Accuracy/copy complexity. If there exists an (\alpha,\beta) additive estimator for the same quantity that uses n copies of the input state, then \widetilde{\mathcal{A}} uses n+\mathsf{poly}\left(1/\alpha,1/\beta\right) copies and matches that estimator’s output with probability at least 1-\beta . 2. Coherent safety with side information. For every joint pure state \ket{\Psi}=\sum_{i}c_{i}\ket{u_{i}}_{W}\ket{v_{i}}_{S}, where S is arbitrary side information, define p_{i}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\Pr[\mathcal{C}(\mathcal{A}(\ket{u_{i}}))=\mathrm{pass}],\qquad p\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\sum_{i}|c_{i}|^{2}p_{i}. If \widetilde{\mathcal{A}} is applied to register W and the post-processing output is \mathrm{pass} , then the post-measurement joint state \ket{\widetilde{\Psi}} obeys \left\|\ket{\Psi}-\ket{\widetilde{\Psi}}\right\|_{2}\leq\alpha(1-p)^{2}. Proof. [ 1 , Theorem 7] (camera-ready version) gives the qualitative statement that such estimation subroutines can be used coherently inside larger quantum computations. For the quantitative wrapper we use the full-version derivation: [ 2 , proof of Theorem 7 in §7.3] gives the coherent estimate-and-uncompute template (including the explicit copy scaling parameter), while [ 2 , Proposition 55 and Theorem 56] formalize the garbage-uncomputation/QSampling step. To obtain the finite-outcome form above, encode \mathcal{A} coherently so that its output register stores y\in\mathcal{Y} , append the predicate \mathcal{C}(y) , and treat “ \mathrm{pass} ” as the acceptance event. Under this encoding, the full-version safe-subroutine argument yields item (2), with p_{i} equal to the pass probability on component \ket{u_{i}} and p=\sum_{i}|c_{i}|^{2}p_{i} . Item (1) is the corresponding polynomial-overhead consequence of that full-version analysis, instantiated with an (\alpha,\beta) reference estimator using n copies. ∎ Lemma 25 (From Joint \ell_{2} -Closeness to Reduced Trace Distance) . Let \ket{\Psi},\ket{\widetilde{\Psi}} be pure states on registers WS , and let \rho_{W}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\mathsf{Tr}_{S}\ket{\Psi}\bra{\Psi},\qquad\widetilde{\rho}_{W}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\mathsf{Tr}_{S}\ket{\widetilde{\Psi}}\bra{\widetilde{\Psi}}. Then \frac{1}{2}\|\rho_{W}-\widetilde{\rho}_{W}\|_{1}\leq\frac{1}{2}\left\|\ket{\Psi}\bra{\Psi}-\ket{\widetilde{\Psi}}\bra{\widetilde{\Psi}}\right\|_{1}\leq\left\|\ket{\Psi}-\ket{\widetilde{\Psi}}\right\|_{2}. Proof. The first inequality is contractivity of trace distance under partial trace. For pure states, the middle term equals \sqrt{1-|\langle\Psi\mid\widetilde{\Psi}\rangle|^{2}} , which is at most \|\ket{\Psi}-\ket{\widetilde{\Psi}}\|_{2} . ∎ Lemma 26 (Multi-observable estimation attack) . Let P=(\ket{\psi},\mathsf{Eval},R) be a testable quantum program that one-time implements a channel \Phi . Let x_{1},\ldots,x_{n} be efficiently preparable input states, and let O_{1},\ldots,O_{t} be efficiently measurable Hermitian observables on the output register with \|O_{i}\|_{\infty}\leq 1 . Then for every \varepsilon,\delta>0 , there is a QPT attacker with oracle access to (\mathsf{Eval},\mathsf{Eval}^{\dagger},R) that outputs values \widehat{\mu}_{i,j} for all i\in[t],j\in[n] such that \Pr\left[\forall i\in[t],j\in[n]:\left|\widehat{\mu}_{i,j}-\mathsf{Tr}\left(O_{i}\Phi(x_{j})\right)\right|\leq\varepsilon\right]\geq 1-\delta. The attacker runs in time \mathsf{poly}\left(|P|,t,n,1/\varepsilon,1/\delta\right) . Proof. Let N\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}tn , and index the pairs (i,j)\in[t]\times[n] in any fixed order (i_{1},j_{1}),\ldots,(i_{N},j_{N}). For each i , define the two-outcome effect E_{i}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}(I+O_{i})/2. Since \|O_{i}\|_{\infty}\leq 1 and O_{i} is Hermitian, we have 0\preceq E_{i}\preceq I . For each input x_{j} , define p_{i,j}^{\star}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\mathsf{Tr}\!\left(E_{i}\Phi(x_{j})\right),\qquad\mu_{i,j}^{\star}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\mathsf{Tr}\!\left(O_{i}\Phi(x_{j})\right)=2p_{i,j}^{\star}-1. Single-call primitive from MW + Laplace. Fix (i,j) and parameters \alpha,\beta,\tau>0 . Because O_{i} is efficiently measurable and 0\preceq E_{i}\preceq I , the two-outcome POVM \{E_{i},I-E_{i}\} has an efficient coherent (Naimark) implementation. We define a verifier A_{i,j} that first checks whether the program register is in \ket{\psi} (using R ), and rejects otherwise; conditioned on passing that check, it applies \mathsf{Eval} on input x_{j} , performs the coherent two-outcome test for E_{i} on the output register, and uncomputes with \mathsf{Eval}^{\dagger} . For this verifier, the corresponding MW operator has the form Q_{i,j}=\Pi_{\psi}M_{i,j}\Pi_{\psi}, where \Pi_{\psi}=\ket{\psi}\bra{\psi} and M_{i,j} is the acceptance effect of the coherent E_{i} -test under \mathsf{Eval} . Hence \ket{\psi} is an eigenvector of Q_{i,j} with eigenvalue p_{i,j}^{\star} . Let m_{0} be the number of MW rounds used by the underlying (pre-compiler) estimator. Now define \mathsf{Est}_{i,j}^{\alpha,\beta,\tau} : 1. Refresh: measure \{\Pi_{\psi},I-\Pi_{\psi}\} using R . If reject, return a failure flag. 2. Conditioned on refresh success (so the program state is exactly \ket{\psi} ), run m_{0} MW rounds for A_{i,j} and write outcome bits to fresh registers Z_{1},\ldots,Z_{m_{0}} . 3. Let S=\sum_{\ell=1}^{m_{0}}Z_{\ell} , and sample \eta\sim\mathrm{Lap}(\sigma) . If |\eta|>\alpha m_{0}/4 , return failure. Otherwise compute \widetilde{p}_{\mathrm{cont}}=\operatorname{clip}_{[0,1]}\!\left(\frac{S+\eta}{m_{0}}\right), then output the quantized value \widetilde{p}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}Q_{r}(\widetilde{p}_{\mathrm{cont}}), where Q_{r} rounds to the nearest point of \mathcal{Y}_{r}=\{0,2^{-r},\ldots,1\} and r is chosen so 2^{-r}\leq\alpha/4 . Because refresh-success inputs are exactly \ket{\psi} and \ket{\psi} is an eigenvector of Q_{i,j} with eigenvalue p_{i,j}^{\star} , Theorem 16 gives i.i.d. Bernoulli bits with mean p_{i,j}^{\star} . Therefore, for the underlying (pre-compiler) call, \displaystyle\Pr\!\left[\text{failure flag}\ \text{or}\ \left|\widetilde{p}-p_{i,j}^{\star}\right|>\alpha\right] \displaystyle\leq\Pr\!\left[\frac{|\eta|}{m_{0}}>\frac{\alpha}{4}\right]+\Pr\!\left[\left|\widetilde{p}-p_{i,j}^{\star}\right|>\alpha\ \wedge\ \frac{|\eta|}{m_{0}}\leq\frac{\alpha}{4}\right] \displaystyle\leq\Pr\!\left[\left|\frac{S}{m_{0}}-p_{i,j}^{\star}\right|>\frac{\alpha}{4}\right]+\Pr\!\left[\frac{|\eta|}{m_{0}}>\frac{\alpha}{4}\right] \displaystyle\leq 2e^{-m_{0}\alpha^{2}/8}+e^{-\alpha m_{0}/(4\sigma)}, where the second inequality uses that, on the event \left|\frac{S}{m_{0}}-p_{i,j}^{\star}\right|\leq\frac{\alpha}{4}\quad\text{and}\quad\frac{|\eta|}{m_{0}}\leq\frac{\alpha}{4}, we have \left|\widetilde{p}_{\mathrm{cont}}-p_{i,j}^{\star}\right|\leq\frac{\alpha}{2}, and then quantization contributes at most 2^{-r}\leq\alpha/4 , so \left|\widetilde{p}-p_{i,j}^{\star}\right|\leq\frac{3\alpha}{4}<\alpha. The output alphabet is finite ( \mathcal{Y}_{r}\cup\{\bot\} ), as required by Theorem 17 . Let q\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\Pr[|\eta|>\alpha m_{0}/4]=e^{-\alpha m_{0}/(4\sigma)}. Because the failure flag is triggered exactly by the event |\eta|>\alpha m_{0}/4 , and \eta is sampled independently of the program register, the pass probability is exactly 1-q for every component in Theorem 17 (2). Choosing \sigma=\Theta(\sqrt{m_{0}}/\tau),\qquad m_{0}=\Theta\!\left(\frac{1}{\alpha^{2}}\log\frac{1}{\beta}+\frac{1}{\alpha^{2}\tau^{2}}\log^{2}\frac{1}{\beta\tau}\right), ensures 2e^{-m_{0}\alpha^{2}/8}+q\leq\beta/3,\qquad q\leq\sqrt{\tau}. Thus the reference estimator has call-failure probability at most \beta/3 . Now apply Theorem 17 directly to this reference estimator with continuation rule \mathcal{C}(y)=\begin{cases}\mathrm{pass}&y\neq\bot,\\ \mathrm{fail}&y=\bot.\end{cases} and compiler parameters (1/2,\beta/3) . Let \widetilde{\mathcal{A}}_{i,j} denote the compiled subroutine. By Theorem 17 (1), \widetilde{\mathcal{A}}_{i,j} disagrees with the reference estimator with probability at most \beta/3 , so by union bound \Pr[\widetilde{\mathcal{A}}_{i,j}\ \text{call fails}]\leq\beta/3+\beta/3<\beta. For disturbance, consider any joint pure input state as in Theorem 17 (2). Because the continuation event is exactly |\eta|\leq\alpha m_{0}/4 , independent of the program component, every component has pass probability 1-q . Hence p_{i}=1-q for all i , so p=1-q . Conditioned on pass, Theorem 17 (2) gives \left\|\ket{\Psi}-\ket{\widetilde{\Psi}}\right\|_{2}\leq\frac{1}{2}(1-p)^{2}=\frac{q^{2}}{2}\leq\tau. Applying Lemma 25 yields the same \tau bound on reduced program-register trace distance. Therefore the compiled subroutine controls disturbance for the entire call (MW rounds plus Laplace readout), even with arbitrary side information. Adding the AR19 compiler overhead m_{\mathrm{wrap}}=\mathsf{poly}\left(1/\alpha,1/\beta,1/\tau\right), yields: 1. per-call failure probability (failure flag or additive error >\alpha ) at most \beta ; 2. post-call program-state disturbance at most \tau from \ket{\psi}\bra{\psi} on refresh-success executions; 3. time/query complexity \mathsf{poly}\left(|P|,m_{0}+m_{\mathrm{wrap}}\right)=\mathsf{poly}\left(|P|,1/\alpha,1/\beta,1/\tau\right). Attack algorithm. Set \alpha\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\varepsilon/4,\qquad\beta\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\delta/(2N),\qquad\tau\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}\delta/(2N). For k=1,\ldots,N , run \mathsf{Est}_{i_{k},j_{k}}^{\alpha,\beta,\tau} . If it returns failure, halt and output failure. Otherwise, with returned value \widetilde{p}_{k} , output \widehat{\mu}_{i_{k},j_{k}}\mathrel{\mathchoice{\vbox{\hbox{$\displaystyle:$}}}{\vbox{\hbox{$\textstyle:$}}}{\vbox{\hbox{$\scriptstyle:$}}}{\vbox{\hbox{$\scriptscriptstyle:$}}}{=}}2\widetilde{p}_{k}-1. Failure probability. The first refresh succeeds with probability 1 because the initial program state is \ket{\psi} . After a successful call, property (2) above gives \frac{1}{2}\left\|\rho^{\prime}-\ket{\psi}\bra{\psi}\right\|_{1}\leq\tau. Hence the next refresh fails with probability at most 1-\mathsf{Tr}(\Pi_{\psi}\rho^{\prime})\leq\frac{1}{2}\left\|\rho^{\prime}-\ket{\psi}\bra{\psi}\right\|_{1}\leq\tau. Each successful-refresh call has call-failure probability at most \beta . By union bound over all N calls, total failure probability is at most N\tau+N\beta=\delta. Accuracy on success. Condition on no failure. Then every call satisfies \left|\widetilde{p}_{k}-p_{i_{k},j_{k}}^{\star}\right|\leq\alpha. Therefore, for each k , \left|\widehat{\mu}_{i_{k},j_{k}}-\mu_{i_{k},j_{k}}^{\star}\right|=2\left|\widetilde{p}_{k}-p_{i_{k},j_{k}}^{\star}\right|\leq 2\alpha=\varepsilon/2<\varepsilon. So all N=tn estimates are simultaneously \varepsilon -accurate with probability at least 1-\delta . Finally, total running time and query complexity are N\cdot\mathsf{poly}\left(|P|,1/\alpha,1/\beta,1/\tau\right)=\mathsf{poly}\left(|P|,t,n,1/\varepsilon,1/\delta\right). ∎