# Blockchain-Based Loyalty Management System
## 2 Literature Review
### Background
#### 2.1.4 Smart Contracts  
Smart contracts are self-executing computer programs stored on the blockchain. The primary purpose of these contracts is to provide a more secure way to produce transactions without having to rely on third parties and question whether the information has been altered for personal benefit. These contracts contain the logic to proceed with transactions, with this logic being defined by programmers. Each contract, when stored in the blockchain, receives a unique address, which is the entry point for the interaction.  
To interact with smart contracts, every user needs a virtual wallet, as every interaction with the blockchain requires a fee payment due to processing effort. The hosted blockchain's native cryptocurrency is used to pay this fee. During the interaction with a smart contract, the user sends data to the contract that will be processed based on its logic.  
The benefits of smart contracts are speed and efficiency due to automatization processes. Once a given condition is met, the execution of the associated contract is triggered, and the transaction is performed without errors or any kind of bureaucracy. Associatedwith automatization, these contracts offer trust and transparency, since there are no third-party entities, and the blockchain encrypts every transaction and shares it across the nodes. Additionally, with a consensus mechanism it is nearly impossible to modify transactions for personal benefit. As a result of their nature, smart contracts help entities save money and time by eliminating intermediaries and the associated delays and expenses.  
Currently, the adaptability and reusability of smart contracts is an open research issue. In [9], the author proposed a design pattern to implement the reusability of verification rules across multiple contracts, which allows reconfigurability at runtime. The study was conducted using permissioned blockchains and Java as the programming language. The proposed design pattern exploits polymorphism and manages inheritance through sealed classes, and includes two layers: abstract and concrete. The abstract layer includes an abstract contract class with a single abstract method (\"checkSC\"), as well as an interface for rule implementation. The concrete layer contains all the contracts, which are classes that extend the abstract contract class and therefore implement its single abstract method (i.e., the contract behaviour). Furthermore, the concrete layer includes the definition of rules, where each rule is encapsulated by a class that implements the rule interface. Although a simple pattern, the proposal in [9] reduces code redundancy and allows configuration at runtime.  
In the same context, the paper [10] details a design pattern, called the proxy pattern, that allows smart contracts to be updated without losing data. OpenZeppelin provides an extensible plugin based on this pattern. It comes with extensive documentation explaining its functionality [11]. Unlike a single contract that combines both data and business logic, the proxy pattern involves splitting the contracts into a proxy contract and a business logic contract. The proxy contract acts as a dedicated storage and delegates calls to the business logic contract, while the business logic contract handles all the business logic operations. In the proposed design pattern, the read and write operations performed by the delegated contract have an impact on the storage of the proxy contract.