Purplecoin Core integration/staging tree

Overview

ℙurplecoin

Discord _pdf whitepaper

Official implementation of Purplecoin, the first stateless cryptocurrency. Requires Rust Nightly >=v1.63.0.

WARNING The source code is still under heavy development. Use at your own risk.

Running tests

Type the following to run the test suite:

cargo +nightly test

Features

  • Scalable: Purplecoin is made up of 256 shards, each representing a different blockchain that processes transactions concurrently. The average transaction size is 450 bytes, with a maximum block size of 380kb, and a production rate of 256 blocks per 30 seconds we can achieve ~12000 transactions per second on a blockchain system that has roughly the same safety guarantees as Bitcoin. Shards are processed in groups, called "shard sectors" in order to stabilise the required hashrate to successfuly attack the system.
  • Decentralized & Secure: Scalability usually comes at the cost of centralization. For example Proof of Stake consensus is scalable and green but brings the security of the network in the hands of the few. Purplecoin fully uses Proof of Work, the most secure and decentralized consensus algorithm. Miners secure the network as is the case of Bitcoin
  • Stateless: Nodes are not required to store all past transactions in order to validate new blocks. A miner only requires storing the latest 50 block headers of each shard, which total a size of 20mb, in order to start mining and fully validating new blocks across all shards. This means that miners and ultra-light nodes can run in memory only mode and and still be able to fully validate blocks.
  • Fast Sync: Due to the stateless design, nodes without a transaction history do not have to download all of the blocks from genesis and can synchronize with the network in seconds. Furthermore, we can still validate new blocks while querying for past transactions. For comparison, synchronizing with the Bitcoin network, regardless of the number and timespan of transactions, takes several days using the same internet speed. When using a trusted bridge, there is no need to query past blocks as the bridge stores and manages the UTXO set.
  • Energy Efficient: Green PoW implementation designed to reduce energy consumption from mining up to 50%

Use cases

  • E-Notary: Due to achieving scalability at the consensus and state layers, Purplecoin can function as an e-notary tool. In order to prove a document has been filed, one only needs the document itself and the witness for the state update. In case of non-encrypted, public documents, the blockchain can serve as a decentralized repository of such documents and can be efficiently queried.
  • Decentralized File Storage: An overlay protocol can be implemented where files are stored in encrypted form on the blockchain and can be efficiently queried.
  • Decentralized Order Book Exchange: The stateless nature of Purplecoin allows decentralized trading without using AMMs but instead using a traditional order book model. Liquidity providers (traditional market makers in our case) can withdraw liquidity at will without compromising the security of the system. Advanced trading strategies can be implemented same as in a traditional Order Book exchange.
  • Transact/Trade Bitcoin, Ethereum, other coins or FIAT with lower fees: The transaction format of Purplecoin coupled with the OBDEX implementation allows transacting with alternative currencies without ever owning any purplecoins. Assuming stablecoin implementations will emerge after launch, one can buy stablecoins or wrapped coins on the Purplecoin blockchain, transact or trade using them, then withdraw them at a later date, all without owning purplecoins. Any token built on top of the Purplecoin blockchain, except NFTs, can be used to pay transaction fees.

Advantages when compared to Bitcoin

  • Scalable
  • Schnorr signatures
  • Advanced smart contracts
  • Merkelized Abstract Syntax Trees
  • Constant chain size
  • Decentralized mining pools
  • Multi-asset
  • Can be mined using the CPU
  • Can be mined on a smartphone via decentralized mining pools

Disadvantages when compared to Bitcoin

  • If one transfer involves outputs stored on multiple shards, it requires settlement on each involved shard. Atomicity is possible only on single-shard transfers
  • Since nodes are not required to store the whole UTXO set in order to validate new blocks, light-nodes have to download their balances from an external party such as a long-running archival node. In theory, there is the non-zero possibility that no node on the network will store the unspent outputs if there is no node online specifically listening for them. In practice, this will almost definitely not happen but can introduce a DOS vector for light-nodes

Advantages when compared to Ethereum v1.0

  • Scalable
  • Schnorr signatures
  • Constant chain size
  • Decentralized mining pools
  • Can be mined using the CPU
  • Can be mined on a smartphone

Disadvantages when compared to Ethereum v1.0

  • No global state, all contract state is passed as an input to the contract
  • Contracts cannot interact with other contracts

Advantages when compared to Ethereum v2.0

  • Simple architecture, more easily provable that it is decentralized/secure
  • Due to the simpler architecture, a higher number of shards is possible, which equals better scalability
  • Energy efficient while not using Proof of Stake, which brings a degree of centralization as a cost to energy efficiency

Disadvantages when compared to Ethereum v2.0

  • While the Green PoW mining model used in Purplecoin is 50% energy efficient, Proof of Stake is 98% energy efficient

Architecture

More details about the architecture.

Sharded Nakamoto Consensus

Purplecoin uses Sharded Nakamoto Consensus to scale beyond the limited transaction throughput of traditional blockchains such as Bitcoin or Ethereum.

Instead of storing a single blockchain of transactions, we would instead store n blockchains with the same consensus rules, each with its own UTXO set and Proof of Work.

In this way, the total balance can be represented as the sum of unspent outputs across all shards. Each shard is an independent blockchain with independent consensus. In this way, transactions are processed concurrently.

For example let's assume Alice wants to send Bob 10 XPU. Alice has two unspent outputs: 7 XPU on shard A and 5 XPU on shard B. She would then create two independent transactions on shard A and B which would create one output of 7 XPU on shard A that Bob can spend and two outputs on shard B: one for 3 XPU which Bob can spend and a 2 XPU change output which Alice can spend.

Scalability benefits of Sharded Nakamoto Consensus

In Sharded Nakamoto Consensus, the total transaction throughput of the system is equal to the throughput of a single chain times the number of shards.

For example, let's suppose that a single shard can process 12 transactions per second, roughly the throughput of the Ethereum blockchain. In the case of Purplecoin, we have 256 equivalent chains that process transactions concurrently, yielding a total of 12 * 256 = 3072 TPS. While of course in our case some transactions might span multiple shards thus creating overhead when compared to a single chain, it would be very rare that a transaction spans all of the shards.

Downsides of Sharded Nakamoto Consensus

The design of this system, however, implies certain downsides compared to traditional blockchain systems:

  • The sharded architecture makes atomic transfers across shards impossible. In the case atomicity is required, a transfer on a single shard should be performed.
  • Shards are independent blockchains, requiring a full-node to process multiple blockchains at the same time. Of course, a full-node can actually be a cluster of nodes, each processing and storing one or several of the shards.
  • Multi-shard transfers might be partially reversed in case of a fork.

Partially spendable outputs

Outputs can be partially spent according to spending script rules, allowing things such as an atomic decentralized asset exchange mechanism.

Decentralized asset exchange

By allowing outputs to be partially spent, and by combining different spending conditions, we can build a decentralized asset exchange where quotes are posted off-chain but settlements happen atomically on-chain. For example, let's asume we have a stablecoin named XUSD with a 1:1 exchange rate to 1 USD, now for the sake of example let's assume 1 XPU is worth 10 XUSD and we pay a miner fee of 0.01 XPU:

  • Alice has one output of 10 XUSD and wants to exchange 5 XUSD for XPU
  • Bob has 1 XPU output he quotes using a spending condition for 10 XUSD.
  • Alice creates a transaction with the following inputs: Bob's XPU input, Alice's XUSD input and it creates the following outputs:
    • Output of 5 XUSD to Bob
    • Output of 5 XUSD to Alice
    • Output of 0.5 XPU to Bob, with the same spending conditions as his previous output
    • Output of 0.49 XPU to Alice
    • Remaining 0.01 XPU is the miner fee paid by Alice

In the same vein, let's suppose we have another stablecoin XEUR with a 1:1 exchange rate to 1 EUR. Now let's suppose the exchange rate for XEUR to XUSD is 1.2 and the exchange rate of 1 XPU to XEUR is 8 and we pay a miner fee of 0.01 XPU:

  • Alice has one output of 20 XUSD and she wants to exchange 10 XUSD for XEUR. She does not have any XPU outputs.
  • Bob has one output of 50 XEUR he quotes in exchange for XEUR at a price of 1.2. He does not have any XPU outputs either.
  • Charlie has one output of 1 XPU he quotes in exchange for XUSD at a price of 10.
  • Alice creates a transaction with 3 inputs: her own XUSD output, Bob's 50 XEUR output and Charlie's 1 XPU output. It creates the following outputs:
    • Output of 42 XEUR to Bob
    • Output of 10 XUSD to Bob
    • Output of 9.99 XUSD to Alice
    • Output of 8 XEUR to Alice
    • Output of 0.99 XPU to Charlie
    • Output of 0.1 XUSD to Charlie
    • Remaining 0.01 XPU is the miner fee paid by Alice

In this example, there is one issue for Charlie: The amount received in exchange for paying the fee, 0.1 XUSD could be too small in order to be able to economically spend the output. The solution for this is liquidity providers setting a minimum allowable exchange quantity in their quote.

Quote adjustment

Adjusting quotes poses one big challenge in this design:

  • Once a quote is posted, anyone can accept it. If a quote is updated to a better price for the liquidity provider, someone can still settle the first transaction, invalidating the updated quote.
  • This means adjusting quotes can only be done upward in case of buy quotes and downward in case of sell quotes, very similarly to how a Dutch auction works. Strategies can then be implemented around this by adjusting the time until expiry and price parameters of a quote update.

Comparison with liquidity pools

We can quickly see that this mechanism resembles a traditional Order Book exchange. This brings several advantages to liquidity pools:

  • Stateless design
  • Market and limit orders
  • No need to lock liquidity in the pool for a long time; Liquidity providers are able to access profits after each trade

Cryptography

Purplecoin uses Schnorr implemented over Ristretto (sr25519) as its signature algorithm and blake3 as the choice of hash function.

Green PoW

Purplecoin uses the Green PoW model which lowers the energy consumption of mining to up to 50%.

ASIC resistance

Purplecoin uses 2 Proof of Work algorithms in tandem: RandomX and a choice out of several hash functions. One is suited to CPU mining and the other for ASIC miners. Algorithms are switched every Green PoW epoch.

Donations

While the development of Purplecoin initially happened in the sphere of Purple Technologies, it is not backed in any way by it or any other company. Purple Technologies is a for-profit company while Purplecoin is a decentralized project. Thereforce, the decisions and development happens at the community level. As such, the project also relies on the community at a funding level.

If you wish to support the development of Purplecoin, donations can be sent to the following BTC address:

bc1qwf7lcc8rsm75c54fmkrpl8s6g57gsp4zh5n34q

Donations can also be sent to the following ETH address:

0x8948F2d65Fa48cB10Aeb2C91930b7f9d28b2E885
You might also like...
A cargo plugin for showing a tree-like overview of a crate's modules.

cargo-modules Synopsis A cargo plugin for showing an overview of a crate's modules. Motivation With time, as your Rust projects grow bigger and bigger

A minimal `syn` syntax tree pretty-printer

prettyplease::unparse A minimal syn syntax tree pretty-printer. Overview This is a pretty-printer to turn a syn syntax tree into a String of well-form

A radix tree implementation for router, and provides CRUD operations.

radixtree A radix tree implementation for router, and provides CRUD operations. Radixtree is part of treemux, on top of which updates and removes are

Embeddable tree-walk interpreter for a "mostly lazy" Lisp-like scripting language.

ceceio Embeddable tree-walk interpreter for a "mostly lazy" Lisp-like scripting language. Just a work-in-progress testbed for now. Sample usage us

Support SIMD low-memory overhead and high-performance adaptive radix tree.

Artful Artful is an adaptive radix tree library for Rust. At a high-level, it's like a BTreeMap. It is based on the implementation of paper, see The A

Key-value store for embedded systems, for raw NOR flash, using an LSM-Tree.

ekv Key-value store for embedded systems, for raw NOR flash, using an LSM-Tree. Features None yet TODO Everything Minimum supported Rust version (MSRV

A tutorial of building an LSM-Tree storage engine in a week! (WIP)

LSM in a Week Build a simple key-value storage engine in a week! Tutorial The tutorial is available at https://skyzh.github.io/mini-lsm. You can use t

Simple, automatic, and customizable tree pretty-printing in Rust.
Simple, automatic, and customizable tree pretty-printing in Rust.

display_tree Simple, automatic, and customizable tree pretty-printing in Rust. This crate provides tools to easily pretty-print data as a tree, includ

Use rust programming language to create a b+ tree.
Use rust programming language to create a b+ tree.

Use rust programming language to create a b+ tree.

Comments
  • Seedable RNG for VM

    Seedable RNG for VM

    In order to generate secure random numbers, the current block_hash + inputs_hash + tx_index + input_idx will be hashed and used as seed. Any transaction which contain random number opcodes can fail even if included in a block and will be rollbacked in case of failures.

    opened by octavonce 0
  • #[cfg(windows)] isn't picked up in the CI environment

    #[cfg(windows)] isn't picked up in the CI environment

    Currently the CI build breaks on Windows due to the wrong path separator being used at compile time. This is determined by the host_family cargo variable being set in the build script:

    #[cfg(windows)]
    const HOST_FAMILY: &str = "windows";
    
    #[cfg(unix)]
    const HOST_FAMILY: &str = "unix";
    
    fn main() {
        #[cfg(any(windows, unix))]
        {
            println!("cargo:rust-cfg=host_family={}", HOST_FAMILY);
        }
    }
    

    Apparently #[cfg(windows)] isn't picked up in the CI environment.

    opened by octavonce 0
Owner
Purplecoin
The stateless blockchain
Purplecoin
Integra8 rust integration test framework Rust with a focus on productivity, extensibility, and speed.

integra8 Integra8 rust integration test framework Rust with a focus on productivity, extensibility, and speed. | This repo is in a "work in progress"

exceptional 3 Sep 26, 2022
VoceChat is a superlight rust written social server. Easy integration to your site/app.

Re-decentralized the Internet through personal cloud computing. VoceChat is the lightest chat server prioritizes private hosting! Easy integratation t

Privoce 134 Feb 22, 2023
Core Temporal SDK that can be used as a base for language specific Temporal SDKs

Core SDK that can be used as a base for all other Temporal SDKs. Getting started See the Architecture doc for some high-level information. This repo u

temporal.io 136 Dec 21, 2022
Rust 核心库和标准库的源码级中文翻译,可作为 IDE 工具的智能提示 (Rust core library and standard library translation. can be used as IntelliSense for IDE tools)

Rust 标准库中文版 这是翻译 Rust 库 的地方, 相关源代码来自于 https://github.com/rust-lang/rust。 如果您不会说英语,那么拥有使用中文的文档至关重要,即使您会说英语,使用母语也仍然能让您感到愉快。Rust 标准库是高质量的,不管是新手还是老手,都可以从中

wtklbm 493 Jan 4, 2023
Core libraries, services and CLIs for Monetæ

Core libraries, services and CLIs for Monetæ

monetæ 1 Nov 1, 2021
Rust library provides a standalone implementation of the ROS (Robot Operating System) core

ROS-core implementation in Rust This Rust library provides a standalone implementation of the ROS (Robot Operating System) core. It allows you to run

Patrick Wieschollek 3 Apr 26, 2023
Repo for apps for the Pocket RISC-V core for Analogue Pocket/OpenFPGA. Multiple branches.

This is a repo meant to host Rust programs for agg23's Pocket RISC-V platform. While Rust can be built out of the openfpga-litex repo directly, this r

null 3 Dec 12, 2023
Serialize & deserialize device tree binary using serde

serde_device_tree Use serde framework to deserialize Device Tree Blob binary files; no_std compatible. Use this library Run example: cargo run --examp

Luo Jia 20 Aug 20, 2022
A Rust implementation of generic prefix tree (trie) map with wildcard capture support

prefix_tree_map A Rust implementation of generic prefix tree (trie) map with wildcard capture support. Design Trie is a good data structure for storin

EAimTY 3 Dec 6, 2022
An embedded key-value storage for learning purpose, which is based on the idea of SSTable / LSM-tree.

Nouzdb An embedded key-value storage for learning purpose, which is based on the idea of SSTable / LSM-tree. Plan Implement a memtable. Implement the

Nouzan 1 Dec 5, 2021