{"id":21970085,"url":"https://github.com/scroll-tech/zktrie","last_synced_at":"2025-08-22T00:32:31.886Z","repository":{"id":61627718,"uuid":"531531456","full_name":"scroll-tech/zktrie","owner":"scroll-tech","description":"Wrapper for zktrie as a rust crate","archived":false,"fork":false,"pushed_at":"2024-04-08T08:23:18.000Z","size":1597,"stargazers_count":36,"open_issues_count":7,"forks_count":17,"subscribers_count":20,"default_branch":"main","last_synced_at":"2024-04-09T02:42:54.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/scroll-tech.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}},"created_at":"2022-09-01T13:27:18.000Z","updated_at":"2024-04-15T09:02:14.455Z","dependencies_parsed_at":"2023-02-17T19:15:26.509Z","dependency_job_id":"f287b6c3-3b4d-4b3d-8a4b-d3a7459a38d8","html_url":"https://github.com/scroll-tech/zktrie","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-tech%2Fzktrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-tech%2Fzktrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-tech%2Fzktrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-tech%2Fzktrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scroll-tech","download_url":"https://codeload.github.com/scroll-tech/zktrie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542289,"owners_count":18242332,"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-11-29T14:30:57.639Z","updated_at":"2024-12-20T06:07:22.967Z","avatar_url":"https://github.com/scroll-tech.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zktrie\n\nzktrie is a binary poseidon trie used in Scroll Network.\n\nGo and Rust implementations are provided inside this repo.\n\n## Design Doc\n\nSee the technical [docs here](docs/zktrie.md).\n\n## Example codes\n\n[Rust example code](https://github.com/scroll-tech/stateless-block-verifier/blob/56b4aaf1d89a297a16a2934f579a116de024d213/src/executor.rs#L103)  \n[Go example code](https://github.com/scroll-tech/go-ethereum/blob/develop/trie/zk_trie.go)\n\n## Rust Usage\n\nWe must init the crate with a poseidon hash scheme before any actions.  [This](https://github.com/scroll-tech/zkevm-circuits/blob/e5c5522d544ce936290ef53e00c2d17a0e9b8d0b/zktrie/src/state/builder.rs#L17) is an example\n\n\nAll the zktrie can share one underlying database, which can be initialized by putting the encoded trie node data directly\n\n```rust\n\nlet mut db = ZkMemoryDb::new();\n\n/* for some trie node data encoded as bytes `buf` */\ndb.add_node_data(\u0026buf).unwrap();\n\n/* or if we have both trie node data and key encoded as bytes */\ndb.add_node_bytes(\u0026buf, Some(\u0026key)).unwrap();\n\n```\n\nWe must prove the root for a trie to create it, the corresponding root node must have been input in the database\n\n```rust\nlet root = hex::decode(\"079a038fbf78f25a2590e5a1d2fa34ce5e5f30e9a332713b43fa0e51b8770ab8\")\n    .unwrap();\nlet root: Hash = root.as_slice().try_into().unwrap();\n\nlet mut trie = db.new_trie(\u0026root).unwrap();\n```\n\nThe trie can be updated by a single 32-bytes buffer if it is storage trie, or a `[[u8;32];4]` array for the account data `{nonce, balance, codehash, storageRoot}` if it is account trie\n\n```rust\nlet acc_buf = hex::decode(\"4cb1aB63aF5D8931Ce09673EbD8ae2ce16fD6571\").unwrap();\nlet code_hash: [u8;32] = hex::decode(\"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\").unwrap().as_slice().try_into().unwrap();\n\n/* update an externally-owned account (so its storageRoot is all zero and code_hash equal to keccak256(nil)) */\nlet newacc: AccountData = [nonce, balance, code_hash, [0; FIELDSIZE]];\ntrie.update_account(\u0026acc_buf, \u0026newacc).unwrap();\n\n```\n\nThe root and mpt path for an address can be query from trie by `ZkTrie::root` and `ZkTrie::prove`\n\n\n## License\n\nLicensed under either of\n\n- Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)\n- MIT License (http://opensource.org/licenses/MIT)\n\nat your discretion.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscroll-tech%2Fzktrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscroll-tech%2Fzktrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscroll-tech%2Fzktrie/lists"}