Coder Social home page Coder Social logo

opact-kadena's Introduction

Opact Wallet - Kadena Blockchain

This repo contains the source code for the Opact Wallet, a web-based ZK-powered private wallet for the Kadena blockchain with innovative Anti Money Laundry features.

The goal of the wallet is to provide users with an easy to use privacy tool that allows them to:

  • Own assets without anyone being able to see their balance
  • Receive payments without revealing their finances to the payer
  • Make payments without revealing the source wallet or its balance

The app should therefore implement a bank secrecy layer on blockchain.

At the same time, the wallet must have a mechanism to disallow illicit actors from making use of it, without any loss to regular user's privacy, security or decentralization.

How it works

The protocol works as a smart contract in the Kadena Blockchain that carries a zero knowledge circuit within it. Opact Wallet is an abstracted wallet - that means it is a single smart contract that receives funds from all users that use it. The smart contract is responsible for keeping track of the balance of each user, and for allowing users to withdraw their funds.

This means that the only information that is effectively stored in the blockchain are the transactions depositing and withdrawing from the Opact Wallet smart contract - because of zero knowledge proofs, however, it is impossible for an external observer to infer who is paying whom and who is the real owner of assets.

Opact Wallet Diagram

Zero Knowledge Circuit

The key to making the protocol work is the zero knowledge circuit. The circuit is a mathematical proof that allows the smart contract to verify that a user is allowed to withdraw funds from the Opact Wallet without revealing any information about the user's balance or the source of the funds.

UTXOs

The system is based on Unspent Transaction Outputs (UTXOs) - a concept pioneered by Bitcoin and later applied in a zero knowledge context by Zcash. This explanation assumes understanding of the UTXO model.

Each UTXO in Opact Wallet is composed of the following variables:

{
    "token": "reference to the token type that the UTXO represents",
    "amount": "amount of tokens in the UTXO",
    "pubkey": "public key of the wallet of the owner of this UTXO",
    "blinding": "randomly generated value"
}
  • pubkey refers to the key-pair that represents the Opact Wallet account belonging to the user
  • token is the hash of a reference to the contract of the token that is stored in the UTXO. This is used to allow the Opact Wallet to store multiple tokens and different asset types such as NFTs.
  • amount is the amount of tokens stored in the UTXO
  • blinding is a randomly generated value that is used to hide the amount of tokens stored in the UTXO. If there were no blinding factor, UTXOs owned by the same wallet with the same amount of funds would always be equal.

Depositing assets

The way through which Opact Wallet keeps balances private is by storing all state within a single Merkle Tree. UTXOs are not stored in the merkle tree as plain text though, they are hashed using the Poseidon Hash. In this way it is impossible to infer the assets that they encode for any observer.

When users deposit assets they simply create new UTXOs with the values deposited and only submit the hashes publicly on chain. The smart contract then adds the UTXOs to the merkle tree and updates the root hash.

This setup only keeps hashes of the UTXOs on-chain which means there is no way to infer the value, type of asset or owner of each UTXO. This generates a powerful privacy system, but it also generates a problem: how can the users keep track of their own balance if they don't know the value of their UTXOs? To solve this problem, every time a user deposits funds, they also send to the contract an encrypted version of the UTXO, using their wallet's public key as the encryption key. This way, the user can decrypt the UTXO and know its value, but no one else can.

Circuit Deposit Flow

Withdrawing assets

The user can then withdraw funds by submitting a zero knowledge proof that they own a UTXO with the amount of funds they want to withdraw. One of the byproducts of these proofs are nullifier values, these values are deterministic for each UTXO and are saved to the contract to hinder double spends of UTXOs - if values were simply removed from the merkle tree then it would be easy to infer their original owner and break the anonymity of the protocol.

To perform a withdraw the user provide a Zero Knowledge proof showing that:

  • They know the private key of the wallet that owns the UTXO
  • They know the unencrypted data of the UTXOs they intend to spend
  • The value of the withdrawal + the value of the change UTXOs being created is equal to the value of the UTXO they are spending
  • The UTXOs being spent have not been flagged as malicious by the AML policy
  • The UTXOs being spent have not been spent before

Anti Money Laundry policy

Opact Wallet includes a framework to allow security data providers to flag UTXOs as malicious. Whenever a UTXO is marked as malicious the circuit can enforce it not to be spendable. This allows, for instance, all deposits that are flagged as coming from smart contract hacking to be automatically blocked from spending.

This works by requiring all withdraw transactions to submit a list of flagged illicit transactions - the ZK circuit evaluates that the UTXOs being used do not belong to that list. There are 2 options on how to enforce this:

  1. Centralized AML provider - The contract designates a specific account as the AML provider and allows that account to update its on-chain list of malicious UTXOs. Whenever a user submits a ZK proof to withdraw, the contract checks that the list used to build the proof matches the list currently stored in the contract's state.

Circuit AML Flow Centralized

  1. Decentralized AML provider - The contract doesn't hold any list of flagged transactions in its state. However, different AML providers can provide public lists and frontends providing access to the contract need to enforce one of those lists. Users that submit invalid lists with their withdraw transactions chain are able to withdraw their assets, however it is publicly visible that they did so by not following the AML policy and can easily be tracked by authorities.

Circuit AML Flow Decentralized

The project chose, for its initial implementation, to not enforce any particular AML protocol in the smart contract level. The security is instead being enforced on the frontend level. This allows for a more flexible implementation and for the possibility of multiple AML providers to coexist.

The frontend hosted by Opact itself is going to chose a specific AML provider. It is possible to identify all transactions that adhere to the AML policy and separate them from eventual rogue transactions directly on chain. Thus bad actors are not able to take advantage of the protocol.

opact-kadena's People

Contributors

1mateus avatar davibauer avatar veigajoao avatar

Stargazers

 avatar

Watchers

Ashwin avatar  avatar

Forkers

1mateus

opact-kadena's Issues

[SDK] define SDK interface

SDK must provide:

  • all contract methods
  • Relayer interactions
  • ZK methods (generate proof)
  • API methods (fetch events data)

SDK must map all functionaity that frontend is going to need and implement it.

[DESIGN] Global Menu

Create a new navbar to be used on all pages.
( Add "Blog" to menu)

  • Desktop
  • Tablet
  • Mobile

[DESIGN] App - Discovery

To better understand how the wallet network functions and how each one positions itself, it is necessary to conduct a benchmark analysis of their key features and note any potential pain points that may arise during the user journey.

Since the problem to be solved has already been identified, there is no need to conduct research specifically aimed at solving a problem. Instead, the research should focus on understanding how the crypto and wallet ecosystem operates, identifying key players, main features, and major pain points.

  • Benchmark Near
  • Benchmark Metamask
  • Benchmark Zkbob
  • Benchmark Uniswap
  • Benchmark Railway
  • Benchmark Curve
  • Matriz CSD

[CIRCUIT] circom circuit structure

ZK circuits implement the state and state transitioning logic of the application. They define how user’s private balances are going to be stored and how users can consume them in a private manner.

Technologies

[Circom](https://docs.circom.io/)

[Snarkjs](https://github.com/iden3/snarkjs) (Plonk verifier)

Styleguide

There are no defined styleguides for the Circom language. Therefore we are going to follow the same styleguide that is being used for TypeScript wherever it applies: https://github.com/airbnb/javascript

Documentation

There are also no in code documentation standards purpose built for circom. We are also going to apply logic from different languages here.

Since circom comments are identical to Javascrpit (// for single line and /* */ for multi line) we are also going to be following TypeDoc guidelines for in code documentation: https://typedoc.org/guides/doccomments/

Requirements

  1. Must allow transactions in any kind of asset
  2. Must allow proofs to be made disassociating transactions from known flagged malicious UTXOs
  3. Must allow viewing key to be added
  4. Must allow proofs to be made over a large number of UTXOs

Specifications

  1. Must store UTXOs in accumulator (merkle tree)
  2. Must enforce that UTXOs are encripted by a given public key
  3. User must provide sparse merkle tree to mark possible UTXO origins as implemented in [privacy pools](https://github.com/ameensol/privacy-pools/tree/main)
  4. User must be able to provide viewing key to decipher transaction (this can be implemented thorugh a different encrypted version of the UTXO, encripted with the viewing key and only stored in events or calldata in contract)

[DESIGN] Export graphics elements to Canva

To assist the marketing team in creating social media posts with the new visual identity of Opact, it is necessary to export certain items and create new ones to maintain brand consistency.

  • Logos
  • Colors
  • Web page elements
  • Post templete - Text Only
  • Post templete - Text and image

[DESIGN] Landing Page - Mobile Version

Create the responsive version of the Opact website for the mobile version of the landing page

  • Menu
  • Banner
  • Section 2
  • Section 3
  • Section4/5
  • Contact us
  • Footer

[CONTRACT] implement smart contract

Implement the described contract.

*This is a megatask - must be broken down before assignment. Create one task for each function in the contract (data engineering must come first).

Next items

  • Create deploy scripts for local server / testnet
  • Investigate how to use gas stations / relayers

Pending items

  • Find a way to set properties contract-kip-0011 and/or contract-kip-0005 as optional or separate the transact method into transact-fungible and transact-poly-fungible.
  • Review Args, ExtData and Token schemas
  • Review properties that must be in the hash (extdata and token)

Hash

  • Hash extdata using blake
  • Hash token using blake

Validations

  • Validate if known merkle root
  • Validate nullifiers
  • Validate public amount
  • Verify proof in plonk
  • Validate extdata hash
  • Validate token hash
  • Validate deposit limits
  • Use map for nullifiers
  • Use groth16 instead of plonk for proof validation

Transactions

  • Deposit token using KIP 0005 (fungible)
  • Deposit token using KIP 0011 (poly fungible)
  • Withdraw token using KIP 0005 (fungible)
  • Withdraw token using KIP 0011 (poly fungible)
  • Implement module reference to inject the token implementation at runtime
  • Add support for native Kadena token deposits/withdrawals (It's already fungible-v2)

Merkle

  • Insert new leaf from output commitment1
  • Insert new leaf from output commitment2
  • Set each nullifier (public values) as spent

Events

  • Emit event for each new commitment
  • Emit event for each new nullifier

[DESIGN] Opact - Webpage - Concept

With the change in marketing strategy, the Opact Landing Page will be renamed to Opact Wallet and will be a tab on the Opact (Hub/Lab) website.

Opact Website Creation

  • Content
  • Sketch
  • Wireframe

[DESIGN] Opact products logos

Decided in the meeting that Opact will be a service provider/consultancy focused on Zero Knowledge (privacy and security).

With this change, it is necessary to update the Opact logo, creating a logo for each project front:

  • Opact Wallet
  • Opact Hub
  • Opact Lab

Having multiple logos might devalue the central name 'Opact.' One option to prevent this could be to keep the name 'Opact' as the central element (Hub/Lab), and then use 'Opact Wallet' to indicate that it is a part of 'Opact'."

[DESIGN] Opact Wallet - Desktop

The mobile app version has been completed. Create a desktop preview version for all flows.

  • Benchmark

Login

  • Create Wallet
  • Recovery Wallet

Home

  • Actions
  • Tokens
  • NFT
  • NFT View
  • Actions (last 8)
  • Side Menu
  • Top Bar
  • Balance

Send

  • Send Flow

Receive

  • Receive Flow

Deposit

  • Deposit Flow

History

  • Activity Flow
  • Search Results | Calendar
  • Search Results | Search
  • Search Results | Filter

Settings

  • Settings Flow

Faucet

  • Faucet Flow

[FRONT] Implement app

Implement the app as a vite app.

*This is a megatask - must be broken down before assignment. Create one task for each functionality in the app.

[DESIGN] Landing page mobile

The desktop version has been finalized, and now it is necessary to make it responsive for mobile.

  • Grid
  • Menu
  • Banner
  • Section 2
  • Section 3
  • Section4/5
  • Contact us
  • Rodapé

[DESIGN] Modal Hide Your Cash Redirect

For users accessing the 'Hideyour.cash' website, a message will appear informing them that the solution has undergone a rebrand and that they need to access the new link to use the application.

[DESIGN] Branding

Logo, base colors and typography for the brand.

  • Colors
  • Logo (typography + iconography)
  • Typography

[DESIGN] Landing page desktop - illustration for banner

Create a banner for the desktop version of the landing page, which will be animated later.
The same banner will also be created for the mobile version of the website, along with its animation.

About the Banner:
The model on which the banner will be based has been defined and it will be 'a component of the Opact logo with elements that simulate a transaction

  • Concept
  • First Design
  • Final Design

[DESIGN] Opact - Webpage - Visual

  • Menu
  • Head
  • Section 1
  • Section 2
  • Section 3
  • Section 4
  • Contact
  • Add Content
  • Desktop (1440)
  • Desktop (1280)
  • Desktop (1024)
  • Tablet (768)
  • Mobile (360)

[CIRCUIT] Implement secure encryption algorithm

Simple ElGamal encryption is not sufficient to guarantee privacy. Ethereum keypair based crypto is not yet implemented in circom.

We need to implement a viable encryption scheme for in-circuit usage so that it can be added to the main circuit and allow reading key options on transactions data.

[DESIGN] Landing page animation

Create animation for web page:

The animation should be created in 3 formats: Mobile, Desktop, and Tablet to maintain the responsiveness of the site.

The content of the animation has not been defined yet. Meetings will be held to determine those details.

  • Desktop
  • Mobile
  • tablet (?)

[CONTRACT] Plonk in Pact

Implement Plonk verifier as a pact module.

Base project on solidity and HYC’s implementations.

Calculation steps:

  • Keccak
  • Templates EJS
  • Challenges
  • Lagrange
  • pl
  • t
  • points
  • pairing
  • Keccak-bs gas test

[Design] - Menu widget for Blog

The menu design allows for using widgets to facilitate access to the blog

Create a Blog widget for menu:

  • Wireframe
  • Desktop
  • Tablet
  • Mobile

[BACKEND] Base Kadena indexer infrastructure

Deploy the folowing infrastructure to our cloud provider:

  • Chainweb-node (with required chainweb-data configs)
  • Chainweb-data (plug with chainweb node and database already initialized)
  • Postgres (With initilization SQL script)

Postgres initialization must:

  • include all tables that are required by chainweb-data
  • include new tables that we are going to use to feed our events
  • create post insert trigger on tables fed by chainweb-data so that it parses the information and saves it to the tables for our events

https://github.com/kadena-io/chainweb-data/blob/master/node-config-for-chainweb-data.yaml

https://www.postgresql.org/docs/current/sql-createtrigger.html

[BACKEND] Implement contract interface in Postgres

Alter postgres initialization to:

  • include correct interface for contract events
  • include correct processing in after insert triggers to populate event tables

For this task to be considered done the indexer must populate the DB with all events emitted by the contract in their respective tables.

[DESIGN] Landing Page Desktop - Visual

The website has been divided into 6 sections. I will list all the sections here along with their status. Each section has its own content, and the first section will be some kind of animation. A deep dive into benchmarking is necessary.

Keep in mind:
Professional page with an institutional character.
Focus on institutions that will look at the page to evaluate the quality of the content.
Elements that refer to blockchain, privacy, and compliance (for example, connected blocks, padlocks, legal artifacts, etc.).
Incorporate elements from the cypherpunk culture.

  • Menu
  • Section 2
  • Section 3
  • Section4/5
  • Contact us
  • Rodapé

[SDK] Implement SDK as TS package

Implement the described SDK as a TS package that can be used in front and backend by other projects.

*This is a megatask - must be broken down before assignment. Create one task for each method in the SDK.

[DESIGN] Landing Page Desktop - Wireframe

After creating the content, we will structure it into a landing page template organized by sections.

  • Content structuring (ordering)
  • Definition of the number of page sections
  • Definition of the content for each section

[DESIGN] Naming

Select name for the product. Must:

  • Not associate directly with Kadena chain
  • Be more friendly and professional than Hideyour.cash

[DESIGN] Rebrand Hideyour.cash

The 'Hide Your Cash' will now be one of Opact's solutions.

With this change, it will be necessary to rebrand the solution to align with Opact's design standards.

Logo - Opact Tickets

  • Create a logo
  • Upload logo in Canva and Drive

New Hide Your Cash flow layout // Opact Tickets

  • Deposit Flow
  • Withdraw Ticket Flow
  • Feedback cards (sucess or error)
  • Add "More info" to cards
  • Transaction Anonymity
  • Background for Opact Tickets

Webpage - Redesign Content for page

  • Wireframe
  • Desktop
  • ● 1440
  • ● 1280
  • ● 1024
  • Tablet
  • Mobile
  • Section Opact Tickets in Headpage
  • Add new page to the Global Menu

Head page - update

  • Opact Wallet Section
  • Opact Tickets Section

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.