Rust 中可验证延迟函数的实现
A Verifiable Delay Function (VDF) is a function that requires substantial time to evaluate (even with a polynomial number of parallel processors) but can be very quickly verified as correct. VDFs can be used to construct randomness beacons with multiple applications in a distributed network environment. By introducing a time delay during evaluation, VDFs prevent malicious actors from influencing output. The output cannot be differentiated from a random number until the final result is computed. See for more details.
This VDF implementation is written in Rust. The GMP library is used for arithmetic and greatest common divisor (GCD) calculations. We use class groups to implement the approaches described in the following papers:
The chosen generator is (2, 1, c), where c is calculated from the provided discriminant. A form is represented internally (a, b, c), with the discriminant not being used in most omputations. This implementation performs reduction is performed after every multiplication and squaring, as not doing so did not give any gains in our benchmarks.
This repo includes three crates:
classgroup: a class group implementation, as well as a trait for class
groups.vdf: a Verifyable Delay Function (VDF) trait, as well as an
implementation of that trait.vdf-cli: a command-line interface to the vdf crate. It also includes
additional commands, which are deprecated and will be replaced by a CLI to
the classgroup crate.Install [Rust]. We (POA Networks) have tested the code with the latest stable, beta, and nightly versions of Rust. It may work with older versions, but this is not guaranteed.
Install the GNU Multiple Precision Library
$ sudo apt-get install -y libgmp-dev$ sudo dnf -y install gmp-develDownload and prepare the repository
$ git clone https://github.com/poanetwork/vdf.git
$ cargo install --path=vdf-cli
$ # or for the competition binary
$ cargo install --path=vdf-competitionTo initiate, use the vdf-cli command followed by 2 arguments:
This generates the Weslowski proof of time. To generate the Pietrzak proof of
time, pass -tpietrzak. For detailed usage information, run vdf-cli --help.
Once complete you will see the output, returned as a Vec. The CLI tool
hex-encodes its output.
Example
$ vdf-cli aa 100
005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915bTo verify, use the vdi-cli command with the same arguments and include the
output.
Example
$ vdf-cli aa 100 005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b
Proof is valid…Benchmarks are provided for the classgroup operations. To run benchmarks:
$ ./bench.sh Additional benchmarks are under development.
These were generated by ./bench.sh aadf. Outliers could be due to preemption
by the OS and/or hypervisor. Changes are relative to the previous test run
done on the same machine. Since the previous run was done with different
settings and/or code than reported here, these changes are not meaningful.
Benchmarking square with seed aadf: 512: Collecting 100 samples in estimated 5.0439 s (374k iteratio square with seed aadf: 512
time: [13.301 us 13.333 us 13.372 us]
change: [-22.286% -21.745% -21.225%] (p = 0.00
## License
Copyright 2018 Chia Network Inc and POA Networks Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.暂无开放 Issues,或尚未同步最近议题。