@@ -19,13 +19,12 @@ pragma solidity 0.7.3;
1919pragma experimental ABIEncoderV2;
2020
2121import "./../colonyNetwork/IColonyNetwork.sol " ;
22- import "./../common/ERC20Extended.sol " ;
2322import "./../patriciaTree/PatriciaTreeProofs.sol " ;
2423import "./../tokenLocking/ITokenLocking.sol " ;
2524import "./ColonyExtension.sol " ;
2625
2726
28- contract VotingBase is ColonyExtension , PatriciaTreeProofs {
27+ abstract contract VotingBase is ColonyExtension , PatriciaTreeProofs {
2928
3029 // Events
3130 event MotionCreated (uint256 indexed motionId , address creator , uint256 indexed domainId );
@@ -96,17 +95,6 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
9695
9796 // Public
9897
99- /// @notice Returns the identifier of the extension
100- function identifier () public override pure returns (bytes32 ) {
101- return keccak256 ("VotingReputation " );
102- }
103-
104- /// @notice Return the version number
105- /// @return The version number
106- function version () public pure override returns (uint256 ) {
107- return 1 ;
108- }
109-
11098 /// @notice Install the extension
11199 /// @param _colony Base colony for the installation
112100 function install (address _colony ) public override {
@@ -190,7 +178,7 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
190178 bytes32 rootHash;
191179 uint256 domainId;
192180 uint256 skillId;
193- uint256 skillRep ;
181+ uint256 maxVotes ;
194182 uint256 totalVotes;
195183 uint256 paidVoterComp;
196184 uint256 [2 ] pastVoterComp; // [nay, yay]
@@ -211,85 +199,24 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
211199 mapping (bytes32 => uint256 ) expenditurePastVotes; // expenditure slot signature => voting power
212200 mapping (bytes32 => uint256 ) expenditureMotionCounts; // expenditure struct signature => count
213201
214- // Public functions (interface)
202+ // Virtual functions
215203
216- /// @notice Create a motion in the root domain
217- /// @param _altTarget The contract to which we send the action (0x0 for the colony)
218- /// @param _action A bytes array encoding a function call
219- /// @param _key Reputation tree key for the root domain
220- /// @param _value Reputation tree value for the root domain
221- /// @param _branchMask The branchmask of the proof
222- /// @param _siblings The siblings of the proof
223- function createRootMotion (
224- address _altTarget ,
225- bytes memory _action ,
226- bytes memory _key ,
227- bytes memory _value ,
228- uint256 _branchMask ,
229- bytes32 [] memory _siblings
230- )
231- public
232- {
233- uint256 rootSkillId = colony.getDomain (1 ).skillId;
234- createMotion (_altTarget, _action, 1 , rootSkillId, _key, _value, _branchMask, _siblings);
235- }
204+ function getInfluence (uint256 _motionId , address _user ) public view virtual returns (uint256 );
236205
237- /// @notice Create a motion in any domain
238- /// @param _domainId The domain where we vote on the motion
239- /// @param _childSkillIndex The childSkillIndex pointing to the domain of the action
240- /// @param _action A bytes array encoding a function call
241- /// @param _key Reputation tree key for the domain
242- /// @param _value Reputation tree value for the domain
243- /// @param _branchMask The branchmask of the proof
244- /// @param _siblings The siblings of the proof
245- function createDomainMotion (
246- uint256 _domainId ,
247- uint256 _childSkillIndex ,
248- bytes memory _action ,
249- bytes memory _key ,
250- bytes memory _value ,
251- uint256 _branchMask ,
252- bytes32 [] memory _siblings
253- )
254- public
255- {
256- // Check the function requires a non-root permission (and thus a domain proof)
257- require (
258- colony.getCapabilityRoles (getSig (_action)) | ROOT_ROLES != ROOT_ROLES,
259- "voting-base-invalid-function "
260- );
261-
262- uint256 domainSkillId = colony.getDomain (_domainId).skillId;
263- uint256 actionDomainSkillId = getActionDomainSkillId (_action);
264-
265- if (domainSkillId != actionDomainSkillId) {
266- uint256 childSkillId = colonyNetwork.getChildSkillId (domainSkillId, _childSkillIndex);
267- require (childSkillId == actionDomainSkillId, "voting-base-invalid-domain-id " );
268- }
269-
270- createMotion (address (0x0 ), _action, _domainId, domainSkillId, _key, _value, _branchMask, _siblings);
271- }
206+ // Public functions (interface)
272207
273208 /// @notice Stake on a motion
274209 /// @param _motionId The id of the motion
275210 /// @param _permissionDomainId The domain where the extension has the arbitration permission
276211 /// @param _childSkillIndex For the domain in which the motion is occurring
277212 /// @param _vote The side being supported (0 = NAY, 1 = YAY)
278213 /// @param _amount The amount of tokens being staked
279- /// @param _key Reputation tree key for the staker/domain
280- /// @param _value Reputation tree value for the staker/domain
281- /// @param _branchMask The branchmask of the proof
282- /// @param _siblings The siblings of the proof
283214 function stakeMotion (
284215 uint256 _motionId ,
285216 uint256 _permissionDomainId ,
286217 uint256 _childSkillIndex ,
287218 uint256 _vote ,
288- uint256 _amount ,
289- bytes memory _key ,
290- bytes memory _value ,
291- uint256 _branchMask ,
292- bytes32 [] memory _siblings
219+ uint256 _amount
293220 )
294221 public
295222 {
@@ -304,7 +231,7 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
304231 uint256 stakerTotalAmount = add (stakes[_motionId][msg .sender ][_vote], amount);
305232
306233 require (
307- stakerTotalAmount <= getReputationFromProof (_motionId, msg .sender , _key, _value, _branchMask, _siblings ),
234+ stakerTotalAmount <= getInfluence (_motionId, msg .sender ),
308235 "voting-base-insufficient-rep "
309236 );
310237 require (
@@ -367,25 +294,12 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
367294 /// @notice Submit a vote secret for a motion
368295 /// @param _motionId The id of the motion
369296 /// @param _voteSecret The hashed vote secret
370- /// @param _key Reputation tree key for the staker/domain
371- /// @param _value Reputation tree value for the staker/domain
372- /// @param _branchMask The branchmask of the proof
373- /// @param _siblings The siblings of the proof
374- function submitVote (
375- uint256 _motionId ,
376- bytes32 _voteSecret ,
377- bytes memory _key ,
378- bytes memory _value ,
379- uint256 _branchMask ,
380- bytes32 [] memory _siblings
381- )
382- public
383- {
297+ function submitVote (uint256 _motionId , bytes32 _voteSecret ) public {
384298 Motion storage motion = motions[_motionId];
385299 require (getMotionState (_motionId) == MotionState.Submit, "voting-base-motion-not-open " );
386300 require (_voteSecret != bytes32 (0 ), "voting-base-invalid-secret " );
387301
388- uint256 userRep = getReputationFromProof (_motionId, msg .sender , _key, _value, _branchMask, _siblings );
302+ uint256 userRep = getInfluence (_motionId, msg .sender );
389303
390304 // Count reputation if first submission
391305 if (voteSecrets[_motionId][msg .sender ] == bytes32 (0 )) {
@@ -396,7 +310,7 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
396310
397311 emit MotionVoteSubmitted (_motionId, msg .sender );
398312
399- if (motion.totalVotes >= wmul (motion.skillRep , maxVoteFraction)) {
313+ if (motion.totalVotes >= wmul (motion.maxVotes , maxVoteFraction)) {
400314 motion.events[SUBMIT_END] = uint64 (block .timestamp );
401315 motion.events[REVEAL_END] = uint64 (block .timestamp + revealPeriod);
402316
@@ -408,33 +322,19 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
408322 /// @param _motionId The id of the motion
409323 /// @param _salt The salt used to hash the vote
410324 /// @param _vote The side being supported (0 = NAY, 1 = YAY)
411- /// @param _key Reputation tree key for the staker/domain
412- /// @param _value Reputation tree value for the staker/domain
413- /// @param _branchMask The branchmask of the proof
414- /// @param _siblings The siblings of the proof
415- function revealVote (
416- uint256 _motionId ,
417- bytes32 _salt ,
418- uint256 _vote ,
419- bytes memory _key ,
420- bytes memory _value ,
421- uint256 _branchMask ,
422- bytes32 [] memory _siblings
423- )
424- public
425- {
325+ function revealVote (uint256 _motionId , bytes32 _salt , uint256 _vote ) public {
426326 Motion storage motion = motions[_motionId];
427327 require (getMotionState (_motionId) == MotionState.Reveal, "voting-base-motion-not-reveal " );
428328 require (_vote <= 1 , "voting-base-bad-vote " );
429329
430- uint256 userRep = getReputationFromProof (_motionId, msg .sender , _key, _value, _branchMask, _siblings );
431- motion.votes[_vote] = add (motion.votes[_vote], userRep );
330+ uint256 influence = getInfluence (_motionId, msg .sender );
331+ motion.votes[_vote] = add (motion.votes[_vote], influence );
432332
433333 bytes32 voteSecret = voteSecrets[_motionId][msg .sender ];
434334 require (voteSecret == getVoteSecret (_salt, _vote), "voting-base-secret-no-match " );
435335 delete voteSecrets[_motionId][msg .sender ];
436336
437- uint256 voterReward = getVoterReward (_motionId, userRep );
337+ uint256 voterReward = getVoterReward (_motionId, influence );
438338 motion.paidVoterComp = add (motion.paidVoterComp, voterReward);
439339
440340 emit MotionVoteRevealed (_motionId, msg .sender , _vote);
@@ -448,58 +348,6 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
448348 tokenLocking.transfer (token, voterReward, msg .sender , true );
449349 }
450350
451- /// @notice Escalate a motion to a higher domain
452- /// @param _motionId The id of the motion
453- /// @param _newDomainId The desired domain of escalation
454- /// @param _childSkillIndex For the current domain, relative to the escalated domain
455- /// @param _key Reputation tree key for the new domain
456- /// @param _value Reputation tree value for the new domain
457- /// @param _branchMask The branchmask of the proof
458- /// @param _siblings The siblings of the proof
459- function escalateMotion (
460- uint256 _motionId ,
461- uint256 _newDomainId ,
462- uint256 _childSkillIndex ,
463- bytes memory _key ,
464- bytes memory _value ,
465- uint256 _branchMask ,
466- bytes32 [] memory _siblings
467- )
468- public
469- {
470- Motion storage motion = motions[_motionId];
471- require (getMotionState (_motionId) == MotionState.Closed, "voting-base-motion-not-closed " );
472-
473- uint256 newDomainSkillId = colony.getDomain (_newDomainId).skillId;
474- uint256 childSkillId = colonyNetwork.getChildSkillId (newDomainSkillId, _childSkillIndex);
475- require (childSkillId == motion.skillId, "voting-base-invalid-domain-proof " );
476-
477- uint256 domainId = motion.domainId;
478- motion.domainId = _newDomainId;
479- motion.skillId = newDomainSkillId;
480- motion.skillRep = getReputationFromProof (_motionId, address (0x0 ), _key, _value, _branchMask, _siblings);
481-
482- uint256 loser = (motion.votes[NAY] < motion.votes[YAY]) ? NAY : YAY;
483- motion.stakes[loser] = sub (motion.stakes[loser], motion.paidVoterComp);
484- motion.pastVoterComp[loser] = add (motion.pastVoterComp[loser], motion.paidVoterComp);
485- delete motion.paidVoterComp;
486-
487- uint256 requiredStake = getRequiredStake (_motionId);
488- motion.events[STAKE_END] = (motion.stakes[NAY] < requiredStake || motion.stakes[YAY] < requiredStake) ?
489- uint64 (block .timestamp + stakePeriod) : uint64 (block .timestamp );
490-
491- motion.events[SUBMIT_END] = motion.events[STAKE_END] + uint64 (submitPeriod);
492- motion.events[REVEAL_END] = motion.events[SUBMIT_END] + uint64 (revealPeriod);
493-
494- motion.escalated = true ;
495-
496- emit MotionEscalated (_motionId, msg .sender , domainId, _newDomainId);
497-
498- if (motion.events[STAKE_END] == uint64 (block .timestamp )) {
499- emit MotionEventSet (_motionId, STAKE_END);
500- }
501- }
502-
503351 function finalizeMotion (uint256 _motionId ) public {
504352 Motion storage motion = motions[_motionId];
505353 require (getMotionState (_motionId) == MotionState.Finalizable, "voting-base-motion-not-finalizable " );
@@ -737,7 +585,7 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
737585 /// @return The voter reward
738586 function getVoterReward (uint256 _motionId , uint256 _voterRep ) public view returns (uint256 ) {
739587 Motion storage motion = motions[_motionId];
740- uint256 fractionUserReputation = wdiv (_voterRep, motion.skillRep );
588+ uint256 fractionUserReputation = wdiv (_voterRep, motion.maxVotes );
741589 uint256 totalStake = add (motion.stakes[YAY], motion.stakes[NAY]);
742590 return wmul (wmul (fractionUserReputation, totalStake), voterRewardFraction);
743591 }
@@ -817,12 +665,7 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
817665 function createMotion (
818666 address _altTarget ,
819667 bytes memory _action ,
820- uint256 _domainId ,
821- uint256 _skillId ,
822- bytes memory _key ,
823- bytes memory _value ,
824- uint256 _branchMask ,
825- bytes32 [] memory _siblings
668+ uint256 _domainId
826669 )
827670 internal
828671 notDeprecated
@@ -839,9 +682,8 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
839682
840683 motion.rootHash = colonyNetwork.getReputationRootHash ();
841684 motion.domainId = _domainId;
842- motion.skillId = _skillId ;
685+ motion.skillId = colony. getDomain (_domainId).skillId ;
843686
844- motion.skillRep = getReputationFromProof (motionCount, address (0x0 ), _key, _value, _branchMask, _siblings);
845687 motion.altTarget = _altTarget;
846688 motion.action = _action;
847689
@@ -853,45 +695,13 @@ contract VotingBase is ColonyExtension, PatriciaTreeProofs {
853695 }
854696
855697 function getRequiredStake (uint256 _motionId ) internal view returns (uint256 ) {
856- return wmul (motions[_motionId].skillRep , totalStakeFraction);
698+ return wmul (motions[_motionId].maxVotes , totalStakeFraction);
857699 }
858700
859701 function flip (uint256 _vote ) internal pure returns (uint256 ) {
860702 return sub (1 , _vote);
861703 }
862704
863- function getReputationFromProof (
864- uint256 _motionId ,
865- address _who ,
866- bytes memory _key ,
867- bytes memory _value ,
868- uint256 _branchMask ,
869- bytes32 [] memory _siblings
870- )
871- internal view returns (uint256 )
872- {
873- bytes32 impliedRoot = getImpliedRootHashKey (_key, _value, _branchMask, _siblings);
874- require (motions[_motionId].rootHash == impliedRoot, "voting-base-invalid-root-hash " );
875-
876- uint256 reputationValue;
877- address keyColonyAddress;
878- uint256 keySkill;
879- address keyUserAddress;
880-
881- assembly {
882- reputationValue := mload (add (_value, 32 ))
883- keyColonyAddress := mload (add (_key, 20 ))
884- keySkill := mload (add (_key, 52 ))
885- keyUserAddress := mload (add (_key, 72 ))
886- }
887-
888- require (keyColonyAddress == address (colony), "voting-base-invalid-colony-address " );
889- require (keySkill == motions[_motionId].skillId, "voting-base-invalid-skill-id " );
890- require (keyUserAddress == _who, "voting-base-invalid-user-address " );
891-
892- return reputationValue;
893- }
894-
895705 function getActionDomainSkillId (bytes memory _action ) internal view returns (uint256 ) {
896706 uint256 permissionDomainId;
897707 uint256 childSkillIndex;
0 commit comments