Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 1.64 KB

File metadata and controls

21 lines (16 loc) · 1.64 KB

TxVar

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 traits TxVarConfig and Clone
  • F, which implements the trait PrimeField from ark_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 transaction
  • N_OUTPUTS: usize: the number of outputs in the transaction
  • LEN_UNLOCK_SCRIPTS: &[usize]: the lengths of the unlocking scripts
  • LEN_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.