{"id":20368011,"url":"https://github.com/mcaptcha/pow_sha256","last_synced_at":"2025-04-12T05:37:49.256Z","repository":{"id":53825312,"uuid":"345004943","full_name":"mCaptcha/pow_sha256","owner":"mCaptcha","description":"SHA256 PoW library used in mCaptcha","archived":false,"fork":false,"pushed_at":"2023-07-04T14:42:36.000Z","size":4209,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:37:41.391Z","etag":null,"topics":["proof-of-work"],"latest_commit_sha":null,"homepage":"","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/mCaptcha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":null,"liberapay":"mcaptcha","issuehunt":null,"custom":["https://mcaptcha.org/donate"]}},"created_at":"2021-03-06T04:30:32.000Z","updated_at":"2024-11-08T05:25:56.000Z","dependencies_parsed_at":"2024-11-15T00:36:14.567Z","dependency_job_id":"78d63fe1-92f9-4610-9fe7-9d83cad74eee","html_url":"https://github.com/mCaptcha/pow_sha256","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mCaptcha%2Fpow_sha256","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mCaptcha%2Fpow_sha256/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mCaptcha%2Fpow_sha256/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mCaptcha%2Fpow_sha256/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mCaptcha","download_url":"https://codeload.github.com/mCaptcha/pow_sha256/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525168,"owners_count":21118616,"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":["proof-of-work"],"created_at":"2024-11-15T00:36:05.229Z","updated_at":"2025-04-12T05:37:49.184Z","avatar_url":"https://github.com/mCaptcha.png","language":"Rust","funding_links":["https://liberapay.com/mcaptcha","https://mcaptcha.org/donate"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003ePoW-SHA256\u003c/h1\u003e\n  \u003cp\u003e\n    \u003cstrong\u003ePoW-SHA256 - SHA256 based Proof-of-Work\u003c/strong\u003e\n  \u003c/p\u003e\n\n[![Documentation](https://img.shields.io/badge/docs-master-blue)](https://mcaptcha.github.io/pow_sha256/pow_sha256/index.html)\n[![Documentation](https://img.shields.io/badge/docs-0.2.1-yellow)](https://mcaptcha.org/docs/api/pow-sha256)\n![CI (Linux)](\u003chttps://github.com/mCaptcha/pow_sha256/workflows/CI%20(Linux)/badge.svg\u003e)\n[![dependency status](https://deps.rs/repo/github/mCaptcha/pow_sha256/status.svg)](https://deps.rs/repo/github/mCaptcha/pow_sha256)\n\u003cbr /\u003e\n[![codecov](https://codecov.io/gh/mCaptcha/pow_sha256/branch/master/graph/badge.svg)](https://codecov.io/gh/mCaptcha/pow_sha256)\n\n\u003c/div\u003e\n\n**NOTE: All versions prior to 0.3.1 produce broken PoWs, upgrade to\nlatest version**\n\n\u003e pow_sha256's copy of `pow_sha256` by\n\u003e [robkorn](https://github.com/robkorn/pow_sha256)\n\u003e which is a modified version of [`pow` library](https://github.com/bddap/pow).\n\u003e All copyrights belong to the original authors.\n\nRust crate which generates SHA256 Proofs of Work on serializable datatypes.\n\nWhether for blockchain-related projects or Hashcash-like schemes, this\ncrate can be used to prove work was done on a given serializable input.\nThe input merely needs to implement `serde::Deserialize` to be used.\n\nThis is a fork of the [`pow` library](https://github.com/bddap/pow) by\n[@robkorn](https://github.com/robkorn/pow_sha256)) with some new\nadditions. Primary of these being:\n\n- PoW datatype now offers a constructor\n- Salt is no longer hard coded into the library, users can provide\n  unique salts.\n\nOther small changes have also been included of various importance but\nmostly just stylistic/ease of use improvements.\n\n## Documentation\n\n- [master-branch](https://mcaptcha.github.io/pow_sha256/pow_sha256/index.html)\n- [All published versions](https://mcaptcha.org/docs/api/pow-sha256)\n\n## Examples\n\nProve work specifically targeting a phrase.\n\n```rust\n\nuse pow_sha256::{ConfigBuilder, PoW};\n\nfn main() {\n    let config = ConfigBuilder::default()\n        .salt(\"myrandomsaltisnotlongenoug\".into())\n        .build()\n        .unwrap();\n\n    let phrase = \"ironmansucks\";\n\n    const DIFFICULTY: u32 = 1000;\n\n    let work = config.prove_work(\u0026phrase, DIFFICULTY).unwrap();\n    assert!(config.calculate(\u0026work, \u0026phrase).unwrap() \u003e= DIFFICULTY);\n    assert!(config.is_valid_proof(\u0026work, \u0026phrase));\n    assert!(config.is_sufficient_difficulty(\u0026work, DIFFICULTY));\n}\n```\n\nProve more difficult work. This time targeting a time.\n\n```rust\n// Greater difficulty this time around. Takes around 100,000 hashes\n// to find a nonce of the correct difficulty.\n\n\nuse pow_sha256::{ConfigBuilder, PoW};\n\nfn main() {\n    let config = ConfigBuilder::default()\n        .salt(\"myrandomsaltisnotlongenoug\".into())\n        .build()\n        .unwrap();\n\n    let phrase = \"ironmansucks\";\n\n    const DIFFICULTY: u32 = 100_000;\n\n    let work = config.prove_work(\u0026phrase, DIFFICULTY).unwrap();\n\n    assert!(config.calculate(\u0026work, \u0026phrase).unwrap() \u003e= DIFFICULTY);\n    assert!(config.is_valid_proof(\u0026work, \u0026phrase));\n    assert!(config.is_sufficient_difficulty(\u0026work, DIFFICULTY));\n}\n\n```\n\n## Hashing Scheme\n\n`SALT` is used as prefix to prevent PoW reuse from other systems such as\nproof of work blockchains.\n\nSHA256 is calculated over the concatenation of the:\n\n- SALT\n- Serialized Input `T`\n- Nonce\n\nThe first 16 bytes of the resulting hash are interpreted as a 128 bit\nunsigned integer and saved as the final result.\n\n## Choosing a difficulty setting.\n\nDepending on your use case, difficulty settings often are best set\ndynamically a la bitcoin.\n\nHowever if your use case requires manual setting then it is trivial to\nset one yourself. One way to do so is to choose the average number of\nhashes desired with a function like this:\n\n```rust\nfn get_difficulty(average: u128) -\u003e u128 {\n    debug_assert_ne!(average, 0, \"It is impossible to prove work in zero attempts.\");\n    let m = u128::max_value();\n    m - m / average\n}\n```\n\nConversely we can use the same equation to calculate the probable number\nof hashes required to satisfy a given difficulty:\n\n```rust\nfn est_average(difficulty: u128) -\u003e u128 {\n    let m = u128::max_value();\n    if difficulty == m {\n        return m;\n    }\n    m / (m - difficulty)\n}\n```\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md)\n\n## License\n\nThis project is dual-licensed under `Apache License Version 2.0` or `MIT license`.\n\n## Funding\n\n### NLnet\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg\n\t\theight=\"150px\"\n\t\talt=\"NLnet NGIZero logo\"\n\t\tsrc=\"./docs/third-party/NGIZero-green.hex.svg\"\n\t/\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n2023 development is funded through the [NGI0 Entrust\nFund](https://nlnet.nl/entrust), via [NLnet](https://nlnet.nl/). Please\nsee [here](https://nlnet.nl/project/mCaptcha/) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcaptcha%2Fpow_sha256","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcaptcha%2Fpow_sha256","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcaptcha%2Fpow_sha256/lists"}