The zero-knowledge circuit of user state transition proof in UniRep
The user state transition proof is used to process attestations from the latest epoch the user transitioned and then compute the latest global state tree leaf.
After all attestations of all epoch keys are processed, the circuit seals all hash chains and computes the epoch tree. (If the output epoch tree root mismatches others' epoch tree roots, then the user state transition proof is invalid because the user process attestations in a wrong way.)
Compute the updated global state tree leaf by
Ideally, the user state transition proof should be in one circuit. But the circuit size is too big to generate a proof in a browser, we separate the proof into three different parts: start transition proof, process attestations proof, and user state transition proof.
The idea of chaining these three proofs but without revealing user's sensitive information is to use blinded_user_state and blinded_hash_chain
In the start transition proof, the circuit will compute the initial blinded_user_state and blinded_hash_chain, the user_tree_root is the latest transitioned user state tree and the hash(identity_commitment, updated_user_state_root) should be in a global state tree. The current_hash_chain is start with 0 as the definition of hash chain.
How blinded user states and blinded hash chains are computed.
After blinded_user_state and blinded_hash_chain are submitted, the user can take them as public inputs and start to process attestations according to the user_tree_root and current_hash_chain. When the attestations limit reaches (e.g. a processAttestations circuit can process only 10 attestations per proof) or all attestations to the epoch key are processed, the circuit will output another blinded_user_state and blinded_hash_chain to continue processing attestations.
How hash chain is processed in process attestations proofs.
How user state tree is processed in process attestation proofs.
The epoch_key_nonce is used in the blinded user state and blinded hash chain to indicate the attestations of which epoch key is processed. In the final userStateTransition proof, it checks all epoch key with different epoch_key_nonce are processed and the hash chain result matches the epoch tree.
There are only one user state tree result after all attestations are processed, so in the final proof it only takes the initial blinded_user_state and the final one and computes the new global state tree leaf. On the other hand, there are numEpochKeyNoncePerEpoch hash chains after processing attestations, so the final circuit will take numEpochKeyNoncePerEpochblinded_hash_chain to check the epoch tree root.
How the final user state transition proof verifies hash chains and user states.
The user state tree root is continuously updated: the output should be the input of another proof, so the processAttestation proof takes blinded_user_state as public input and output another blinded_user_state. The hash chain results might not be continuously. When all attestations of one epoch key is processed, the hash chain of the next epoch key should be 0 but not the previous hash chain. Therefore, processAttestation proof does not take blinded_hash_chain as input.
While verifying all of the proofs, there are the following things to check to make sure it follows the rules:
startTransitionProof takes a valid global state tree root as a public input.
processAttestationsProof takes blinded_user_state as public input and blinded_hash_chain as private input from either startTransitionProof or another processAttestationsProof.
userStateTransitionProof takes two blinded_user_state, one is from startTransitionProof and the other is from the latest processAttestationsProof.
userStateTransitionProof takes numEpochKeyNoncePerEpochblinded_hash_chain from processAttestationsProof.
1. Start Transition proof
Public inputs
GST_root
Public outputs
blinded_user_state
blinded_hash_chain_result
Private inputs
epoch
epoch_key_nonce
user_tree_root
identity_nullifier
identity_trapdoor
GST_path_elements
GST_path_index
Contraints
1. Check if user exists in the Global State Tree
Check if hash(identity_commitment, UST_root) is one of the leaves in the global state tree of root GST_root.