-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from LayerXcom/feature/sonic
Implement SONIC outline
- Loading branch information
Showing
45 changed files
with
4,302 additions
and
2,414 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,12 @@ clap = "~2.32" | |
[dependencies.basic-authorship] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-basic-authorship' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.consensus] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-consensus-aura' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.ctrlc] | ||
features = ['termination'] | ||
|
@@ -50,56 +50,52 @@ version = '3.0' | |
[dependencies.inherents] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-inherents' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.network] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-network' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
|
||
[dependencies.node-executor] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.zero-chain-runtime] | ||
path = 'runtime' | ||
|
||
[dependencies.primitives] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-primitives' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.sr-io] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.substrate-cli] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.substrate-client] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.substrate-executor] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.substrate-service] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[dependencies.transaction-pool] | ||
git = 'https://github.com/paritytech/substrate.git' | ||
package = 'substrate-transaction-pool' | ||
rev = '9112a28af677b75cd6f935dda34d283bb4f676e7' | ||
rev = '59d5ec144704cec017a01f3e4dbb6b73c5542bf7' | ||
|
||
[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' | ||
|
@@ -113,17 +109,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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,6 @@ impl AsBytesRef for SigVerificationKey { | |
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "sonic" | ||
version = "0.1.0" | ||
authors = ["Osuke Sudo <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
pairing = { git = "https://github.com/LayerXcom/librustzcash", branch = "zero-chain" } | ||
bellman = { git = "https://github.com/LayerXcom/librustzcash", branch = "zero-chain" } | ||
rand = "0.4" | ||
merlin = "1.0" | ||
futures = "0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
//! This module contains some type difinitions like `LinearCombination`, `Variable`, and `Coeff` | ||
//! and implementation of some operator overloadings for those types. | ||
use pairing::{Engine, Field}; | ||
use std::ops::{Add, Sub, Neg}; | ||
|
||
|
||
/// This represents a linear combination of some variables, with coefficients | ||
/// in the scalar field of a pairing-friendly elliptic curve group. | ||
#[derive(Clone)] | ||
pub struct LinearCombination<E: Engine>(Vec<(Variable, Coeff<E>)>); | ||
|
||
impl<E: Engine> From<Variable> for LinearCombination<E> { | ||
fn from(var: Variable) -> LinearCombination<E> { | ||
LinearCombination::<E>::zero() + var | ||
} | ||
} | ||
|
||
impl<E: Engine> AsRef<[(Variable, Coeff<E>)]> for LinearCombination<E> { | ||
fn as_ref(&self) -> &[(Variable, Coeff<E>)] { | ||
&self.0 | ||
} | ||
} | ||
|
||
/// Return an empty linear combination | ||
impl<E: Engine> LinearCombination<E> { | ||
pub fn zero() -> LinearCombination<E> { | ||
LinearCombination(vec![]) | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` + `(Coeff, Variable)` = `LinearCombination` | ||
impl<E: Engine> Add<(Coeff<E>, Variable)> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn add(mut self, (coeff, var): (Coeff<E>, Variable)) -> LinearCombination<E> { | ||
self.0.push((var, coeff)); | ||
self | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` - `(Coeff, Variable)` = `LinearCombination` | ||
impl<E: Engine> Sub<(Coeff<E>, Variable)> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn sub(self, (coeff, var): (Coeff<E>, Variable)) -> LinearCombination<E> { | ||
self + (-coeff, var) | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` + `(Coeff::One, Variable)` = `LinearCombination` | ||
impl<E: Engine> Add<Variable> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn add(self, var: Variable) -> LinearCombination<E> { | ||
self + (Coeff::One, var) | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` - `(Coeff::one, Variable) = `LinearCombination` | ||
impl<E: Engine> Sub<Variable> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn sub(self, var: Variable) -> LinearCombination<E> { | ||
self - (Coeff::One, var) | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` + `&LinearCombination` = `LinearCombination` | ||
impl<'a, E: Engine> Add<&'a LinearCombination<E>> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn add(mut self, other: &'a LinearCombination<E>) -> LinearCombination<E> { | ||
for s in &other.0 { | ||
// `LinearCombination` = `LinearCombination` + `(Coeff, Variable)` | ||
self = self + (s.1, s.0); | ||
} | ||
|
||
self | ||
} | ||
} | ||
|
||
/// Operetor overloading for linear combination | ||
/// `LinearCombination` - `&LinearCombination` = `LinearCombination` | ||
impl<'a, E: Engine> Sub<&'a LinearCombination<E>> for LinearCombination<E> { | ||
type Output = LinearCombination<E>; | ||
|
||
fn sub(mut self, other: &'a LinearCombination<E>) -> LinearCombination<E> { | ||
for s in &other.0 { | ||
// `LinearCombination` = `LinearCombination` - `(Coeff, Variable)` | ||
self = self - (s.1, s.0); | ||
} | ||
|
||
self | ||
} | ||
} | ||
|
||
/// A difinition of Variable for linear combination used in our constraint system. | ||
#[derive(Copy, Clone, Debug)] | ||
pub enum Variable { | ||
A(usize), // input variable in r1cs | ||
B(usize), // Auxillary variable in r1cs | ||
C(usize), | ||
} | ||
|
||
/// A difinition of Coefficient for linear combination used in our constraint system. | ||
#[derive(Debug)] | ||
pub enum Coeff<E: Engine> { | ||
Zero, | ||
One, | ||
NegativeOne, | ||
Full(E::Fr), | ||
} | ||
|
||
impl<E: Engine> Copy for Coeff<E> {} | ||
impl<E: Engine> Clone for Coeff<E> { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
/// Multiply the coefficient with a given variable. | ||
impl<E: Engine> Coeff<E> { | ||
pub fn multiply(&self, with: &mut E::Fr) { | ||
match self { | ||
Coeff::Zero => { | ||
*with = E::Fr::zero(); | ||
}, | ||
Coeff::One => {}, | ||
Coeff::NegativeOne => { | ||
with.negate(); | ||
}, | ||
Coeff::Full(val) => { | ||
with.mul_assign(val); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Operetor overloading for Coefficient | ||
/// used for Substraction overloading for linear combination | ||
impl<E: Engine> Neg for Coeff<E> { | ||
type Output = Coeff<E>; | ||
|
||
fn neg(self) -> Self { | ||
match self { | ||
Coeff::Zero => Coeff::Zero, | ||
Coeff::One => Coeff::NegativeOne, | ||
Coeff::NegativeOne => Coeff::One, | ||
Coeff::Full(mut a) => { | ||
a.negate(); | ||
Coeff::Full(a) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.