Skip to content

Commit

Permalink
Merge pull request #111 from LayerXcom/feature/client_init
Browse files Browse the repository at this point in the history
Submit extrinsic via RPC
  • Loading branch information
osuketh committed Jun 6, 2019
2 parents aa602d3 + defd043 commit e63e2f3
Show file tree
Hide file tree
Showing 29 changed files with 2,557 additions and 2,277 deletions.
1,914 changes: 1,046 additions & 868 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 29 additions & 23 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,63 +31,70 @@ 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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
branch = "patch-zerochain"

[dependencies.consensus]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-consensus-aura'
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
branch = "patch-zerochain"

[dependencies.network]
git = 'https://github.com/paritytech/substrate.git'
git = 'https://github.com/osuketh/substrate.git'
package = 'substrate-network'
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
git = 'https://github.com/osuketh/substrate.git'
branch = "patch-zerochain"

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

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

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

[dependencies.substrate-service]
git = 'https://github.com/paritytech/substrate.git'
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7'
branch = "patch-zerochain"

[package]
authors = ['Osuke Sudo<[email protected]>']
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
4 changes: 2 additions & 2 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 = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7', default-features = false }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7', 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 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
10 changes: 6 additions & 4 deletions core/primitives/src/prepared_vk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use parity_codec_derive::{Encode, Decode};
/// Prepared Verifying Key for SNARKs proofs
#[derive(Eq, PartialEq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct PreparedVk(
pub Vec<u8>
);
pub struct PreparedVk(Vec<u8>);

impl PreparedVk {
pub fn into_prepared_vk(&self) -> Option<bellman_verifier::PreparedVerifyingKey<Bls12>> {
Expand All @@ -33,6 +31,10 @@ impl PreparedVk {

PreparedVk(writer)
}

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

impl Into<PreparedVk> for bellman_verifier::PreparedVerifyingKey<Bls12> {
Expand Down Expand Up @@ -76,7 +78,7 @@ mod tests {
let mut buf_vk = vec![];
vk_reader.read_to_end(&mut buf_vk).unwrap();

PreparedVk(buf_vk)
PreparedVk::from_slice(&buf_vk[..])
}

#[test]
Expand Down
8 changes: 6 additions & 2 deletions core/primitives/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use substrate_primitives::hexdisplay::AsBytesRef;

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

impl Proof {
pub fn into_proof(&self) -> Option<bellman_verifier::Proof<Bls12>> {
Expand All @@ -24,6 +24,10 @@ impl Proof {
proof.write(&mut &mut writer[..]).unwrap();
Proof(writer.to_vec())
}

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

impl Into<Proof> for bellman_verifier::Proof<Bls12> {
Expand Down Expand Up @@ -58,7 +62,7 @@ mod tests {
#[test]
fn test_proof_into_from() {
let proof: [u8; 192] = hex!("8e7b55a0a7bf1e34fc9a031a883dd1b3c7217a325388b0fe38acb8294632c63d14c95bb2d596a5bfd3b887211b1ba726949b91456d17d0648d2981c44b6e53636c98f155789b69b793b06be8f83a18120253ae004ff607eb396c8e5492325a4d02cd84adc379b91638e5a1a2cafcd25311e9efd082136eaa8f7a4e4eb8214d2ea08eae54a30508c176596746b0ada2218ebc3cb934504345f89c21e3d3c011196002ef65218989f6bfc1b7aa6a69be7d339d7d11b7a7c336cc836367e216ab54");
let proof_a = Proof(proof.to_vec());
let proof_a = Proof::from_slice(&proof[..]);

let proof_v = proof_a.into_proof().unwrap();
let proof_b = Proof::from_proof(&proof_v);
Expand Down
6 changes: 3 additions & 3 deletions core/proofs/src/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,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 All @@ -192,7 +192,7 @@ mod tests {
let params = &JubjubBls12::new();
let p_g = FixedGenerators::NoteCommitmentRandomness; // 1
let rng = &mut XorShiftRng::from_seed([0xbc4f6d44, 0xd62f276c, 0xb963afd0, 0x5455863d]);

let sk_fs = Fs::rand(rng);
let r_fs1 = Fs::rand(rng);
let r_fs2 = Fs::rand(rng);
Expand Down
26 changes: 19 additions & 7 deletions core/proofs/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 @@ -52,12 +52,12 @@ impl<E: JubjubEngine> ProofGenerationKey<E> {
}

/// Generate proof generation key from origin key cast as bytes
pub fn from_ok_bytes(
ok: &[u8],
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 @@ -118,12 +118,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::NoteCommitmentRandomness)
.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
6 changes: 5 additions & 1 deletion demo/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ edition = "2018"
rand = "0.4"
proofs = { package = "zero-chain-proofs", path = "../../core/proofs" }
clap = "~2.32"
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' }
primitives = { package = "substrate-primitives", git = "https://github.com/osuketh/substrate", branch = "patch-zerochain" }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/osuketh/substrate", branch = "patch-zerochain" }
zpairing = { package = "zero-chain-pairing", path = "../../core/pairing" }
pairing = { git = "https://github.com/LayerXcom/librustzcash", branch = "zero-chain" }
bellman = { git = "https://github.com/LayerXcom/librustzcash", branch = "zero-chain" }
Expand All @@ -22,6 +23,9 @@ byteorder = "1"
keys = { path = "../../core/keys" }
wasm-utils = {package = "zerochain-wasm-utils", path = "../wasm-utils"}
hex = "0.3.2"
polkadot-rs = { git = "https://github.com/LayerXcom/polkadot.rs" }
parity-codec = "3.2"
zero-chain-runtime = { path = "../../runtime" }

[dependencies.blake2-rfc]
git = "https://github.com/gtank/blake2-rfc"
Expand Down
Loading

0 comments on commit e63e2f3

Please sign in to comment.