To prove correct mixing of confidential assets, the Zei library makes use of Bulletproofs. The protocol here follows a modular design. We first present the shuffle gadget and RHS-merge-or-not gadget as well as some helper functions, and then we describe how to construct the mixing protocol.
This gadget enforces that b_amount,b_asset_type is a result of shuffling from a_amount,a_asset_type, where the amount and the asset type are being shuffled together, and each vector has length ℓ.
Obtain two random challenges α,β∈F from the Bulletproofs R1CS interface. Note that Bulletproofs R1CS interface allows the program to pull random challenges in the middle.
Compute a random linear combination for (a_amount,a_asset_type).
This gadget enforces that (b_amount,b_asset_type) is obtained by doing \emph{optional} RHS merging over (a_amount,a_asset_type) when the asset types of the two consecutive ones are the same. Each vector has length ℓ.
Copy tmp_amount:=a_amount and tmp_asset_type:=a_asset_type. We will be working over these two temporary vectors.
For i=0,1,...,ℓ−1,
If tmp_asset_type[i]=tmp_asset_type[i+1], then a merge is \emph{permitted}. Otherwise, a merge is prohibited.
If a merge is permitted and b_amount[i]=0, then the merge happens, we update tmp_amount and tmp_asset_type,
tmp_amount[i+1]:=tmp_amount[i]+tmp_amount[i+1]
tmp_amount[i]:=0
Otherwise, the merge does not happen, we do not update tmp_amount and tmp_asset_type.
Require tmp_amount=b_amount and tmp_asset_type=b_asset_type.
Ask the prover to provide a shuffled version of (a_amount,a_asset_type) and (b_amount,b_asset_type). An honest prover is expected to sort the entries in each vector in a way that the entries for the same asset type are consecutive to each other. There is no particular requirement on the order of this sorting.
Let (sorted_a_amount,sorted_a_asset_type) and (sorted_b_amount,sorted_b_asset_type) be the vectors that the prover provides.
Ask the prover to provide a merged version of (sorted_a_amount,sorted_a_asset_type) and (sorted_b_amount,sorted_b_asset_type). An honest prover is expected to perform RHS merging whenever possible.
Let (merged_a_amount,merged_a_asset_type) and (merged_b_amount,merged_b_asset_type) be the vectors that the prover provides.
To prove that a pair of Pedersen commitments are committing a valid amount in confidential payments, the Zei library makes use of Bulletproofs.
This is a proof of knowledge, since a Pedersen commitment could be committing any number. What is being shown in this proof is that a prover knows a binding that can interpret a Pedersen commitment with a specific valid number that the prover knows. Assuming that the discrete log problem is hard and the CRS is secure, it is sufficient for confidential payments.
We omit a detailed description, as it simply invokes the proving and verifying algorithms for range checks in the Bulletproofs library that the Zei library depends on.