{"id":24492865,"url":"https://github.com/noway/sha256-var-circom","last_synced_at":"2026-04-14T17:32:01.749Z","repository":{"id":43467981,"uuid":"458788068","full_name":"noway/sha256-var-circom","owner":"noway","description":"Variable length sha256 hash function in Circom","archived":false,"fork":false,"pushed_at":"2023-12-08T12:20:29.000Z","size":93,"stargazers_count":6,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T03:28:07.252Z","etag":null,"topics":["circom","circuit","sha256","variable-length","zk-snarks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/noway.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":"2022-02-13T11:23:22.000Z","updated_at":"2024-02-08T19:43:31.000Z","dependencies_parsed_at":"2025-03-15T03:36:22.831Z","dependency_job_id":null,"html_url":"https://github.com/noway/sha256-var-circom","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/noway/sha256-var-circom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noway%2Fsha256-var-circom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noway%2Fsha256-var-circom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noway%2Fsha256-var-circom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noway%2Fsha256-var-circom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noway","download_url":"https://codeload.github.com/noway/sha256-var-circom/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noway%2Fsha256-var-circom/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31808505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T11:13:53.975Z","status":"ssl_error","status_checked_at":"2026-04-14T11:13:53.299Z","response_time":153,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["circom","circuit","sha256","variable-length","zk-snarks"],"created_at":"2025-01-21T19:14:39.743Z","updated_at":"2026-04-14T17:32:01.734Z","avatar_url":"https://github.com/noway.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sha256Var.circom\nVariable length sha256 hash function in [Circom](https://docs.circom.io/).\n\n## Problem\n- [Sha256](https://github.com/iden3/circomlib/tree/master/circuits/sha256) function from [circomlib](https://github.com/iden3/circomlib) requires length of the input to be known at compile time.\n- [Sha256](https://github.com/TheFrozenFire/snark-jwt-verify/blob/master/circuits/sha256.circom) function from [TheFrozenFire/snark-jwt-verify](https://github.com/TheFrozenFire/snark-jwt-verify) requires the input to be crafted in a special format by an out-of-circuit function.\n\n## Solution\nBuilding on [TheFrozenFire/snark-jwt-verify](https://github.com/TheFrozenFire/snark-jwt-verify), this circuit implements variable length sha256 hash function in Circom.\n\n## Usage\nGiven `input` (in bits) of length `input_len` (in bits), the following code returns the hash of `input`:\n\n```circom\nvar BLOCK_LEN = 512;\nvar MAX_BLOCKS = 2;\nvar SHA256_LEN = 256;\n\n// See bellow for explanation\nvar BlockSpace = 1;\n\ncomponent sha256 = Sha256Var(BlockSpace);\n\n// Set input\nsha256.len \u003c== input_len;\nfor (var i = 0; i \u003c BLOCK_LEN * MAX_BLOCKS; i++) {\n    sha256.in[i] \u003c== input[i];\n}\n\n// Export the sha256 hash\nfor (var i = 0; i \u003c SHA256_LEN; i++) {\n    hash[i] \u003c== sha256.out[i];\n}\n```\n\nFor more usage, see [test/sha256var.js](test/sha256var.js).\n\n## Block space cheat sheet\n- 1 block space = max 2 blocks = max 960 bits = 0-119 characters\n- 2 block space = max 4 blocks = max 1984 bits = 0-247 characters\n- 3 block space = max 8 blocks = max 4032 bits = 0-503 characters\n- 4 block space = max 16 blocks = max 8128 bits = 0-1015 characters\n\n## How it works\nWe take the avaialble block space and prepare `2^BlockSpace` blocks. We put the data into the blocks. Each block is prepared using the `Sha256InputBlock` component which expects the block to either be the last block or not. If it is the last block, `L` is added in the last 64 bits. If it's not, block is copied over normally. The `1` bit is also set at the end of the input length.\n\n## Limitations\nThe bigger the block space, the bigger the circuit. While 1 and 2 block spaces are ok, the 3 block space is slow and the 4 is slower.\n\n## Performance\nMeasured on a Mac\n\n|              | compile time (s) | run time (s) | constraints (lines in .sym file) |\n|--------------|------------------|--------------|----------------------------------|\n| BlockSpace=1 |            6.221 |       27.303 |                           435332 |\n| BlockSpace=2 |           12.055 |        96.13 |                           869606 |\n| BlockSpace=3 |           24.241 |       350.22 |                          1738150 |\n| BlockSpace=4 |           51.843 |     1356.917 |                          3475234 |\n\n## Tests\n- Run `make test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoway%2Fsha256-var-circom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoway%2Fsha256-var-circom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoway%2Fsha256-var-circom/lists"}