Prototype Proof of Stake application for Web3 curriculum
- Build client
npm run build:client
- Build the blockchain
npm run build:blockchain
- Start node server with a name
NAME=Camper npm run start:node
- This will dynamically open a port, which is shown in the same terminal. Open the shown port.
-
Intermediate JavaScript and Node.js
-
Basic HTML and CSS
-
Cryptography
- Hashing Functions
- Signing
- Verifying
- Programatically Solving Hashes
-
Blockchains
- Linked Lists
- Blocks
- Tokens
-
Wallets
- Addresses
- Private Keys
- Public Keys
-
Smart Contracts
- Creation
- Testing
- Deployment
- Validating
- Staking
- Security
- 51% Attacks
- Rust
- Accumulation of resources increases probability of being chosen to do work
- If chosen to do work, you have the option of doing what is requested, or misbehaving
- Completing work gets you a reward
- Misbehaving might get you more of a reward
- Misbehaving might get you a punishment
- Punishment is reduction of resources
- Whether you get punished or not is dependent on the number of players watching you
- If you own
>50%
of the resources, you can misbehave without punishment, provided there is only one player watching you
Intern at freeCodeCamp in our server room. Help debug this VM. Improve it, or introduce more bugs. If you introduce any jQuery, you have definitely misbehaved
- Resources
- Money to purchase skillsets. Buy Nodejs Course... Buy jQuery course to misbehave
- Reputation - trust - watched less closely by nodes. Higher rep === more work
- Tasks
- Quiz
Node - An instance of a server running the blockchain protocol Client - A browser that connects to the blockchain Validator - A node ensuring validity of the blockchain Miner - A node chosen to mine the next block
The miner forges the next miner, upon validation.
The miner is determined by weight of reputation and staking.
A validator is determined by weight of reputation.
The number of validators is determined by some weight of the miner's reputation.
At least two nodes are requested to validate a view of the blockchain by a client
Specification
- Genesis block is forged by initial node
- Block predetermines the miner and validator(s)
- Next validator(s) are responsible for distributing reward
- Last validator(s) are responsible for distributing blockchain to client
- Pool is sorted by weight
- Reward is
+1
token, and+1
reputation - Incorrect block yields no reward
- Misbehaved block yields punishment of
-1
token, and-1
reputation
Terms
Weight
Validator
// List of elements sorted by weight
[ele1, ele2, ele3]
// Example list
=> [0.66, 0.16, 0.16]
// Cumulative weight summation
=> c_v = [0.66, 0.82, 1.0]
random_number = generate_random_number(0, 1)
for ele, index in enumerate(c_v):
if random_number < ele:
return index // Index of element interested in
Miner
["Block"]
Genesis block will contain all data for initial nodes. A Node joining the network will create a new block.
{
"id": 0,
"hash": "0x0",
"previous_hash": "genesis",
"timestamp": 1496314658000,
"data": [
{
"name": "Camper",
"staked": 0,
"tokens": 1,
"reputation": 1
}
],
"nonce": 0,
"next_miner": "Camper",
"next_validators": ["Tom", "Mrugesh", "Quincy"]
}
{
"name": "Camper",
"peer_id": "0x1234567890123456789012345678901234567890",
"staked": 0,
"tokens": 1,
"reputation": 1
}
Same as Node
Client request streams are not necessarily persisted, as mining could take too long. Instead, response from network is always just result of connection.
Always pass chain
to and from node/blockchain.
node_1
starts- Tries to connect to
peers
- Fails, because no other peers are available
- Listens for connections from
clients
- Tries to connect to
node_2
starts- Tries to connect to
peers
- Succeeds, because
node_1
is available
- Succeeds, because
- Listens for connections from
clients
- Tries to connect to
- Initialise
chain
- Wait for at least 3 nodes on the network
- Intial
node
mines genesis block (pass inchain
, getchain
back)
Hole: Currently, any node can alter the blockchain code, and still mine a valid block. Patch: Blockchain (Rust code) should be compiled with a checksum, and if the checksum fails, the block is invalid.
Hole: If low rep validator is chosen, perhaps its validations should be validated.
-
Reputation is chance-based
-
Story: 25% chance to earn rep on first, 50% chance on second
-
Rep still determines how many server-racks
-
Maybe buy rack with tokens - spend tokens
-
unlock ability to buy rack, by gaining rep
-
Camper starts with
10 tokens
,0 rep
-
Must spend
x tokens
to buyrep
(rack)
Camper is getting hacked. You notice just in time to save 1 rack (10 tokens).
n1
initialises chain (no validation)n1
listens for connectionsn2
connects ton1
n1
sends chain ton2
(no validation)n2
adds self to chainn2
broadcasts chain for validationn1
validates chainn1
broadcasts chain as valid
- Genesis block is mined
- Task is assigned
- Task is submitted
- Task is validated
- Validation result is mined with data
- Block is validated
n1
mines genesis blockn1
gets taskn2
gets chain fromn1
n1
submits taskn2
validates taskn1
mines with validation resultn2
validates and broadcasts chain