Clever system of decentralized trustless verification, based on some of the math born in cryptography.

## Ledgers and Digital Signatures

A bunch of friends (Alice, Bob, Charlie and You) exchange money pretty frequently. Sometimes the do not have the cash on them. They trust each other and therefore are willing to advance money to their friends (money they will be repaid when possible). Even though they trust each other's good faith (they know their friend will repay what they owe), they don't trust their memory. To overcome this simple limitation, they use a paper ledger.

### The baseless ledger

Naturally, they create a ledger to keep track of who owes what to who. Every time Alice gives money to Bob, they record it in the ledger like so:

From | To | CHF |
---|---|---|

Alice | Bob | 10 |

When Bob repays alice they add another line:

From | To | CHF |
---|---|---|

Alice | Bob | 10 |

Bob | Alice | 10 |

Once they're out of space in the sheet (let's add a few more lines), they do the tally:

From | To | CHF |
---|---|---|

Alice | Bob | 10 |

Bob | Alice | 10 |

Bob | Charlie | 10 |

Charlie | Alice | 10 |

You | Alice | 10 |

Alice | Bob | 5 |

To visualize all these lines you can create a graph with n links, on each person:

```
Bob ---- Alice
| \ / |
| X |
| / \ |
You ---- Charlie
```

How much does Bob owe to Alice ? To cruch this in brute force, you go over the whole ledger, find each line mentionning Bob and Alice (both in *From* and *To*). Here we have these lines:

| From | To | CHF | | Alice | Bob | 10 | | Bob | Alice | 10 | | Alice | Bob | 5 |

We can compute Alice's credit at Bob, by adding a `-`

sign every time Bob's name appears first (in the *From*):

Creditor | Debitor | CHF |
---|---|---|

Alice | Bob | 10 |

Bob | Alice | -10 |

Alice | Bob | 5 |

We add everything up: 10 + -10 + 5 = 15. Alice has a credit of 15 in Bob's "personal bank". Which means Bob owes **15 CHF** to Alice. Automatically whe know how much Bob owes to Alice as well. We need to do this for every pair once. So `(n-1)!`

times.

Let's see who owes what at the end of the month:

Creditor | Debitor | CHF |
---|---|---|

Alice | Bob | 15 |

Charlie | Bob | -10 |

You | Bob | 0 |

Alice | Charlie | -10 |

Alice | You | -10 |

You | Charlie | 0 |

Now we can start from one node, say Alice, and check if she owes money to one of her debtor's debtor.

Remember, "your debtor's debtor, is your debtor!"

Therefore, if Alice owes her debtor's debtor, it cancels out. Here, we see Charlie owes Bob 10 CHF, and luckily she owes Charlie 10 CHF as well. Thus we can cancel 10 out of the 15 CHF that Bob owes to Alice.

We do this compensation process for everyone and we find out that Bob owes Alice 5 CHF, and Alice owes you 10 CHF.

Creditor | Debitor | CHF |
---|---|---|

Alice | Bob | 5 |

Charlie | Bob | 0 |

You | Bob | 0 |

Alice | Charlie | 0 |

Alice | You | -10 |

You | Charlie | 0 |

**NOTE**: We will not transfer Bob's debt to Alice to you, because you would now have to bear the burden of recouping that money from Bob. Which my have some bias.

Fast forward, You go ask Alice for your due money and suddenly she realizes that because Bob cannot repay her (the dog ate the bank note), she can only repay you half of what she owes you. You were counting on this money to pay the mafia, but now you can't, which means you are dead.

Sad story indeed.

Would you have preferred a different system that makes sure everyone has the amount of money the "borrow" from you ?

**IMPORTANT**: this system between friends, it was agreed that no one would borrow money if they did not have the amount at home. The system was intended only to facilitate life among friends by sparing them the hassle to go home pick the money they wanted to spend, when some other friend was there and had the money they needed.

## Accounting for balances

Now that you died once, because you trusted everyone to have the amount they were spending, you decide to come up with a better solution for the next round. You require that everyone brings their money to the Friends Bank. It's a bank Bob just started, having learned his lesson, he now has a safe his dog cannot access. His money is really safe now, and disappearing bank notes are not problem anymore.

All friends trusting Bob, decide that to make sure everyone has the money they spend, Bob will be given everyone's money, and they will add an initial balance to everyone...