hossam-magdy / erc721-nft-zokrates-zksnarks

Decentralized/blokchain-based real-estate listing project using ERC721 (NFT), zero-knowledge proofs (zk-SNARKS / ZoKrates), and open marketplace (OpenSea). It is the final project in Blockchain developer nanodegree: https://udacity.com/course/nd1309

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capstone Project: Decentralized Housing

Links, addresses and TX hashes:

Collection/marketplace on OpenSea: https://testnets.opensea.io/collection/hcustomerc721token

Contracts addresses

Tokens minted and listed for sale:

https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/1 https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/2 https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/3 https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/5 https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/7 https://testnets.opensea.io/assets/0xb30721f2c6873aeec65e43259804ee1541a34f45/9

These tokens were owned and marked for sale by 0x6c0ebe2a2cdbea429fd3719f56fb57d7719396f7, then bought by 0xecc93d9486493ed1022298d1f43305ab85b1ea70.

To run the tests

  • Install truffle of the version mentioned below
  • Clone the repo
  • yarn install
  • truffle test

Versions used:

Truffle v5.4.25 (core: 5.4.25)
Solidity - 0.8.11 (solc-js)
Node v14.18.1
Web3.js v1.5.3
ZoKrates v0.7.10

Development

Using ZoKrates:

ZoKrates CLI

shortcut cmd: yarn zokrates-all

cd zokrates/code
yarn zokrates compile -i ./square/square.zok
yarn zokrates setup
# generates witness with the args (fn inputs) 3 and 9 (3*3 == 9, so the inputs[1] should be 1)
yarn zokrates compute-witness -a 3 9 && cp witness ./generated/witness1
# generates `proof.json`
yarn zokrates generate-proof && cp proof.json ./generated/proof1.json
yarn zokrates export-verifier
yarn zokrates-cp && yarn format

For generating 10 proofs and witnesses (witness, contains the relealed info "square root"): for i in {3..12}; do yarn zokrates compute-witness -a $(( i * 20 )) $(( i * i * 20 * 20 )) && cp witness ./generated/witness$(( i - 2 )) && yarn zokrates generate-proof && cp proof.json ./generated/proof$(( i - 2 )).json; done;

[OR] the detailed/manual version:

docker run -it -v ${PWD}/zokrates/code:/home/zokrates/code -w /home/zokrates/code zokrates/zokrates:0.7.10 /bin/bash

# ref: https://zokrates.github.io/gettingstarted.html
# compile - Generates: `out` binary
zokrates compile -i ./square/square.zok
# perform the setup phase - Generates: `proving.key` and `verification.key` (uses `out` binary)
zokrates setup
# execute the program - Generates: `witness` (uses `out` binary)
zokrates compute-witness -a 337 113569
# generate a proof of computation - Generates: `proof.json` (uses `proving.key` and `witness`)
zokrates generate-proof
# export a solidity verifier - Generates: `verifier.sol` (uses `verification.key`)
zokrates export-verifier
# or verify natively
zokrates verify

Useful resources for ZoKrates and zk-SNARKs

Resources:

  • Fleek makes it easy to build websites and apps on the new open web: permissionless, trustless, censorship resistant, and free of centralized gatekeepers
  • Kite: Code Faster. Stay in Flow. Kite adds AI powered code completions to your code editor, giving developers superpowers
  • If you are interested in becoming an ethereum freelancer in blocklancer will interest you.
  • The World’s First Real Estate NFT, one way to turn this Udacity project into a reality.
  • This interesting article about a new dApp called Bloom
  • Learn Ethereum is a book to go deeper in the technical topics and algorithms in Ethereum. This is an advanced technical book. In the book you will explore the blockchain-based decentralized platform and understand how Ethereum works with Dapps examples.

Expand/Collapse

Source: https://github.com/udacity/Blockchain-Capstone

Udacity Blockchain Capstone

The capstone will build upon the knowledge you have gained in the course in order to build a decentralized housing product.

Project Steps

  1. Clone the project repository
  2. Explore the code base.
  3. Fill out ERC721 Mintable Contract in ERC721Mintable.sol
  4. Write test cases TestERC721Mintable.js
  5. Compile and pass test cases in TestERC721Mintable.js
  6. Implement Zokrates
    • Using Docker to install and instantiate a Zokrates zkSnarks development environment
    • Completes the Zokrates proof in square.code by adding the variable names in square.code
    • Compile program
    • Trusted setup
    • Compute witness
    • Generate Proof
    • Export Verifier.sol
    • Note: This project uses solidity version 0.5.2 so you will be required to update the code in Verifier.sol accordingly based on the compiler errors you receive
  7. Write a test script to verify the solidity contract generated by Zokrates executed successfully - TestSquareVerifier.js
  8. Write test contract for ZK and ERC721 integration - SolnSquareVerifier.sol
  9. Compile and pass with TestSolnSquareVerifier.js
  10. Deploy latest contracts generated by Zokrates (a.k.a verifier.sol)
  11. Deploy SolnSquareVerifier contract to Rinkeby network
  12. Mint 10 tokens
  13. Generate OpenSea marketplace
  14. Test and Verify OpenSea with your SolnSquareVerifier tokens
    • List 5 of your tokens on the marketplace
    • Purchase those 5 tokens using a different address
  15. Complete required documentation and submit!

Project Resources

About

Decentralized/blokchain-based real-estate listing project using ERC721 (NFT), zero-knowledge proofs (zk-SNARKS / ZoKrates), and open marketplace (OpenSea). It is the final project in Blockchain developer nanodegree: https://udacity.com/course/nd1309


Languages

Language:Solidity 84.1%Language:JavaScript 15.2%Language:Shell 0.7%