-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtraits.rs
More file actions
48 lines (42 loc) · 1.64 KB
/
traits.rs
File metadata and controls
48 lines (42 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use ark_ff::{Field, PrimeField};
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget, prelude::Boolean, uint8::UInt8};
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use crate::constraints::tx::{TxVar, TxVarConfig};
/// Serialisation according to Bitcoin software specification for PreSigHash calculation
pub trait PreSigHashSerialise<F: Field> {
fn pre_sighash_serialise(&self) -> Result<Vec<UInt8<F>>, SynthesisError>;
}
/// Predicate to enforce conditions of the form `C((l_out, u_stx, stx), w) = 1`
pub trait BitcoinPredicate<F: PrimeField, P: TxVarConfig + Clone> {
type LockingData: Clone + Into<Vec<F>>;
type UnlockingData: Clone + Into<Vec<F>>;
type Witness: Clone;
type LockingDataVar: AllocVar<Self::LockingData, F>;
type UnlockingDataVar: AllocVar<Self::UnlockingData, F>;
type WitnessVar: AllocVar<Self::Witness, F>;
fn generate_constraints(
&self,
cs: ConstraintSystemRef<F>,
locking_data: &Self::LockingDataVar,
unlocking_data: &Self::UnlockingDataVar,
spending_data: &TxVar<F, P>,
witness: &Self::WitnessVar,
) -> Result<Boolean<F>, SynthesisError>;
fn enforce_constraints(
&self,
cs: ConstraintSystemRef<F>,
locking_data: &Self::LockingDataVar,
unlocking_data: &Self::UnlockingDataVar,
spending_data: &TxVar<F, P>,
witness: &Self::WitnessVar,
) -> Result<(), SynthesisError> {
self.generate_constraints(
cs.clone(),
locking_data,
unlocking_data,
spending_data,
witness,
)?
.enforce_equal(&Boolean::<F>::TRUE)
}
}