Repository navigation
Token and hybrid voting #90
Description
9.3.2 Token weighted voting
Unlike with reputation, we do not have the ability to ‘freeze’ the token distribution when a vote starts. While this is effectively possible with something like the MiniMe token [8], we envision token-weighted votes will still be regular enough within a Colony that we do not wish to burden users with the gas costs of deploying a new contract every time.
When conducting a token weighted vote, steps must be taken to ensure that tokens cannot be
used to vote multiple times. In the case of “The DAO”, once a user had voted their tokens were locked until the vote completed. This introduced peculiar incentives to delay voting until as late as possible to avoid locking tokens unnecessarily. Our locking scheme avoids such skewed incentives. Instead, once a vote enters the reveal phase, any user who has voted on that vote will find themselves unable to see tokens sent to them, or be able to send tokens themselves — their token balance has become locked. To unlock their token balance, users only have to reveal the vote they cast for any polls that have entered the reveal phase — something they can do at any time. Once their tokens are unlocked, any tokens they have notionally received since their tokens became locked are added to their balance.
It is possible to achieve this locking in constant gas by storing all submitted secrets for votes in a sorted linked list indexed by close_time. If the first key in this linked list is earlier than now when a user sends or would receive funds, then they find their tokens locked. Revealing a vote causes the key to be deleted (if the user has no other votes submitted for polls that closed at the same time). This will unlock the tokens so long as the next key in the list is a timestamp in the future. A more detailed description of our implementation can be found on the Colony blog [9].
Insertion into this structure can also be done in constant gas if the client supplies the correct insertion location, which can be checked efficiently on-chain, rather than searching for the correct location to insert new items.
9.3.3 Hybrid voting
A hybrid vote would allow both reputation holders and token holders to vote on a decision. We envision such a vote being used when the action being voted on would potentially have a sizeable impact on both reputation holders and token holders. This would include altering the supply of the colony tokens beyond the parameters already agreed (see Section 5.1) or when deciding whether to execute an arbitrary transaction (see Section 11.4).
In order for a proposal to successfully pass through a hybrid vote, both the reputation holders and the token holders must have reached quorum, and a majority of both reputation and token holders who vote must agree that the change should be enacted.
Activity
mametrine commentedon Sep 10, 2018
Ok thanks. I was missing some setup process and didn't notice this script. Is this the same Resolver instance that is stored at the beginning of the storage contracts:
address resolver?elenadimitrova commentedon Sep 10, 2018
Yes the resolver address in the beginning of the storage contracts is there as a declaration to match the address in
EtherRouteras storage slots have to match between the two.mametrine commentedon Sep 14, 2018
I've come across this unfamiliar nested statement for two abstract contracts. Is this a conversion or a reference to functions from two contracts?
address clnyToken = IColony(IColonyNetwork(colonyNetwork).getMetaColony()).getToken();elenadimitrova commentedon Sep 16, 2018
We are twice casting an address to interface in order to satisfy Solidity type safety and call the functions on an address we know is of certain interface. Now however we have a slightly better and shorter way to achieve the above, which essentially gets the CLNY token address.
We store the Meta colony address on the Colony Network at
metaColonythis is accessible inside theColonyNetworkcontract instance via the property name itself and outside - via theIColonyNetwork.getMetaColonyfunction. After you have that, to get the CLNY token address you just can just do one cast :address clnyToken = IColony(metaColony).getToken();mametrine commentedon Sep 17, 2018
I'm trying to decide on what the mappings should look like for the new token weighted voting storage. For every hashed list and value that used to update the EternalStorage mappings, would there be any problems making a global
bytes32 => bytes32mapping instead? I'm considering all the mixed types.elenadimitrova commentedon Sep 17, 2018
You mean for storing the secret votes? That is indeed a
bytes32voting key mapped to abytes32voting secret. Not sure what you mean by "considering all the mixed types" but hopefully I've answered your question.mametrine commentedon Sep 17, 2018
Yes, but for example I also mean the other storage entries like:
EternalStorage(_storageContract).setUIntValue(keccak256("Poll", pollId, "startTime"), now);which I think is uint. Maybe I'm over-complicating.
elenadimitrova commentedon Sep 17, 2018
Oh right you're asking in general how you should model the storage. I imagine there will be a few structs like
Poll,Voteetc and some mappings to store these e.gmapping(uint256 => Poll) public polls;mametrine commentedon Sep 18, 2018
Good, thanks. Apart from making this issue fit the EtherRouter pattern, is there anything else in particular that should change?
elenadimitrova commentedon Sep 18, 2018
I can't think of anything but the token locking which needs to reuse the one we've already implemented. Although it has been two years after we wrote it and I'm pretty sure in the course of implementation there maybe changes needed.
mametrine commentedon Sep 25, 2018
Going on the struct idea in previous comments, this old code will not be compatible with a mapping to struct type:
var pollOptionCount = EternalStorage(_storageContract).getUIntValue(keccak256("Poll", pollId, "OptionsCount"));So if it's the
uint256value being assigned topollOptionCountI'm hoping it will be safe to change this to:uint256 pollOptionCount = option[keccak256(abi.encodePacked("Poll", pollId, "OptionsCount"))].pollOptionCount;elenadimitrova commentedon Sep 26, 2018
Bear in mind that the
EternalStoragedesign was made to ensure mapping keys are unique, hence the long key"Poll", pollId, "OptionsCount"...being hashed. You don't have to do any of that in theEtherRouterand can just mapuint256 -> Pollmametrine commentedon Sep 26, 2018
ok, that will look a lot nicer as well. So I don't go too far, I have a Gist showing a concept for this. Is it similar to what you are expecting? https://gist.github.com/markhainesii/f06ad9f928d554aead30fc1ada53042b
elenadimitrova commentedon Sep 26, 2018
I don't know what storage will end up looking like but this seems like a good enough starting point. I expect there will be further normalization of the storage design needed once you start refactoring.
mametrine commentedon Oct 3, 2018
Does a linked list have to be at least two polls: one zero poll and one real poll so as to keep the "closed" relationship:
prevTimestamp>prevPollId>nextTimestamp>nextPollId?elenadimitrova commentedon Oct 3, 2018
Yes exactly @markhainesii
mametrine commentedon Oct 4, 2018
Great. And I know it's not necessary this time, but how should I interpret mapping keys like
"Voting", userAddress, prevTimestamp, "secrets", zeroUint, "nextPollId"so I can create new struct variables?elenadimitrova commentedon Oct 5, 2018
I'm not sure I understand completely but basically yes, there will likely need to be a struct defined containing some of these properties. Also as a general comment, it might be best to get a branch in so we can have a look at actual implementation changes.
[-]Token weighted voting[/-][+]Token and hybrid voting[/+]