GithubHelp home page GithubHelp logo

narger-ef / pos-simulator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14.98 MB

Source code for the WIP paper "Looking for Stability in Proof-of-Stake based Consensus Mechanisms"

License: MIT License

Julia 100.00%

pos-simulator's Introduction

Proof of Stake Simulator

Binder

In this repository we present a Proof-of-Stake Simulator written in Julia. We used this simulator in order to study the trend of Gini coefficient under different consensus algorithms.

Parameters

  • n_epochs: The number of epochs to be simulated, that corresponds to the number of blocks (virtually) validated.
  • proof_of_stake: The type of PoS to be used. It takes values in the set Weighted, OppositeWeighted, GiniStabilized.
  • initial_stake_volume: The initial number of coins, distributed among the peers according to the next parameter.
  • initial_distribution: The initial distribution of coins among the validators. It takes values in the set Uniform, Gini, Random.
  • n_peers: The number of participants (the same as $N$ in the formulas above) in the blockchain that aim to be selected as validators.
  • n_corrupted: The number of validators in the blockchain that could exhibit corrupted behavior according to a probability p_fail.
  • p_fail: The probability that a corrupted validator tries not to validate correctly the block.
  • penalty_percentage: The percentage of coins removed (slashed) from the amount of coins staked by the corrupted validators, in case they show corrupted behavior.
  • p_join: The probability, at each epoch, of a new user to join the validators. The new user can be labeled as corrupted with a probability equal to the initial ratio of corrupted peers over the total number of peers.
  • p_leave: The probability, at each epoch, of any validator to quit the pool.
  • join_amount: The amount of coins owned by a peer that just joined the set of validators. It takes values in the set Average, Random, Max, Min.

How to use

First import the required simulator:

include ("src/Simulator.jl")

be sure to point the correct src folder.

Next, create a Parameter object containing all the parameters. A basic set of parameters can be created as follows:

parameters = Parameters()

Then, each parameter can be changed individually. In order to execute a simulator, we require two other elements: an initial stake and a set of corrupted peers. The first one can be created as follows:

stakes = generate_peers(parameters.n_peers, 
                            parameters.initial_stake_volume, 
                            parameters.initial_distribution, 
                            parameters.starting_gini);

Then the subset of corrupted peers, is simply created as follows

corrupted = rand(1:parameters.n_peers, parameters.n_corrupted)

We can finally run an experiment as follows:

history, peers = simulate(stakes, corrupted, parameters);

The variable history will contain the Gini coefficient computed at the end of each epoch, and peers will contain the number of peers at the end of each epoch. Examples can be found in the examples folder, and are described below.

Experiment 1 and 2

Online notebook available: Binder

We use Weighted PoS in order to show the trend for $g$ to go to 1, and OppositeWeighted PoS in order to show the trend for $g$ to go to 0

Experiment 3

Online notebook available: Binder

We use GiniStabilized PoS to show that it is possible to control the Gini coefficient $g$. We set a target value $\theta = 0.3$ and plot the trend of $g$. In particular, we chose a Constant update for GiniStabilized

Experiment 4

Online notebook available: Binder

We use GiniStabilized PoS and Linear updates, showing that it is possible to obtain a smooth trend for the Gini coefficient around the target value $\theta$.

Experiment 5

In this experiment we want to run different simulations on different types of ${\tt g_funct}$ All the simulations share a lot of parameters (such as the number of epochs, the number of peers, the PoS type and so on), but they differ on the function applied to $s$ at each epoch. We remark that:

  • Constant $$s = k$$
  • Linear $$s = |s - \theta| / k$$
  • Quadratic
  • $$s = |s - \theta|^2 / k$$ We run the following five simulations:
  1. Constant, $k=1 / 1000$
  2. Linear, $k = 10$
  3. Linear, $k = 100$
  4. Quadratic, $k = 10$
  5. Quadratic, $k = 100$

Test it online here: Binder

Authors

Made with <3 at Bicocca Security Lab, at University of Milan-Bicocca.

BisLab logo

pos-simulator's People

Contributors

narger-ef avatar

Watchers

 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.