Smart Contract Concepts and Practice

( 1 user )

The success of Blockchain 1.0 with Cryptocurrency demonstrated to the world that efficiency and intangible technological benefits await the rest of the industry. The next such application at massive scale is Smart Contracts facilitated by Blockchain 2.0. The first blockchain approach is modified to suit Smart Contract Applications.

A contract is a written agreement between two parties, creating legal binding while performing individual acts or transactions like Tenancy, Property dealings, Employment, Service, etc. A contract is desired when assets of value are exchanging hands. A Smart Contract is useful when two parties are ready to enter into a digital agreement. Implementation of DLT embedded with Smart Contracts provides a high level of compliance, cost-efficiency, Time savings, accountability, and Privacy. Any service that requires a contract and can be better provided using Smart Contract.

Smart Contracts are computer code, in which the terms of the contract are incorporated in a Programming Language, instead of Legal language. Since it is a code, Smart Contracts are executed by the system under the prescribed terms in a self-enforcing manner to facilitate, execute, enforce, validate an agreement, mostly independent of the Legal and Executive System of the domicile. Smart Contracts are applications that use Blockchain and layered on top of Distributed Ledger Technology. Therefore, Smart Contracts inherit properties like Consensus-based ledger updation, Immutability, Provenance, and Finality from Blockchain and Distributed Ledger Technologies.

Richard Gendal Brown considers Smart Contract to be an event-driven program with values and states of the transaction. Essentially, the purpose of the Smart Contract is to take custody of the assets listed in the distributed ledger.

Execution steps for a Smart Contract

The sequence of steps that goes into the execution of Smart Contract are:

  1. Setting the business rules of transaction and validation
  2. Triggering the transaction –Ex: A wants to sell a Car
  3. Validation & Verification – As per the rules of business, the transaction happens between buyer, seller; verified and approved by the rules of the bank, insurance, or so. Also, Consensus is part of this phase.
  4. Creating a new block – A new block is created with the above verified and validated record, along with the hash of the previous block.
  5. Adding the block to the chain – the created new block is communicated to all participating nodes to be appended to the shared ledger in append-only mode.
Smart Contract Execution Steps
Figure.10.1 Smart Contract Execution Steps

A case study on Smart Contract

Scenario: Vehicle Life Cycle Management

"A car manufactured by a manufacturer is sent to a Dealer for sales. A buyer approaches a dealer for buying the vehicle. The buyer is interested in Car Loan or Lease. Buyer and Leasing Company/Bank evaluates the options. Licensing Authority certifies and issues a license to the vehicle. The manufacturer tracks the life of the vehicle and at the end of life suggests the vehicle to be scrapped."

Now let us see how these activities are handled in a Traditional System and a Smart Contract System. The stakeholders involved are Manufacturer, Buyer, Dealer, Leasing Company, Bank, and Licensing Authority.

Traditional System: This is a Centralized Ledger System i.e., each stakeholder maintains his own Ledger and communicates to the other stakeholders as necessitated to obtain desired information or approvals. The communication has no coherence. The response is generated from each one’s Ledger. There is no transparency. It is a trusted third party response from each of the authorities. Only the regulating licensing authority has communication with all stakeholders, while others have limited channels. Figure 10.2.a is a pictorial representation of the traditional transaction model.

Traditional Transaction
Figure.10.2.a Traditional Transaction
Smart Transaction
Figure.10.2.b Smart Transaction

Smart Contract System: This is a Distributed Network environment. All the stakeholders are connected in a Distributed Network. A distributed Shared Ledger is maintained by the select stakeholders of the network. A Smart Contract code facilitates the communication, verification, validation, updation in the Blockchain ecosystem. The rules for loan sanctioning / leasing, licensing, age monitoring, etc., are in-built in the Smart Contract code.

Smart Contract eliminates the trusted third party but the trust is inbuilt in the system. The stakeholders involved can view the desired information as per their access control rights. Figure 10.2.b is a diagrammatic representation of Smart Contract Activity.

Components of Smart Contract

Smart Contract Components
Figure.10.3 Smart Contract Components

Blockchain Technology - Cryptocurrency BC is said to manage on-chain assets, while Smart Contracts are said to manage off-chain assets. Off-chain assets are better managed in permissioned blockchain configurations as this requires finality. Hence Smart Contracts applications are designed using permissioned blockchain network. Therefore, only a select set of nodes to have permission to write a transaction in the shared ledger. The validators are identifiable in the permissioned network. The anonymity or pseudonymity is insufficient for Smart Contracts, as the assets with ownership are dealt with as part of contracts.

Permissioned blockchains are Private blockchains. And this requires only reasonable computational resources making it affordable to enterprises.

Distributed Shared Ledger - A shared ledger is a more than a replicated database that keeps track of who holds the asset. The asset may be financial, digital or physical. The attributes of Shared Ledger are:

  • Reconciliation and hence accuracy
  • Security maintained using Cryptography
  • Ledger replicated as necessitated
  • Granular Access Control, Transparency and Privacy

Because of the DLT use, Smart Contracts eliminate the issue of single-point failure in Centralized traditional transaction model.

Consensus - Lamport Byzantine Fault tolerance is deterministic and is useful in Smart Contract Systems. Consenses converge with certainty, and hence transaction s are confirmed or rejected immediately. This is useful for Characteristics required for Smart Contracts. It is this consensus that ensures the finality of the transactions.

What makes a blockchain permissioned or permissionless is their consensus mechanism. Proof of Work is an unnecessary overload for Blockchain business applications. PoW is required in BC, where participants are anonymous.

Tokens - Tokenisation is required for digitalizing assets to be traded over Blockchain. Ethereum like BCT, supports the creation of noncurrency tokens and hence facilitates Smart Contracts Operations. These assets which are traded using smart contracts are called off-chain assets.

Technical code and Scripting Language: The terms of execution of a Smart Contract are coded using scripting languages meant for this type of programming. This ensures the terms of execution of a contract to be hardcoded, reducing the flexibility for changes at a later stage. This code is called Technical code or computer code. A well thought out design of a Smart Contract is necessary. The scripting languages used in Smart Contracts belong to Turing Complete category.

The legal code is 'extrinsic', i.e., if the rules are broken, consequences are enforced by the court of law for breach of compliance. However, the technical code of Smart Contract is ‘intrinsic.’ In intrinsic execution, if rules are broken, code finds an error during execution and terminates probably declaring the violation type. The breach is instantaneously deterred, and the breach is not allowed to happen at all.

Security is about "thing that should happen, should happen; and things that should not happen, should not be allowed to happen." This is exactly what happens with Computer technical code.

Solidity, C++, Go, RUST, Javascript, Python, Rholang, etc., are few of the popular coding languages used in Smart Contract Programming.

Interoperabilty: The Smart Contracts can be coded with necessary conditions and states using Turing Complete blockchain script. This creates interoperability or interaction with systems outside blockchain too.

Smart Contract Platforms

Hyperledger, Ethereum, NEM, Waves, Stellar, OpenZeppelin, R3: Corda are few of the most popular Smart Contract Platforms. All these platforms provide the necessary tools for design, development, and deployment of Smart Contracts.

Applications of Smart Contracts

Regulatory Compliance, Product Traceability, Service Management, Counterfeit Product Detection, Fraud Detection in sectors like Food, Energy, Pharmaceutical, Transport, Health and Travel services, B2B services, Collateral and Guaranteed Lending, Crowdfunding, etc.

Risks in using Smart Contracts

  • The reliance on the computer system that executes the contract code
  • The technical vulnerabilities of the code and security
  • Legal and Regulatory issues like Jurisdiction

To Do

* Note : These actions will be locked once done and hence can not be reverted.

1. Track your progress [Earn 200 points]

2. Provide your ratings to this chapter [Earn 100 points]

Note : At the end of this chapter, there is a ToDo section where you have to mark this chapter as completed to record your progress.