{"id":13532463,"url":"https://github.com/poanetwork/vdf","last_synced_at":"2025-04-05T08:07:49.517Z","repository":{"id":53153765,"uuid":"156712885","full_name":"poanetwork/vdf","owner":"poanetwork","description":"An implementation of Verifiable Delay Functions in Rust","archived":false,"fork":false,"pushed_at":"2021-04-04T08:51:45.000Z","size":1093,"stargazers_count":179,"open_issues_count":19,"forks_count":54,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-29T07:08:07.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poanetwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-08T13:42:29.000Z","updated_at":"2025-02-15T20:23:46.000Z","dependencies_parsed_at":"2022-09-13T17:50:28.185Z","dependency_job_id":null,"html_url":"https://github.com/poanetwork/vdf","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poanetwork%2Fvdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poanetwork%2Fvdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poanetwork%2Fvdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poanetwork%2Fvdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poanetwork","download_url":"https://codeload.github.com/poanetwork/vdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305934,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:11.134Z","updated_at":"2025-04-05T08:07:49.495Z","avatar_url":"https://github.com/poanetwork.png","language":"Rust","funding_links":[],"categories":["Rust","Cryptography"],"sub_categories":["Others"],"readme":"# Verifiable Delay Function (VDF) Implementation in Rust\n\n## What is a VDF?\n\nA Verifiable Delay Function (VDF) is a function that requires substantial time\nto evaluate (even with a polynomial number of parallel processors) but can be\nvery quickly verified as correct. VDFs can be used to construct randomness\nbeacons with multiple applications in a distributed network environment. By\nintroducing a time delay during evaluation, VDFs prevent malicious actors from\ninfluencing output. The output cannot be differentiated from a random number\nuntil the final result is computed.  See \u003chttps://eprint.iacr.org/2018/712.pdf\u003e\nfor more details.\n\n## Description\n\nThis VDF implementation is written in Rust.  The GMP library is used for\narithmetic and greatest common divisor (GCD) calculations.  We use class groups\nto implement the approaches described in the following papers:\n\n1. [Simple Verifiable Delay Functions](https://eprint.iacr.org/2018/627.pdf). Pietrzak, 2018\n2. [Efficient Verifiable Delay Functions](https://eprint.iacr.org/2018/623.pdf). Wesolowski, 2018\n\nThe chosen generator is (2, 1, c), where c is calculated from the provided\ndiscriminant.  A form is represented internally (a, b, c), with the\ndiscriminant not being used in most omputations.  This implementation performs\nreduction is performed after every multiplication and squaring, as not doing so\ndid not give any gains in our benchmarks.\n\n\nThis repo includes three crates:\n\n* `classgroup`: a class group implementation, as well as a trait for class\n    groups.\n* `vdf`: a Verifyable Delay Function (VDF) trait, as well as an\n    implementation of that trait.\n* `vdf-cli`: a command-line interface to the vdf crate. It also includes\n    additional commands, which are deprecated and will be replaced by a CLI to\n    the classgroup crate.\n\n## Usage\n\n- Install [Rust].  We (POA Networks) have tested the code with the latest\n    stable, beta, and nightly versions of Rust.  It may work with older\n    versions, but this is not guaranteed.\n- Install the [GNU Multiple Precision Library](https://gmplib.org/)\n    * On Debian and derivatives (including Ubuntu):\n        ```sh\n        $ sudo apt-get install -y libgmp-dev\n        ```\n    * On Red Hat and derivatives (Fedora, CentOS)\n        ```sh\n        $ sudo dnf -y install gmp-devel\n        ```\n- Download and prepare the repository\n\n    ```sh\n    $ git clone https://github.com/poanetwork/vdf.git\n    $ cargo install --path=vdf-cli\n    $ # or for the competition binary\n    $ cargo install --path=vdf-competition\n    ```\n\n### Command Line Interface\n\nTo initiate, use the `vdf-cli` command followed by 2 arguments:\n\n- _challenge_: byte string of arbitrary length\n- _difficulty_: number of iterations, each iteration requires more time to evaluate\n\nThis generates the Weslowski proof of time.  To generate the Pietrzak proof of\ntime, pass `-tpietrzak`.  For detailed usage information, run `vdf-cli --help`.\n\nOnce complete you will see the output, returned as a `Vec\u003cu8\u003e`.  The CLI tool\nhex-encodes its output.\n\n**Example**\n\n```sh\n$ vdf-cli aa 100\n005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b\n```\n\nTo verify, use the `vdi-cli` command with the same arguments and include the\noutput.\n\n**Example**\n\n```sh\n$ vdf-cli aa 100 005271e8f9ab2eb8a2906e851dfcb5542e4173f016b85e29d481a108dc82ed3b3f97937b7aa824801138d1771dea8dae2f6397e76a80613afda30f2c30a34b040baaafe76d5707d68689193e5d211833b372a6a4591abb88e2e7f2f5a5ec818b5707b86b8b2c495ca1581c179168509e3593f9a16879620a4dc4e907df452e8dd0ffc4f199825f54ec70472cc061f22eb54c48d6aa5af3ea375a392ac77294e2d955dde1d102ae2ace494293492d31cff21944a8bcb4608993065c9a00292e8d3f4604e7465b4eeefb494f5bea102db343bb61c5a15c7bdf288206885c130fa1f2d86bf5e4634fdc4216bc16ef7dac970b0ee46d69416f9a9acee651d158ac64915b\nProof is valid\n```\n### VDF Library\n\n\u003c!--\nKeep as is, and possibly include argument explanations as well (for byte_length for example). May not be needed though is CLI is main user interaction tool.\n--\u003e\n\n```rust\nextern crate vdf;\nuse vdf::{InvalidProof, PietrzakVDFParams, VDFParams, WesolowskiVDFParams, VDF};\n\n/// The correct solution.\nconst CORRECT_SOLUTION: \u0026[u8] =\n  b\"\\x00\\x52\\x71\\xe8\\xf9\\xab\\x2e\\xb8\\xa2\\x90\\x6e\\x85\\x1d\\xfc\\xb5\\x54\\x2e\\x41\\x73\\xf0\\x16\\\n  \\xb8\\x5e\\x29\\xd4\\x81\\xa1\\x08\\xdc\\x82\\xed\\x3b\\x3f\\x97\\x93\\x7b\\x7a\\xa8\\x24\\x80\\x11\\x38\\\n  \\xd1\\x77\\x1d\\xea\\x8d\\xae\\x2f\\x63\\x97\\xe7\\x6a\\x80\\x61\\x3a\\xfd\\xa3\\x0f\\x2c\\x30\\xa3\\x4b\\\n  \\x04\\x0b\\xaa\\xaf\\xe7\\x6d\\x57\\x07\\xd6\\x86\\x89\\x19\\x3e\\x5d\\x21\\x18\\x33\\xb3\\x72\\xa6\\xa4\\\n  \\x59\\x1a\\xbb\\x88\\xe2\\xe7\\xf2\\xf5\\xa5\\xec\\x81\\x8b\\x57\\x07\\xb8\\x6b\\x8b\\x2c\\x49\\x5c\\xa1\\\n  \\x58\\x1c\\x17\\x91\\x68\\x50\\x9e\\x35\\x93\\xf9\\xa1\\x68\\x79\\x62\\x0a\\x4d\\xc4\\xe9\\x07\\xdf\\x45\\\n  \\x2e\\x8d\\xd0\\xff\\xc4\\xf1\\x99\\x82\\x5f\\x54\\xec\\x70\\x47\\x2c\\xc0\\x61\\xf2\\x2e\\xb5\\x4c\\x48\\\n  \\xd6\\xaa\\x5a\\xf3\\xea\\x37\\x5a\\x39\\x2a\\xc7\\x72\\x94\\xe2\\xd9\\x55\\xdd\\xe1\\xd1\\x02\\xae\\x2a\\\n  \\xce\\x49\\x42\\x93\\x49\\x2d\\x31\\xcf\\xf2\\x19\\x44\\xa8\\xbc\\xb4\\x60\\x89\\x93\\x06\\x5c\\x9a\\x00\\\n  \\x29\\x2e\\x8d\\x3f\\x46\\x04\\xe7\\x46\\x5b\\x4e\\xee\\xfb\\x49\\x4f\\x5b\\xea\\x10\\x2d\\xb3\\x43\\xbb\\\n  \\x61\\xc5\\xa1\\x5c\\x7b\\xdf\\x28\\x82\\x06\\x88\\x5c\\x13\\x0f\\xa1\\xf2\\xd8\\x6b\\xf5\\xe4\\x63\\x4f\\\n  \\xdc\\x42\\x16\\xbc\\x16\\xef\\x7d\\xac\\x97\\x0b\\x0e\\xe4\\x6d\\x69\\x41\\x6f\\x9a\\x9a\\xce\\xe6\\x51\\\n  \\xd1\\x58\\xac\\x64\\x91\\x5b\";\nfn main() {\n    // The length of the prime numbers generated, in bits.\n    let num_bits: u16 = 2048;\n\n    // An instance of the VDF.  Instances can be used arbitrarily many times.\n    let pietrzak_vdf = PietrzakVDFParams(num_bits).new();\n\n    // Solve for the correct answer.  This will take a minute or two.\n    assert_eq!(\n        \u0026pietrzak_vdf.solve(b\"\\xaa\", 10000).unwrap()[..],\n        CORRECT_SOLUTION\n    );\n\n    // Verify the answer.  This should be far faster (less than a second).\n    assert!(pietrzak_vdf.verify(b\"\\xaa\", 10000, CORRECT_SOLUTION).is_ok());\n}\n```\n\n## Benchmarks\n\nBenchmarks are provided for the classgroup operations. To run benchmarks:\n\n```sh\n$ ./bench.sh \u003cyour challenge here\u003e\n```\n\nAdditional benchmarks are under development.\n\n### Current Benchmarks\n\nThese were generated by `./bench.sh aadf`.  Outliers could be due to preemption\nby the OS and/or hypervisor.  Changes are relative to the previous test run\ndone on the same machine.  Since the previous run was done with different\nsettings and/or code than reported here, these changes are not meaningful.\n\n```text\nBenchmarking square with seed aadf: 512: Collecting 100 samples in estimated 5.0439 s (374k iteratio                                                                                                    square with seed aadf: 512\n                        time:   [13.301 us 13.333 us 13.372 us]\n                        change: [-22.286% -21.745% -21.225%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 22 outliers among 100 measurements (22.00%)\n  5 (5.00%) high mild\n  17 (17.00%) high severe\n\nBenchmarking multiply with seed aadf: 512: Collecting 100 samples in estimated 5.0452 s (293k iterat                                                                                                    multiply with seed aadf: 512\n                        time:   [17.219 us 17.251 us 17.287 us]\n                        change: [-24.323% -23.739% -23.149%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 10 outliers among 100 measurements (10.00%)\n  4 (4.00%) high mild\n  6 (6.00%) high severe\n\nBenchmarking square with seed aadf: 1024: Collecting 100 samples in estimated 5.0822 s (177k iterati                                                                                                    square with seed aadf: 1024\n                        time:   [28.672 us 28.716 us 28.767 us]\n                        change: [-29.947% -29.339% -28.708%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 8 outliers among 100 measurements (8.00%)\n  1 (1.00%) low mild\n  1 (1.00%) high mild\n  6 (6.00%) high severe\n\nBenchmarking multiply with seed aadf: 1024: Collecting 100 samples in estimated 5.0886 s (136k itera                                                                                                    multiply with seed aadf: 1024\n                        time:   [37.163 us 37.207 us 37.254 us]\n                        change: [-21.403% -20.750% -20.170%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 8 outliers among 100 measurements (8.00%)\n  1 (1.00%) low mild\n  1 (1.00%) high mild\n  6 (6.00%) high severe\n\nBenchmarking square with seed aadf: 2048: Collecting 100 samples in estimated 5.2519 s (76k iteratio                                                                                                    square with seed aadf: 2048\n                        time:   [69.115 us 69.254 us 69.430 us]\n                        change: [-28.091% -27.738% -27.341%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 8 outliers among 100 measurements (8.00%)\n  1 (1.00%) low mild\n  1 (1.00%) high mild\n  6 (6.00%) high severe\n\nBenchmarking multiply with seed aadf: 2048: Collecting 100 samples in estimated 5.0554 s (56k iterat                                                                                                    multiply with seed aadf: 2048\n                        time:   [90.922 us 91.057 us 91.201 us]\n                        change: [-25.236% -24.794% -24.336%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 13 outliers among 100 measurements (13.00%)\n  2 (2.00%) low mild\n  5 (5.00%) high mild\n  6 (6.00%) high severe\n```\n\n[Rust]: \u003chttps://doc.rust-lang.org/cargo/getting-started/installation.html\u003e\n\n\n## License\n\nCopyright 2018 Chia Network Inc and POA Networks Ltd.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoanetwork%2Fvdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoanetwork%2Fvdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoanetwork%2Fvdf/lists"}