diff --git a/Cargo.lock b/Cargo.lock index 14f4232..3860506 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "arrayvec" version = "0.4.7" diff --git a/Cargo.toml b/Cargo.toml index 3c523b2..b520f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ phase2 = "0.2.1" pairing = "0.14" rand = "0.4" blake2-rfc = "0.2" +rust-crypto = "0.2" [dependencies.byteorder] version = "1" diff --git a/README.md b/README.md index 33dc133..0f5e11e 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,77 @@ -# sapling-mpc +# mpc -This code can be used to participate and verify the Sapling network upgrade MPC. +This document is a guide to participate in Multi-party Computation(MPC) phase 2 and verify the result. -## What do I do? +## What should I do ? -Contact **mpc@z.cash** to schedule a time to participate. You'll need the latest (stable) [Rust compiler](https://www.rust-lang.org/) to participate using this code. +1. Send an application email to tronz_mpc@tronz.io in order to participate in MPC. Please introduce yourself in the email and tell us your available time. For example: + ``` + Hi Tronz, + + I'm Brown Jiang, applying to participate in the MPC project. My available time is 2020-01-20 ~ 2020-01-22, 08:00~10:00, UTC+8. As a student of Peking University, I'm living in Beijing China now, focusing on Blockchain technology. + + Yours Faithfully, + Brown Jiang + ``` +2. TRONZ will send you an email about the time for you to participate in MPC. -When it's your turn, you'll receive a `params` file from us. Place this file in the current directory and run: +3. When it is your turn, TRONZ will send you a notification email and give you a params file link which you will need to download. +4. Download and install IM tool [keybase](https://keybase.io/). If you don't have an account yet, create an account and add TRONZ's account as your friend. TRONZ's account is `tronz_mpc`. + +5. Prepare your server. Recommended server requirements: + + Processor (CPU): Intel Core i5 (sixth generation or newer) or equivalent + + Operating System: Linux (Recommended) / macOS / Windows 7+ + + Memory: 8 GB RAM + + Storage: 4 GB free Disk storage + +  On Windows, please go to [rust](https://www.rust-lang.org/learn/get-started) homepage for installation instruction, then install [Microsoft Visual C++ Build Tools](http://go.microsoft.com/fwlink/?LinkId=691126); at last, jump to next step. + +  On Mac, install xcode command line tools first: ``` -cargo run --release --bin compute +# xcode-select --install +``` +  On Mac/Linux, Run the following code in your terminal to download Rustup and install Rust, then follow the instructions if you are running on macOS / Linux / another Unix-like OS: +``` +# curl https://sh.rustup.rs -sSf | sh +``` +and choose 1 when prompted. After installation, run: +``` +# source $HOME/.cargo/env ``` -This will compute for a little while, and then spit out a `new_params` file. That's what you'll upload back to us. +6. Obtain the source code of project `mpc`: +``` +# git clone https://github.com/tronprotocol/mpc +``` +  If git has not been installed on your computer, please download and install [git](https://git-scm.com/downloads) first. -The tool also prints a hash. This hash is what you and others can use to verify that your contribution actually ended up in the final parameters, so you're encouraged to save it to check later! +7. In the `mpc` directory, download `params` file, then run: +``` +# cargo run --release --bin compute +``` + +  When it’s finished, you will get a `new_params` file and a `hash` which you must need to record. You can find the `hash` and `new_params` as shown below: +![](https://raw.githubusercontent.com/tronprotocol/documentation-en/master/docs_without_index/internal-test/mpc-output.jpg) + +  Notice: this process could take 0.5 ~ 1 hours depending on your hardware capacity and occupy 1.5 ~ 2GB of memory. + +8. Send your result to TRONZ. Please send the file `new_params` by keybase; send `hash` string by email, feel free to state your os version in email, E.g. windows 7/centos 7. + +## Dependency +We reuse the phase 2 result of zcash https://download.z.cash/sapling-mpc/params as the first `params` of the process. In the end of the process, we generate a random beacon by using one Bitcoin block's hash as the seed of pseudo random number generator. The block's height will not be determined until the last participant completes his operation. After we've verified all participants' contributions, we will publish all the hashes on project [wiki](https://github.com/tronprotocol/mpc/wiki) page. + +## How to verify my contribution ? + +After all participants have finished the process, we will announce the final params at AWS. Anyone can verify their contribution as below : +``` +# cd mpc +# wget https://mpcfilepub.s3.amazonaws.com/mpc/params +# wget https://mpcfilepub.s3.amazonaws.com/powersoftau/powersoftau_phase1_files.tar +# tar xvf powersoftau_phase1_files.tar && cp powersoftau_phase1_files/* . +# cargo run --release --features="verification" --bin verify +``` +This verification may take about 1 hour to output all participants' contributions. Find whether your hash is on the list. ## License @@ -27,7 +84,4 @@ at your option. ### Contribution -Unless you explicitly state otherwise, any contribution intentionally -submitted for inclusion in the work by you, as defined in the Apache-2.0 -license, shall be dual licensed as above, without any additional terms or -conditions. +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..b42d725 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,73 @@ +# 多方计算 + +多方计算(Multi-party Computation,MPC)是创建匿名交易需要的公共参数的的第二步,本文档说明如何参与TRONZ组织的mpc以及如何验证最终公共参数。 + +## 如何参与 ? + +1. 请发送邮件到tronz_mpc@tronz.io申请参与mpc,请简要介绍自己,并说明合适的参与时间。 + +2. TRONZ会回复邮件告知你参与mpc的时间点。 + +3. 当轮到你参与的时候,TRONZ给你发送一封通知邮件,包括你的序号和`params`文件的链接。 +4. 下载并安装IM工具 [keybase](https://keybase.io/),如果你没有账户新建一个。有任何问题,请添加`tronz_mpc`为好友来解决。 +5. 准备好你的服务器,推荐的最小硬件要求如下: + + Processor (CPU): Intel Core i5 (第六代或以上) or equivalent + + Operating System: Linux (推荐) / macOS / Windows 7+ + + Memory: 8 GB RAM + + Storage: 500 GB internal storage drive + +  如果你使用Windows系统,参考[rust](https://www.rust-lang.org/learn/get-started) 官方主页来安装。 + +  如果你使用macOS系统, 请先安装xcode命令行工具: +``` +# xcode-select --install +``` +6. 下载mpc项目的源码: +``` +# git clone https://github.com/tronprotocol/mpc +``` +  如果你还没有安装git环境,先安装 [git](https://git-scm.com/downloads). + +7. 如果你的系统是macOS/Linux,打开终端切换到mpc目录下,运行以下命令,如有提示请选择1. +``` +# sh compute.sh +``` +如果你的系统是Windows, 下载`params`文件放在mpc目录下,然后在该目录下执行以下命令: +``` +# cargo run --release --bin compute +``` +  当计算完成后,程序输出一个`new_params`文件和hash,请保存该hash值。类似于以下: +![](https://raw.githubusercontent.com/tronprotocol/documentation-en/master/docs_without_index/internal-test/mpc-output.jpg) + +  这个计算过程大约耗时半小时~1小时,根据硬件环境可能稍有不同,占用1.5 ~ 2GB物理内存。 + +8. 请把你的结果告知TRONZ。通过Keybase来发送`new_params`文件,然后把hash值通过邮件告知我们,告知操作系统版本更好,例如Windows 7/Centos 7。 + +## 依赖 +我们重用了zcash的多方计算第二阶段的最终结果 https://download.z.cash/sapling-mpc/params 作为我们的起始参数,添加额外一些参与者。每个参与者把结果发送给我们后,我们会验证生成的参数是否有效。在最后一个参与者结束迭代计算后,我们采用比特币最新区块的hash值作为伪随机函数的种子来生成随机信标(Random Beacon)。在mpc结束后,我们把所有参与者的贡献发布在本项目的[wiki](https://github.com/tronprotocol/mpc/wiki) 。所有参与者可以验证自己的贡献是否保存在最终参数中。 + + +## 如何验证我的贡献 ? + +在所有参与者完成迭代后,我们把最终的`params`发布于aws上,永久存储。可以通过以下方式验证: +``` +# cd mpc +# wget https://mpcfilepub.s3.amazonaws.com/mpc/params +# wget https://mpcfilepub.s3.amazonaws.com/powersoftau/powersoftau_phase1_files.tar +# tar xvf powersoftau_phase1_files.tar && cp powersoftau_phase1_files/* . +# cargo run --release --features="verification" --bin verify +``` +验证过程大约耗时一小时,输出所有参与者的hash值。查询自己保存的hash值是否在输出的hash列表中。 + +## License + +Licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/compute.sh b/compute.sh new file mode 100755 index 0000000..5af8016 --- /dev/null +++ b/compute.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# install rust +if [[ `rustc -V | grep '('` = '' ]] +then +curl https://sh.rustup.rs -sSf | sh +source $HOME/.cargo/env +fi + +# download params file +echo "download params: "$1 +wget --no-check-certificate $1 -O params + +# execute mpc +cargo run --release --bin compute \ No newline at end of file diff --git a/participants.md b/participants.md new file mode 100644 index 0000000..fe409ca --- /dev/null +++ b/participants.md @@ -0,0 +1,106 @@ +## Completed participants + +Index | Name | Email | Completed date +------------ |------------ | ------------- | ------------- +001 | Marco - TRON Family | info@tron-family.de | 2020-01-06 +002 | Crypto Guy | cryptoguyinza@gmail.com | 2020-01-06 +003 | Jason Neely | bondibox@gmail.com | 2020-01-07 +004 | Dirk Frank | dirk.frank@tron-europe.org | 2020-01-07 +005 | Dimitris Apostolou | dimitris.apostolou@icloud.com | 2020-01-08 +006 | Fbsobreira| cryptochainbrazil@gmail.com | 2020-01-09 +007 | Carsten Stöcker| carsten.stoecker@spherity.com | 2020-01-10 +008 | Bruno Campos | baiano@tronwallet.me | 2020-01-11 +009 | Justin Sun | sunyu******@gmail.com | 2020-01-12 +010 | Matt | mbranton@gmail.com | 2020-01-20 +011 | sun | shydesky@gmail.com | 2020-01-22 +012 | Aaron Musk| aaronmusk1989@gmail.com | 2020-01-23 +013 | Edward | blake2s@protonmail.com | 2020-01-23 +014 | Miffy Tang | timothychungkitwai@gmail.com | 2020-01-31 +015 | Alberto Zhang | alberto.zhangbo@gmail.com | 2020-02-01 +016 | Abner Frank | abner725@aol.com | 2020-02-01 +017 | Martin | martin012020@aol.com | 2020-02-02 +018 | Holt Hou | holy.holt@aol.com | 2020-02-02 +019 | Hong Guo | tsabo_gh@163.com | 2020-02-02 +020 | Cathy Tan | lotusLeaffy@protonmail.com | 2020-02-02 +021 | Ben Peng | ben.peng18@gmail.com | 2020-02-03 +022 | Elvis Zhang | zhangheng1536@gmail.com | 2020-02-03 +023 | Miraculous Wong | wm18840987261@163.com | 2020-02-03 +024 | Stan Lee | stanlee8080@outlook.com | 2020-02-04 +025 | Ray Wu | wgq.quan@gmail.com | 2020-02-04 +026 | Joe Kim | ksl2945@icloud.com | 2020-02-04 +027 | Rani | greatcanaka123@protonmail.com | 2020-02-04 +028 | Xing | xingyuan15@gmail.com | 2020-02-05 +029 | Matthew To | mattopolitan@gmail.com | 2020-02-05 +030 | Taihao Fu | taihao.fu@gmail.com | 2020-02-05 +031 | Wayne Zhang | shiziwen@gmail.com | 2020-02-05 +032 | LEUNG Cheung | fledna@ymail.com | 2020-02-06 +033 | Oleksandr Zolotarov | xgakamusic@gmail.com | 2020-02-06 +034 | Sakary Jia | starsakary@gmail.com| 2020-02-06 +035 | Maik (TRON-Family) | schierholz@eulibi.de | 2020-02-06 +036 | Jeancky Jiang | jeancky.jiang@outlook.com | 2020-02-07 +037 | Adi Lee | nwolvip@outlook.com | 2020-02-07 +038 | Alex Huang | oday0311@hotmail.com | 2020-02-08 +039 | Olivier Zhang | olenheim@hotmail.com | 2020-02-08 +040 | dzhcrypto  | dzhcrypto@gmail.com | 2020-02-08 +041 | Harry Xu | myfocus3722@gmail.com | 2020-02-08 +042 | Mangumpit Leo | mangumpitnorca@outlook.com | 2020-02-09 +043 | Leon Ji | leon.ji4965@gmail.com | 2020-02-09 +044 | Nile | freundjackie1982@gmail.com | 2020-02-09 +045 | Cris Wang | wangzihecisco@gmail.com | 2020-02-09 +046 | Imart Kang | imart.kang@gmail.com | 2020-02-10 +047 | Dorian Wu | yit323487@163.com | 2020-02-10 +048 | Allen Cheng | ctx157194515@126.com | 2020-02-10 | +049 | Dzyk | yes@dzyk.ru | 2020-02-11 | +050 | Allen Lee | al6303076@gmail.com | 2020-02-11 +051 | Rick Zhu | zkkzkk@icloud.com | 2020-02-11 +052 | Charis Wang | hccyqw@163.com | 2020-02-11 +053 | Zhang Yu | 971071009@qq.com | 2020-02-12 +054 | Matt Yue | yrp1990@gmail.com | 2020-02-12 +055 | Daryl Morey | just4onetime01@gmail.com | 2020-02-12 +056 | Adam Silver | adam.silver1024@gmail.com | 2020-02-13 +057 | Bruce | 001mawork@gmail.com | 2020-02-13 +058 | Yuki Xue | xueyuanying123@gmail.com | 2020-02-13 +059 | Boyan Shen | shenboyan0325@gmail.com | 2020-02-13 +060 | Slogan.Wang | wangxuguo@gmail.com | 2020-02-14 +061 | David Stern | loktarogar1@163.com | 2020-02-14 +062 | James | codewellliu@gmail.com | 2020-02-14 +063 | Holly Jiang | jianghong5215@gmail.com | 2020-02-15 +064 | Andrew Shulgin | shultz.andrey@gmail.com | 2020-02-17 +065 | Teslenko Andrey | tinkoya3@gmail.com | 2020-02-17 +066 | Kane Sun | kanesun0626@gmail.com | 2020-02-18 +067 | Maxim Sergeev | allugra@mail.ru | 2020-02-18 +068 | JK | houjingkuan1024@outlook.com | 2020-02-18 +069 | Victoria Green | mongogo2010@outlook.com | 2020-02-19 +070 | Valery Dzyk | dzykland@gmail.com | 2020-02-19 +071 | KrazyKewl Bruce | krazykewlgameztoken@gmail.com | 2020-02-20 +072 | Steven Cabrera Londoño | sevenupsoyo12@gmail.com | 2020-02-20 +073 | Captain Liu | workuseliubin@gmail.com | 2020-02-20 +074 | Kuntanury | kuntanury@gmail.com | 2020-02-20 +075 | Jacky | limaolei.jacky@gmail.com | 2020-02-21 +076 | Denis Pitcher | mail@denispitcher.com | 2020-02-22 +077 | Eric He | adhcname@gmail.com | 2020-02-24 +078 | Ekaterina Bukina | misssixty@mail.ru | 2020-02-24 +079 | Alan | ppb772074568@gmail.com | 2020-02-25 +080 | Moon Liu | june.jk9999@gmail.com | 2020-02-25 +081 | Jimmy | himalayan.8848.asia@gmail.com | 2020-02-26 +082 | Josie Wang | josie.wang66@gmail.com | 2020-02-27 +083 | Tiffani Yang | yangting950803@gmail.com | 2020-02-28 +084 | Mustafa khater | khatermustafa5@gmail.com | 2020-02-28 +085 | Bella Zhao | zling041@gmail.com | 2020-03-02 +086 | Hang Li | li1360214027@gmail.com | 2020-03-02 +087 | Yana | yana552200@gmail.com | 2020-03-04 +088 | shadow Q | qq07shadow@gmail.com | 2020-03-05 +089 | Elon Xu | xuchina67@gmail.com | 2020-03-06 +090 | Aldo Urem | aldo.urem@gmail.com | 2020-03-07 +091 | Zhiqiang Yu | zhiqiangyu.pku@gmail.com | 2020-03-09 +092 | Davi Nunes | davi@edu.unifor.br | 2020-03-11 +093 | Red An | hongan2020@outlook.com | 2020-03-12 +094 | Slash Wang | corechords@gmail.com | 2020-03-12 +095 | Roney Charles | roneycharles@edu.unifor.br | 2020-03-13 +096 | Nico Yang | luoyang103206@gmail.com | 2020-03-16 +097 | Charlie | charlie.liu77@gmail.com | 2020-03-18 +098 | Daimeng Zhang | daimengzhang0330@gmail.com | 2020-03-19 +099 | Iryna Sychuk | mimi.krich@gmail.com | 2020-03-20 +100 | TronLive | admin@tron.live | 2020-03-24 +Random Beacon| - | - | 2020-06-09 + diff --git a/src/bin/beacon.rs b/src/bin/beacon.rs index ada2a3d..386c1e8 100644 --- a/src/bin/beacon.rs +++ b/src/bin/beacon.rs @@ -7,6 +7,8 @@ extern crate byteorder; #[macro_use] extern crate hex_literal; +extern crate crypto; + use std::fs::File; use std::io::{BufWriter, BufReader}; use blake2_rfc::blake2b::Blake2b; @@ -32,9 +34,31 @@ fn main() { use byteorder::{ReadBytesExt, BigEndian}; use rand::{SeedableRng}; use rand::chacha::ChaChaRng; + use crypto::sha2::Sha256; + use crypto::digest::Digest; - // Place beacon value here (2^42 SHA256 hash of Bitcoin block hash #534861) - let beacon_value: [u8; 32] = hex!("2bf41a959668e5b9b688e58d613b3dcc99ee159a880cf764ec67e6488d8b8af3"); + // Place block hash here (block number #632800) + let mut beacon_value: [u8; 32] = hex!("00000000000000000002b7b77db5165aa09d80009c6688bf98746615d9c7ceb2"); + + // Performs 2^n hash iterations over it + const N: usize = 40; + + for i in 0..(1u64<