Skip to content

Commit

Permalink
Merge pull request #14 from xelis-project/dev
Browse files Browse the repository at this point in the history
Version 1.7.0
  • Loading branch information
Slixe committed Dec 9, 2023
2 parents ba4c723 + 0d4b452 commit a175531
Show file tree
Hide file tree
Showing 64 changed files with 3,894 additions and 1,535 deletions.
732 changes: 626 additions & 106 deletions API.md

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"xelis_common",
Expand Down
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# XELIS Blockchain
All rights reserved.

XELIS is a blockchain made in Rust and powered by Tokio, using account model.
It allows deploy custom assets working exactly like the native coin in transactions and wallet.
A from scratch blockchain made in Rust and powered by Tokio, using account model. XELIS is based on an event-driven system combined with the native async/await and works with a unique and from scratch p2p system. This allow to be notified on any events happening on the network and to be able to react to them instead of checking periodically for updates.

This project is based on an event-driven system combined with the native async/await and works with a unique and from scratch p2p system.
BlockDAG is enabled to improve the scalability and the security of the network. Homomorphic Encryption using ElGamal is used to provide privacy on transactions (transfered amounts) and balances.

ElGamal cryptosystem was choosen because it's a well known and studied encryption algorithm which has homomorphism features. ElGamal is fast and is used in combination with Ristretto255 curve to provide a good level of security (~128 bits of security). Homomorphic operations available using ElGamal are addition/subtraction between ciphertexts and/or plaintext and multiplication against plaintext value.

Account Model allows to have a more flexible system than UTXO model and to have a better privacy because there is no need to link inputs and outputs, which provide real fungibility. It allows also the fast-sync feature to only download the last state of the blockchain instead of downloading all the history.

Pruning system is also available to reduce the size of the blockchain by removing old blocks and transactions.

We also aims to enabled Smart Contracts support in the future.

We provide differents built-in network:
- Mainnet: Not released yet
- Testnet: Running
- Devnet: this network is used for local development purpose where you want to create your own local chain. It has no peers

### Objectives

Expand Down Expand Up @@ -216,22 +228,39 @@ All theses data are saved in plaintext.
| hash_by_topo | Integer | Hash | Save a topo height for a specific block hash |
| cumulative_difficulty | Hash | Integer | Save the cumulative difficulty for each block hash |
| assets | Hash | Integer | Verify if an assets exist and its registration height |
| nonces | Public Key | Integer | Store the highest topoheight of versioned nonce |
| nonces_topoheight | Public Key | Versioned Nonce | Tree name is composed of prefix + topoheight |
| rewards | Hash | Integer | Save the block reward |
| supply | Hash | Integer | Calculated supply (past + block reward) at each block |
| rewards | Integer | Integer | Save the block reward |
| supply | Integer | Integer | Calculated supply (past + block reward) at each block |
| difficulty | Hash | Integer | Difficulty for each block |
| tx_blocks | Hash | Array of Hash | All blocks in which this TX hash is included |
| assets_hash | Public Key | Integer | Asset hash with last topoheight of versioned balance |
| assets_balances | Public Key | Versioned Balance | Tree name is hash of asset + topoheight |
| balances | Custom | Integer | Last topoheight of versioned balance |
| nonces | Public Key | Integer | Store the highest topoheight of versioned nonce |
| versioned_balances | Custom | Versioned Balance | Key is composed of topoheight + public key |
| versioned_nonces | Custom | Versioned Nonce | Key is composed of topoheight + public key |

**NOTE**:
- Balances and nonces are versioned, which means they are stored each time a change happened on disk.
- Tree `balances` has a custom key which is composed of 32 bytes of Public Key and 32 bytes of Asset.
- Balances and nonces are versioned, which means they are stored each time a change happened in chain.
- Using a Tree per version is too heavy because of overhead per trees, solution is to hash a generated key based on properties.
- Assets registered have in value their topoheight at which it was registered.
- Supply and block rewards are only stored when the block is topologically ordered

The database engine used is sled. It may changes in future.

Current overhead per block is:
- Tree `blocks` saving Block header (132 bytes with no TXs) value using Hash (32 bytes) key.
- Trees `topo_by_hash` and `hash_by_topo` saving both Hash (32 bytes) <=> topoheight (8 bytes) pointers. (x2)
- Tree `difficulty` saving Difficulty value of a block (8 bytes) using Hash (32 bytes) key.
- Tree `rewards` saving block reward value (8 bytes) using topoheight (8 bytes) key.
- Tree `supply` saving current circulating supply value (8 bytes) using topoheight (8 bytes) key.
- Tree `versioned_balances` is updated at each block (for miner rewards), and also for each account that had interactions (transactions): 32 bytes for key and 16 bytes for value.
- Tree `versioned_nonces` is updated for each account that send at least one TX per topoheight: 32 bytes for key and 16 bytes for value

At this moment with current implementation, minimal overhead per new account is 160 bytes for keys and 48 bytes for values:
- `balances` Public Key (32 bytes) + Asset (32 bytes) => topoheight of last versioned balance (8 bytes)
- `nonces` Public Key (32 bytes) => topoheight of last versioned nonce (8 bytes)
- `versioned_balances` Hash of (Public Key + Topoheight) (32 bytes) => Versioned Balance (16 bytes)
- `versioned_nonces` Hash of (Public Key + Topoheight) (32 bytes) => Versioned Nonce (16 bytes)

## Wallet

Wallet keep tracks of all your transactions on chain, all your assets you own.
Expand Down Expand Up @@ -338,6 +367,10 @@ XSWD stay open but request a manual action from user to accept the connection of
When accepted, the dApp can requests JSON-RPC methods easily and the user can set/configure a permission for each method.
If no permission is found for a request method, it will be prompted/asked to the user for manual verification.

XSWD also have the ability to sends JSON-RPC requests to the daemon directly.
For this, set the prefix `node.` in front of daemon requests, it will not be requested to the user as it's public on-chain data.
For wallets RPC methods, set the prefix `wallet.` which will requests/use the permission set by the user.

DApp can also request to sign the `ApplicationData` to persist the configured permissions on its side and then provide it when user would reconnect later.

First JSON message from the dApp must be in following format to identify the application:
Expand Down
4 changes: 3 additions & 1 deletion xelis_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "xelis_common"
version = "1.6.0"
version = "1.7.0"
edition = "2021"
authors = ["Slixe <slixeprivate@gmail.com>"]
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down Expand Up @@ -32,6 +33,7 @@ actix-ws = { version = "0.2.5", optional = true }
futures-util = { version = "0.3.28", optional = true }
async-trait = { version = "0.1.64", optional = true }
regex = "1"
serde_regex = "1.1.0"

[features]
json_rpc = ["dep:reqwest"]
Expand Down
21 changes: 21 additions & 0 deletions xelis_common/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is executed before the build and fetch the commit hash from git
// we create the build version and set it as an environment variable for the build.

use std::process::Command;

fn main() {
// Run git command to get the commit hash
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.expect("Failed to execute git command");

// Convert the commit hash to a string
let commit_hash = String::from_utf8_lossy(&output.stdout).trim().to_string();

// Set the result as an environment variable for the build
let build_version = format!("{}-{}", env!("CARGO_PKG_VERSION"), commit_hash);
println!("cargo:rerun-if-env-changed=BUILD_VERSION");
println!("cargo:BUILD_VERSION={}", build_version);
println!("cargo:rustc-env=BUILD_VERSION={}", build_version);
}

0 comments on commit a175531

Please sign in to comment.