TxVar is the struct representing the R1CS version of a Bitcoin transaction.
It implements the AllocVar trait from ark_r1cs_std for generics T that can be borrowed as Tx.
The struct TxVar depends on two generics:
P, which implements the traitsTxVarConfigandCloneF, which implements the traitPrimeFieldfromark_ff
The trait TxVarConfig specifies the structure of the transaction being allocated in the circuit.
This trait is especially useful when the circuits are used in SNARKs with a circuit-specific setup, as it makes it easier to detect errors due to the use of proving/verifying keys incompatible with a given transaction structure.
TxVarConfig requires the user to set six constants:
N_INPUTS: usize: the number of inputs in the transactionN_OUTPUTS: usize: the number of outputs in the transactionLEN_UNLOCK_SCRIPTS: &[usize]: the lengths of the unlocking scriptsLEN_LOCK_SCRIPTS: &[usize]: the lengths of the locking scripts
The TxVarConfig trait is used to generate default transactions at setup time.
More precisely, the function default_tx takes a generic P : TxVarConfig and returns a transaction with the structure specified by P (albeit filled with meaningless data).
In this way, we can safely complete the SNARK setup using a dummy transaction with the specified structure.