{"id":28349714,"url":"https://github.com/hackbg/cw-storage-benchmarks","last_synced_at":"2025-07-11T05:04:19.451Z","repository":{"id":233122173,"uuid":"654107084","full_name":"hackbg/cw-storage-benchmarks","owner":"hackbg","description":"Gas benchmarks for implementations of storage structures in CosmWasm.","archived":false,"fork":false,"pushed_at":"2023-08-05T16:58:22.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T07:35:28.730Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackbg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-15T11:59:49.000Z","updated_at":"2023-11-10T09:43:13.000Z","dependencies_parsed_at":"2024-04-14T01:55:11.110Z","dependency_job_id":"71226695-16af-406b-a0d7-ce4cf24a83e5","html_url":"https://github.com/hackbg/cw-storage-benchmarks","commit_stats":null,"previous_names":["hackbg/cw-storage-benchmarks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackbg/cw-storage-benchmarks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackbg%2Fcw-storage-benchmarks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackbg%2Fcw-storage-benchmarks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackbg%2Fcw-storage-benchmarks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackbg%2Fcw-storage-benchmarks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackbg","download_url":"https://codeload.github.com/hackbg/cw-storage-benchmarks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackbg%2Fcw-storage-benchmarks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264734635,"owners_count":23655712,"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":"2025-05-27T20:10:57.353Z","updated_at":"2025-07-11T05:04:19.445Z","avatar_url":"https://github.com/hackbg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CosmWasm storage structures gas cost benches\n\nPersistence is an important aspect of smart contracts.\nIn CosmWasm, smart contract developers have access to\na fundamental storage primitive: the key-value store.\nIn the case of Secret Network, libraries like Fadroma\nand secret-toolkit build upon the CosmWasm KV store to\nimplement additional storage structures.\n\n`secret-toolkit` predominantly uses binary blob pages,\nwhere each page contains multiple items in the form of JSON bytes.\nPresumably, this done to reduce the number of FFI calls\nrequired to fetch data from the CosmWasm storage runtime.\nHowever, this dramatically increases the complexity of the\nimplementation of those storage structures.\n\nIn contrast, Fadroma uses data mappings where each operation\n(insert or get) for each item is a call (or more, depending\non the data structure) to storage.\n\nThe purpose of this repo is to measure the gas efficiency of\nthese distinct approaches with the purpose to hopefully derive\nnovel and better approaches to more efficiently implement such\nstorage structures.\n\nThe approach would of course greatly depend on the functionality\ndesired by the structure.\n\n## Map\n\nJust like a regular map, the implementations allow\ninserting and getting values from the map, based on a given key.\nThey also allow for iterating over all the values inserted.\n\nIt should be noted that the secret-toolkit version also allows for\niterating over the keys (as opposed to values), whereas Fadroma doesn't.\n\nThe benchmark here is the contract accepts N number of items which it then\ninserts one by one into the map, then uses the map iterator to iterate over\nthe values inserted, collecting them into a Vec to include in the response\n(just so that we have something to do with those values). Finally, it removes\nall the values previously inserted from the map.\n\nThe result is, even when bypassing Fadroma's binary serialization by using JSON,\nit is still slightly more efficient.\n\n|N items|secret-toolkit (baseline)|Fadroma (w/ JSON serialization)|Fadroma (w/ binary serialization)|\n|-------|--------------|------------------------------------------|---------------------------------|\n|10     |51318         |50071   (2.43% cheaper)                   |47472   (7.49% cheaper)          |\n|20     |65834         |63556   (3.46% cheaper)                   |58479   (11.17% cheaper)         |\n|50     |109160        |103702  (5.00% cheaper)                   |91792   (15.91% cheaper)         |\n|100    |182156        |170392  (6.46% cheaper)                   |147534  (19.01% cheaper)         |\n|200    |325335        |303299  (6.77% cheaper)                   |256324  (21.21% cheaper)         |\n|500    |759707        |703917  (7.34% cheaper)                   |586556  (22.79% cheaper)         |\n|1000   |1482880       |1369681 (7.63% cheaper)                   |1138502 (23.22% cheaper)         |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackbg%2Fcw-storage-benchmarks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackbg%2Fcw-storage-benchmarks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackbg%2Fcw-storage-benchmarks/lists"}