Delegated voting over five proposals, with the chairperson handing out voting rights
Historical Significance
Voting with delegation is the example the Solidity documentation used to teach structs, mappings and access control together, and it is the ancestor of the governance contracts that followed. The delegation chain it walks, where a voter hands their weight to someone who may have delegated in turn, is the mechanism vote-escrow and liquid democracy designs kept.
Context
Deployed in December 2015 on the Frontier chain, compiled with solc v0.1.1 and the optimiser enabled.
Key Facts
Description
A voting contract in the pre-struct form of the Solidity Ballot example, where each part of a voter's record lives in its own mapping: voterWeight, voted, votes and delegations. The account that deploys it becomes the chairperson and is the only one who may call giveRightToVote. A voter may either vote for one of five proposals or delegate to another address, in which case the contract follows the delegation chain to its end before transferring the weight. winningProposal scans the tallies and returns the leader. The proposal count is fixed at five in the constructor.
Source Verified
Heuristic Analysis
The following characteristics were detected through bytecode analysis and may not be accurate.
Frontier Era
The initial release of Ethereum. A bare-bones implementation for technical users.
Bytecode Overview
Verified Source Available
Source verified through compiler archaeology and exact bytecode matching.
View Verification ProofShow source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
contract Ballot {
address public chairperson;
uint8 public numProposals;
mapping(address => uint) public voterWeight;
mapping(address => bool) public voted;
mapping(address => uint8) public votes;
mapping(address => address) public delegations;
mapping(uint8 => uint) public voteCounts;
function Ballot() {
chairperson = msg.sender;
numProposals = 5;
}
function winningProposal() constant returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < numProposals; prop++)
if (voteCounts[prop] > winningVoteCount) {
winningVoteCount = voteCounts[prop];
_winningProposal = prop;
}
}
function delegate(address to) {
address sender = msg.sender;
if (voted[sender]) return;
while (delegations[to] != address(0) && delegations[to] != sender)
to = delegations[to];
if (to == sender) return;
voted[sender] = true;
delegations[sender] = to;
if (voted[to])
voteCounts[votes[to]] += voterWeight[sender];
else
voterWeight[to] += voterWeight[sender];
}
function vote(uint8 toProposal) {
address sender = msg.sender;
if (voted[sender] || toProposal >= numProposals) return;
voted[sender] = true;
votes[sender] = toProposal;
voteCounts[toProposal] += voterWeight[sender];
}
function giveRightToVote(address voter) {
if (msg.sender != chairperson || voted[voter]) return;
voterWeight[voter] = 1;
}
}External Links
Related contracts
Greeter
Same eraA HelloWorld greeter deployed at block 51,909 on 8 August 2015, one of a run of contracts from the same account that week.
0x412fda...7267edAugust 8, 2015Greeter
Same eraA Greeter with the message 'Ethereum will change the world smarter' - deployed Aug 8, 2015 by a developer connected to the Tokyo Smart Contract meetup.
0xda0c1c...7a68ebAugust 8, 2015MessageStore
Same eraA 6-line contract storing a single public string, deployed Day 9 of Ethereum by a prolific early experimenter who shipped 18 contracts in one week.
0xd2eccd...ff3d6bAugust 8, 2015Greeter
Same eraThe go-ethereum Contract Tutorial greeter, deployed with the greeting: Hello World!
0x506f4b...466983August 8, 2015Contract 0xd4eae4...a2c77a
Same eraThe ethereum.org crowdsale tutorial, deployed on the ninth day of the public chain, with the funding goal, deadline and price fixed at construction.
0xd4eae4...a2c77aAugust 8, 2015Greeter
Same eraA Frontier-era Greeter contract with the message: 'Hello World!'
0x113158...72fa8aAugust 8, 2015