-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathresource-machine.hoon
137 lines (137 loc) · 3.5 KB
/
resource-machine.hoon
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/+ anoma
!.
=> anoma
|%
:: type definitions
+$ resource
$~ :*
label=*@t
logic=*resource-logic
ephemeral=|
quantity=`@u`1
data=*[@u @]
nullifier-key=*@I
nonce=*@I
rseed=%fake
==
$:
label=@t :: the label; some binary, @t for convenience
logic=resource-logic :: the logic predicate
ephemeral=? :: the ephemerality flag
quantity=@u :: quantity; some nonnegative integer
data=[len=@u val=@] :: arbitrary data; see lengthy comment in
:: resource.ex. words mean things
nullifier-key=@I :: npk; 256 bits
nonce=@I :: nonce for uniqueness; 256 bits
rseed=%fake :: useless field. meaningless value
==
+$ commitment @
+$ nullifier @
+$ public-inputs
$:
commitments=(list commitment) :: commitment set
nullifiers=(list nullifier) :: nullifier set
self-tag=@ :: exactly one commitment or nullifier
other-public=* :: some other public inputs
==
+$ private-inputs
$:
committed-resources=(list resource) :: committed resource set
nullified-resources=(list resource) :: nullified resource set
other-private=* :: some other private inputs
==
+$ resource-logic
$~ =>(~ |=(* &))
$-([public-inputs private-inputs] ?)
+$ logic-proof
[resource=resource inputs=[public-inputs private-inputs]]
+$ compliance-proof %compliance
+$ proof ?(compliance-proof logic-proof)
+$ action
$~ :*
commitments=~
nullifiers=~
proofs=~
app-data=**
==
$:
commitments=(list commitment) :: commitment set
nullifiers=(list nullifier) :: nullifier set
proofs=(list proof) :: proof set
app-data=* :: arbitrary data
==
+$ cm-root @ :: commitment set root
+$ resource-kind
[label=@t logic=resource-logic]
+$ delta-element
[k=resource-kind v=@s]
+$ delta (list delta-element) :: delta (opaque)
+$ transaction
$~ :*
roots=~
actions=~
delta=*delta
delta-proof=%delta
==
$:
roots=(list cm-root) :: root set for spent resources
actions=(list action) :: action set
delta=delta :: delta (opaque)
delta-proof=%delta :: delta proof (trivial)
==
:: provided functions
++ private :: DO NOT USE!
|%
++ uncommit
|= =commitment
;; resource
(cue (~(rsh block 3) 3 commitment))
++ unnullify
|= =nullifier
;; resource
(cue (~(rsh block 3) 3 nullifier))
--
++ commit :: commit to a resource
|= =resource
^- commitment
(~(cat block 3) 'CM_' (jam resource))
++ nullify :: nullify a resource
|= =resource
^- nullifier
(~(cat block 3) 'NF_' (jam resource))
++ kind
|= =resource
^- resource-kind
[label.resource logic.resource]
++ prove-logic :: prove a resource logic given all inputs
|= =logic-proof
(jam logic-proof)
++ prove-action :: prove action compliance, trivially
|= *
%compliance
++ delta-add
|= [d1=delta d2=delta]
^- delta
!!
++ delta-sub
|= [d1=delta d2=delta]
^- delta
!!
++ resource-delta
|= =resource
^- delta
~[[(kind resource) (sun quantity.resource)]]
++ action-delta
|= =action
^- delta
!!
++ make-delta :: make delta from actions (to make a transaction)
|= actions=(list action)
^- delta
!!
++ prove-delta :: prove delta, trivially
|= *
%delta
++ zero-delta :: the value of the zero delta, for convenience
~
--