---
title: Argument-Swap Protocol
url: https://www.emergentmind.com/topics/argument-swap-protocol
type: topic
---

# Argument-Swap Protocol

In the cited literature, an argument-swap protocol is not a single standardized formalism but a recurring pattern in which two semantically distinct operands are preserved, exchanged, compared, or conditionally transferred under explicit correctness constraints. In software analysis, the relevant object is the accidental interchange of positional arguments at a call site. In quantum information and structured-light systems, it is the controlled exchange of registers or amplitudes by SWAP, c-SWAP, \( \sqrt{\mathrm{SWAP}} \), or \( \sqrt{i\text{SWAP}} \)-type interactions. In networking and blockchain systems, it is the rule-governed exchange of entanglement resources or escrowed assets across a graph. Taken together, these works suggest that an argument-swap protocol is best understood as a protocol schema for deciding when two positions should remain fixed, when they should be exchanged, and how that decision is certified by names, measurements, capacities, or cryptographic conditions [2009.09117][2006.07994][2110.04116][2211.00208].

## 1. Core abstraction

A common formal pattern appears across otherwise unrelated domains. In the software-analysis setting, a call \(f(a_1,\dots,a_n)\) is problematic when arguments at positions \(i\) and \(j\) correspond semantically better to parameters \(p_j\) and \(p_i\) than to \(p_i\) and \(p_j\). In the standard quantum setting, a controlled-SWAP gate acts on basis states by
\[
|c,a,b\rangle \mapsto
\begin{cases}
|0,a,b\rangle, & c=0,\\
|1,b,a\rangle, & c=1,
\end{cases}
\]
while the SWAP test transforms state overlap into a measurable control probability,
\[
p(0)=\frac{1+|\langle \psi|\varphi\rangle|^2}{2}.
\]
These formulations differ in ontology, but each isolates two payloads, a control or evidence mechanism, and a correctness criterion for exchange versus non-exchange [2009.09117][2006.07994].

This suggests a unifying abstraction with three recurrent elements. First, there are two candidate “arguments,” broadly construed as call-site values, quantum subsystems, queued resources, or escrowed assets. Second, there is a decision mechanism, such as morpheme-level coverage, corpus statistics, a Hadamard-controlled interference pattern, a scheduling rule, or a hashlock circuit. Third, there is an application-specific notion of acceptable outcome: semantic alignment in code, large state overlap or exact SWAP in physics, bounded backlog in networking, or safety and liveness predicates in blockchain protocols.

## 2. Static-analysis protocols for swapped call arguments

In software engineering, the argument-swap problem arises in languages with positional arguments when two parameters share the same or compatible types and the call accidentally uses a non-canonical order. The motivating examples include signatures such as `int kill(pid_t pid, int sig);` followed by a call like `kill(SIGKILL, cpid);`, where the program type-checks but the process ID and signal are semantically interchanged. “Out of Sight, Out of Place: Detecting and Assessing Swapped Arguments” implements a static-analysis checker, SwapD, that exploits natural-language information in code rather than relying only on types or control/data flow. It extracts identifier names from AST nodes, splits them into morphemes with Ronin, compares argument and parameter morphemes with a domain-adapted similarity relation \(a \sim p\), and combines two independent detectors: a cover-based checker and a statistical checker [2009.09117].

The cover-based checker defines
\[
\mathit{C}(A,P)=\min_{p\in P}\max_{a\in A}(a\sim p),
\]
where \(A_i\) and \(P_i\) are the morpheme sets of argument \(i\) and parameter \(i\). A candidate swap between positions \(i\) and \(j\) is produced when
\[
C(A_i,P_i)<0.5,\quad C(A_j,P_j)<0.5,
\]
but
\[
C(A_i,P_j)>0.75,\quad C(A_j,P_i)>0.75.
\]
The statistical checker instead uses corpus counts \(w(f,m,i)\) over triples \((f,i,m)\) and the relative-frequency score
\[
\psi(f,m,i,j)=\frac{w(f,m,i)}{w(f,m,j)},
\]
requiring, among other conditions, that \(\min(\psi(a_i,j,i),\psi(a_j,i,j))>\gamma\) with \(\gamma=5\). Cover-based candidates are then statistically vetted and filtered by heuristics, including white-list words such as `swap`, `exchange`, `rotate`, and `flip`, a maximum swap distance \(|i-j|\le 2\), geometric-pattern suppression, type checks, nearby declaration checks, nearby correct-call checks, and repeated swap-frequency checks within a caller. On 6541 Fedora 29 SRPM C/C++ projects totaling approximately 417 million lines of code, the full configuration \(C\{1234\}\) achieved precision \(0.6667\) with yield \(154\) true positives; \(C\{34\}\) achieved precision \(\sim 0.891\) with yield \(90\). Across configurations, 4141 unique warnings were generated, 859 were manually triaged, and 183 were classified as true positives. The paper reports that 42% of the true positives involved names with more than one morpheme, and that the cover-based and statistical detectors had only modest overlap, with 15 shared true positives, so their combination materially increased coverage [2009.09117].

## 3. Controlled-SWAP and SWAP-test protocols

In quantum information, the canonical argument-swap primitive is the controlled-SWAP or Fredkin gate, together with the SWAP test. The SWAP test prepares the control qubit in \(|0\rangle\), applies a Hadamard, performs a c-SWAP on \(|\psi\rangle\) and \(|\varphi\rangle\), applies a second Hadamard, and measures the control. The resulting outcome statistics satisfy \(p(0)=(1+|\langle\psi|\varphi\rangle|^2)/2\), so repeated trials estimate overlap without full state tomography. “Implementation of a simultaneous message passing protocol using optical vortices” realizes a classical optical analog of this construction with structured light, using Laguerre–Gauss modes, polarization as the control, positive OAM indices \(m>0\) for Alice, and negative indices \(m<0\) for Bob [2006.07994].

The optical protocol maps one control polarization to an even number of reflections and hence no OAM helicity flip, while the orthogonal polarization undergoes an odd number of reflections and therefore \(m\to -m\), which exchanges Alice’s and Bob’s channels. After the two Hadamard-equivalent half-wave plates and the polarization-sensitive Mach–Zehnder interferometer, the output powers obey
\[
P_x \propto \sum_m |A_m+B_m|^2,\qquad
P_y \propto \sum_m |A_m-B_m|^2,
\]
with overlap parameter
\[
\gamma=\frac{P_y-P_x}{P_y+P_x}
= -\frac{2\sum_m \mathrm{Re}(A_mB_m^\ast)}
{\sum_m (|A_m|^2+|B_m|^2)}.
\]
For binary phase encoding \(A_m,B_m\in\{+1,-1\}\), this simplifies to
\[
\gamma = 2\frac{n}{N}-1,
\]
where \(n/N\) is the fraction of equal bits. The implemented system used one OAM channel per sender and many bits via time-division multiplexing, operated a digital micromirror device with a maximum rate of \(9.5\) kHz and an effective modulation rate of \(7.5\) kHz, and achieved approximately 40 time bins per detector integration window, corresponding to 40-bit messages per sender per comparison. The study reports comparisons for overlap values from 0% to 100% in 10% steps, together with a two-reference normalization scheme that used 100% and 0% overlap reference blocks to correct for drift and interferometric imbalance. A recurrent misconception is that this optical simultaneous message-passing protocol inherits quantum security from the SWAP test; the paper explicitly distinguishes it as a classical, quantum-mimetic implementation whose privacy-preserving character is logical rather than guaranteed by no-cloning or measurement disturbance [2006.07994].

## 4. Exchange gates, partial swaps, and bidirectional state transfer

A second major line of work treats argument-swap as a coherent exchange interaction rather than as a comparison test. In superconducting transmon architectures, “High-fidelity \( \sqrt{i\text{SWAP}} \) gates using a fixed coupler driven by two microwave pulses” studies two fixed-frequency qubits \(Q_1,Q_2\) coupled through a fixed-frequency transmon coupler \(Q_c\), with only the coupler driven. The induced two-qubit gate has the form
\[
U_{\text{swap}}=
\begin{bmatrix}
1&0&0&0\\
0&\cos\theta&-i\sin\theta&0\\
0&-i\sin\theta&\cos\theta&0\\
0&0&0&1
\end{bmatrix},
\]
and \(\theta=\pi/4\) gives exactly \( \sqrt{i\text{SWAP}} \). The protocol uses two microwave tones on the coupler, tuned near two-photon resonances involving the coupler’s second excited state, together with smoothed flat-top Gaussian pulses. For the ABA architecture the paper reports fidelity \(\approx 94.60\%\) after single-qubit phase compensation and \(>99.92\%\) for a \( \sqrt{i\text{SWAP}} \)-like target including a conditional phase \(\phi\approx 1.044\) rad; for the ABC architecture it reports \(\approx 99.63\%\) and \(>99.93\%\), respectively, with \(\phi\approx 0.246\) rad [2404.17824].

A more representation-theoretic version appears in “The Power of Power-of-SWAP: Postselected Quantum Computation with the Exchange Interaction,” which defines exchange gates
\[
U(\theta)=e^{i\theta E_{ij}}=\cos\theta\,\mathbf{1}+i\sin\theta\,\mathrm{SWAP},
\]
so that \(U(\pi/4)=\sqrt{\mathrm{SWAP}}\) and \(U(\pi/2)=i\,\mathrm{SWAP}\). The paper introduces XQP circuits, consisting of computational-basis SPAM and exchange interactions only, and proves
\[
\mathrm{PostXQP}(\pi/4)=\mathrm{PostXQP}=\mathrm{PostBQP}=\mathrm{PP}.
\]
It further shows that efficient multiplicative-error simulation of XQP would collapse the polynomial hierarchy to its third level, that random \( \sqrt{\mathrm{SWAP}} \)-only circuits form unitary \(t\)-designs over \(SU(2)\)-invariant unitaries with \(t\ge n-2\), and that the entangling power of \(U(\theta)\) is
\[
e_{p_0}(U(\theta))=\frac{1-\cos(4\theta)}{12},
\]
maximized at \( \sqrt{\mathrm{SWAP}} \) [2603.28527].

A third variant dispenses with universal local control and uses scrambling. “Bidirectional teleportation using scrambling dynamics: a practical protocol” considers collective subsystems \(A,B,C\), global scramblers \(U_{AB}\) and \(U_{CB}^\dagger\), and a postselection on subsystem \(B\). The effective map
\[
\tilde S_{AC}=\frac{1}{\sqrt{p}\,\langle\phi|_B U_{CB}^\dagger U_{AB}|\phi\rangle_B}
\]
approximates \(\mathrm{SWAP}_{AC}\) when the mediator dimension satisfies \(d_B\gg d_A^2\), with average postselection probability \(\bar p\simeq 1/d_A^2\) in the optimal regime. The paper also proves a general dimension-dependent limitation: for \(\dim \mathcal H_A=\dim \mathcal H_C=d\) and \(\dim \mathcal H_B=m\), there exists an input state with SWAP fidelity bounded by
\[
F(\Psi)\le \sqrt{\frac{m+1}{d^2+1}}.
\]
The proposed implementation uses Dicke-type spin–boson dynamics in cavity-QED or trapped-ion systems, thereby making bidirectional state exchange an experimentally motivated protocol rather than only a circuit identity [2601.15536].

## 5. Resource-swapping in quantum networks

In quantum networking, swapping is a scheduling and queueing operation rather than a gate applied to two qubits in isolation. “Entanglement Swapping in Quantum Switches: Protocol Design and Stability Analysis” studies a star topology with one quantum switch and \(K\) end nodes. Link-level Bell pairs \(\ket{\Psi_{0i}}\) arrive at rates \(p_i\), entanglement requests \(A_{ij}(t)\) enter queues \(U_{ij}(t)\), and the switch chooses swap attempts \(F_{ij}(t)\), each succeeding with probability \(q\), subject to the resource constraints
\[
\sum_i F_{ij}(t)\le E_{0j}(t)+C_{0j}(t),\qquad
\sum_{i,j}F_{ij}(t)\le W.
\]
The capacity region is characterized by flow variables \(f_{ij}\) satisfying
\[
\sum_i f_{ij}\le p_j,\qquad
\sum_{i,j}f_{ij}\le W,\qquad
\lambda_{ij}\le q f_{ij}.
\]
Stability is defined through
\[
g_{ij}(V)=\limsup_{t\to\infty}\frac1t\sum_{\tau=0}^{t-1}\Pr[U_{ij}(\tau)>V],
\]
with stability requiring \(g_{ij}(V)\to 0\) as \(V\to\infty\). The paper develops stationary protocols, on-demand protocols that need not know \(\lambda_{ij}\), \(p_k\), or \(q\), and an on-demand protocol with virtual requests
\[
\tilde A_{ij}(t)=A_{ij}(t)+\lceil (t+1)^\alpha\rceil-\lceil t^\alpha\rceil,\qquad \alpha\in(1/2,1),
\]
which achieves zero average latency under stronger assumptions. In discrete-event simulations with \(K=4\) or \(K=8\), slot length \(1000\) ns, \(p=0.9\), \(q=0.9\), memory slots per interface of 100, and \(T_2=1\) ms, the on-demand protocols were reported as computationally efficient and as achieving high fidelity and low latency [2110.04116].

## 6. Predicate-based asset swaps and HTLC characterizations

In distributed-ledger systems, an argument-swap protocol becomes a cryptographically enforced exchange of assets across a directed graph. “Invited Paper: Fault-tolerant and Expressive Cross-Chain Swaps” models a swap as a strongly connected digraph \(G=(V,A)\), with a Boolean variable for each arc and a predicate for each participant. The general safety predicate is
\[
S_x :=
\left(
\bigwedge_{i=1}^k ((x,u_i)\implies I_x^{(x,u_i)})
\right)\wedge O_x,
\]
and the liveness predicate is
\[
L_x:=S_x\wedge \left(\bigvee_{i=1}^k I_x^{(x,u_i)}\right).
\]
Global solutions satisfy
\[
\phi(\mathcal P)=\bigwedge_{p\in\mathcal P} p,
\]
and each satisfying assignment defines a feasible swap digraph \(G_s\). The paper introduces redundancy providers, conflicting solutions, and two protocols. ProtocolA is described as high collateral and fast settlement: it computes all satisfying solutions, builds swap schemes for them, runs escrow in parallel, and then selects a maximal non-conflicting subset \(S_c\) for redeem. ProtocolB is low collateral and fixed time: it augments each predicate with an exclusivity constraint \(r_x\), imposes an ordering \(S^\ast=\{s_1^\ast,\dots,s_k^\ast\}\), and uses priority-sensitive circuits
\[
C^{new}_{s_j^\ast,q}:=
\left(
\bigwedge_{\substack{i<j\\ q'\in Q(T(S))\\ s_j^\ast \text{ conflicts with } s_i^\ast}}
\neg C_{s_i^\ast,q'}
\right)\wedge C_{s_j^\ast,q}.
\]
The point of both constructions is that acceptable subsets of swaps can still complete even when some parties deviate, rather than enforcing only an all-or-nothing outcome [2211.00208].

A more restrictive but sharper line of work asks when standard HTLCs suffice. “On HTLC-Based Protocols for Multi-Party Cross-Chain Swaps” shows that an atomic HTLC-based protocol exists if and only if the swap digraph is a reuniclus digraph. In the single-secret case, the exact class is the bottleneck digraphs. The paper defines bottleneck digraphs as strongly connected digraphs with a vertex lying on every cycle, gives the BDP protocol for that case using distances \(D^-_v\), \(D^+_v\), and timeouts
\[
\tau_{uv}=D^\ast + D^+_v,
\]
and generalizes to reuniclus digraphs with RDP, using bottleneck components arranged in a rooted tree, the distance parameter \(B^-_v\), and timeouts
\[
\tau_{uv}=B^\ast + D^+_v.
\]
The main negative result is equally important: HTLC-only mechanisms are not sufficient for arbitrary strongly connected digraphs under the paper’s model, so atomic multi-party swap design has a sharp topological boundary [2403.03906].

## 7. Comparative perspective and limitations

A recurrent misconception is that any swap primitive is interchangeable with any other. The literature instead records domain-specific notions of evidence, correctness, and feasibility. In software, SwapD is heuristic and depends on meaningful identifier names, English-like morphemes, empirically chosen thresholds, and the assumption that most code in the corpus is correct; it is explicitly limited by naming quality, macro complexity, and the possibility that false-positive filters suppress real bugs [2009.09117]. In structured-light simultaneous message passing, the measurement yields a global similarity metric without bitwise readout, but the implementation uses classical intense light and therefore does not inherit the physical privacy guarantees of quantum fingerprinting [2006.07994].

Quantum gate constructions also separate naturally into different regimes. Exchange-only models such as XQP are sub-universal without postselection yet remain hard to simulate under standard complexity assumptions; this places them in an intermediate regime rather than identifying them with unrestricted BQP [2603.28527]. Scrambling-based SWAP protocols succeed only probabilistically and require a mediator dimension scaling as \(d_B\gg d_A^2\) for high-fidelity generic SWAP, so global interactions alone do not remove capacity constraints [2601.15536]. In blockchain settings, standard atomicity and fault tolerance are not the same property: all-or-nothing protocols can be safe while still failing to complete any acceptable subset after deviation, whereas predicate-based protocols address precisely that gap; conversely, when one restricts the execution layer to standard HTLCs, expressiveness is lost and only reuniclus digraphs admit atomic protocols [2211.00208][2403.03906].

Taken as a whole, the cited work supports a precise but plural understanding of argument-swap protocols. They are protocols whose central operation is an exchange decision between two positions, but the surrounding theory depends on the substrate: morpheme semantics in static analysis, interference and overlap in optical and quantum systems, flow constraints in network switches, and predicates plus cryptographic timing in distributed ledgers. The term therefore names a family of protocol designs rather than a single canonical construction.

Source: https://www.emergentmind.com/topics/argument-swap-protocol