{"id":22558906,"url":"https://github.com/xujiandong/ckb-fixed-solution","last_synced_at":"2026-04-29T18:34:23.228Z","repository":{"id":266030887,"uuid":"895406864","full_name":"XuJiandong/ckb-fixed-solution","owner":"XuJiandong","description":"Solution to consistent calculations between on-chain scripts and off-chain applications on CKB.","archived":false,"fork":false,"pushed_at":"2024-12-05T08:53:30.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T11:43:50.899Z","etag":null,"topics":["ckb","rust","wasm"],"latest_commit_sha":null,"homepage":"","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/XuJiandong.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,"publiccode":null,"codemeta":null}},"created_at":"2024-11-28T06:37:37.000Z","updated_at":"2024-12-05T08:53:35.000Z","dependencies_parsed_at":"2025-03-28T11:42:55.484Z","dependency_job_id":"8dd932d1-f61a-4812-9080-523b7ce0f3c9","html_url":"https://github.com/XuJiandong/ckb-fixed-solution","commit_stats":null,"previous_names":["xujiandong/ckb-fixed-solution"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/XuJiandong/ckb-fixed-solution","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XuJiandong%2Fckb-fixed-solution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XuJiandong%2Fckb-fixed-solution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XuJiandong%2Fckb-fixed-solution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XuJiandong%2Fckb-fixed-solution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XuJiandong","download_url":"https://codeload.github.com/XuJiandong/ckb-fixed-solution/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XuJiandong%2Fckb-fixed-solution/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32439277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T18:12:22.909Z","status":"ssl_error","status_checked_at":"2026-04-29T18:11:33.322Z","response_time":110,"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":["ckb","rust","wasm"],"created_at":"2024-12-07T20:18:07.303Z","updated_at":"2026-04-29T18:34:23.210Z","avatar_url":"https://github.com/XuJiandong.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ckb-fixed-solution\nWhen developing on-chain scripts for CKB, numeric calculations are often required.\nSome developers prefer using [fixed-point arithmetic](https://en.wikipedia.org/wiki/Fixed-point_arithmetic)\ndue to its simplicity. To ensure consistent calculations between on-chain scripts\nand off-chain applications, we provide a solution based on WASM and Rust.\n\nThis solution consists of two parts:\n1. A Rust library ([ckb-fixed](./crates/ckb-fixed)) for on-chain scripts. It is based on [fixed](https://crates.io/crates/fixed).\n2. WASM bindings of the same Rust library for off-chain applications, generated using `wasm-pack`\n\nThis approach ensures identical numerical behavior across both environments.\n\n## How to Integrate\n\n### Prerequisites\nInstall required tools:\n```bash\n# Install wasm-pack for WASM bindings generation\ncargo install wasm-pack --version 0.13.1\n\n# Add WebAssembly target to Rust\nrustup target add wasm32-unknown-unknown\n```\n\n### For Off-chain Applications (JavaScript/WASM)\nGenerate WASM bindings:\n```bash\ncd crates/ckb-fixed\nmake wasm-pack\n```\nThe generated WASM bindings will be available in the `pkg` directory. For usage instructions, refer to the [wasm-pack documentation](https://rustwasm.github.io/docs/wasm-pack/).\n\n### For On-chain Scripts (Rust)\nAdd the dependency to your `Cargo.toml`:\n```toml\n[dependencies]\nckb-fixed = \"1.0.0\"\n```\n\nFor implementation examples, see our [on-chain script example](./contracts/fixed-script-example).\n\n## Bugs found by Fuzzing\nWe've implemented [fuzzing](./crates/ckb-fixed-tests/fuzz) for the ckb-fixed\ncrates. The fuzzer executes WASM bytecode using\n[wasmer](https://github.com/wasmerio/wasmer) and compares the results with\nnative Rust code execution.\n\nFindings from fuzzing:\n\n- [panic in log2](https://github.com/XuJiandong/ckb-fixed-solution/pull/1/commits/1e50dc4df7b521c0e8b35839d3cec0bd87ce8e34#diff-594adab37e284643cf296678c3be41f68995df76e36e888cbe6a742cb39ff19eL215)\n- [overflow in exp](https://github.com/XuJiandong/ckb-fixed-solution/pull/4/commits/036745abf00aed45942b1afd88cebc6f8b64abc8#diff-594adab37e284643cf296678c3be41f68995df76e36e888cbe6a742cb39ff19eR263)\n- [very low performance on sin](https://github.com/XuJiandong/ckb-fixed-solution/pull/4/commits/036745abf00aed45942b1afd88cebc6f8b64abc8#diff-594adab37e284643cf296678c3be41f68995df76e36e888cbe6a742cb39ff19eR404)\n- [negate with overflow in exp](https://github.com/XuJiandong/ckb-fixed-solution/pull/4/commits/036745abf00aed45942b1afd88cebc6f8b64abc8#diff-594adab37e284643cf296678c3be41f68995df76e36e888cbe6a742cb39ff19eR259)\n\nBasically, these are not bugs in the WASM implementation but rather in the native implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxujiandong%2Fckb-fixed-solution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxujiandong%2Fckb-fixed-solution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxujiandong%2Fckb-fixed-solution/lists"}