I am interested to know the basic concept of Fidelity bonds in finance and how will it be used in Joinmarket.
What are Fidelity bonds?
Fidelity bond is a type of insurance contract designed to protect from losses caused due to forgery, theft etc. Normally used by employers in form of business insurance which generally covers the dishonest activities performed by its employees.
First ever mention of fidelity bonds. The idea is basically invented by Peter Todd: https://bitcointalk.org/index.php?topic=134827.0
Old idea for combining fidelity bonds with mixers: https://bitcointalk.org/index.php?topic=172047.0
Suggestion that is very close to the fidelity bonds idea in Joinmarket. He talks about requiring a deposit from makers, but nobody is able to come up with a way to make such a deposit decentralized and trustless: https://www.reddit.com/r/Bitcoin/comments/2zc5tc/joinmarket_increase_the_privacy_of_bitcoin_and/ctk37hn/?context=1
Adding fidelity bonds in Joinmarket:
Pull request which added Fidelity Bonds in Joinmarket: https://github.com/JoinMarket-Org/joinmarket-clientserver/pull/872
The changes to the joinmarket protocol are backward-compatible. You can read docs/fidelity-bonds.md for more details. Below is a summary from it:
Fidelity bonds are a feature of JoinMarket which improves the resistance to sybil attacks, and therefore improves the privacy of the system.
A fidelity bond is a mechanism where bitcoin value is deliberately sacrificed to make a cryptographic identity expensive to obtain. The sacrifice is done in a way that can be proven to a third party. Takers in JoinMarket will have a higher probability to create coinjoins with makers who publish more valuable fidelity bonds. This has the effect of making the system much more expensive to sybil attack, because an attacker would have to sacrifice a lot of value in order to be chosen very often by takers when creating coinjoin.
As a maker you can take part in many more coinjoins and therefore earn more fees if you sacrifice bitcoin value to create a fidelity bond. The most practical way to create a fidelity bond is to send bitcoins to a time-locked address which uses the opcode OP_CHECKLOCKTIMEVERIFY. The valuable thing being sacrificed is the time-value-of-money. Note that a long-term holder (or hodler) of bitcoins can buy time-locked fidelity bonds essentially for free, assuming they never intended to transact with their coins anyway.
The private keys to fidelity bonds can be kept in cold storage for added security. (Note: not implemented in JoinMarket yet)
Financial mathematics of JoinMarket fidelity bonds: https://gist.github.com/chris-belcher/87ebbcbb639686057a389acb9ab3e25b
How many coins to lock up and for how long?
Fidelity bonds UTXOs are valuable as soon as they confirmed. The simplified formula for a fidelity bond value with locked coins is:
bond_value = (locked_coins * exp(interest_rate * locktime))^2
At any time you can use the orderbook watcher script to see your own fidelity bond value.
Consider also the warning on the bitcoin wiki page on timelocks
At the time of writing fidelity bonds are not deployed yet in the wild, but I would recommend locking as many coins are you're comfortable with for a period of between 6 months and 2 years. Perhaps at the very start lock for only 1 month or 2 months(?) It's a marketplace and the rules are known to all, so ultimately you'll have to make your own decision.