GithubHelp home page GithubHelp logo

distributedsystemssocialnetworkanalysis / decentralized-rating-platform Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 5.0 958 KB

Create a set of smart contracts to support rating platforms, and offer the features of transparency and immutability

License: MIT License

Solidity 38.24% JavaScript 61.76%

decentralized-rating-platform's Introduction

Smart contracts for Rating platforms

Goal

Create a set of smart contracts to support rating platforms (or recommender systems) like Tripadvisor. The smart contracts, intended to run on a public blockchain, offer the features of transparency and immutability, granting the possibility to audit and not repudiate the data stored. The downsides are the performance, the fees and the limited amount of data that can be stored on a public chain.

Nomenclature

  • User: a user of a rating platform;
  • Item: the content of a rating platform (e.g. restaurant on Tripadvisor);
  • Skill: a keywork identifying the property of an item (if the item is a restaurant, a skill can be "Vegan cousine"; if an item is a company, the skill can be "Tech company");
  • Experience: the "reputation" a user has on a particular skill. The experience improves every time a user rates an item.
  • RatingFunction: function computing the final score of an Item given all its ratings as input. The usage of such functions follows the Strategy design pattern. Examples:
    • Simple average on the item scores;
    • Weighted average on the blocks (time): newer ratings have more impact;
    • Weighted average on the experience: higher experienced ratings have more impact;
    • A weighted combination of the above.

Overview

The smart contract build up a system, with an entry point called RSF (Rating System Framework). People have to register themselves in order to publish items (contents) or rate existing items and become users. Item owners (users) can give permissions to rate their items to customers (users as well): both permissions grant, revoke and ratings are stored on the smart contracts, thus on the blockchain.

The ratings can be read and used to compute the item final score by smart contracts called RatingFunctions. A rating function can implements any formulas, for example a simple average or weighted average on certain parameters.

Moreover, the smart contracts provide the concept of "skill", i.e. a keyword identifying the property of an item. When a user rates an item he collects experience on the item's skill. If the user has high enough experience on the rated item's skill the user receives a discount proportional to the experience: the discount is represented by ERC20 tokens and can be used only on the item that issued them. In this way, each Item owner can set the best properties for them to the token (like price, total amount etc).

The Grant Permission shown in the figure below has the following semantics: if the customer pays (in crypto) the amount expected by the restaurant, the customer automatically receives the permissions to rate the restaurant. In the code such Grant Permission is called commitPermission. The motivation is described below the contract diagram.

imgs

Features

  • Basic access control mechanism to store a rating;
  • Store the ratings of an Item;
  • Provide RatingFunctions to compute the score of the items according to customizable formulas;
  • Provide the skill system for the computation of the discount;
  • Issue ERC20 compliant tokens to implement the discount mechanism.

Class diagram

classes

Note: In the diagram the contract Item has two grantPermission functions. However, due to issues from Truffle with function overloading (ref) in the code the Item contract the function grantPermision(to, amount) is called commitPermission(to, amount).

Installation and usage

Requirements

  • nodeJs and npm
  • Truffle framework: website
    • npm -g install truffle (may require sudo)
  • Ethereum local testnet: Ganache (GUI) or ganache-cli (CLI)

Installation

npm install

The package.json includes utility packages for the framework, such as truffle-hdwallet-provider to interact with Ethereum online test networks, and the openzeppelin contracts.

  • Tutorial with Truffle and Infura as provider: read here.

Workflow

  • Compile the contracts in contracts/
    • truffle compile
  • Migrate (deploy) the contracts to the target network
    • truffle migrate --network <network name>
    • The code provides 2 networks: development and ropsten.
  • Testing
    • truffle test --network <network name>
    • The provided tests work with the migration script targeting the development network.

Future works

  • Refactor the system:
    • Reduce the gas cost by applying patterns (e.g. the factory pattern to avoid new());
    • Are there components, or functions, not usefult for an Ethereum based application?
  • Explore the usage of HTLC (Hash Time Locked Contracts) for the atomic exchange of rating / tokens (ref1, ref2, atomic swaps);
  • Explore privacy issues;
  • Explore vulnerabilities and abuses:
    • Fake review problem;
    • Get too rich with discounts;
    • Sell review with an high experienced account;

Authors

Andrea Lisi: 0Alic

Samuel Fabrizi: samuelfabrizi

License

MIT license

decentralized-rating-platform's People

Contributors

0alic avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.