cicorias
3/10/2017 - 12:23 AM

Some Smart Contract stuff

Some Smart Contract stuff

Skip to contentCrypto Posts https://rajbhadra.wordpress.com/2016/09/26/blockchain-based-letter-of-credit-implementation/ Home About Contact Blockchain based Letter of Credit implementation Posted on September 26, 2016 by rajbhadra Alice lives in America has an animal husbandry farm. Her farm has developed a cattle breed with advantageous properties. She is keen on selling them and lets people know of her desire.

Bob hears extremely positive reviews of Alice’s endeavor from his American peers and decides to purchase a bunch her cattle to fulfill the needs of his Belgian farm.

He requests Alice for a large order and they reach an agreement. Alice will ship the goods through Charlie the Carrier. Alice wants the funds to be delivered in Bank of Alice and Bob will utilize Bank of Bob. Alice does not trust Bob and being a canny businesswoman requests a Letter of Credit.

What is a Letter of Credit?

Letter of Credit assures a seller payment on presentation of documents stipulated at the time of agreement.

Alice gets a substitute for the trust in Bob through the trust in LC provided by Bank of Bob.

Bob will have to request Bank of Bob to provide him a LC. The bank will evaluate the agreement and Bob’s creditworthiness and Bob’s LC application. If deemed proper, the bank grants a LC.

normaltradewithoutnumbers The trade starts with Bank of Bob providing an LC to Alice Bank of Bob sends a LC to Alice Alice gets a transport verification document in exchange of shipping the goods through Charlie Alice presents this document to her bank Bank of Alice sends it to Bank of Bob Bank of Bob releases the payment and sends the document to Bob Bob shows Charlie the document and gets possession of his goods The scale

LCs are used for around 11-15% of international trade which comes to trillions of USD each year. For LCs to be used across countries and banks, their usage had to be standardized to some extent. LCs are granted and used under a set of rules called Uniform Customs and Practice for Documentary Credits (UCP).

Conceptually, some of the problems in this approach are,

Easy to go wrong in formulating an LC application. Miscommunication between the Bob and Alice or lack of UCP understanding can result in impossible or non compliant requirements. It would be difficult for Alice and Bob to understand all the costs and risks associated with the LC. The laws of each country have to be known before dealing with them which take a lot of effort for Alice and it is difficult for her and Bob to predict all the scenarios and to study corresponding laws without experiencing them beforehand. LCs are not in accordance to the needs of the commercial market. Reconciliation and document checking is needed at each step which slows down the process. Banks have to rely on a number of technical checkers whose checking might be questionable or slow. It would be difficult for both the banks to deal if they do not have a prior relationship. Information is not efficiently shared between all the parties involved. Each step in the above diagram results in a message sent from one party to another. Upon receiving the message, the party has to be assured of the authenticity of the source of the message and the truth of whether the message contains the truth from a trusted party. This seems like an interesting use case for a blockchain approach.

A blockchain approach

Looking at the problems mentioned above, the Banks come up with a blockchain approach to make LCs more manageable.

blocktrade The conceptualized blockchain implementation Alice, Bank of Alice, Bob, Bank of Bob and Charlie now communicate and transmit messages on a blockchain contract. They establish a high level flow as,

Bank of Bob submits a contract on the blockchain All the participants interact with the contract updating its state Once the contract reaches a successful state, Alice gets paid What is a blockchain?

A blockchain is a distributed ledger which maintains a continuously growing list of records called blocks from tampering or revision. In bitcoins and other cryptocurrencies, it is used for storing transactions.

Blockchain 2.0

Blockchain 2.0 is the application of similar technologies for creating contracts for economic and financial purposes. It allows for distribution and transfer of many other kinds of assets beyond currency by allowing complex transactions.

What is blockchain doing here?

When converting an existing system to a blockchain implementation, it is important to identify the parts of existing system that blockchain solves, simplifies or improves. In this case, it is all about synchronization. The blockchain implementation models the document flows as message flows. Synchronization is the co ordination of events to operate a system in unison. Synchronization consists of data sync and process sync. Data sync refers to keeping multiple copies of data set in coherence with each other. Data sync is inherently handled by the blockchain. In process sync, multiple processes join up or handshake at a certain point in order to reach an agreement or commit to a certain sequence of data. The process sync is handled by the smart contract. To conduct this process sync, the contract accepts messages from authenticated originating parties which change the contract state and communicate this to all the parties involved.

What has changed? Transition from a decentralized system to a centralized contract running on a distributed system Alice, Bob and the banks now move their trust from the documentation by trusted parties to the contract code and state A more concrete implementation They decide to create a consortium of traders, banks, carriers and customs for the blockchain to limit access and create a set of identities for each participant. The contracts are to be implemented on Ethereum using Solidity.

What is Ethereum?

Ethereum is a platform for running contracts on the blockchain. It sets up a Turing complete scripting system along with state storage which let anyone create their own set of rules for ownership, transactions and state transitions. Solidity is a high level language that compiles to the code for Ethereum Virtual Machine.

The come up with the following flow,

flowminblog Alice and Bob get started by selecting a smart contract in accordance with their countries, banks and trade type. The banks will keep a set of acceptable smart contracts and Alice and Bob can select the one that fits their needs an is compatible with Bank of Alice and Bank of Bob. Bob sends the request to Bank of Bob which verifies the credit worthiness of Bob and the smart contract details. This verification happens offline and manually. Bank of Bob and Bank of Alice then validate and clear the contract based on its acceptance and details. The contract is then published on the blockchain by Bank of Bob setting the initial conditions. /**

  • @dev Setup the initial parameters for the contract
  • and the start time
  • @param cred The credit given by the buyer's bank
  • @param b The buyer address
  • @param s The seller address
  • @param sb The seller bank
  • @param val The time validity of the contract from the start time */ function LC(uint cred, address b, address s, address sb, uint val) { issuer = msg.sender; credit = cred; buyer = b; seller = s; sellerBank = sb; startTime = now; validTime = val; } Alice then adds Charlie as a channel of transport for the goods.

struct Channel{ string channelName; address channelAddress; string channelChecks; bool initialized; bool active; bool checked; bool finished; bool error; string failedChecks; bool issuerAccepted; } Channel[] public channelSequence; /**

  • @dev Add a channel of transport for the contract
  • @param cName The name of the channel
  • @param cAddress The address of the channel
  • @param cRole The role played by the address
  • @param cChecks The checks made by the channel / function addChannel(string cName, address cAddress, string cRole, string cChecks) { if (msg.sender != seller) throw; if (now < startTime + validTime) throw; channelSequence.push(Channel({ channelName: cName, channelAddress: cAddress, channelChecks: cChecks, initialized: false, active: false, checked: false, finished: false, error: false, failedChecks: "", issuerAccepted: false })); } The contract is locked by Bob with setting Charlie as a required channel. /*
  • @dev A method for the LC issuer to set the required channels
  • whose confirmation and finish is required for
  • releasing the credit
  • @param required The set of required channels from current channels / function setRequiredChannels(bool[] required){ if (issuer != msg.sender) throw; requiredChannels = required; } Charlie then messages the contract in accordance with its physical contact with the goods. /*
  • @dev A method for a channel to indicate that it is now
  • active in the transportation */ function channelActivate(uint cIndex){ address cAddress = channelSequence[cIndex].channelAddress; if (cAddress == address(0)) throw; if (cAddress != msg.sender) throw; if (now < startTime + validTime) throw; channelSequence[cIndex].initialized = true; channelSequence[cIndex].active = true; }

/**

  • @dev A method for a channel to indicate that it is now
  • inactive in the transportation */ function channelDeactivate(uint cIndex){ address cAddress = channelSequence[cIndex].channelAddress; if (cAddress == address(0)) throw; if (cAddress != msg.sender) throw; if (now < startTime + validTime) throw; channelSequence[cIndex].active = false; }

/**

  • @dev A method for a channel to indicate that it has now
  • successfully finished it's part of transportation */ function channelFinish(uint cIndex){ address cAddress = channelSequence[cIndex].channelAddress; if (cAddress == address(0)) throw; if (cAddress != msg.sender) throw; if (now < startTime + validTime) throw; channelSequence[cIndex].finished = true; }

/**

  • @dev A method for the channel to indicate that it has
  • failed in it's transportation or it's checks / function channelError(uint cIndex, string failed){ address cAddress = channelSequence[cIndex].channelAddress; if (cAddress == address(0)) throw; if (cAddress != msg.sender) throw; if (now < startTime + validTime) throw; channelSequence[cIndex].error = true; channelSequence[cIndex].failedChecks = failed; } On finish by Charlie, Alice can now claim her payment. /*
  • @dev A method for the seller to request transfer of credit
  • which will be successful if all the required channels have
  • confirmed and finished */ function getPayment(){ if (seller != msg.sender) throw; for (uint i = 0; i < channelSequence.length; i++){ if (requiredChannels[i] == true){ if (channelSequence[i].finished == false || channelSequence[i].error == true ) throw; } } transferCredit(credit, seller, sellerBank); }

The participants have thus modeled the physical flow to a digital flow by converting subjective paperwork to objective messages.

Whats better?

Easy for Alice and to analyze the smart contract than to lookup UCP and laws of the corresponding countries. Faster sync of messages for all the participants. Messages are from originating parties and are always authenticated. Each participant is aware of the state of contract after every message. Can accommodate varied flows and requirements. Multiple channels can be set and used. Why blockchain? Fully centralized systems cause differences on a system level in international contracts. As such systems may have different requirements for each pair of countries, it is not possible to establish a completely centralized system and this gave rise the current decentralized model with UCP guidelines.

Once a distributed neutral Turing complete platform is established, the differences in requirements are in the form of logic which can be modeled on the system exponentially quicker than an equivalent centralized system between the pair of countries. This also gives rise to system which is more hand in hand with the current trading needs.

A fully digitized model

A fully digitized model can be evolved from the current implementation in which Bobs credit worthiness can be evaluated digitally using a blockchain KYC platform. Bob then can get funded by any bank or crowdfuned. The channel messages can be automated using IoT devices implanted on goods. Such a model might drive out all manual intervention in implementing a LC.

Advertisements

Share this: TwitterFacebookGoogle

Tagged blockchain, ethereum, letter of credit Leave a Reply

Search

Search for: Blog at WordPress.com. Follow

LOC https://wiki.hyperledger.org/requirements/use-cases/use-case-trade-finance-letter-of-credit

https://rajbhadra.wordpress.com/2016/09/26/blockchain-based-letter-of-credit-implementation/