Strengthening Smart Contracts to Handle Unexpected Situations Shuze Liu * , Farhad Mohsin † , Lirong Xia ‡ and Oshani Seneviratne § Department of Computer Science, Rensselaer Polytechnic Institute Troy, NY 12180, USA Email: * lius17@rpi.edu, † mohsif@rpi.edu, ‡ xial@cs.rpi.edu, § senevo@rpi.edu Abstract—Decentralized application users may face unexpected situations that the smart contract implementing the application should handle, but cannot, because the smart contract cannot be modified once it is deployed. Therefore, we need ‘stronger’ smart contracts with flexible structures that are resilient in such unexpected situations. In this paper, we propose a generic mechanism to strengthen smart contracts and handle possible unexpected situations. Given a smart contract, this mechanism automatically generates an action list which offers actions as interfaces to change parameters of smart contracts and a voting system that utilizes a limited voter group randomly chosen from the peers. Each action in the action list can change a corresponding parameter of smart contracts. The actions, when approved by the majority, are executed to change the parameters. When users face unexpected situations in a transaction, they choose some actions as the solution and pass them to the voting system. Since a smart contract has finite parameters, there are finite actions. By arranging and combining these actions, our mechanism offers solutions that can handle wide-ranging unexpected situations. Also, to execute a solution, the majority of voters need to approve it, thus not violating the protocol of the original smart contract. Voters are rewarded based on quadratic rules for peer pre- diction, which makes telling true preferences the only way to maximize rewards. Using machine learning, we predict users’ preferences based on the voting records. The predictions are provided as default values for future votes to avoid users’ need to vote manually each time. Index Terms—Blockchain Theory, Decentralized Applications, Smart Contracts, Unexpected Situations, Computational Social Choice, Machine Learning I. I NTRODUCTION Decentralized applications (DApps), unlike centralized ap- plications, do not require any administrator and are trustworthy due to the immutable ledger behind the scenes that is recording all the transactions originating from the DApp. Thus, many companies venturing their business operations to blockchain systems are deciding to use DApps in place of their traditional systems. For instance, Walmart uses a decentralized system to track the originals of their products [1]. DApps use smart contracts to ensure each transaction is executed properly. Smart contracts are self-executing contracts in which terms of contracts between two parties are directly written into lines of code. However, once the decentralized applications are deployed to the network, they are hard to modify, since making every peer in the network agree on the modification is almost impossible. A smart contract’s response at an unexpected situation is dependent on the designers foresight, and not every possible situation can be covered. Users may face unexpected situations when they are using decentralized applications. For example, in a decentralized medical record sharing application, doctors may need the signature of their patient to access the patient records. However, if a patient is unconscious and cannot give the signature and the authorized doctor is also unreachable, a new doctor may not be able to access the record. If this situation has not been written in smart contracts, it is hard for the doctor to access the record because no administrator can help the doctor pass this requirement. Therefore, decentralization requires us to design stronger smart contracts with flexible structures. We propose a mechanism to handle existing smart contracts and strengthen them with flexible structures while keeping their original functions unchanged. Our mechanism has three main parts and has been implemented in Hyperledger Com- poser which is a decentralized application platform developed by the Linux Foundation. We suggest creating smart contracts equipped with the ability to host a voting mechanism which allow users to vote for a solution to resolve unexpected situations. We target resolving unexpected situations that can be resolved by directly changing relevant parameter values in the smart contract. In our design, we have a preprocessor that takes a smart contracts as input, analyzes the smart contract and adds an action for each parameter in the smart contract. These actions form an action list which provides interfaces for users. Because we have finite parameters for each smart contracts, this action list is finite. However, by arranging them in proper orders, users can deal with wide-ranging unexpected situations. The prepro- cessor eliminates the need to write these actions manually and provides a comprehensive action list. It also adds in a voting mechanism to vote on a solution of an unexpected situation. Facing an unexpected situation, users can start a poll through this mechanism along with an action list that will resolve the situation. Peers vote on approving the proposed action list, and based on the peer votes our mechanism may apply the solution to resolve the situation. The preprocessor is not a necessity, because these functions and voting mech- anisms may be added in by a developer as well. However, this greatly increases the efficiency and correctness of creating strengthened smart contracts. Finally, we incorporate a learn-