{"id":21754476,"url":"https://github.com/e00dan/ckb-voting","last_synced_at":"2025-03-21T03:14:48.205Z","repository":{"id":143126940,"uuid":"364999960","full_name":"e00dan/ckb-voting","owner":"e00dan","description":"Simple voting system on Nervos CKB.","archived":false,"fork":false,"pushed_at":"2021-05-10T16:08:50.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T23:45:40.795Z","etag":null,"topics":["blockchain"],"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/e00dan.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":"2021-05-06T18:18:29.000Z","updated_at":"2023-06-04T03:44:02.000Z","dependencies_parsed_at":"2023-03-17T00:45:31.054Z","dependency_job_id":null,"html_url":"https://github.com/e00dan/ckb-voting","commit_stats":null,"previous_names":["e00dan/ckb-voting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e00dan%2Fckb-voting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e00dan%2Fckb-voting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e00dan%2Fckb-voting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e00dan%2Fckb-voting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e00dan","download_url":"https://codeload.github.com/e00dan/ckb-voting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244728235,"owners_count":20500023,"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":["blockchain"],"created_at":"2024-11-26T09:14:04.129Z","updated_at":"2025-03-21T03:14:48.188Z","avatar_url":"https://github.com/e00dan.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ckb-voting\n\nBuild contracts:\n\n``` sh\ncapsule build\n```\n\nRun tests:\n\n``` sh\ncapsule test\n```\n\n# Architecture\n\n- 1 Core Cell\n- 2 Vote Cells (yes/no)\n- X SUDT Cells\n\nX is the number of voters. The addresses of the voters should be known before creating the vote.\n\n## Core Cell\n\n### Type Script:\n\nArgs in Type Script should be blake2b256 hash of first Input Cell in transaction. This is so-called type ID pattern. It is generated based on Input Cell Outpoint + Output index of Core Cell: 0.\n\n### Data\n\n| Bytesize  | Name                     | Description\n| --------- | ------                   | ----\n| 32        | TOKEN_CODE_HASH          | Voting token code hash, hash_type is data\n| 32        | VOTE_TITLE               | Title of the vote\n| 16        | TOTAL_DISTRIBUTED_TOKENS | Total tokens distributed to all addresses\n| 1         | IS_VOTING_FINISHED       | 0 = NO, 1 = YES\n| 1         | VOTE_RESULT_OPTION_TYPE  | Result of the vote, 0 = NO, 1 = YES\n\n## Vote Cell\n\n### Type Script:\n\nVote Cell args should be exactly the same as Core Cell's args.\n\n### Data:\n- 1 byte - VOTE_OPTION_TYPE\n- 8 bytes - TOTAL_VOTES_COLLECTED\n\nVOTE_OPTION_TYPE - 0 for no, 1 for yes\nTOTAL_VOTES_COLLECTED - all UDT tokens collected by this cell as votes\n\n### Logic\n\n1. Only 1 Cell of this type can exist in the output except for Minting and Burning the cell itself.\n2. 2 Cells of this type need to be passed as input when Settling the vote.\n3. If Vote Cell is used in conjunction with Core Cell in the same transaction Vote Cell args should be the same as Core Cell args.\n\n## Simple User Defined Token (SUDT)\n\nToken Type Script is SUDT. It is possible to mint, transfer and burn this token. \n\nLock Script: Anyone Can Pay\n\n### Type Script\n\n- code_hash: sudt type script\n- args: owner lock script hash\n\n### Data\n\n- amount: uint128 (16 bytes)\n\n# Transactions\n\n## Create new vote\n\n[Check \"test_can_create_vote\" in dao_core.rs.](tests/src/dao_core.rs)\n\nAssuming we have 3 voters.\n\nInput:\n1. A cell that's going to be used as a Seed Cell (could be any cell)\n\nOutput:\n1. Core Cell\n2. Vote No Cell\n3. Vote Yes Cell\n4. SUDT Voter 1 Cell\n5. SUDT Voter 2 Cell\n6. SUDT Voter 3 Cell\n\nVoter Cells with SUDT are locked with ACP locks for the addresses. \n\n## Vote\n\nAssuming Voter 1 votes for No.\n\nInput:\n\n1. Vote No Cell\n2. SUDT Voter 1 Cell\n\nOutput:\n\n1. Vote No Cell\n2. SUDT Voter 1 Cell if not all tokens were used for voting\n\n## Finish voting\n\nONE OF THE VOTE CELLS NEED TO HAVE 51% OF ALL MINTED TOKENS.\n\nInput:\n1. Core Cell\n2. Vote No Cell\n3. Vote Yes Cell\n\nOutput:\n1. Core Cell\n\n# Known issues\n\nWe're using a Simple User Defined Token standard and we're not restricting how it could be minted. We could do so but we chose not to for the sake of simplicity.\n\nTo detect a fraud in this simple application we could scan the chain for the total number of SUDT in circulation and if we see that the number went up for no good reason, we could withdraw from honoring vote result.\n\nWe're designing a simple voting system. This would be sufficient for on-chain voting, but off-chain execution. For example, we vote on a new chairman for the committee. The blockchain is evidence of the vote, but the actual handing is done in real life, not attached to the chain at all. In this respect, being able to detect a fraud by organizers is all that is important. However, this type of a system is not sufficient for something like on-chain management of a large sum of cryptocurrency with automatic execution of transfers based on voting. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe00dan%2Fckb-voting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe00dan%2Fckb-voting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe00dan%2Fckb-voting/lists"}