okdonga / GiftList

Alchemy Ethereum Bootcamp Week 2 Project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gift List

Project Description

The goal of this project is to demonstrate an understanding of merkle trees by building a client and server system. In a blockchain network, all nodes must store and verify transactions, but data storage capacity can be a limiting factor. In this project, the server can only store up to 32 bytes of data and is unable to store an entire list of names (as seen in the provided niceList.json).

The client's objective is to determine whether a given name is present in the list of names. To accomplish this, I utilized my knowledge of creating valid merkle trees to generate a merkle root and its corresponding merkle proof.

Specifically, the client generates a merkle proof and passes the name, proof, and merkle root to the server. The server then verifies if the name is present in the merkle tree by reconstructing the merkle root using the provided proof and comparing it to the merkle root transmitted by the client.

How it works

Note: install packages for client and node first

node server/index.js 
node client/index.js [name]

To pass a name as a command line argument when running the client, use the following format: node client/index.js "Sidney Kertzmann"

Instructions

To get started with the repository, clone it and then run npm install in the top-level directory to install the depedencies.

There are three folders in this repository:

Client

You can run the client from the top-level directory with node client/index. This file is a script which will send an HTTP request to the server.

Think of the client as the prover here. It needs to prove to the server that some name is in the MERKLE_ROOT on the server.

Server

You can run the server from the top-level directory with node server/index. This file is an express server which will be hosted on port 1225 and respond to the client's request.

Think of the server as the verifier here. It needs to verify that the name passed by the client is in the MERKLE_ROOT. If it is, then we can send the gift!

Utils

There are a few files in utils:

  • The niceList.json which contains all the names of the people who deserve a gift this year (this is randomly generated, feel free to add yourself and others to this list!)
  • The example.js script shows how we can generate a root, generate a proof and verify that some value is in the root using the proof. Try it out from the top-level folder with node/example.js
  • The MerkleTree.js should look familiar from the Merkle Tree module! This one has been modified so you should not have to deal with any crypto type conversion. You can import this in your client/server
  • The verifyProof.js should also look familiar. This was the last stage in the module. You can use this function to prove a name is in the merkle root, as show in the example.

About

Alchemy Ethereum Bootcamp Week 2 Project


Languages

Language:JavaScript 100.0%