Skip to content

Commit

Permalink
Merged master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
osuketh committed Jun 6, 2019
2 parents 0389735 + e63e2f3 commit d2a8a5f
Show file tree
Hide file tree
Showing 63 changed files with 9,554 additions and 3,240 deletions.
3,198 changes: 1,724 additions & 1,474 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ trie-root = '0.11.0'
bellman-verifier = { path = "core/bellman-verifier"}
demo = { package = "zero-chain-cli", path = "demo/cli" }
zcrypto = { package = "zero-chain-crypto", path = "core/crypto" }
jubjub = { path = "core/jubjub" }
zpairing = { package = "zero-chain-pairing", path = "core/pairing" }
zprimitives = { package = "zero-chain-primitives", path = "core/primitives" }
proofs = { package = "zero-chain-proofs", path = "core/proofs" }
Expand All @@ -32,74 +31,77 @@ lazy_static = "1.3.0"
wasm-utils = {package = "zerochain-wasm-utils", path = "demo/wasm-utils"}
hex = "0.3.2"
clap = "~2.32"
polkadot-rs = { git = "https://github.com/LayerXcom/polkadot.rs" }
zjubjub = { package = "jubjub", path = "core/jubjub"}

[dependencies.basic-authorship]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-basic-authorship'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[dependencies.consensus]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-consensus-aura'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[dependencies.ctrlc]
features = ['termination']
version = '3.0'

[dependencies.inherents]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-inherents'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[dependencies.network]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-network'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'

[dependencies.node-executor]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[dependencies.zero-chain-runtime]
path = 'runtime'

[dependencies.primitives]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-primitives'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[dependencies.runtime-primitives]
git = 'https://github.com/osuketh/substrate.git'
package = 'sr-primitives'
branch = "patch-zerochain"

[dependencies.sr-io]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

[dependencies.substrate-cli]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

[dependencies.substrate-client]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

[dependencies.substrate-executor]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

[dependencies.substrate-service]
git = 'https://github.com/paritytech/substrate.git'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

[dependencies.transaction-pool]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-transaction-pool'
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7'
branch = "patch-zerochain"

[package]
authors = ['Osuke Sudo<[email protected]>']
build = 'build.rs'
edition = '2018'
name = 'zero-chain'
version = '0.9.0'
version = '1.0.0'

[[bin]]
name = 'zero-chain'
Expand All @@ -113,17 +115,17 @@ path = 'demo/cli/src/main.rs'
members = [
"core/bellman-verifier",
"core/crypto",
"demo/cli",
"demo/cli",
"core/jubjub",
"core/pairing",
"core/primitives",
"core/proofs",
"runtime",
"core/keys",
"modules/indices",
"core/sonic",
"modules/executive",
]
exclude = [
"runtime/wasm",
"demo/wasm-utils",
"runtime/wasm",
"demo/wasm-utils",
]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
[![Build Status](https://travis-ci.com/LayerXcom/zero-chain.svg?branch=master)](https://travis-ci.com/LayerXcom/zero-chain)
[![Gitter](https://badges.gitter.im/LayerXcom/Zerochain.svg)](https://gitter.im/LayerXcom/Zerochain?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Zerochain is a privacy-preserving blockchain on substrate.
Zerochain is a privacy-preserving blockchain on substrate.
It is designed to get efficient zero-knowledge proving, reduce the on-chain storage cost and bring the flexibility for developing applications.

## Status
**WARNING: Zerochain is alpha quality software, improvements and fixes are made frequently, and documentation for technical details doesn't yet exist.**

For now, only supported for the "confidential payment PoC".
For now, only supported for the "confidential payment PoC" inspired by [Zether](https://crypto.stanford.edu/~buenz/papers/zether.pdf) paper.

- Balance for each account is encrypted
<div align="center">
Expand Down Expand Up @@ -95,6 +95,12 @@ You can send the transaction from firefox browser.
### Documentations
- [Announcing Zerochain: Applying zk-SNARKs to Substrate](https://medium.com/layerx/announcing-zerochain-5b08e158355d)

### References
- [Substrate](https://github.com/paritytech/substrate)
- [Zcash Protocol Specification](https://github.com/zcash/zips/blob/master/protocol/protocol.pdf)
- [Zether](https://crypto.stanford.edu/~buenz/papers/zether.pdf): Towards Privacy in a Smart Contract World
- [Sonic](https://eprint.iacr.org/2019/099.pdf): Zero-Knowledge SNARKs from Linear-Size Universal and Updatable Structured Reference Strings

## Contributing
- Feel free to submit your own issues and PRs
- For further discussions and questions talk to us on [Gitter](https://gitter.im/LayerXcom/Zerochain)
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/src/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ mod tests {

let r_fs = Fs::rand(rng);

let address = EncryptionKey::<Bls12>::from_ok_bytes(alice_seed, params);
let address = EncryptionKey::<Bls12>::from_seed(alice_seed, params);
let enc_alice_val = Ciphertext::encrypt(alice_value, r_fs, &address.0, p_g, params);

let bdk = ProofGenerationKey::<Bls12>::from_ok_bytes(alice_seed, params).bdk();
let bdk = ProofGenerationKey::<Bls12>::from_seed(alice_seed, params).bdk();

let dec_alice_val = enc_alice_val.decrypt(bdk, p_g, params).unwrap();
assert_eq!(dec_alice_val, alice_value);
Expand Down
28 changes: 20 additions & 8 deletions core/keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const PRF_EXPAND_PERSONALIZATION: &'static [u8; 16] = b"zech_ExpandSeed_";
pub const CRH_BDK_PERSONALIZATION: &'static [u8; 8] = b"zech_bdk";
pub const KEY_DIVERSIFICATION_PERSONALIZATION: &'static [u8; 8] = b"zech_div";

pub fn bytes_to_fs<E: JubjubEngine>(bytes: &[u8]) -> E::Fs {
pub fn bytes_to_uniform_fs<E: JubjubEngine>(bytes: &[u8]) -> E::Fs {
let mut h = Blake2b::with_params(64, &[], &[], PRF_EXPAND_PERSONALIZATION);
h.update(bytes);
let res = h.finalize();
Expand All @@ -66,13 +66,13 @@ impl<E: JubjubEngine> ProofGenerationKey<E> {
)
}

/// Generate proof generation key from origin key cast as bytes
pub fn from_ok_bytes(
ok: &[u8],
/// Generate proof generation key from seed
pub fn from_seed(
seed: &[u8],
params: &E::Params
) -> Self
{
Self::from_origin_key(&bytes_to_fs::<E>(ok), params)
Self::from_origin_key(&bytes_to_uniform_fs::<E>(seed), params)
}

/// Generate the randomized signature-verifying key
Expand Down Expand Up @@ -133,12 +133,24 @@ impl<E: JubjubEngine> EncryptionKey<E> {
proof_generation_key.into_encryption_key(params)
}

pub fn from_ok_bytes(
ok: &[u8],
pub fn from_decryption_key(
decryption_key: &E::Fs,
params: &E::Params,
) -> Self
{
let pk_d = params
.generator(FixedGenerators::Diversifier)
.mul(*decryption_key, params);

EncryptionKey(pk_d)
}

pub fn from_seed(
seed: &[u8],
params: &E::Params
) -> Self
{
Self::from_origin_key(&bytes_to_fs::<E>(ok), params)
Self::from_origin_key(&bytes_to_uniform_fs::<E>(seed), params)
}

pub fn write<W: io::Write>(&self, mut writer: W) -> io::Result<()> {
Expand Down
16 changes: 8 additions & 8 deletions core/pairing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern crate alloc;

#[cfg(not(feature = "std"))]
mod std {
pub use core::*;
pub use core::*;
pub use alloc::vec;
pub use alloc::string;
pub use alloc::boxed;
Expand Down Expand Up @@ -140,7 +140,7 @@ pub trait CurveProjective:
+ Copy
+ Clone
+ Send
+ Sync
+ Sync
+ rand::Rand
+ 'static
{
Expand Down Expand Up @@ -242,8 +242,8 @@ pub trait CurveAffine:

/// Converts this element into its compressed encoding, so long as it's not
/// the point at infinity.
fn into_compressed(&self) -> Self::Compressed {
<Self::Compressed as EncodedPoint>::from_affine(*self)
fn into_compressed(&self) -> Self::Compressed {
<Self::Compressed as EncodedPoint>::from_affine(*self)
}

/// Converts this element into its uncompressed encoding, so long as it's not
Expand Down Expand Up @@ -341,7 +341,7 @@ pub trait Field:
}

res
}
}
}

/// This trait represents an element of a field that has a square root operation described for it.
Expand All @@ -365,7 +365,7 @@ pub trait PrimeFieldRepr:
+ Ord
+ Send
+ Sync
+ Default
+ Default
+ 'static
+ rand::Rand
+ AsRef<[u64]>
Expand Down Expand Up @@ -409,7 +409,7 @@ pub trait PrimeFieldRepr:
fn write_be<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
use byteorder::BigEndian;

let mut buf = [0u8; 8];
let mut buf = [0u8; 8];
for digit in self.as_ref().iter().rev() {
BigEndian::write_u64(&mut buf, *digit);
writer.write(&buf)?;
Expand Down Expand Up @@ -452,7 +452,7 @@ pub trait PrimeFieldRepr:
for digit in self.as_mut().iter_mut() {
reader.read(&mut buf)?;
*digit = LittleEndian::read_u64(&buf);
}
}

Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jubjub = { path = "../jubjub", default-features = false }
zcrypto = { package = "zero-chain-crypto", path = "../crypto", default-features = false }
rand = { version = "0.4", default-features = false }
fixed-hash = { version = "0.3.0", default-features = false }
substrate-primitives = { git = "https://github.com/paritytech/substrate", rev = '9112a28af677b75cd6f935dda34d283bb4f676e7', default-features = false }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", rev = '9112a28af677b75cd6f935dda34d283bb4f676e7', default-features = false }
substrate-primitives = { git = "https://github.com/osuketh/substrate.git", branch = "patch-zerochain", default-features = false }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/osuketh/substrate.git", branch = "patch-zerochain", default-features = false }
keys = { path = "../keys", default-features = false }
hex-literal = '0.1'

Expand All @@ -32,19 +32,19 @@ features = ["spin_no_std"]

[features]
default = ["std"]
std = [
"parity-codec/std",
std = [
"parity-codec/std",
"parity-codec-derive/std",
"serde",
"serde/std",
"serde_derive",
"byteorder/std",
"byteorder/std",
"pairing/std",
"bellman-verifier/std",
"bellman-verifier/std",
"jubjub/std",
"zcrypto/std",
"rand/std",
"blake2-rfc/std",
"blake2-rfc/std",
"fixed-hash/std",
"substrate-primitives/std",
"runtime-primitives/std",
Expand Down
6 changes: 5 additions & 1 deletion core/primitives/src/ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use substrate_primitives::hexdisplay::AsBytesRef;

#[derive(Eq, PartialEq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct Ciphertext(pub Vec<u8>);
pub struct Ciphertext(Vec<u8>);

impl Ciphertext {
pub fn into_ciphertext(&self) -> Option<elgamal::Ciphertext<Bls12>> {
Expand All @@ -26,6 +26,10 @@ impl Ciphertext {
ciphertext.write(&mut writer[..]).unwrap();
Ciphertext(writer.to_vec())
}

pub fn from_slice(slice: &[u8]) -> Self {
Ciphertext(slice.to_vec())
}
}

impl Into<Ciphertext> for elgamal::Ciphertext<Bls12> {
Expand Down
7 changes: 7 additions & 0 deletions core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ pub mod proof;
pub mod sig_vk;
pub mod prepared_vk;

pub use pkd_address::PkdAddress;
pub use signature::RedjubjubSignature;
pub use ciphertext::Ciphertext;
pub use proof::Proof;
pub use sig_vk::SigVerificationKey;
pub use prepared_vk::PreparedVk;

use lazy_static::lazy_static;
use jubjub::curve::JubjubBls12;

Expand Down
4 changes: 1 addition & 3 deletions core/primitives/src/pkd_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ impl AsBytesRef for PkdAddress {
mod tests {
use super::*;
use rand::{Rng, SeedableRng, XorShiftRng};
use pairing::bls12_381::Bls12;
use keys::*;
use jubjub::curve::JubjubBls12;

#[test]
Expand All @@ -90,7 +88,7 @@ mod tests {
let mut seed = [0u8; 32];
rng.fill_bytes(&mut seed[..]);

let addr1 = EncryptionKey::from_ok_bytes(&seed[..], &JUBJUB as &JubjubBls12);
let addr1 = EncryptionKey::from_seed(&seed[..], &JUBJUB as &JubjubBls12);

let account_id = PkdAddress::from_encryption_key(&addr1);
let addr2 = account_id.into_encryption_key().unwrap();
Expand Down
Loading

0 comments on commit d2a8a5f

Please sign in to comment.