Giter VIP home page Giter VIP logo

rp-chaincode's Introduction

rp-chaincode

This repo contains three smart contracts (written in Go) demonstrating the three security vulnerabilities explored in my bachelor thesis: Revisiting Smart Contract Vulnerabilities in Hyperledger Fabric. The paper explores three reported smart contract-specific vulnerabilities in Hyperledger Fabric, their methods of exploitation, impact severity estimation and possible countermeasures. The vulnerabilities include global variables, updates using rich queries and pseudorandom number generators.

Each contract includes the commands used to deploy and reproduce the exploitation of the contract. The exploitations are explained in more detail in the paper.

Disclaimer: these contracts are vulnerable to exploitation and should only be used for educational purposes in a designated test environment.


Setup and Install

It is recommended to use the Hyperledger Fabric test network to deploy these contracts. The specific Hyperledger Fabric version used for the thesis was v2.2.3.

  1. Install the prerequisite software (Git, cURL, Docker and Docker Compose) according to this Hyperledger Fabric guide. Additionally, installing Hyperledger Explorer is recommended (but not necessary) to more easily inspect the blocks on the blockchain.
  2. To install and setup the test network, follow the official Hyperledger Fabric tutorial.
  3. Make sure that the environment variables are set correctly according to the section "Interacting with the network" in the above tutorial. The CORE_PEER environmental variables define the peer used for the peer CLI. The set_peer.sh script can be used to quickly set the current peer to organization 1 or 2.

Contract deployment

To deploy a contract use the following command:

./network.sh deployCC          \
	-ccn <chaincode_name>      \
	-ccp <path_to_chaincode>   \
	-ccl <chancode_language>   \
	-ccep <endorsement_policy>

The -ccep flag can be left out, in which case the endorsement policy will default to "AND('Org1MSP.peer','Org2MSP.peer')".


Contract invocation

The Hyperledger Fabric peer CLI distinguishes between query transactions (read-only) and update transactions.

The following command can be used to invoke query transactions with N arguments:

peer chaincode query  \
  -C <channel_name>   \
  -n <chaincode_name> \
  -c '{"Args":["<function_name>", "<argument1>",...,"<argumentN>"]}'

Query transactions are only executed by the peer whose address is stored in CORE_PEER_ADDRESS.

Similarly, the following command can be used to invoke update transactions with N arguments:

peer chaincode invoke                     \
  -o <orderer_information>                \
  -C <channel_name> -n <chaincode_name>   \
  --peerAddresses <peer1_information>     \
  --peerAddresses <peer2_information>     \
  -c '{"function":"<function_name>", "Args":["<argument1>,...,<argumentN>]}'

This update transaction will be executed by all the peers whose addresses are specified after the --peerAddresses flag. You therefore need to include enough peer addresses to pass the endorsement policy.


Enabling CouchDB

The rich queries vulnerability requires that CouchDB is set as the state database (which is LevelDB by default). To set CouchDB as the state database do the following:

  • Start the test network with ./network.sh up CreateChannel -s couchdb, where the -s flag specifies the state database type to deploy. Dropping the -s flag will deploy the default state database.
  • (Optional) To make CouchDB the default database: change DATABASE=leveldb to DATABASE=couchdb in fabric-samples/test-network/network.sh

To inspect the CouchDB instance of a peer, use localhost:<port_of_peer>/_utils to access the Fauxton GUI.

rp-chaincode's People

Contributors

cathrinepaulsen avatar

Stargazers

 avatar  avatar Ichheit_lbt avatar Robin Siep avatar

Watchers

 avatar

Forkers

ramaguru-forks

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.