-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallet.ak
More file actions
67 lines (64 loc) · 2.19 KB
/
Copy pathwallet.ak
File metadata and controls
67 lines (64 loc) · 2.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//// A UTxO may be spent if and only if a user can provide the proper NIZK
//// elements to prove that g^z = g^r * u^c for a given (g, u) register.
//// It is assumed that the set of all elements (g, u) is unique such that
//// no two datums have the same hash. This should allow an arbitrary amount
//// of UTxOs to be spent inside a single TX, allowing the contract to act like
//// a wallet for some user who knows a secret value x. A user can always
//// find their UTxOs by searching all Register datums for a (g, u) element where
//// g^x = u. Another user can send a UTxO to the (g, u) element by selecting a
//// large random integer d then doing the transformation,
//// (g, u) -> (g^d, u^d). This preserves the g and u relationship while
//// providing privacy as the new element, (g^d, u^d), can not be inverted into
//// the original (g, u) element.
////
use aiken/collection/list
use cardano/transaction.{OutputReference, Transaction}
use schnorr.{Proof, Register}
validator contract(_any: Data) {
spend(
maybe_register: Option<Data>,
proof: Proof,
_utxo: OutputReference,
self: Transaction,
) {
//
// do a data structure check
when maybe_register is {
Some(register) ->
if register is Register {
//
// Spend with Schnorr's Σ-protocol if the datum is of type Register using a
// random verification key hash as a one-time pad.
//
// Without the one-time pad, the funds could be respendable
// due to the tx being dropped during a rollback event!
//
and {
// zk proof to spend the utxo
schnorr.verify(
register.generator,
register.public_value,
proof.z_b,
proof.g_r_b,
proof.vkh,
)?,
// forces a one time pad via a random key signature
list.has(self.extra_signatories, proof.vkh)?,
}
} else {
//
// incorrect data structures should be spendable
//
True
}
//
// missing data structures should be spendable
//
None -> True
}
}
// Spend Only
else(_) {
fail
}
}