• This repository has been archived on 01/Mar/2022
  • Stars
    star
    144
  • Rank 247,504 (Top 6 %)
  • Language
    Rust
  • Created almost 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Obsolete - don't use

Confidential Token Program

This program is a companion to the SPL Token program that enables confidential (not anonymous) transfers of SPL Tokens.

Any SPL Token can take enable confidential transfers. However SPL Tokens with a freeze authority can optionally enable a feature that allows a global auditor to also view all confidential transfer balances, and the freeze authority extends to confidential token accounts.

The overview and the description of the cryptographic protocol can be found in the work-in-progress documents part1 and part2.

Development Environment

Setup

A master branch of the Solana monorepo is required for development.

Then clone this repository, then run

$ ./setup.sh

Transfer Demo

To run the simple confidential transfer demo, first build the BPF program:

$ cd ./program/
$ cargo build-bpf

Then start the solana-test-validator:

$ ./solana/validator/solana-test-validator --reset --limit-ledger-size 500000000 \
    --bpf-program ZkTokenXHhH6t1juaWF74WLcfv4XoNocjXA6sPWHNg1 \
    target/deploy/spl_zk_token.so

Finally in another shell, run:

$ cd ./demo/
$ cargo run -- -ul

Use cases

Enabling confidential transfers for an SPL Token mint

Before a confidential transfers may be used on a given SPL Token, the ConfidentialTokenInstruction::ConfigureMint instruction must be executed. Depending on the configuration of the SPL Token, this instruction may either be permissionless or require the Mint's freeze authority to sign.

ConfidentialTokenInstruction::ConfigureMint notably creates the single omnibus token account used to store all SPL Tokens deposited into the confidential token accounts.

Note: As there is one omnibus token account for each token mint, confidential token deposits and withdrawals for a given SPL Token will be implicitly serialized by the runtime during transaction execution. An alternative would be for each SPL Token to have several omnibus token accounts that users could random select for deposits and withdrawals. However this complicates withdrawals in particular, as now clients need to potentially check multiple omnibus accounts to to find one with sufficient funds for the withdrawal. A rebalancing scheme between multiple omnibus accounts would likely be needed as well.

Determining if confidential transfers has been enabled for an SPL Token mint

Check for the existence of the omnibus SPL Token account. Use get_omnibus_token_address() to derive its address for an SPL Token mint. The token balance of the omnibus account contains the total number of tokens that have been deposited into the confidential transfer system

Reading the contents of the get_transfer_auditor_address() account will indicate if a transfer auditor is enabled for the SPL Token mint. If so, all confidential transfers for the SPL Token must include additional ciphertext to allow the transfer auditor to observe the transfer amount.

Enabling confidential transfers for a particular token holder

Once confidential transfers are enabled for a SPL Token mint, a token holder can opt in to confidential transfers by executing the ConfidentialTokenInstruction::ConfigureAccount instruction and providing their confidential public encryption key.

The confidential token account address is a PDA derived from their normal token.

Determining if a token holder has enabled confidential transfers

Check for the existence of the user's confidential token account. Use get_confidential_token_address() to derive its address from the user's SPL Token account.

Depositing funds into a confidential token account

SPL Tokens can be deposited into any confidential token account using the ConfidentialTokenInstruction::Deposit instruction.

Withdrawing funds from a confidential token account

SPL Tokens can be withdrawn from a confidential token account using the ConfidentialTokenInstruction::Withdraw instruction.

Confidential token account ownership changes

Since the confidential token account is a companion to a normal SPL Token account, ownership changes of the SPL Token account automatically convey to the confidential token account.

However the close authority of the SPL Token account does not convey to the confidential token account.

Note that it is possible to "brick" a confidential token account by closing the corresponding SPL Token account, as no future instructions that require the account authority would be permitted. This is unlikely to occur unintentionally because the confidential token account must be created by the same wallet that holds the SPL Token account, and therefore is already confidential token aware.

Freezing of confidential funds

Freezing the primary SPL Token account also causes the companion confidential token account to be frozen.

Making a confidential transfer [TODO: This section is out of date]

Multiple transactions are required to perform a confidential transfer due to the current max the transaction size of 1232 bytes.

To affect a transfer, the sender must issue two ConfidentialTokenInstruction::SubmitTransferProof instructions, in separate transactions in parallel. Once both transactions are confirmed they then issue a ConfidentialTokenInstruction::Transfer instruction. These instructions are in flux and are likely to change as the design evolves

Since the transfer process is not atomic, it's possible for multiple senders to race during a transfer to the same recipient. In this case, one of the senders will lose the race and will need to retry the entire transfer sequence. This condition will be reported via a specific program error code.

Confidential transfers are not supported in cross-program invocations.

More Repositories

1

solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Rust
11,861
star
2

solana-program-library

A collection of Solana programs maintained by Solana Labs
Rust
2,861
star
3

solana-web3.js

Solana JavaScript SDK
TypeScript
1,749
star
4

dapp-scaffold

Scaffolding for a dapp built on Solana
TypeScript
1,636
star
5

token-list

The community maintained Solana token registry
Go
1,415
star
6

wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.
TypeScript
1,180
star
7

solana-pay

A new standard for decentralized payments.
TypeScript
1,173
star
8

example-helloworld

Hello world on Solana
TypeScript
855
star
9

solana-season

338
star
10

break

Break Solana Game
TypeScript
279
star
11

governance-ui

TypeScript
260
star
12

explorer

Explorer for Solana clusters
TypeScript
166
star
13

defi-hackathon

165
star
14

octane

Octane is a gasless transaction relayer for Solana.
TypeScript
164
star
15

chatgpt-plugin

TypeScript
160
star
16

ecosystem

Project files for Solana ecosystem members
150
star
17

solana-solidity.js

Compile, deploy, and use Solidity contracts on Solana
TypeScript
114
star
18

oyster

TypeScript
109
star
19

oyster-swap

TypeScript
109
star
20

solana-accountsdb-plugin-postgres

Rust
72
star
21

solana-payments-app

Solana Pay for Commerce Platforms
TypeScript
68
star
22

solana-bigtable

Shell
62
star
23

oyster-lending

TypeScript
60
star
24

whitepaper

Solana whitepaper LaTeX source
TeX
60
star
25

perpetuals

Solana perpetuals reference implementation
Rust
57
star
26

dexterity

Reference implementation of a decentralized exchange for custom instruments, risk, and fees
Rust
55
star
27

eslint-plugin-require-extensions

JavaScript
48
star
28

wallet-standard

TypeScript
46
star
29

solana-pay-scaffold

Scaffolding for a dapp using Solana Pay
TypeScript
41
star
30

solana-perf-libs

C and CUDA libraries to enhance Solana
C
37
star
31

example-tictactoe

Tic-Tac-Toe built on Solana
JavaScript
34
star
32

wormhole-hackathon

34
star
33

governance-program-library

Rust
33
star
34

example-token

Obsoleted by https://spl.solana.com/token (Token Example)
Rust
33
star
35

solana-ping-api

solana ping api server
Go
32
star
36

example-messagefeed

Simple message feed built on Solana
JavaScript
32
star
37

browser-extension

Solana Chrome Extension
TypeScript
32
star
38

security-audits

Published security audits
31
star
39

obsolete-dontuse-example-webwallet

Example Solana Web-based Wallet
JavaScript
31
star
40

platform-tools

Shell
30
star
41

cluster

Cluster Infrastructure
Shell
25
star
42

rust-bpf-sysroot

Rust sysroot source for Berkley Packet Filter Rust programs
C
20
star
43

governance-docs

JavaScript
19
star
44

solana-labs.github.io

Organization Pages
16
star
45

auto-emissions

Python
16
star
46

token-ops

Scripts and tools for token accounting and operation
Shell
14
star
47

example-move

Solana example which runs a Libra Move program
JavaScript
14
star
48

rust-bpf-builder

Dockerfile
13
star
49

solana-voib-demo

Voice over Internet & Blockchain (VoIB) demo
Rust
13
star
50

buffer-layout-utils

TypeScript utilities for using buffer-layout with Solana programs
TypeScript
12
star
51

sealevel

A parallel runtime for layer 1 blockchains
11
star
52

eslint-config-solana

ESLint rules to be shared across all Solana Labs projects
JavaScript
11
star
53

networkexplorer

Retired
JavaScript
11
star
54

twamm

Solana twamm reference implementation
TypeScript
11
star
55

network_simulation

Python
11
star
56

governance-api

TypeScript
10
star
57

wbtc

TypeScript
10
star
58

bench-tps-dos-test

UDP and QUIC dos test for buildkite using bench-tps utility
Shell
9
star
59

token-aggregator

Aggregates tokens listed in onchain token registry
TypeScript
9
star
60

newlib

Newlib is a C library intended for use on embedded systems.
C
9
star
61

solana-flagged-accounts

A community-maintained registry of flagged accounts
JavaScript
8
star
62

launchpad

Solana launchpad reference implementation
Rust
8
star
63

llvm-builder

Builds customized LLVM for Solana
Dockerfile
8
star
64

tour-de-sol

Tour de SOL
Rust
8
star
65

interns-codehub

Public repo for Solana interns
TypeScript
8
star
66

solminer

Cross-platform Solana Replicator UI ⛏️
JavaScript
7
star
67

oyster-margin

7
star
68

cargo-run-solana-tests

Cargo command to compile and run BPF test
Rust
7
star
69

ledger-app-solana

Solana app for Ledger Wallet
7
star
70

secure-wrap-token

Rust
7
star
71

dc-homedir-skeleton

Base directory struct for the `solana` user on Solana's datacenter infrastructure
Shell
6
star
72

contributor-access-policy

This document outlines the procedure for getting contributor access to various Solana Labs source code repositories
6
star
73

reddit-scaling-demo

Demo for Reddit scaling
Rust
6
star
74

inc-20210825

Tool for audit and reclaim of delegated SPL Token accounts
Rust
6
star
75

bridge-adapter

TypeScript
6
star
76

kurtosis-solana-testing

Rust
5
star
77

governance-ui-landing

Governance UI Landing Page - realms.today
TypeScript
5
star
78

k8s-cluster

5
star
79

farms

Solana Farms
Rust
5
star
80

solana-build

Rust
4
star
81

solana-tokens

Utility for distributing Solana tokens
4
star
82

prettier-config-solana

A Prettier config consistent to all Solana Labs projects
4
star
83

solana-graphql-playground

GraphQL web IDE for working with the Solana RPC-GraphQL resolver
TypeScript
4
star
84

validator-tracker

https://metrics.solana.com:3000/d/jrdi4uUWz/validator-tracker
Shell
3
star
85

oyster-bridge

3
star
86

solana-pkcs8

A utility to parse DER-encoded PKCS #8 files
Rust
3
star
87

governance-sdk

Governance SDK
TypeScript
3
star
88

solana-json-rpc-https-proxy

DEPRECATED - Provides a TLS proxy for web-based Solana JSON RPC users
Shell
2
star
89

oyster-gov

1
star
90

ipfs-ledger

1
star
91

sync_test

For developing a Github Action to sync solana-labs/solana from anza-xyz/agave
1
star
92

spl-token-subscription

Rust
1
star