{"id":18014278,"url":"https://github.com/dhl/blake2b-solidity","last_synced_at":"2025-06-22T03:41:38.880Z","repository":{"id":258145937,"uuid":"869955754","full_name":"dhl/blake2b-solidity","owner":"dhl","description":"A BLAKE2b implementation in Solidity, with support for keying, salting, and personalization","archived":false,"fork":false,"pushed_at":"2024-10-16T05:45:13.000Z","size":126,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T23:41:34.292Z","etag":null,"topics":["blake2","blake2b","ethereum","evm","smart-contracts","solidity"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhl.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-09T07:36:32.000Z","updated_at":"2025-04-02T08:52:45.000Z","dependencies_parsed_at":"2024-10-17T20:50:11.872Z","dependency_job_id":null,"html_url":"https://github.com/dhl/blake2b-solidity","commit_stats":null,"previous_names":["dhl/blake2b-solidity"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dhl/blake2b-solidity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhl%2Fblake2b-solidity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhl%2Fblake2b-solidity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhl%2Fblake2b-solidity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhl%2Fblake2b-solidity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhl","download_url":"https://codeload.github.com/dhl/blake2b-solidity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhl%2Fblake2b-solidity/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261232844,"owners_count":23128169,"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":["blake2","blake2b","ethereum","evm","smart-contracts","solidity"],"created_at":"2024-10-30T04:07:34.322Z","updated_at":"2025-06-22T03:41:33.863Z","avatar_url":"https://github.com/dhl.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# blake2b-solidity\n\n![tests and coverage](https://github.com/dhl/blake2b-solidity/actions/workflows/test.yml/badge.svg)\n[![codecov](https://codecov.io/github/dhl/blake2b-solidity/graph/badge.svg?token=4WOC5GEC7H)](https://codecov.io/github/dhl/blake2b-solidity)\n\n`blake2b-solidity` is a high-performance Solidity implementation of the [BLAKE2b](https://www.blake2.net/) hash\nfunction.\n\n## Table of Contents\n\n- [Motivation](#motivation)\n- [Features](#features)\n- [Gas Usage](#gas-usage)\n- [Testing](#testing)\n- [Caveats](#caveats)\n- [Acknowledgements](#acknowledgements)\n- [References](#references)\n- [License](#license)\n\n## Motivation\n\nThe primary goal of this project is to provide the most efficient and feature-complete BLAKE2b implementation for the\nEthereum Virtual Machine (EVM) to support interoperability with other cryptographic applications and Proof-of-Work (PoW)\nalgorithms.\n\nBLAKE2b is renowned for its speed, security, and simplicity. Notable applications of BLAKE2b in blockchain include:\n\n* [Zcash](https://z.cash): A privacy-focused blockchain that uses BLAKE2b for its Equihash proof-of-work algorithm.\n* [IPFS](https://ipfs.tech): A decentralized file storage system that uses BLAKE2b for content addressing.\n\nThe lack of full native support for BLAKE2b in the Ethereum Virtual Machine (EVM) poses challenges for application\ndevelopers to validate and interoperate with these applications within Solidity smart contracts. Consequently,\ndevelopers are often forced to either adopt another hashing algorithm such as keccak-256 or sha256, both of which enjoy\nnative support in EVM, or trust validation performed by some trusted operator.\n\nEfforts such as [EIP-152](https://eips.ethereum.org/EIPS/eip-152)\nand [Project Alchemy](https://github.com/Consensys/Project-Alchemy/tree/master/contracts/BLAKE2b) by Consensys have\nattempted to provide a BLAKE2/BLAKE2b implementation. However, EIP-152 only provides a precompiled F compress function\ninstead of the full hash function, and Project Alchemy, which started before EIP-152, could not take advantage of the\nprecompile compress function, did not pass all reference implementation test vectors, and is no longer maintained.\n\n`blake2b-solidity` aims to address these limitations by providing a high-performance, gas-efficient, and\nfeature-complete BLAKE2b implementation in Solidity, enabling developers to leverage the benefits of BLAKE2b directly\nwithin Ethereum smart contracts.\n\n## Features\n\n1. **Gas-efficient** ⛽️ (See [Gas Usage](#gas-usage)).\n2. **Variable Input Support**: Accepts up to a theoretical maximum of 16 exbibytes ($2^{64}$ bytes,\n   see [Caveats](#caveats)).\n4. **Salting**: Supports salting for added security.\n5. **Personalized Hashes**: Supports personalized hashes.\n6. **Zero External Dependency**: No external Solidity dependency. Only the EIP-152 precompiled contract is used.\n\n## Gas Usage\n\nThe `blake2b-solidity` implementation is gas efficient.\n\nWe benchmarked our implementation against other available hash functions by hashing the test vectors in the test suite\nand returning the result in `bytes`. Test vectors that involve optional extensions (keying, salting, personalization)\nwere excluded in our benchmark.\n\n| Hash Function          | Implementation        | Average Gas Cost | Digest Size (bits) | Relative Gas Cost (%) |\n|------------------------|-----------------------|------------------|--------------------|-----------------------|\n| Blake2b (Consensys)    | Solidity              | 255,427          | 512                | 1047%                 |\n| Blake2b (this project) | Solidity + Precompile | 27,853           | 512                | 114%                  |\n| ripemd160              | Native                | 25,719           | 160                | 105%                  |\n| sha256                 | Native                | 24,834           | 256                | 102%                  |\n| keccak256              | Native                | 24,400           | 256                | 100%                  |\n\n## Caveats\n\n1. Input size above 1 MiB ($2^{20}$ bytes) will likely fail due to block gas limit constraints (30 million gas at time\n   of writing).\n2. Only the lower 64-bit of the `t` counter is implemented to save gas. This restricts the maximum supported input size\n   to $2^{64}$ bytes. The maximum allowed input size for BLAKE2b is $2^{128}$ bytes. Given the input size constraint\n   above, this is not going to be an issue.\n\n## Testing\n\nThis project includes a comprehensive test suite to ensure strict conformance to the BLAKE2b specification.\n\nCore test vectors are taken from the\nBLAKE2b [reference implementation](https://github.com/BLAKE2/BLAKE2/blob/5cbb39c9ef8007f0b63723e3aea06cd0887e36ad/testvectors/blake2-kat.json).\n\nAdditional test vectors are taken from official [libsodium](https://github.com/jedisct1/libsodium) tests.\n\n## Acknowledgements\n\nWe are grateful\nto [Tjaden Hess](https://github.com/tjade273), [Matt Luongo](https://github.com/mhluongo), [Piotr Dyraga](https://github.com/pdyraga),\nand [James Hancock](https://github.com/MadeOfTin) for their contributions to EIP-152 and the initial reference\nimplementation of the BLAKE2b F compression function in [go-ethereum](https://github.com/ethereum/go-ethereum).\n\nWe would also like to thank [Emil Bay](https://github.com/emilbayes) for making his work on BLAKE2b test vectors\navailable.\n\n## References\n\n1. [RFC-7693: The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC)](https://datatracker.ietf.org/doc/html/rfc7693)\n2. [BLAKE2: Simpler, Smaller, Fast as MD5](https://www.blake2.net/blake2.pdf)\n3. [EIP-152: Add BLAKE2 compression function `F` precompile](https://eips.ethereum.org/EIPS/eip-152)\n\n## License\n\n`blake2b-solidity` is released under the [MIT License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhl%2Fblake2b-solidity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhl%2Fblake2b-solidity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhl%2Fblake2b-solidity/lists"}