-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
1606 lines (1327 loc) · 118 KB
/
main.tex
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[9pt]{article} % use "amsart" instead of "article" for AMSLaTeX format
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{a4paper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for rotated page geometry
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx} % Use pdf, png, jpg, or eps§ with pdflatex; use eps in DVI mode
% TeX will automatically convert eps --> pdf in pdflatex
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{hyperref}
\usepackage{doi}
\usepackage{pf2}
\usepackage{todonotes}
%\usepackage{amsthm}
%\newtheorem{theorem}{Theorem}
%\newtheorem{lemma}{Lemma}
\newcommand\el[1]{\textcolor{orange}{{\bf Erick: }#1}}
\newcommand{\defeq}{\overset{\mathrm{def}}{=}}
\newcommand{\mergeop}{\overset{\sqcup}\rightarrow}
\newcommand{\localop}{\overset{\textbf{local}}\rightarrow}
\newcommand{\anyop}[1]{\overset{#1}\rightarrow}
\title{GOC-Ledger: State-based Conflict-Free Replicated Ledger from Grow-Only Counters}
\author{Erick Lavoie \\
University of Basel \\
\href{mailto:erick.lavoie@unibas.ch}{erick.lavoie@unibas.ch}}
%\date{March, 13, 2023} % Activate to display a given date or no
\begin{document}
\maketitle
\begin{abstract}
Conventional blockchains use consensus algorithms that totally order updates across all accounts, which is stronger than necessary to implement a replicated ledger. This makes updates slower and more expensive than necessary. More recent consensus-free replicated ledgers forego consensus algorithms, with significant increase in performance and decrease in infrastructure costs. However, current designs are based around reliable broadcast of update operations to all replicas which require reliable message delivery and reasoning over operation histories to establish convergence and safety.
In this paper, we present a replicated ledger as a state-based conflict-free replicated data type (CRDT) based on grow-only counters. This design provides two major benefits: 1) it requires a weaker eventual transitive delivery of the latest state rather than reliable broadcast of all update operations to all replicas; 2) eventual convergence and safety properties can be proven easily without having to reason over operation histories: convergence comes from the composition of grow-only counters, themselves CRDTs, and safety properties can be expressed over the state of counters, locally and globally. In addition, applications that tolerate temporary negative balances require no additional mechanisms and applications that require strictly non-negative balances can be supported by enforcing sequential updates to the same account across replicas.
Our design is sufficient when executing on replicas that might crash and recover, as common in deployments in which all replicas are managed by trusted entities. It may also provide a good foundation to explore new mechanisms for tolerating adversarial replicas.
\end{abstract}
\section{Introduction}
\label{sec:introduction}
% Consensus is not necessary
Global replicated ledgers, also known as \textit{blockchains}, provide the ability for untrusted parties to exchange tokens world-wide, with Bitcoin~\cite{nakamoto2008bitcoin} and Ethereum~\cite{buterin2014next} being the most popular examples. It has been shown that using consensus algorithms to totally order updates across all accounts in replicated ledgers is stronger than necessary to prevent overspending~\cite{guerraoui2021consensus}: sequentially ordering updates on the same account (\textit{e.g.},~\cite{frey:hal-03346756}) and even only the outgoing transactions is sufficient (\textit{e.g.},~\cite{collins2020broadcast-payment}). Foregoing the use of consensus algorithms drastically increases throughput and decreases latency~\cite{collins2020broadcast-payment,baudet2020fastpay}. Published consensus-free replicated ledgers~\cite{collins2020broadcast-payment,baudet2020fastpay,sliwinski2020abc,guerraoui2021consensus,auvolat2021money,frey:hal-03346756,kuznetsov2021permissionless,cholvi2021bdso,georghiades2021needs} are based on broadcast abstractions that require reliable delivery of account operations.
% Opportunity of state-based CRDTs
In parallel to work on replicated ledgers, Conflict-Free Replicated Data Types (CRDTs)~\cite{shapiro:hal-00932836} have been proposed to simplify the design and implementation of distributed systems. CRDTs are replicated mutable objects designed according to simple constraints to ensure convergence to the same state \textit{eventually}, \textit{i.e.}, at some point in the future after updates have stopped, and \textit{automatically}, \textit{i.e.} using deterministic conflict-resolution rules in the presence of concurrent updates. The state-based declination of CRDTs~\cite{shapiro:hal-00932836} requires only 1) eventual transitive delivery of the latest state rather than reliable broadcast of all update operations to all replicas, and 2) a simple merging procedure between different states. The state-based approach tolerates by design lost, re-ordered, stale, and duplicate updates containing copies of other replicas' state by ensuring the possible states and operations follow a few simple constraints.
In this paper, \textit{we show that a replicated ledger can be implemented as a state-based conflict-free data type based on the composition of grow-only counters}, which we call \textit{Grow-Only-Counters-Ledger} (GOC-Ledger). The key idea is to use a separate grow-only counter for every kind of state-updating operation, which represents the total contribution of all past similar operations to the current balance. For example, a specific grow-only counter is used to track the total amount ever sent from a sender account to a specific receiver account. The current balance of an account is then computed by adding every balance-increasing counters and subtracting every balance-reducing counters.
To the best of our knowledge, we are the first to propose this design, which provides numerous benefits. First, as for all state-based CRDTs, it lowers the requirements on the communication channels and connection topology between replicas. Effectively, grow-only counters act as a summary of all previous operations of the same kind, which removes the need to reason about and individually track previous operations. Second, eventual convergence of all account replicas to the same balance can be simply proven by the composition of grow-only counters, that are themselves simple state-based CRDTs. The convergence of account replica balances is guaranteed even in the presence of overspending, which we show can only occur in the presence of concurrent updates to the same account from multiple replicas.
% Local crypto-tokens opportunity
%The use of crypto-tokens has been popularized by global replicated ledgers, also known as \textit{blockchains}, for anonymous transactions between untrusted parties world-wide, with Bitcoin~\cite{nakamoto2008bitcoin} and Ethereum~\cite{buterin2014next} being the most popular.
%However, high transactions fees preclude their use for many local economic applications~\cite{lavoie2022localcryptotokens}.
%Local economies are characterized by repeated interactions within a community of participants that know each other, providing higher trust levels than is otherwise assumed by participants on global blockchains. Revisit underlying economic assumptions behind the current designs to enable simpler and more affordable infrastructure in local contexts.
As additional benefits, a GOC-Ledger might be particularly appropriate for supporting local economic applications~\cite{lavoie2022localcryptotokens}, that are characterized by repeated interactions within a community of participants that know each other. Some local applications may tolerate temporary negative balances, for example because existing trust between participants or reputation loss are sufficient to incentivize maintaining a non-negative balance. For other applications in which a non-negative balance should be maintained at all times, our design can be combined with an additional mechanism that ensures all updates to the same account are ordered, similar to existing designs~\cite{collins2020broadcast-payment,baudet2020fastpay}. Either case should be relatively straight-forward to implement when all replicas are managed by a single organization or a restricted set of mutually-trusting entities.
However, our design is not sufficient by itself to operate in the presence of adversarial replicas, as happens in peer-to-peer settings. It is still an open research question to design practical and frugal replicated ledgers that work in those settings. We believe GOC-Ledger is a good foundation for such explorations, and plan to use it to design the necessary mechanisms.
In the rest of this paper, we present the design of the GOC-Ledger (Section~\ref{sec:design}), we prove its convergence, as well as its balance safety and liveness properties (Section~\ref{sec:proofs}), we position it in the context of other related work and highlight open challenges to tolerate adversarial failures (Section~\ref{sec:related-work}). We finally conclude with a brief summary and outline future research directions (Section~\ref{sec:conclusion}).
\newpage
\section{Grow-Only-Counters (GOC) Ledger}
\label{sec:design}
In this section, we present the design of a GOC-Ledger in two parts: we first present state-based conflict-free replicated \textit{accounts} (Section~\ref{sec:account}) and then the \textit{ledger} proper (Section~\ref{sec:ledger}). Our notation and conventions are explained as they are introduced and collected in Appendix~\ref{apdx:notation}.
\subsection{Account}
\label{sec:account}
Account replicas track the current balance of tokens for a given owner identified by their \textit{identifier} ($id$). The state of an account is decomposed into multiple internal counters such that all counters are \textit{monotonically increasing}, \textit{i.e.}, every operation leaves counters either unchanged or larger.
Before explaining what each internal counter represents, we give an overview of account operations. Each owner can \textit{create} new tokens, if they have the capability; \textit{burn} tokens they own; and transfer some or all their tokens to other accounts, identified by different $id$s. We split the transfer into two operations: the sender \textit{gives} tokens to a receiver account, which immediately decreases the balance of the sender; however, the balance of the receiver is only increased after an explicit \textit{acknowledgement}. This decomposition enables the reception of tokens to be tracked as a separate event: this allows, for example, other replicas to check if the receiver account has received (and accepted) the tokens.\footnote{It is possible to always automatically acknowledge the reception of tokens immediately upon reception and not expose the acknowledgment operation to the user. However, having the operation performed explicitly also gives the opportunity to the receiver to ignore tokens sent to them. We therefore prefer the explicit operation.} The implementation follows easily, with each operation modifying separate internal counter(s).
We first present the state and operations in the following section (Section~\ref{sec:account:state-operations}), and the ordering and merging operations necessary for concurrency, in the next (Section~\ref{sec:account:ordering-merging}).
\subsubsection{State and Operations}
\label{sec:account:state-operations}
The implementation of the state and corresponding operations is listed in Algorithm~\ref{alg:account} and ~\ref{alg:query}. We now present each operation in turn.
\begin{algorithm}
\begin{algorithmic}[1]
\State \textbf{Require} $\mathds{C}$, the set of identifiers allowed to create tokens
\State
\Function{initialize$_\mathds{A}$}{\textit{id}}
\State $A_{\scriptsize\textbf{id}} \leftarrow id$
\State $A_\uparrow ~\leftarrow 0$ \Comment{Created amount (real positive number)}
\State $A_\downarrow ~\leftarrow 0$ \Comment{Burned amount (real positive number)}
\State $A_\rightarrow \leftarrow \{ \}$ \Comment{GivenTo: Dictionary of $\textit{id}$s associated to $\textit{amount}$s}
\State $A_\leftarrow \leftarrow \{ \}$ \Comment{AckFrom: Dictionary of $\textit{id}$s associated to $\textit{amount}$s}
\State \Return $A$
\EndFunction
\State
\Function{create}{$A,\textit{amount}$}
\If{$A_{\scriptsize\textbf{id}} \in \mathds{C} \wedge \textit{amount} > 0$}
\State $A' \leftarrow \textit{copy}(A)$
\State $A'_\uparrow \leftarrow A_\uparrow + \textit{amount}$
\State \Return $A'$
\Else
\State \Return $A$
\EndIf
\EndFunction
\State
\Function{burn}{$A,\textit{amount}$}
\If{$\textit{amount} > 0 \wedge \texttt{balance}(A) \geq \textit{amount}$} \label{ln:burn-balance-check}
\State $A' \leftarrow \textit{copy}(A)$
\State $A'_\downarrow \leftarrow A_\downarrow + \textit{amount}$
\State \Return $A'$
\Else
\State \Return $A$
\EndIf
\EndFunction
\State
\Function{giveTo}{$A,\textit{amount}, \textit{id}$}
\If{$\textit{amount} > 0 \wedge \texttt{balance}(A) \geq \textit{amount}$} \label{ln:give-balance-check}
\State $A' \leftarrow \textit{copy}(A)$
\If{$id \notin A_{\rightarrow *}$}
\State $A'_{\rightarrow}[id] \leftarrow \textit{amount}$
\Else
\State $A'_{\rightarrow}[id] \leftarrow A_{\rightarrow}[id] + \textit{amount}$
\EndIf
\State \Return $A'$
\Else
\State \Return $A$
\EndIf
\EndFunction
\State
\Function{ackFrom}{$A, B$}
\If{$\texttt{unackedFrom}(A,B) > 0$}
\State $A' \leftarrow \textit{copy}(A)$
\If{$B_{\scriptsize\textbf{id}} \notin A_{\leftarrow *}$}
\State $A'_{\leftarrow}[B_{\scriptsize\textbf{id}}] \leftarrow B_{\rightarrow}[A_{\scriptsize\textbf{id}}]$
\Else
\State $A'_{\leftarrow}[B_{\scriptsize\textbf{id}}] \leftarrow \texttt{max}(A_{\leftarrow}[B_{\scriptsize\textbf{id}}], B_{\rightarrow}[A_{\scriptsize\textbf{id}}])$
\EndIf
\State \Return $A'$
\Else
\State \Return $A$
\EndIf
\EndFunction
\end{algorithmic}
\caption{\label{alg:account} Account: State Initialization and State-Changing Operations}
\end{algorithm}
\begin{algorithm}
\begin{algorithmic}[1]
\State
\Function{balance}{A}
\State $\textit{debits} \leftarrow A_\uparrow + \sum\limits_{id \in A_{\leftarrow *}} A_{\leftarrow}[id]$
\Comment{Keys of $A_\leftarrow$ written $A_{\leftarrow *}$}
\State $\textit{credits} \leftarrow A_\downarrow + \sum\limits_{id \in A_{\rightarrow *}} A_{\rightarrow}[id]$
\Comment{Keys of $A_\rightarrow$ written $A_{\rightarrow *}$}
\State \Return $\textit{debits} - \textit{credits}$
\EndFunction
\State
\Function{unackedFrom}{$A, B$}
\If{$A_{\scriptsize\textbf{id}} \in B_{\rightarrow *} \wedge B_{\scriptsize\textbf{id}} \in A_{\leftarrow *} $}
\State \Return $B_{\rightarrow A_{\tiny\textbf{id}}} - A_{\leftarrow B_{\tiny\textbf{id}}}$
\ElsIf{$A_{\scriptsize\textbf{id}} \in B_{\rightarrow *}$}
\State \Return $B_{\rightarrow A_{\tiny\textbf{id}}}$
\Else
\State \Return $0$
\EndIf
\EndFunction
\end{algorithmic}
\caption{\label{alg:query} Account: Query Operations}
\end{algorithm}
A replica of an account belonging to owner $id$ is created with \texttt{initialize} (Alg.~\ref{alg:account}). This initializes the internal identifier $A_{\textbf{id}}$ to $id$, the number of created tokens $A_\uparrow$ to $0$, the number of burned tokens $A_\downarrow$ to $0$, the dictionary of given tokens $A_\rightarrow$ to an empty dictionary, and the dictionary of acknowledged tokens $A_\leftarrow$ to an empty dictionary as well.\footnote{The direction of the arrow notation suggests the corresponding direction of funds: up or down for creation or destruction of tokens, and left or right for tokens flowing into and out of an account.}
The \texttt{create} operation (Alg.~\ref{alg:account}) takes the current state of an account $A$ and a requested \textit{amount} then returns a new state $A'$.\footnote{A practical implementation may actually encapsulate the state of an account in an object and modify it in place. We explicitly associate the different states to different variables to make the labels of the states in proofs (Section~\ref{sec:proofs}) easier to relate to the implementation.} Only allowed creators, \textit{i.e.}, those with ids within the set of allowed identifiers $\mathds{C}$, may create new tokens.\footnote{The set of allowed creator identifiers might be distributed to replicas beforehand or derived from cryptographic mechanisms. The design of such mechanisms is outside the scope of this paper.} If the owner of the account is indeed allowed to create tokens, the creation counter is increased by \textit{amount} and $A'_\uparrow = A_\uparrow + \textit{amount}$. This has the effect of increasing the balance by \textit{amount}. Otherwise, the counter is unchanged ($A'_\uparrow=A_\uparrow$) and the balance remains the same.
The \texttt{burn} operation (Alg.~\ref{alg:account}) is similar to \texttt{create} with an opposite effect on the balance: it takes the current state of an account $A$ and a requested \textit{amount} to burn, then returns a new state $A'$. If the balance is equal or larger than \textit{amount}, the burn counter is increased by \textit{amount}, resulting in $A'_\downarrow = A'_\downarrow + \textit{amount}$, and the balance correspondingly decreased by the same amount resulting in a non-negative balance. Otherwise, $A'_\downarrow = A_\downarrow$ and the balance is unchanged. In contrast to \texttt{create}, any account is allowed to burn tokens.\footnote{Restricting burning tokens to a set of identifiers would also be possible. However, the restriction would not be effective unless transfer operations were also restricted to only valid addresses because giving to an invalid or unused address effectively makes the tokens unavailable, similar to burning. Restricting transfers to only valid addresses would require tracking the set of valid accounts and most likely synchronization with highly-available replicas. We therefore take the simpler and more open approach of allowing any account to burn tokens.}
The \texttt{giveTo} operation (Alg.~\ref{alg:account}) sends \textit{amount} tokens from account $A$ to the recipient account associated to $id$, resulting in a new state $A'$. The account state tracks the total amount ever sent to $id$ using the dictionary $A_{\rightarrow}$, using $id$ as a key to access the associated monotonic counter, written $A_{\rightarrow}[id]$. This counter is only increased if the local balance is higher or equal than the \textit{amount} sent, resulting in a non-negative balance for $A'$.
\texttt{Burn} and \texttt{giveTo} are the only two operations on accounts that may decrease the balance. As we prove later by simple induction (Section~\ref{section:proof:sequential-non-negative}), it is sufficient to sequentially order all account operations, potentially across replicas, to guarantee that the balance for that account will always be non-negative. A contrario, as we also discuss next (Section~\ref{sec:account:ordering-merging}), concurrent updates to the same account in different replicas may eventually result in a negative balance, even if the balance resulting from individual operations was always non-negative.
The \texttt{ackFrom} operation (Alg.~\ref{alg:account}) acknowledges the reception of tokens from account $B$ on account $A$. If there are unacknowledged tokens that $B$ sent to $A$,
then $A$'s counter $A_{\leftarrow}[B_{\scriptsize \textbf{id}}]$, which tracks the total amount ever acknowledged by $A$ from $B$, is increased by the number of unacknowledged tokens, with a corresponding increase the balance of $A'$. If $A$ had never acknowledged tokens from $B$ before, the new counter value $A'_{\leftarrow}[B_{\scriptsize \textbf{id}}]$ is simply the total amount ever sent by $B$ to $A$ up to that point, written $B_{\rightarrow}[A_{\scriptsize \textbf{id}}]$. Otherwise, if $A$ had already acknowledged tokens from $B$, the new counter value $A'_{\leftarrow}[B_{\scriptsize \textbf{id}}]$ is the maximum of the previous value $A_{\leftarrow}[B_{\scriptsize \textbf{id}}]$ and $B_{\rightarrow}[A_{\scriptsize \textbf{id}}]$. This definition correctly handles acknowledging with a stale state $B^{-1}$ because the corresponding counter $B^{-1}_{\rightarrow}[A_{\scriptsize \textbf{id}}]$ would be equal or smaller than the counter in the most recent state of $B$, $B_{\rightarrow}[A_{\scriptsize \textbf{id}}]$, and therefore $A$ would not be updated.\footnote{It could also be useful to check that the balance of $B$ was non-negative prior to updating the state of $A$: this would limit the propagation of overspent tokens by $B$\footnote{ This would not completely prevent the propagation because different accounts may have individually acknowledged tokens from B before B's state would reflect the overspending.}. Checking for a non-negative balance from $B$ is however superfluous if the application is actually intended to handle negative balances (Section~\ref{sec:economics})}.
As follows from the previous explanations, the \texttt{balance} of an account $A$ (Alg.~\ref{alg:query}) is the sum of counters that increase the balance (\textit{debits}) subtracted by the sum of counters that decrease it (\textit{credits}). The \texttt{balance} operation does not modify the state of the account. The debits are the sum of created tokens and the sum of the tokens acknowledged from other accounts. The credits are the sum of tokens burnt and given to other accounts.
The last operation, \texttt{unackedFrom} (Alg.~\ref{alg:query}) returns the number of tokens sent from account $B$ that have not yet been acknowledged by account $A$. It does not modify the state of $A$ nor $B$. This is implemented by subtracting the tokens acknowledged by $A$ from $B$, from the tokens sent by $B$ to $A$. If the result is greater than zero, there are unacknowledged tokens.
\subsubsection{Comparing and Merging Concurrent States}
\label{sec:account:ordering-merging}
We now augment our previous account definition with one relation and one operation to enable comparing states and merging concurrently modified states. The augmented definition forms a \textit{monotonic join semi-lattice}, which informally, is a mathematical structure that combines an ordering between states with constraints on operations that captures the notion of progress without having to explicitly reason about time and ordering between different operations. We now present its different components.
The relation $\leq_\mathds{A}$ (Alg.~\ref{alg:account-ordering}) establishes an ordering between states of the same account, \textit{i.e.}, account states with the same id. The operations of the previous section (Alg.~\ref{alg:account} and ~\ref{alg:query}) have been carefully designed to be \textit{monotonic}, \textit{i.e.} they either do not modify the state of an account, or result in a new state $A'$ larger than the previous state $A$ according to $\leq_\mathds{A}$. Because of the monotonicity of the operations, if $A <_\mathds{A} A'$,\footnote{$A \leq_\mathds{A} A'$ and $A \neq A'$} then $A$ has happened before $A'$ and therefore $A'$ also contains all the updates that led to $A$. This ordering is however \textit{partial}: \textit{i.e.} if neither $A <_\mathds{A} A'$ nor $A' <_\mathds{A} A$, then neither $A$ or $A'$ has happened before the other and both are therefore the result of concurrent updates. The relation $A \leq_\mathds{A} A'$ is implemented as follows: it is true if and only if the set of identifiers for given and acknowledged tokens of $A$ are subsets of those of $A'$ \textit{and} every counter of $A$ are smaller or equal to the corresponding counters in $A'$. Note that counters in $A'$ not present in $A$ have no effect, because they would be the result of operations that have happened after $A$.
\begin{algorithm}
\begin{algorithmic}[1]
\Function{$\leq_\mathds{A}$}{$A$, $A'$} \Comment{Compare, call written in infix notation, \textit{e.g.}, $A \leq_\mathds{A} A'$}
\State $\textit{created} \leftarrow A_\uparrow \leq A'_\uparrow$
\State $\textit{burned} \leftarrow A_\downarrow \leq A'_\downarrow$
\State $\textit{given} \leftarrow A_{\rightarrow *} \subseteq A'_{\rightarrow *} \wedge \bigwedge\limits_{id \in A_{\rightarrow *}} A_{\rightarrow}[id] \leq A'_{\rightarrow}[id]$ \Comment{Keys of $A_\rightarrow$ written $A_{\rightarrow *}$}
\State $\textit{acked} \leftarrow A_{\leftarrow *} \subseteq A'_{\leftarrow *} \wedge \bigwedge\limits_{id \in A_{\leftarrow *}} A_{\leftarrow}[id] \leq A'_{\leftarrow}[id]$
\State \Return $A_{\footnotesize \textbf{id}} = A'_{\footnotesize \textbf{id}} \wedge \textit{created} \wedge \textit{burned} \wedge \textit{given} \wedge \textit{acked}$
\EndFunction
\State
\Function{$\sqcup_\mathds{A}$}{$A$, $A'$} \Comment{Merge, call written in infix notation, \textit{e.g.}, $A \sqcup_\mathds{A} A'$}
\If{$A_{\footnotesize \textbf{id}} \neq A'_{\footnotesize \textbf{id}}$}
\textbf{error}
\EndIf
\State
\State $A'' \leftarrow \texttt{initialize}(A_{\footnotesize \textbf{id}})$
\State $A''_\uparrow \leftarrow \texttt{max}(A_\uparrow, A'_\uparrow)$
\State $A''_\downarrow \leftarrow \texttt{max}(A_\downarrow, A'_\downarrow)$
\State
\State $R \leftarrow A_{\rightarrow *} \cup A_{\rightarrow *}'$ \Comment{Receiver ids}
\For{$id ~\textbf{in}~ R$}
\If{$id \in A_{\rightarrow *} \wedge id \in A'_{\rightarrow *} $}
\State $A''_{\rightarrow}[id] \leftarrow \texttt{max}(A_{\rightarrow}[id], A'_{\rightarrow}[id])$
\ElsIf{$id \in A_{\rightarrow *}$}
\State $A''_{\rightarrow}[id] \leftarrow A_{\rightarrow}[id]$
\Else
\State $A''_{\rightarrow}[id] \leftarrow A'_{\rightarrow}[id]$
\EndIf
\EndFor
\State
\State $S \leftarrow A_{\leftarrow *} \cup A_{\leftarrow *}'$ \Comment{Sender ids}
\For{$id ~\textbf{in}~S$}
\If{$id \in A_{\leftarrow *} \wedge id \in A_{\leftarrow *}'$}
\State $A''_{\leftarrow}[id] \leftarrow \texttt{max}(A_{\leftarrow}[id], A'_{\leftarrow}[id])$
\ElsIf{$id \in A_{\leftarrow *}$}
\State $A''_{\leftarrow}[id] \leftarrow A_{\leftarrow}[id]$
\Else
\State $A''_{\leftarrow}[id] \leftarrow A'_{\leftarrow}[id]$
\EndIf
\EndFor
\State
\State \Return $A''$
\EndFunction
\end{algorithmic}
\caption{\label{alg:account-ordering} Account: Ordering and Merging}
\end{algorithm}
The account merge operation, $\sqcup_\mathds{A}$, (Alg.~\ref{alg:account-ordering}) is also a monotonic operation that combines different states for the same account, possibly resulting from concurrent operations. It computes the smallest state $A''$ from any two states $A$ and $A'$, such that $A''$ is equivalent to having applied the operations that led to both $A$ and $A'$. In mathematical terms, $A''$ is the \textit{least upper bound} of both $A$ and $A'$ according to $\leq_\mathds{A}$. Because it is a least upper bound, merging two states $A$ and $A'$ such that $A$ has happened before $A'$, \textit{i.e.} $A \leq_\mathds{A} A'$, results in a new state $A'' = A'$. This property allows merging with duplicate and out-of-order previous states without impacting the result. Moreover, because a later merged state implicitly contains the updates that led to previous states across replicas, the convergence of all replicas to the same state only requires the latest state of all replicas to have been propagated to other replicas \textit{transitively}, \textit{i.e.} through intermediate replicas. This requires less messages and better tolerates lost messages than operation-based approaches, which require explicit broadcast of every operation to all replicas~\cite{shapiro:hal-00932836}. The merge operation is implemented by merging all counters from both states and taking the maximum value of those that are present on both states.\footnote{This implementation is not strictly equivalent to merging all operations that have happened across replicas because taking the maximum value of two resulting counter is not equivalent to the sum of increments from their previous common state: \textit{i.e.} if $c' = x + c$ and $c'' = y + c$, $max(c', c'')$ is equal to $c + x + y$ only if $x$ or $y$ is $0$. In effect, the merge effectively considers two concurrent increments as having a shared component that is not duplicated even if done concurrently. This subtle distinction is what enables not having to reason about ordering between operation updates. Concurrent operations on different counters are however equivalent to merging all operations.}
The state and monotonic operations of Section~\ref{sec:account:state-operations} augmented with the partial ordering induced by relation $\leq_\mathds{A}$ and the account merge operation $\sqcup_\mathds{A}$ is a Conflict-Free Replicated Data Type~\cite{shapiro:hal-00932836} (with proof in Section~\ref{sec:proof:account}) because all replicas are guaranteed to converge to the same state eventually. However, concurrent updates may result in a negative balance: \textit{e.g.}, two concurrent burn and give operations may have a sufficient balance to complete independently and concurrently but the combined net previous balance may not be sufficient to cover both.\footnote{As follows from the previous note, if there were no transfers, concurrent burns would never result in a negative balance because only the largest burnt amount, which was locally valid, would be retained instead of the sum of all burnt amounts.} That being said, \textit{only concurrent updates} may result in a negative balance: if all updates are sequential, the pre-condition on crediting operations (Alg.~\ref{alg:account}, line~\ref{ln:burn-balance-check} and \ref{ln:give-balance-check}) prevents the balance from going negative (see proof in Section~\ref{section:proof:sequential-non-negative}).
\subsubsection{Negative Balance Condition}
While not necessary to define a state-based CRDT, we define an additional operation $\sqcap_\mathds{A}$ (Alg.~\ref{alg:account-hlb}) that is the symmetrical opposite of the merge operation: \textit{i.e.}, the \textit{greatest lower bound} of two account states. This definition completes the semi-lattice formed by the $\leq_\mathds{A}$ relation and the $\sqcup_\mathds{A}$ operation into a complete lattice. Informally, $A'' = A \sqcap_\mathds{A} A'$ computes the resulting state $A''$ from the largest set of updates that led to both $A$ and $A'$. It is implemented by keeping the minimum value of counters that are present in both states.
\begin{algorithm}
\begin{algorithmic}[1]
\Function{$\sqcap_\mathds{A}$}{$A$, $A'$} \Comment{Call written in infix notation, \textit{e.g.}, $A \sqcap_\mathds{A} A'$}
\If{$A_{\footnotesize \textbf{id}} \neq A'_{\footnotesize \textbf{id}}$}
\textbf{error}
\EndIf
\State
\State $A'' \leftarrow \texttt{initialize}(A_{\footnotesize \textbf{id}})$
\State $A''_\uparrow \leftarrow \texttt{min}(A_\uparrow, A'_\uparrow)$
\State $A''_\downarrow \leftarrow \texttt{min}(A_\downarrow, A'_\downarrow)$
\For{$id ~\textbf{in}~ A_{\rightarrow *} \cap A_{\rightarrow *}'$} \Comment{Receiver ids}
\State $A''_{\rightarrow}[id] \leftarrow \texttt{min}(A_{\rightarrow}[id], A'_{\rightarrow}[id])$
\EndFor
\For{$id ~\textbf{in}~ A_{\leftarrow *} \cap A_{\leftarrow *}'$} \Comment{Sender ids}
\State $A''_{\leftarrow}[id] \leftarrow \texttt{min}(A_{\leftarrow}[id], A'_{\leftarrow}[id])$
\EndFor
\State \Return $A''$
\EndFunction
\end{algorithmic}
\caption{\label{alg:account-hlb} Account: Greatest Lower Bound}
\end{algorithm}
We use $\sqcap_\mathds{A}$ to establish the precise conditions under which merging two account states with non-negative balances may result in a new state with a negative balance. Informally, there must have been more credits issued than debits received from the non-overlapping updates implicitly contained in $A$ and $A'$, as well as not enough reserves to cover the difference. Formally, the balance of the merge result of $A$ and $A'$, \textit{i.e.}, \texttt{balance}($A \sqcup_\mathds{A} A'$), will be negative if and only if the sum of differences in credits between $A$ and $A'$ is larger than the sum of differences in debits between $A$ and $A'$, and \texttt{balance}($A \sqcap_\mathds{A} A'$) was sufficiently low (see proof in Section~\ref{sec:proofs:merge-concurrent-accounts}):
\begin{equation}
\texttt{balance}(A \sqcup_\mathds{A} A') < 0 \Leftrightarrow \Delta_\downarrow + \Delta_\rightarrow > \Delta_\uparrow + \Delta_\leftarrow + \texttt{balance}(A \sqcap_\mathds{A} A')
\end{equation}
This completes our presentation of a single account CRDT. The next section explains how to combine multiple accounts.
\subsection{Ledger}
\label{sec:ledger}
Ledger replicas track the most up-to-date state of a set of accounts. They are essentially implemented as a grow-only dictionary of account replicas (Alg.~\ref{alg:ledger}), so the implementation of state and operations is straight-forward.
\begin{algorithm}
\begin{algorithmic}[1]
\Function{initialize}{}
\State $L \leftarrow \{ \}$ \Comment{Dictionary of $\textit{id} \rightarrow \textit{accounts}$ }
\State \Return $L$
\EndFunction
\State
\Function{add}{L, A}
\State $L' \leftarrow \textit{copy}(L)$ \Comment{Deep copy}
\If{$A_{\scriptsize\textbf{id}} \notin L_*$}
\State $L'[A_{\scriptsize\textbf{id}}] \leftarrow A$
\Else
\State $L'[A_{\scriptsize\textbf{id}}] \leftarrow L[A_{\scriptsize\textbf{id}}] \sqcup_A A$ \Comment{$\sqcup_A$ definition in Alg.~\ref{alg:account-ordering}}
\EndIf
\State \Return $L'$
\EndFunction
\State
\Function{$\leq_\mathds{L}$}{$L$, $L'$}
\State \Return $L_* \subseteq L'_* \wedge \bigwedge_{id \in L_*} L[id] \leq_A L'[id]$ \Comment{$\leq_A$ definition in Alg.~\ref{alg:account-ordering}}
\EndFunction
\State
\Function{$\sqcup_\mathds{L}$}{$L$, $L'$}
\State $L'' \leftarrow \texttt{initialize}()$
\State $I \leftarrow L_* \cup L'_*$
\For{$id ~\textbf{in}~ I$}
\If{$id \in L_* \wedge id \in L'_*$}
\State $L''[id] \leftarrow L[id] \sqcup_A L'[id]$ \Comment{$\sqcup_A$ definition in Alg.~\ref{alg:account-ordering}}
\ElsIf{$id \in L_*$}
\State $L''[id] \leftarrow L[id]$
\Else
\State $L''[id] \leftarrow L'[id]$
\EndIf
\EndFor
\State \Return $L''$
\EndFunction
\State
\Function{balances}{L}
\State \Return $\{~ (\textit{id}, \texttt{balance}(L[id])) \textbf{~for~} id ~\textbf{in}~ L_* ~\}$ \Comment{$L_*$ returns the set of ids in $L$}
\EndFunction
\end{algorithmic}
\caption{\label{alg:ledger} Ledger}
\end{algorithm}
The \texttt{initialize} operation creates a new dictionary $L$ representing the ledger. The \texttt{balances} operation returns the balance of account replicas stored in $L$, in a new dictionary also indexed by account identifiers.
The \texttt{add} operation adds a new account replica in $L$, returning a new dictionary $L'$. If account $A$ is not already present in $L$, it creates a new entry with a key corresponding to $A$'s identifier and the state of $A$ as a value. Otherwise, it merges the state of account $A$ with the state of the stored replica in $L$ with the same identifier, updating the ledger in the process.
The compare relation for ledger states $L$, and $L'$, written $L \leq_L L'$, returns true if the state of $L$ is smaller or equal than the state of $L'$. It does not modify the state of either $L$ or $L'$. The comparison is true if and only if $L$'s keys are a subset of keys in $L'$ and every account associated to the keys ($id$s) in $L$ is smaller than the same account in $L'$, using the compare relation for accounts ($\leq_A$).
The merge operation between ledger states $L$ and $L'$, written $L'' = L \sqcup_L L'$, returns a new ledger state $L''$ that is the smallest state according to $\leq_L$ that is also larger than both $L$ and $L'$. It is implemented by taking 1) the union of all keys (identifiers) on both $L$ and $L'$ and 2) associating each keys to the most up-to-date corresponding account state. The second is implemented with the merge operation on accounts ($\sqcup_A$, Alg.~\ref{alg:account-ordering}) if the account is present in both states, otherwise it takes the state of the account either in $L$ or $L'$, whichever is present.
This ledger design is also a Conflict-Free Replicated Data Type (see proof in Section~\ref{sec:proof:ledger}) because all replicas are guaranteed to converge to the same state eventually. To the exception of the possibility that accounts may have negative balance, there is no additional issue related to concurrency: any concurrent account updates will result in a correct ledger. We outline the exact safety and liveness conditions on balances next in Section~\ref{sec:safety-liveness}, after a brief discussion on compatible system models.
\subsection{Compatible System Models}
The design we presented is compatible with crash recoveries~\cite{cachin2011introduction}, as long as replicas eventually recover and stay available long enough to exchange the latest state information. In case a replica crashes and never recovers, only the latest operations that could not be replicated prior to the crash will be lost.
Our design is however not compatible with adversarial replicas because the latter could allow accounts that are not part of the creator set to create an arbitrary number of tokens, as well as transfer arbitrary amounts of tokens to other accounts regardless of their local balance.
\subsection{Safety and Liveness Properties of Account Balances}
\label{sec:safety-liveness}
We now outline the balance safety and liveness conditions of our design.
Given a set $\mathcal{A}$ of the largest state of every account (differentiated by $id$) across replicas and a set $\mathcal{C \subseteq \mathcal{A}}$ of accounts allowed to create tokens, the tokens circulating between accounts with non-negative balances either were created or were overspent but not burnt. Formally, the following equality always hold and is therefore a safety property of the design (see proof in Section~\ref{sec:proof:balance-safety}):
\begin{equation}
\label{eq:balance-safety}
\sum\limits_{A \in \mathcal{A}^{\geq 0}} \texttt{balance}(A) \leq
\sum\limits_{C \in \mathcal{C}} C_\uparrow
- \sum\limits_{A \in \mathcal{A}} A_\downarrow
+ \sum\limits_{A \in \mathcal{A}^{< 0}} -\texttt{balance}(A)
\end{equation}
For deployments in which negative balances are ruled out by design, \textit{e.g.}, if concurrent operations on the same account are not possible, then the inequality simply says that tokens in circulation were created but not burnt.
A slight variation replacing $\mathcal{A}$ by a ledger $L$ such that $\texttt{values}(L) \subseteq \mathcal{A}$, locally holds as long as $L$ is a \textit{transitive closure} over all accounts, \textit{i.e.}, as long as all accounts that sent tokens that were acknowledged by accounts in $L$ are also in $L$. Formally, the inequality is true if $\texttt{values}(L)$ contains all accounts that are referred by $id$ in $A_{\leftarrow *}$ for every account $A$ in $\texttt{values}(L)$:
\begin{eqnarray*}
\label{eq:balance-safety-ledger}
& \texttt{values}(L) = \{ A \in \mathcal{A} : \exists A' \in \texttt{values}(L) \wedge A_{\scriptsize \textbf{id}} \in A'_{\leftarrow *} \}
\Rightarrow \\
& \sum\limits_{A \in \texttt{values}(L)^{\geq 0}} \texttt{balance}(A) \leq
\sum\limits_{C \in \mathcal{C}} C_\uparrow
- \sum\limits_{A \in \texttt{values}(L)} A_\downarrow
+ \sum\limits_{A \in \texttt{values}(L)^{< 0}} -\texttt{balance}(A)
\end{eqnarray*}
This is the case because whatever the state of sender accounts, they cannot influence the balance of other accounts unless the tokens they sent were first acknowledged. If $L$ is not a transitive closure of accounts, the inequality may or may not hold: \textit{e.g.}, if $\mathcal{A}$ contains only two accounts $A$ and $C$ with different ids such that $C \in \mathcal{C}$, $A \notin \mathcal{C}$, $\texttt{values}(L) = \{ A \}$, and $C$ has given tokens to $A$, then it does not hold.
The inequality still holds for account states in the ledger that are not the latest among all replicas, as long as the state of every sender accounts $S$ in $L$ is greater or equal than they were at the time the receiver account $R$ acknowledged receiving the token. This is true if and only if $R_{\leftarrow}[S_{\scriptsize \textbf{id}}] \leq S_{\rightarrow}[R_{\scriptsize \textbf{id}}]$. This is always the case in concurrent execution in which all operations we presented for ledgers and accounts terminate but may not hold after a partial replication, as would happen if the merge operation between two ledger states were interrupted.
Finally, all the previous inequalities are eventually turned into strict equalities if every receiver account eventually acknowledges the tokens that were sent (see proof in Section~\ref{sec:proof:balance-liveness}). Using an inequality as a safety property, instead of enforcing the equality after each update, allows an eventually consistent implementation of a ledger.
This completes the presentation of the Grow-Only Counters Ledger (GOC-Ledger). The design should be compatible with any eventually-consistent replicated database, such as Secure-Scuttlebutt~\cite{kermarrec2020gossiping}. The properties we claimed for the design are supported with proofs in the next section. The system costs of core operations and required supporting mechanisms, which would depend on the deployment environment, have not yet been characterized: they will be covered in future work. We would happy to hear about any
\section{Proofs}
\label{sec:proofs}
In this section, we prove the properties discussed informally in Section~\ref{sec:design}. To make the proofs more accessible to practitioners and non-mathematicians, we follow the structured proof approach suggested by Lamport~\cite{lamport2012write}.
\subsection{Definitions}
We first make the semantics of algorithms more precise with the following definitions:
\begin{proof}
\begin{pfenum}
\item $\mathds{R}^+$ is the set of real positive numbers, including zero.
\item $\mathds{I}$ is the set of all possible identifiers.
\item $\mathds{C} \subseteq \mathds{I}$ is the set of identifiers allowed to create tokens.
\item $\mathds{D}$ is the set of all possible \textit{grow-only dictionaries of grow-only counters} indexed by identifiers, \textit{i.e.}, $\mathds{D}$ is the power set of the cartesian product of $\mathds{I}$ and $\mathds{R}$ ($\mathds{D} = \mathcal{P}(\mathds{I} \times \mathds{R}))$, with the additional constraint that for any $D \in \mathds{D}$ and any $(\textit{id},r)$ such that $\textit{id} \in \mathds{I}$ and $r \in \mathds{R}$, $id$ appears in at most one tuple in $D$.
\item $D \leq_\mathds{D} D' \Leftrightarrow D_* \subseteq D'_* \wedge \bigwedge\limits_{id \in D_*} D[id] \leq D'[id] $
\item $\mathds{A}$ is the set of all possible account states, \textit{i.e.}, $\mathds{A}$ is the cartesian product $\mathds{I} \times \mathds{R}^+ \times \mathds{R}^+ \times \mathds{D} \times \mathds{D}$, such that $(A_{\footnotesize \textbf{id}}, A_\uparrow, A_\downarrow, A_\rightarrow, A_\leftarrow) \in \mathds{A}$.
\item $\mathds{L}$ is the set of all possible ledger states, \textit{i.e.} the power set of the cartesian product of $\mathds{I}$ and $\mathds{A}$ ($\mathds{L} = \mathcal{P}(\mathds{I} \times \mathds{A})$) with the additional constraints that for any $L \in \mathds{L}$ and any $(\textit{id}, A) \in L$ $\textit{id} = A_{\footnotesize \textbf{id}}$ and \textit{id} appears in at most one tuple in $L$.
\end{pfenum}
\end{proof}
\subsection{Lemmas}
In this section, we prove one lemma that is used later to simplify a proof.
\subsubsection{The composition of least upper bounds is a least upper bound.}
\label{sec:lemma:lub-composition}
\begin{proof}
\assume{\begin{pfenum}
\item $\mathds{A}$ and $\mathds{B}$ are sets
\item Binary relations $\leq_\mathds{A}$ and $\leq_\mathds{B}$ define semi-lattices $\mathds{S}_\mathds{A}$ and $\mathds{S}_\mathds{B}$
\item Equality $=$ relationship exists for $\mathds{A}$ and $\mathds{B}$
\item Binary operators $\alpha$ and $\beta$ compute least upper bounds, respectively in $\mathds{S}_\mathds{A}$ and $\mathds{S}_\mathds{B}$
\end{pfenum}}
\define{\begin{pfenum}
\item $a <_\mathds{A} a' \defeq a \leq_\mathds{A} \wedge~ a \neq a'$ and $b <_\mathds{B} b' \defeq a \leq_\mathds{B} \wedge~ b \neq b'$
\item $\mathds{C} = \mathds{A} \times \mathds{B}$, \textit{i.e.}, the cartesian product of $\mathds{A}$ and $\mathds{B}$ such that $C \in \mathds{C} \Rightarrow (C = (a,b)) \wedge a \in \mathds{A} \wedge b \in \mathds{B}$
\item $C \leq_\mathds{C} C' \Leftrightarrow (a,b) \leq_\mathds{C} (a',b') \Leftrightarrow a \leq_\mathds{A} a' \wedge~ b \leq_\mathds{B} b'$ which defines a semi-lattice $\mathds{S}_\mathds{C}$
\item $C = C' \Leftrightarrow (a,b) = (a',b') \defeq a = a' \wedge b = b'$
\item $C <_\mathds{C} C' \defeq C \leq_\mathds{C} C' \wedge C \neq C'$
\item $C ~\tau~ C' \Leftrightarrow (a,b)~\tau~(a',b') \defeq (a~\alpha~a', b~\beta~b')$
\end{pfenum}}
\prove{$C'' = C ~\tau~ C'$ is the least upper bound of $C$ and $C'$ in $\mathds{S}_\mathds{C}$}
\step{lbl:lub:def-1}{$C \leq_\mathds{C} C''$}
\begin{proof}
\step{}{$C'' = C ~\tau~ C' = (a,b) ~\tau~ (a',b') = (a ~\alpha~ a', b ~\beta~ b') = (a'', b'')$}
\begin{proof}
By definition.
\end{proof}
\step{lbl:lub:def-1:1}{$a \leq_\mathds{A} (a ~\alpha~ a') = a''$}
\begin{proof}
By assumption on $\alpha$ and the definition of least upper bound.
\end{proof}
\step{lbl:lub:def-1:2}{$b \leq_\mathds{B} (b ~\beta~ b') = b''$}
\begin{proof}
By assumption on $\beta$ and the definition of least upper bound.
\end{proof}
\qedstep
\begin{proof}
By \stepref{lbl:lub:def-1:1} and \stepref{lbl:lub:def-1:2} and definition.
\end{proof}
\end{proof}
\step{lbl:lub:def-2}{$C' \leq_\mathds{C} C''$}
\begin{proof}
\textit{Idem} \stepref{lbl:lub:def-1} by replacing $C$ for $C'$.
\end{proof}
\step{lbl:lub:def-3}{$\nexists C''' \in \mathds{C} : C \leq_\mathds{C} C''' \wedge C' \leq_\mathds{C} C''' \wedge C''' <_\mathds{C} C'' $}
\begin{proof}
\step{lbl:lub:def-3-1}{
\assume{\begin{pfenum}
\item $a \in \mathds{A}$
\item $a' \in \mathds{A}$
\item $a'' = a ~\alpha~ a'$
\end{pfenum}}
\prove{$\nexists a''' \in \mathds{A} : a \leq_\mathds{A} a''' \wedge a' \leq_\mathds{A} a''' \wedge a''' <_\mathds{A} a'' $}
\pf~By assumption, because $\alpha$ computes a least upper bound.
}
\step{lbl:lub:def-3-2}{
\assume{\begin{pfenum}
\item $b \in \mathds{B}$
\item $b' \in \mathds{B}$
\item $b'' = b ~\beta~ b'$
\end{pfenum}}
\prove{$\nexists b''' \in \mathds{B} : b \leq_\mathds{B} b''' \wedge b' \leq_\mathds{B} b''' \wedge b''' <_\mathds{B} b'' $}
\pf~By assumption, because $\beta$ computes a least upper bound.
}
\qedstep
\begin{proof}
By the conjunction of \stepref{lbl:lub:def-3-1} and \stepref{lbl:lub:def-3-2}, associativity of $\wedge$ and definitions.
\end{proof}
\end{proof}
\qedstep
\begin{proof}
By the conjunction of \stepref{lbl:lub:def-1}, \stepref{lbl:lub:def-2}, and \stepref{lbl:lub:def-3}, which is the definition of a least upper bound.
\end{proof}
\end{proof}
\subsection{Convergence}
To establish the convergence of both accounts and ledger, we need to establish that their states form a \textit{monotonic semi-lattice}~\cite{shapiro:hal-00932836}, which involves three propositions: First, that all possible states can be organized in a semi-lattice $\mathds{S}$ ordered by $\leq$. This is a requisite for the next two properties. Second, that merging two states computes their \textit{Least Upper Bound} (LUB) in $\mathds{S}$. This ensures that the merge is \textit{commutative}, \textit{associative}, and \textit{idempotent}, providing \textit{safety}, \textit{i.e.}, that replicas will agree on the final state regardless of ordering, delays, or duplication of merge operations. Third, that all operations modify the state $S$ of a replica such that the new state $S'$ is either equal or larger than the previous state $S$ in $\mathds{S}$ (\textit{monotonicity}). This ensures all state changes will be eventually reflected in the new state of all replicas, either because the same update(s) will have concurrently been applied or because the new state will be the result of a merge. Assuming an underlying communication medium that ensures new states to be eventually delivered to other replicas, the three propositions combined ensure both \textit{liveness} and \textit{safety}: all state changes are going to be replicated on all replicas \textit{and} all replicas will agree on the final state automatically, i.e. \textit{strong eventual consistency}~\cite{shapiro:hal-00932836}.
Because an account state is the composition of \textit{grow-only counters} ($A_\uparrow$ and $A_\downarrow$) and \textit{grow-only dictionaries of grow-only counters}~\cite{lavoie2023statebased} ($A_\leftarrow$ and $A_\rightarrow$), and the ledger state is a \textit{grow-only dictionary of accounts}, the convergence proofs are straight-forward. We first prove that account replicas converge, then prove that ledgers converge as well.
\subsubsection{Account}
\label{sec:proof:account}
\begin{proof}
\prove{The Account design listed in Alg.~\ref{alg:account}, ~\ref{alg:query}, and \ref{alg:account-ordering} is a state-based (convergent) CRDT.}
\pfsketch ~An account is the composition of state-based grow-only counters and grow-only dictionaries of grow-only counters. The three properties of \textit{ordering}, \textit{least upper bound}, and \textit{monotonicity} that are sufficient to define a state-based CRDT are the conjunction of corresponding properties on grow-only counters and grow-only dictionaries of grow-only counters.
\end{proof}
\begin{proof}
\step{lbl:account:ordering}{
\textbf{Ordering:}
Ordering $\mathds{A}$ by $\leq_\mathds{A}$ (Alg.~\ref{alg:account-ordering}) forms a semi-lattice $\mathds{S}_\mathds{A}$.
}
\begin{proof}
\pfsketch~ $\leq_\mathds{A}$ is the conjunction of the $\subseteq$ and $\leq$ relationships, respectively forming partial orders on sets of identifiers in dictionaries in $\mathds{D}$ and real positive numbers $\mathds{R}^+$ that compose the possible states. Specifically:
\begin{pfenum}
\item $\leq$ creates partial orders on $A_\downarrow$ and $A_\uparrow$ counters (\textit{created} and \textit{burned} booleans).
\item conjunction of $\subseteq$ on dictionary keys and $\leq$ on dictionary values creates partial orders on $A_\rightarrow$ and $A_\leftarrow$ dictionaries, (\textit{given} and \textit{acked} booleans).
\item The conjunction of \textit{created}, \textit{burned}, \textit{given}, and \textit{acked} is also a partial order.
\end{pfenum}
Detailed proofs have already been published for grow-only counters of natural numbers, grow-only dictionaries of grow-only counters, and the conjunction of partial orders~\cite{lavoie2023statebased}. Those proofs apply directly to this proposition by replacing natural numbers by real numbers and adding a conjunction of dictionaries and grow-only counters.
\end{proof}
\step{lbl:account:lub}{
\textbf{Least Upper Bound:}
\assume{\begin{pfenum}
\item $A \in \mathds{A}, A' \in \mathds{A}$
\item \label{lbl:account:assumption:id} $A_{\footnotesize \textbf{id}} = A'_{\footnotesize \textbf{id}}$
\end{pfenum}}
\prove{$A'' = A \sqcup_\mathds{A} A'$ is the LUB of $A$ and $A'$ in $\mathds{S}_\mathds{A}$.}}
\begin{proof}
\step{lbl:account:lub:counter}{ $A''_\uparrow = \texttt{max}(A_\uparrow, A'_\uparrow)$ is the least upper bound of $A_\uparrow$ and $A'_\uparrow$ in the semi-lattice of real numbers $\mathds{S}_{\mathds{R}^+}$ formed by $\leq$. Idem for $A''_\downarrow = \texttt{max}(A_\downarrow, A'_\downarrow)$ in $\mathds{S}_{\mathds{R}^+}$.}
\begin{proof}
Same proof as in Annex of~\cite{lavoie2023statebased}, but on real numbers instead.
\end{proof}
\step{lbl:account:lub:dict}{$A''_{\leftarrow}$ is the least upper bound of $A_{\leftarrow}$ and $A'_{\leftarrow}$ in the semi-lattice of dictionaries $\mathds{S}_\mathds{D}$ formed by $\leq_\mathds{D}$. Idem for $A''_{\rightarrow }$ in $\mathds{S}_\mathds{D}$ formed by $\leq_\mathds{D}$.
}
\begin{proof}
Same proof as for dictionaries in Annex of~\cite{lavoie2023statebased}: their \texttt{compare} method on dictionaries is defined similarly as the \textit{given} and \textit{acked} conditions of $\leq_\mathds{A}$ in Alg.~\ref{alg:account-ordering}.
\end{proof}
\qedstep
\begin{proof}
By \stepref{lbl:account:lub:counter} and \stepref{lbl:account:lub:dict} and LUB composition lemma of Section~\ref{sec:lemma:lub-composition}.
\end{proof}
\end{proof}
\step{lbl:account:monotonicity}{
\textbf{Monotonicity:}
All operations that may generate a new state, when applied on account state $A$ and any possible arguments, result in a new account state either equal or larger than $A$ in $\mathds{S}_\mathds{A}$ according to $\leq_\mathds{A}$.}
\begin{proof}
\step{}{\case{$A = \texttt{Initialize}(id)$}}
\begin{proof}
Initializes a new $A$ but not from an existing state, so monotonicity does not apply.
\end{proof}
\step{}{\case{$A' = \texttt{create}(A,\textit{amount})$}}
\begin{proof}
\step{}{\case{$A_{\footnotesize \textbf{id}} \in \mathds{C} \wedge \textit{amount} > 0$}}
\begin{proof}
$A'_\uparrow = A_\uparrow + \textit{amount} > A_\uparrow$ and all others properties of $A'$ are equal to those of $A$, therefore $A <_\mathds{A} A'$.
\end{proof}
\step{}{\case{$A_{\footnotesize \textbf{id}} \notin \mathds{C} \vee \textit{amount} \leq 0$}}
\begin{proof}
$A=A'$
\end{proof}
\end{proof}
\step{}{\case{$A' = \texttt{burn}(A,\textit{amount})$}}
\begin{proof}
\step{}{\case{$\textit{amount} > 0 \wedge \texttt{balance}(A) \geq \textit{amount}$}}
\begin{proof}
$A'_\downarrow = A_\downarrow + \textit{amount} > A_\downarrow$ and all others properties of $A'$ are equal to those of $A$, therefore $A <_\mathds{A} A'$.
\end{proof}
\step{}{\case{$\textit{amount} \leq 0 \vee \texttt{balance}(A) < \textit{amount}$}}
\begin{proof}
$A=A'$
\end{proof}
\end{proof}
\step{}{\case{$A' = \texttt{giveTo}(A,\textit{amount},\textit{id})$}}
\begin{proof}
\step{}{\case{$\textit{amount} > 0 \wedge \texttt{balance}(A) \geq \textit{amount}$}}
\begin{proof}
\step{}{\case{$\textit{id} \notin A_\rightarrow [id]$}}
\begin{proof}
$A_{\rightarrow *} \cup \{ \textit{id} \} = A'_{\rightarrow *}$ therefore $A_{\rightarrow *} \subset A'_{\rightarrow *}$. All other properties of $A'$ are equal to those of $A$, therefore $A <_\mathds{A} A'$.
\end{proof}
\step{}{\case{$\textit{id} \in A_\rightarrow[id]$}}
\begin{proof}
$A_\rightarrow[id] + \textit{amount} = A'_\rightarrow[id]$ therefore $A_\rightarrow[id] < A'_\rightarrow[id]$. All others properties of $A'$ are equal to those of $A$, therefore $A <_\mathds{A} A'$.
\end{proof}
\end{proof}
\step{}{\case{$\textit{amount} \leq 0 \vee \texttt{balance}(A) < \textit{amount}$}}
\begin{proof}
$A=A'$
\end{proof}
\end{proof}
\step{}{\case{$A' = \texttt{ackFrom}(A,B)$}}
\begin{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \in B_{\rightarrow *}$}}
\begin{proof}
\step{}{\case{$B_{\scriptsize \textbf{id}} \notin A_{\leftarrow *}$}}
\begin{proof}
$A_{\leftarrow *} \cup \{ B_{\scriptsize \textbf{id}} \} = A'_{\leftarrow *}$ therefore $A_{\leftarrow *} \subset A'_{\leftarrow *}$. All other properties of $A'$ are equal to those of $A$, therefore $A <_\mathds{A} A'$.
\end{proof}
\step{}{\case{$B_{\scriptsize \textbf{id}} \in A_{\leftarrow *}$}}
\begin{proof}
$A'_\leftarrow[B_{\scriptsize \textbf{id}}] = \texttt{max}(A_\leftarrow[B_{\scriptsize \textbf{id}}], B_\leftarrow[A_{\scriptsize \textbf{id}}])$ therefore $A_\leftarrow[B_{\scriptsize \textbf{id}}] \leq A'_\leftarrow[B_{\scriptsize \textbf{id}}]$. All others properties of $A'$ are equal to those of $A$, therefore $A \leq_\mathds{A} A'$.
\end{proof}
\end{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \notin B_{\rightarrow *}$}}
\begin{proof}
$A=A'$
\end{proof}
\end{proof}
\step{}{\case{$b = \texttt{balance}(A)$}}
\begin{proof}
Does not modify the state of $A$.
\end{proof}
\step{}{\case{$b = \texttt{unackedFrom}(A,B)$}}
\begin{proof}
Does not modify the state of $A$.
\end{proof}
\step{}{\case{$b = A \leq_\mathds{A} A'$}}
\begin{proof}
Does not modify the state of $A$ or $A'$.
\end{proof}
\step{}{\case{$A'' = A \sqcup_\mathds{A} A'$}}
\begin{proof}
$A \leq_\mathds{A} A'' \wedge A' \leq_\mathds{A} A''$ because $\sqcup_\mathds{A}$ computes a LUB in $\mathds{S}_\mathds{A}$.
\end{proof}
\end{proof}
\qedstep
\begin{proof}
By the conjunction of \stepref{lbl:account:ordering}, \stepref{lbl:account:lub}, \stepref{lbl:account:monotonicity} which is the definition of a state-based CRDT.
\end{proof}
\end{proof}
\subsubsection{Ledger}
\label{sec:proof:ledger}
\label{th:ledger-crdt}
\prove{The ledger of Algorithm~\ref{alg:ledger} is a state-based (convergent) conflict-free replicated data type.}
\begin{proof}
\pfsketch~ The ledger is a grow-only dictionary of accounts, that are themselves state-based CRDTs.
\pf~
\step{lbl:ledger:ordering}{
\textbf{Ordering:}
Ordering $\mathds{L}$ by $\leq_\mathds{L}$ (Alg.~\ref{alg:ledger}) forms a semi-lattice $\mathds{S}_\mathds{L}$.
}
\begin{proof}
\pfsketch~ The ordering of $\mathds{L}$ is the conjunction the $\subseteq$ partial order on sets of identifiers that serve as dictionary keys, and $\leq_\mathds{A}$ on account states that serve as dictionary values. The proof is similar as for grow-only dictionaries of grow-only counters~\cite{lavoie2023statebased}.
\end{proof}
\step{lbl:ledger:lub}{
\textbf{Least Upper Bound:}
\assume{\begin{pfenum}
\item $L \in \mathds{L}, L' \in \mathds{L}$
\end{pfenum}}
\prove{$L'' = L \sqcup_\mathds{L} L'$ is the LUB of $L$ and $L'$ in $\mathds{S}_\mathds{L}$.}}
\begin{proof}
\step{lbl:ledger:lub:def-1}{$L \leq_\mathds{L} L''$}
\begin{proof}
\step{lbl:ledger:lub:def-1:1}{$L_* \subseteq L''_*$}
\begin{proof}
$L_* \subseteq (L_* \cup L'_*) = L''_*$.
\end{proof}
\step{lbl:ledger:lub:def-1:2}{$\forall_{\textit{id} \in L_*} L[\textit{id}] \leq_\mathds{A} L''[\textit{id}]$}
\begin{proof}
\step{lbl:ledger:lub:def-1:2:1}{\case{$\textit{id} \in L_* \wedge \textit{id} \in L'_*$}}
\begin{proof}
$ L[\textit{id}] \leq_\mathds{A} L[\textit{id}] \sqcup_\mathds{A} L'[\textit{id}] = L''[\textit{id}]$
\end{proof}
\step{lbl:ledger:lub:def-1:2:2}{\case{$\textit{id} \in L_* \wedge \textit{id} \notin L'_*$}}
\begin{proof}
$L[\textit{id}] = L''[\textit{id}]$
\end{proof}
\end{proof}
\qedstep
\begin{proof}
$\leq_\mathds{L}$ is the conjunction of \stepref{lbl:ledger:lub:def-1:1} and \stepref{lbl:ledger:lub:def-1:2}.
\end{proof}
\end{proof}
\step{lbl:ledger:lub:def-2}{$L' \leq_\mathds{L} L''$}
\begin{proof}
\textit{Idem} \stepref{lbl:ledger:lub:def-1} on $L'$ instead of $L$.
\end{proof}
\step{lbl:ledger:lub:def-3}{$\nexists L''' \in \mathds{L} : L \leq_\mathds{L} L''' \wedge L' \leq_\mathds{L} L''' \wedge L''' <_\mathds{L} L''$}
\begin{proof}
\pfsketch~ We show that both of the only two possible conditions which individually could make the proposition false are not possible, therefore the proposition is always true.
\step{lbl:ledger:lub:def-3:ids}{It is not possible for $L_* \subseteq L'''_* \wedge L'_* \subseteq L'''_* \wedge L'''_* \subset L''_*$. }
\begin{proof}
$L''_* = L_* \cup L'_*$ is the least upper-bound of $L_*$ and $L'_*$ in $\mathds{S}_{\mathcal{P}(\mathds{I})}$ ordered by $\subseteq$ because $\cup$ computes the least upper bound on sets of identifiers (see \cite{lavoie2023statebased}).
\end{proof}
\step{lbl:ledger:lub:def-3:accounts}{
\assume{$L'''_* \subseteq L''_*$ (otherwise it is not possible for $L''' <_\mathds{L} L''$)}
\prove{$\forall_{\textit{id} \in L'''_*}$, it is not possible for $L'''[\textit{id}] <_\mathds{A} L''[\textit{id}]$ and $L[\textit{id}] \leq_\mathds{A} L'''[\textit{id}]$ (if $id \in L_*$) and $L'[\textit{id}] \leq_\mathds{A} L'''[\textit{id}]$ (if $id \in L'_*$)} }
\begin{proof}
\step{}{\case{$\textit{id} \in L_* \wedge \textit{id} \notin L'_*$}}
\begin{proof}
$L''[\textit{id}] = L[\textit{id}]$
\end{proof}
\step{}{\case{$\textit{id} \notin L_* \wedge \textit{id} \in L'_*$}}
\begin{proof}
$L''[\textit{id}] = L'[\textit{id}]$
\end{proof}
\step{}{\case{$\textit{id} \in L_* \wedge \textit{id} \in L'_*$}}
\begin{proof}
$L''[\textit{id}] = L[\textit{id}] \sqcup_\mathds{A} L'[\textit{id}] = \textit{LUB}(L[\textit{id}], L'[\textit{id}])$
\end{proof}
\qedstep
\begin{proof}
Either $L''[id]$ is a least upper bound of $L[id]$ or $L''[id]$, or is equal to one or the other, therefore it is not possible.
\end{proof}
\end{proof}
\qedstep
\begin{proof}
\stepref{lbl:ledger:lub:def-3:ids} and \stepref{lbl:ledger:lub:def-3:accounts} are the only two possible conditions which individually could make the proposition false, and they are are not possible, therefore the proposition is always true.
\end{proof}
\end{proof}
\qedstep
\begin{proof}
The conjunction of \stepref{lbl:ledger:lub:def-1}, \stepref{lbl:ledger:lub:def-2}, \stepref{lbl:ledger:lub:def-3} is the definition of a least upper bound.
\end{proof}
\end{proof}
\step{lbl:ledger:monotonicity}{
\textbf{Monotonicity:}
All operations that may generate a new state, when applied on ledger state $L$ and any possible arguments, result in a new ledger state either equal or larger than $L$ in $\mathds{S}_\mathds{L}$ according to $\leq_\mathds{L}$.}
\begin{proof}
\step{}{\case{$L = \texttt{initialize}()$}}
\begin{proof}
Initializes a new $L$ but not from an existing state so monotonicity need not apply.
\end{proof}
\step{}{\case{$L' = \texttt{add}(L,A)$}}
\begin{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \notin L_*$}}
\begin{proof}
$L_* \subset L_* \cup \{ A_{\scriptsize \textbf{id}} \} = L'_*$ and all dictionary values of $L$ are equal to those of $L'$.
\end{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \in L_*$}}
\begin{proof}
$L_* = L'_*$, $L[A_{\scriptsize \textbf{id}}] \leq_\mathds{A} (L[A_{\scriptsize \textbf{id}}] \sqcup_\mathds{A} A) = L'[A_{\scriptsize \textbf{id}}]$, and all other properties of $L'$ are equal to those of $L$.
\end{proof}
\end{proof}
\step{}{\case{$b = L \leq_\mathds{L} L'$}}
\begin{proof}
Does not return a new ledger state so monotonicity need not apply.
\end{proof}
\step{}{\case{$L'' = L \sqcup_\mathds{L} L'$}}
\begin{proof}
By definition because $L''$ is a least upper bound (\stepref{lbl:ledger:lub}).
\end{proof}
\step{}{\case{$B = \texttt{balances}(L)$}}
\begin{proof}
Does not return a new ledger state so monotonicity need not apply.
\end{proof}
\end{proof}
\qedstep
\begin{proof}
By the conjunction of \stepref{lbl:ledger:ordering}, \stepref{lbl:ledger:lub}, \stepref{lbl:ledger:monotonicity} which is the definition of a state-based CRDT.
\end{proof}
\end{proof}
\subsection{Greatest Lower-Bound on Accounts}
\label{sec:hlb}
\assume{\begin{pfenum}
\item $A \in \mathds{A}$
\item $A' \in \mathds{A}$
\item $A_{\scriptsize \textbf{id}} = A'_{\scriptsize \textbf{id}}$
\end{pfenum}}
\prove{\textbf{Greatest Lower Bound:} $A'' = A \cap_\mathds{A} A'$ (Algorithm~\ref{alg:account-hlb}) is the greatest lower bound of $A$ and $A'$ in $\mathds{S}_\mathds{A}$.}
\pfsketch~ The \texttt{minimum} function computes the greatest lower bound on numbers. The intersection ($\cap$) computes the greatest lower bound on sets of identifiers. The composition of greatest lower bounds is also a greatest lower bound on the cartesian products of domains (proof is similar to that for lowest upper bound of Section~\ref{sec:lemma:lub-composition}). $\cap_\mathds{A}$ is a composition of \texttt{min} on grow-only counters an $\cap$ on sets of identifiers, therefore it also computes an greatest lower bound.
\begin{proof}
\pf~
Alternatively a direct proof, using the definition of greatest lower bound:
\step{lbl:hlb-1}{$A'' \leq_\mathds{A} A$}
\begin{proof}
\step{lbl:hlb-1-1}{$A''_\downarrow = \texttt{min}(A_\downarrow, A'_\downarrow) \leq A_\downarrow$ \newline
$A''_\uparrow = \texttt{min}(A_\uparrow, A'_\uparrow) \leq A_\uparrow$
}
\step{lbl:hlb-1-2}{$A''_{\leftarrow *} = A_{\leftarrow *} \cap A'_{\leftarrow *} \subseteq A_{\leftarrow *}$ \newline
$A''_{\rightarrow *} = A_{\rightarrow *} \cap A'_{\rightarrow *} \subseteq A_{\rightarrow *}$
}
\step{lbl:hlb-1-3}{
\assume{
$id \in A_{\leftarrow *} \wedge id \in A'_{\leftarrow *}$
}
$A''_{\leftarrow}[id] = \texttt{min}(A_{\leftarrow}[id], A'_{\leftarrow}[id]) \leq A_{\leftarrow}[id]$
\assume{
$id \in A_{\rightarrow *} \wedge id \in A'_{\rightarrow *}$
}
$A''_{\rightarrow}[id] = \texttt{min}(A_{\rightarrow}[id], A'_{\rightarrow}[id]) \leq A_{\rightarrow}[id]$
}
\qedstep
\begin{proof}
The five required conditions for $\leq_\mathds{A}$ to be true (Alg.~\ref{alg:account-ordering}) are satisfied by the followings:
\begin{pfenum}
\item By assumption $A_{\scriptsize \textbf{id}} = A'_{\scriptsize \textbf{id}}$;
\item ($\textit{created}$) By \stepref{lbl:hlb-1-1};
\item ($\textit{burned}$) By \stepref{lbl:hlb-1-1};
\item ($\textit{given}$) By \stepref{lbl:hlb-1-2} and \stepref{lbl:hlb-1-3} for all $id \in A''_{\rightarrow *}$, the required assumption on \stepref{lbl:hlb-1-3} all satisfied because $A''_{\rightarrow *} = A_{\rightarrow *} \cap A'_{\rightarrow *}$;
\item ($\textit{acked}$) Idem but on $A''_{\leftarrow *}$.
\end{pfenum}
\end{proof}
\end{proof}
\step{lbl:hlb-2}{$A'' \leq_\mathds{A} A'$}
\begin{proof}
Idem \stepref{lbl:hlb-1} but on $A'$ instead of $A$.
\end{proof}
\step{lbl:hlb-3}{$\nexists A''' \in \mathds{A} : A''' \leq_\mathds{A} A \wedge A''' \leq_\mathds{A} A' \wedge A'' <_\mathds{A} A'''$}
\begin{proof}
Assume by contradiction that such a $A'''$ exists. Therefore one or multiple of these conditions should be true (taken from Alg.~\ref{alg:account-ordering} and removing the equality case):
\begin{pfenum}
\item $A''_\uparrow < A'''_\uparrow$
\item $A''_\downarrow < A'''_\downarrow$
\item $A''_{\leftarrow *} \subset A'''_{\leftarrow *}$
\item $\forall id \in A''_{\leftarrow *} : A''_{\leftarrow}[id] < A'''_{\leftarrow}[id] $
\item $A''_{\rightarrow *} \subset A'''_{\rightarrow *}$
\item $\forall id \in A''_{\rightarrow *} : A''_{\rightarrow}[id] < A'''_{\rightarrow}[id] $
\end{pfenum}
However, for every number comparison ($<$) a larger value is not smaller than the corresponding values of $A$ and $A'$ because it is larger than either or both. Similarly, for set comparisons ($\subset$) a larger subset is smaller than the corresponding identifiers sets of $A$ and $A'$ because it is larger than either or both.
Since none of the conditions above can be true, such a $A'''$ does not exist.
\end{proof}
\qedstep
\begin{proof}
The conjunction of \stepref{lbl:hlb-1}, \stepref{lbl:hlb-2}, and \stepref{lbl:hlb-3} is the definition of a greatest lower bound.
\end{proof}
\end{proof}
\subsection{Balance}
\label{sec:proof:balance}
In this section we present proofs related to the balance of accounts.
\subsubsection{Sequences of Account Operations Maintain a Non-Negative Balance}
\label{section:proof:sequential-non-negative}
\assume{\begin{pfenum}
\item $A,B \in \mathds{A}$
\item $\texttt{balance}(A) \geq 0$
\item $x \in \mathds{R}$
\item $\textit{id} \in \mathds{I}$
\item $\mathds{C}$ is the set of identifiers allowed to create tokens
\end{pfenum}}
\prove{For any sequence of operations on $A$ resulting in a new state $A'$, $\texttt{balance}(A') \geq 0$.}
\begin{proof}
\pfsketch~ By induction.
For every case that modifies the state of $A$, we list the properties that have changed between the original state of an account, and its following states (marked with $'$), that influence the balance computation. Every non-listed properties stays the same.
\pf~
\step{seq:nn-bal:create}{\case{$A' = \texttt{create}(A,x)$}}
\begin{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \in \mathds{C} \wedge x > 0$}}
\begin{proof}
\begin{pfenum}
\item $A'_\uparrow = A_\uparrow + x$
\item $\texttt{balance}(A') = \texttt{balance}(A) + x > 0$
\end{pfenum}
\end{proof}
\step{}{\case{$A_{\scriptsize \textbf{id}} \notin \mathds{C} \vee x \leq 0$}}
\begin{proof}
\begin{pfenum}
\item $A'_\uparrow = A_\uparrow$
\item $\texttt{balance}(A') = \texttt{balance}(A) \geq 0$
\end{pfenum}
\end{proof}
\end{proof}
\step{seq:nn-bal:burn}{\case{$A' = \texttt{burn}(A,x)$}}
\begin{proof}
\step{}{\case{$x > 0 \wedge \texttt{balance}(A) \geq x$}}
\begin{proof}
\begin{pfenum}
\item $A'_\downarrow = A_\downarrow + x$
\item $\texttt{balance}(A') = \texttt{balance}(A) - x \geq 0$
\end{pfenum}
\end{proof}
\step{}{\case{$x \leq 0 \vee \texttt{balance}(A) < x$}}
\begin{proof}
\begin{pfenum}
\item $A'_\downarrow = A_\downarrow$
\item $\texttt{balance}(A') = \texttt{balance}(A) \geq 0$
\end{pfenum}
\end{proof}
\end{proof}
\step{seq:nn-bal:giveTo}{\case{$A' = \texttt{giveTo}(A,x,\textit{id})$}}
\begin{proof}
\step{}{\case{$x > 0 \wedge \texttt{balance}(A) \geq x$}}
\begin{proof}
\step{}{\case{$id \notin A_{\rightarrow *}$}}
\begin{proof}
\begin{pfenum}
\item $A'_{\rightarrow *} = A_{\rightarrow *} \cup \{ \textit{id} \}$
\item $A'_\rightarrow [\textit{id}] = x$
\item $\texttt{balance}(A') = \texttt{balance}(A) - x \geq 0$
\end{pfenum}
\end{proof}
\step{}{\case{$id \in A_{\rightarrow *}$}}
\begin{proof}
\begin{pfenum}
\item $A'_\rightarrow [\textit{id}] = A_\rightarrow [\textit{id}] + x$
\item $\texttt{balance}(A') = \texttt{balance}(A) - x \geq 0$
\end{pfenum}
\end{proof}
\end{proof}
\step{}{\case{$x \leq 0 \vee \texttt{balance}(A) < x$}}
\begin{proof}
\begin{pfenum}
\item $A'_\downarrow = A_\downarrow$
\item $\texttt{balance}(A') = \texttt{balance}(A) \geq 0$
\end{pfenum}
\end{proof}
\end{proof}
\step{seq:nn-bal:ackFrom}{\case{$A' = \texttt{ackFrom}(A,B)$}}
\begin{proof}
\step{}{\case{$A_{\scriptsize\textbf{id}} \in B_{\rightarrow *} \wedge \texttt{balance}(B) \geq 0$}}
\begin{proof}
\step{}{\case{$B_{\scriptsize\textbf{id}} \notin A_{\leftarrow *}$}}
\begin{proof}
\begin{pfenum}
\item $A'_{\leftarrow *} = A_{\leftarrow *} \cup \{ \textit{id} \}$
\item $A'_\leftarrow [\textit{id}] = B_{\rightarrow}[A_{\scriptsize\textbf{id}}]$
\item $\texttt{balance}(A') = \texttt{balance}(A) + B_{\rightarrow}[A_{\scriptsize\textbf{id}}] \geq 0$, because only \texttt{giveTo} may have modified $B_{\rightarrow}[A_{\scriptsize\textbf{id}}]$ and only by increasing by a positive number.
\end{pfenum}
\end{proof}