Skip to content

This repository is a project showcasing the use of Axiom as a ZK coprocessor in order to update the color of an NFT based on a ZKP of historical balances of other tokens owned by the same address.

License

Notifications You must be signed in to change notification settings

koalateectrl/axiom-zk-nfts

Repository files navigation

Axiom Quickstart

Setup Part 1 (Deploying Contracts)

The steps below assume that you have Node.js and Typescript installed on your machine.

  1. Install dependencies npm i and forge install
  2. Create a .env file and copy + paste the contents of .env.example into it. Fill this with your information.
  3. Deploy the contract DummyToken1.
    1. forge create --rpc-url <ALCHEMY_ENDPOINT> --private-key <SEPOLIA_PRIVATE_KEY> src/DummyToken1.sol:DummyToken1
  4. Verify the contract DummyToken1.
    1. forge verify-contract --etherscan-api-key <ETHERSCAN_API_KEY> --chain-id 11155111 <DummyToken1Addr> DummyToken1
  5. Deploy the contract DummyToken2.
    1. forge create --rpc-url <ALCHEMY_ENDPOINT> --private-key <SEPOLIA_PRIVATE_KEY> src/DummyToken2.sol:DummyToken2
  6. Verify the contract DummyToken2.
    1. forge verify-contract --etherscan-api-key <ETHERSCAN_API_KEY> --chain-id 11155111 <DummyToken2Addr> DummyToken2
  7. Deploy the Axiom callback contract ChangeColorClient.
    1. forge create --rpc-url <ALCHEMY_ENDPOINT> --private-key <SEPOLIA_PRIVATE_KEY> src/ChangeColorClient.sol:ChangeColorClient --constructor-args 0x83c8c0B395850bA55c830451Cfaca4F2A667a983 11155111
  8. Verify the contract ChangeColorClient.
    1. forge verify-contract --etherscan-api-key <ETHERSCAN_API_KEY> --chain-id 11155111 --constructor-args $(cast abi-encode "constructor(address,uint64)" 0x83c8c0B395850bA55c830451Cfaca4F2A667a983 11155111) <ChangeColorClientAddr> ChangeColorClient
  9. Deploy the NFT contract ZKColors.
    1. forge create --rpc-url <ALCHEMY_ENDPOINT> --private-key <SEPOLIA_PRIVATE_KEY> src/ZKColors.sol:ZKColors --constructor-args <ChangeColorClientAddr>
  10. Verify the NFT contract ZKColors.
  11. forge verify-contract --etherscan-api-key <ETHERSCAN_API_KEY> --chain-id 11155111 --constructor-args $(cast abi-encode "constructor(address)" <ChangeColorClientAddr>) <ZKColorsAddr> ZKColors
  12. Call the updateNFTAddr function in ChangeColorClientAddr to point it to the ZKColors address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> <ChangeColorClientAddr> "updateNFTAddr(address)" <ZKColorsAddr> --rpc-url <ALCHEMY_ENDPOINT>

Setup Part 2 (Minting Tokens)

  1. Mint N DummyToken1s to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> <DummyToken1Address> "mint(uint256)" <N> --rpc-url <ALCHEMY_ENDPOINT>
  2. Mint M DummyToken2s to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> <DummyToken2Address> "mint(uint256)" <M> --rpc-url <ALCHEMY_ENDPOINT>
  3. Mint an NFT to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> <ZKColorsAddr> "mint()" --rpc-url <ALCHEMY_ENDPOINT>

Generate ZKP

  1. Compile circuit and generate compiled.json.
    1. npx axiom circuit compile app/axiom/balance.circuit.ts --provider <ALCHEMY_ENDPOINT>
  2. Generate proof.
    1. npx axiom circuit prove app/axiom/data/compiled.json app/axiom/data/inputs.json --provider <ALCHEMY_ENDPOINT>
  3. Generate query parameters used to call AxiomV2Query.
    1. npx axiom circuit query-params <ChangeColorClientAddr> --sourceChainId 11155111 --refundAddress <Your EOA Address> --provider <ALCHEMY_ENDPOINT>
  4. Send the query on-chain
    1. cast send --rpc-url <ALCHEMY_ENDPOINT> --private-key <SEPOLIA_PRIVATE_KEY> --value <payment value> 0x83c8c0B395850bA55c830451Cfaca4F2A667a983 <sendQueryCalldata> where sendQueryCalldata is the value in the calldata field from the json output file sendQuery.json that was generated from the previous step.

Sample Addresses

  • DummyToken1: 0xd04D6724Fb95BAda8ef799Ff3E2Cb4728c9f145D
  • DummyToken2: 0x8B17E3629C1253805dbDBAFee6C7382aB5F1Bf75
  • ChangeColorClient: 0xf4bE653537F157Ea1139d4405203C17e7F7445d0
  • ZKColors: 0xa98Da97faE6234b515415fF8BD9496F53E0cBa3b

Frontend Setup

Part 1: Fill out environment variables

  • Fill out /axiom-zk-nfts/.env.example, save as .env.
  • Fill out /axiom-zk-nfts/app/.env.local.example, save as .env.local.

Part 2: Send dummy tokens / nft to your account

  1. Create a Sepolia address, accessible by browser (metamask, walletconnect)
  2. Mint N DummyToken1s to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> 0xd04D6724Fb95BAda8ef799Ff3E2Cb4728c9f145D "mint(uint256)" <N> --rpc-url <ALCHEMY_ENDPOINT>
  3. Mint M DummyToken2s to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> 0x8B17E3629C1253805dbDBAFee6C7382aB5F1Bf75 "mint(uint256)" <M> --rpc-url <ALCHEMY_ENDPOINT>
  4. Mint an NFT to your address.
    1. cast send --private-key <SEPOLIA_PRIVATE_KEY> 0xa98Da97faE6234b515415fF8BD9496F53E0cBa3b "mint()" --rpc-url <ALCHEMY_ENDPOINT>

Part 3: Update circuit inputs and start the development environment

  1. Update axiom/data/inputs.json with the latest Sepolia block number, dummy token addresses, your address, and your NFT token ID.
  2. Navigate to the '/app' directory in the terminal.
  3. Enter 'npm run dev'.
  4. Open your browser and navigate to 'localhost:3000'.
  5. Follow the app instructions to generate a proof and send a query.

About

This repository is a project showcasing the use of Axiom as a ZK coprocessor in order to update the color of an NFT based on a ZKP of historical balances of other tokens owned by the same address.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published