Summary
A standard interface for the Soft Majority Voting system.
Abstract
The following proposal defines the standard interface designed to implement SMV system in TON blockchain within smart contracts. This proposal provides basic functionality to creating proposals and voting for them.
Motivation
We need a system of voting contracts to regulate governance and decision making in Free TON. This contract is a principal tool of decentralization. It is supposed to be used in many aspects of Free TON blockchain to provide mechanisms for community governance.
Specification
Glossary
Voting Initiator Contract (VIC
) - a smart contract that can create new proposal and contains ids of all proposals
Proposal Contract (PC
) - a smart contract for each proposal that manage voting process
Voter Wallet (VW
) - a smart contract that can be used for voting by Voters
Proposal Creator Contract Public Key (VICPK
) - public key of Proposal contract creator
Voter Waller Public Key (VWPC
) - public key of Voter Wallet
Requirements
- Should be at least two roles:
Initiator
andVoter
-
Initiator
should be able to createProposal
-
Voter
should be able to vote forProposal
- Proposal should have two options of voting: “YES” or “NO”
-
Voter
can vote only once on each proposal - Protect Voting system from incorrect usage
-
Proposal
at the end of voting should notify about results - Contract or any other contract in the system should not store voting participants ledger
Description
We have two roles for users:
-
Initiator
of voting system has two possibilities: to grant the voting rights, create new proposal. The right to vote is a signature ofVW's
address, so to give the voting rightInitiator
have to send signature on chain by directly toVW's
address. To create a new proposal,Initiator
should submit a unique proposal id, uuid, start and finish times of voting and amount of voters. -
Voter
(using voting rights) can vote once for a specific Proposal. To obtain the voting right (signature),Voter
should provide address of deployedVW
.
And we have three smart contracts:
- Voting Initiator Contract (
VIC
) has possibilities: create a new proposal byInitiator
, obtain deployed Proposals and provide code forVW
. - Voter Wallet (
VW
) has possibilities: vote by using addressPC
and voting rights. Voter can’t deploy own implementation of smart contract and should use implementation provided byVIC
. So to avoid double voting on oneProposal
, need to remember address - Proposal contract (
PC
) has possibilities: vote “YES” or “NO” for proposal, provide details about proposal: title, uuid and etc.PC
should verifyVW
smart contract by using code of smart contract andVWPC
. AndPC
should verify signature by usingVICPK
.
Flow
-
Initiator
deployVIC
withVICPK
; -
Voters
deployVW
from code provided byVIC
; -
Initiator
grant voting rights by saving signature ofVW's
address toVWs
; -
Initiator
create newProposal
with parameters: proposal id, uuid, start time, finish time, voters amount; -
Voter
obtain address ofPC
fromVIC
by proposal id; -
Voter
send signature and vote to address ofPC
usingVW
; -
PC
count choice. - When voting is finished
PC
should emit out message with results;
Functions
Interface VotingInitiator
Smart contract should store code of VW
smart contract.
createProposal
External function. Create new proposal with parameters. Proposal
id must unique. Return address of deployed PC
.
function createProposal(
uint256 proposalId,
bytes uuid,
uint256 startTime,
uint256 finishTime,
uint256 votersAmount
) onlyInitiator returns (address)
getVoterCode
Return code for Voter
contract.
function getVoterCode() view returns (TvmCell)
getProposalAddress
Return address of PC
by proposal id or throw error.
function getProposalAddress() view returns (address)
Interface VoterWallet
Smart contract should store address of VotingInitiator.
vote
External function. Vote for proposal. This method should ensure that Voter
cannot vote more that once for proposal contract address. Choice should be " YES" or “NO”.
function vote(
address proposalContractAddress,
Choice choice
) onlyVoter
saveSignature
External function. Save signature which is voting right. Also we should protect this function from Initiator
spam.
function saveSignature(
uint512 signature
) onlyInitiator
Interface ProposalContract
Smart contract should store code of VW
contract and VICPK
.
Choice
enum Choice { NO, YES }
ProposalResult
event ProposalResult(
uint256 yesChoices,
uint256 noChoices,
uint256 amountVoters
)
vote
Internal function. Vote for proposal “YES” or “NO”.
Function should verify that msg sender is address of valid VW
. Should use stored code of VW
code and sender’s public key. (example: Verification check )
Next Function should verify signature. Need to hash senders address with proposal id and check signature with VICPK. (tvm.checkSign())
Function should verify current time and active time of proposal by start and finish time.
Function should count “YES” and “NO” choices.
function vote(
uint512 signature,
Choice choice
)
finish
External function. Check finish time of proposal. If time is expired so emit event result. Should invoke only once.
function finish()
getProposalId
function getProposalId() view returns (uint256)
getUuid
function getUuid() view returns (bytes)
getAmountVoters
function getAmountVoters() view returns (uint256)
getStartTime
function getStartTime() view returns (uint256)
getFinishTime
function getFinishTime() view returns (uint256)
Rationale
Advantages:
- Shouldn’t store ledger of voters due to use of signature.
- Shouldn’t store ledger of voters to avoid voting more than once for one proposal.
- Can add rule for distribution of Voting rights by sending not only signature but message with rule signed initiator.
- Has possibility to upgrade code of
PC
andVIC
.
Limitations:
- Can’t reject the Voting rights
- Can’t upgrade
VW