Blockchain smart contracts: avoid the pitfalls – Hacker Noon

1. Herstatt risk due to currency volatility

Herstatt risk or settlement risk is the risk that a foreign exchange rate will change after a contract is locked in at a specified amount of a specified currency. Obviously this is a two-way risk, as if the exchange rate goes up, the buyer will pay more; and if the exchange rate goes down, the seller will receive less. The more volatile the currency and the longer the time until settlement, the greater the risk.

This is critical in cryptocurrencies right now since they are so volatile compared to the normal currencies of the developed world, which typically change against one another in single-digit percentages in any given year. Further, most cryptocurrencies have little historical data for assessment and don’t respond to the same geopolitical events in the same way as fiat currencies.


From a Herstatt risk perspective, cryptocurrencies’ volatility and lack of historical data definitely introduces challenges. More stable currencies can be more easily hedged for Herstatt risk, but cryptocurrencies are all over the map on any given day right now. With bitcoin and Ether, as the two major examples, both having climbed substantially over the past couple of years and dropped in 2018, smart contracts have been favoring the seller more than the buyer. But short-term smart contracts, which is what most of them have been to date, have been risky in both directions. The weekly Ethereum price has a range of over $80 USD, roughly 40%.

The 24-hour volatility doesn’t inspire much more confidence as this recent example with a swing of close to $40 or around 15% shows. These are currencies with a high Herstatt risk at any but the shortest time periods.

Of course, with any risk comes hedges to accommodate the risk. The easiest is just shortening the time period until settlement gets to an acceptable level. But as the volatility in even very short contracts shows, the risk remains very high. This is minimized somewhat by the reduction of escrow fees, so there will undoubtedly be buyers and sellers who choose to accept the risk regardless in business models where high escrow fees currently hold true.

A second hedge has more merit, I think. A smart contract can be set up to reference external exchange rates, for example the stable US dollar to the volatile ether. This would be implemented by having an external program feed the exchange rate at completion into a variable in the smart contract, or by having a constant feed of exchange rates into a blockchain accessible by all contracts. The contract can be for a certain USD value at the point of contract completion based upon an agreed upon external provider of exchange rates. The payment is in ether equal to the USD price agreed upon. In this case, the escrow account has to participate in the hedge by holding the likely largest amount of the cryptocurrency given volatility.

For example, you have a website and want an ecommerce payment system added to it. You contract a developer to implement it. He tells you it will take a month and cost $2,000. You agree and enter into a smart contract using Ethereum. You jointly agree that the likely maximum volatility is 50% down and 100% up. Using $400 ether exchange rates, you would need 5 ethers for the payment. Given the volatility, you might see from 2.5 ethers to 10 ethers required. You transfer 10 ethers into the smart contract’s escrow. You agree upon a third-party service which will validate the existence of the ecommerce service in your website in a month and which is able to update a variable in the smart contract.

Upon a month being up, there are a few outcomes.

  • The ecommerce system isn’t in the website. The smart contract returns 10 ethers to you.
  • The ecommerce system is in the website and:
     — The exchange rate is at $200. The smart contract transfers all ethers to the developer.
     — The exchange rate is at $800. The smart contract transfers 2.5 ethers to the developer and 7.5 ethers to you.
     — The exchange rate is at $400. The smart contract transfers 5 ethers to both you and the developer.
     — The exchange rate is $1000, outside of the agreed volatility range but on the upside. The smart contract gives 2 ether to the developer and 8 to you.

Those are the uninteresting scenarios in that the risk hedging worked as intended. The final scenario is more interesting. The exchange rate is $100. Now there is only $1000 USD equivalent in escrow. This leads to a last couple of options.

  • The developer could have put a license key into the ecommerce software, with your knowledge, and code in the license management could be set to enable or disable the license key depending on the equivalent of $2000 being available in escrow. If it isn’t, then the smart contract could be set to allow you to submit more ether to match the $2000 or have the ecommerce software not work. You’ve got a serious choice to make because you’ve already sunk $4,000 into something worth $2,000 to you and now you have to decide if it’s worth another $1,000.
  • The developer could also just accept the Herstatt risk for the sake of convenience. In this case, the contract pays out. Once again, you are out $4,000 assuming you transferred funds into ether for the purpose of contracting, but the developer only receives $1,000.

Obviously, the volatility range is an important factor in your hedge, and it’s difficult to predict. You want the range to be lower to limit the risk of the last scenario where you effectively lose a bunch of money. The seller wants it to be higher to limit the chance of not getting paid for work. After all, it’s only in one of the above scenarios that the developer is at risk of getting no money, but there are two where you are out $4,000 or more.

Externalizing settlement to non-cryptocurrencies is another solid business strategy. Hyperledger does not support direct cryptocurrencies at all, although one has been built in it and there are implementations of loyalty tokens. All currency settlements in Hyperledger are expected to through external, 3rd-party payment systems, which could be either fiat- or crypto-currency based. The under development Eos technology is designing to allow both options. And certainly, while Ethereum smart contracts assume escrow settlements in Ether or other Ether-based currencies, it’s possible to externalize payments in this case as well.

Lastly, the entire challenge of volatility has given rise to stablecoins, which use a variety of hedging and governance strategies to remain at par or close to at par with a fiat currency, most often the US dollar.

read original article here