-
Notifications
You must be signed in to change notification settings - Fork 0
/
RawCounterTransaction.juvix
83 lines (68 loc) · 2.04 KB
/
RawCounterTransaction.juvix
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
module RawCounterTransaction;
import Anoma.Transaction open;
import Stdlib.Prelude open;
import Anoma.Extra open;
open Transaction;
open DeltaComponent;
-- Required for Demo only
import Anoma.Transaction as Demo;
privKey : Nat :=
0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac11662fc6e7829efcb0f4500827d49bb699af7b5475cef5220fd600ebbf9709a58;
pubKey : Nat :=
0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac1;
counterLogic (r : Resource) (tx : Transaction) : Bool :=
let
rs : ResourcePartition := partitionResources tx;
in case
ResourcePartition.consumed rs
, ResourcePartition.created rs
of
| [old], [new] :=
if
| Resource.eph old := Resource.data new == 0
| else :=
Resource.label new == Resource.label old
&& Resource.data new == Resource.data old + 1
| _ := false;
mkCounter (ephemeral : Bool) (n : Nat) : Resource :=
Resource.mk@{
logic := counterLogic;
label := 0;
quantity := 1;
data := n;
eph := ephemeral;
npk := pubKey;
nonce := 0;
rseed := 0
};
zeroedCounter : Resource := mkCounter false 0;
incrementedCounter : Resource := mkCounter false 1;
dummy : Resource := mkCounter true 666666;
counterTransaction : Transaction :=
Transaction.mk@{
roots := [];
commitments := [commitment incrementedCounter];
nullifiers := [nullifier zeroedCounter privKey];
proofs := [zeroedCounter; incrementedCounter];
delta := [];
extra := 0;
preference := 0
};
mkCounterTransaction
(consumed : Resource)
(created : Resource)
: Transaction :=
Transaction.mk@{
roots := [];
commitments := [commitment created];
nullifiers := [nullifier consumed privKey];
proofs := [consumed; created];
delta := [];
extra := 0;
preference := 0
};
init (resource : Resource) : Transaction :=
mkCounterTransaction dummy resource;
update (old new : Resource) : Transaction :=
mkCounterTransaction old new;
main : Transaction := init zeroedCounter;