-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logic.juvix
49 lines (43 loc) · 1.51 KB
/
Logic.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
module Logic;
-- Imports
import Stdlib.Prelude open;
import Stdlib.Data.Set as Set open using {Set};
import Anoma open;
import Applib open;
import Interface.Projection open using {getCount};
-- Resource Logic
counterLogic
(publicInputs : Logic.Instance) (privateInputs : Logic.Witness) : Bool :=
let
consumed := privateInputs |> Logic.Witness.consumed |> Set.toList;
created := privateInputs |> Logic.Witness.created |> Set.toList;
in case consumed, created of
| [consumedCounter], [createdCounter] :=
sameKindCheck@{
consumedCounter;
createdCounter;
}
&& case
both HasEphemerality.get (consumedCounter, createdCounter)
of {
| Ephemeral, NonEphemeral :=
creationCheck@{
createdCounter;
}
| NonEphemeral, NonEphemeral :=
incrementationCheck@{
consumedCounter;
createdCounter;
}
| _, _ := false
}
| _, _ := false;
sameKindCheck (consumedCounter createdCounter : Resource) : Bool :=
kind consumedCounter == kind createdCounter;
creationCheck (createdCounter : Resource) : Bool :=
getCount createdCounter == 0 && HasQuantity.get createdCounter == 1;
incrementationCheck (consumedCounter createdCounter : Resource) : Bool :=
let
expected := getCount consumedCounter + 1;
actual := getCount createdCounter;
in expected == actual;