Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rules": {
"indent": ["error", 4],

"compiler-fixed": false,
"compiler-fixed": false,
"no-simple-event-func-name": false,
"two-lines-top-level-separator": false
}
Expand Down
12 changes: 5 additions & 7 deletions contracts/libs/RealMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ pragma solidity ^0.5.2;

/**
* RealMath: fixed-point math library, based on fractional and integer parts.
* Using uint256 as real216x40, which isn't in Solidity yet.
* 40 fractional bits gets us down to 1E-12 precision, while still letting us
* go up to galaxy scale counting in meters.
* Using uint256 as real248x8, which isn't in Solidity yet.
* Internally uses the wider uint256 for some math.
*
* Note that for addition, subtraction, and mod (%), you should just use the
Expand All @@ -23,7 +21,7 @@ library RealMath {
/**
* How many fractional bits are there?
*/
uint256 constant private REAL_FBITS = 40;
uint256 constant private REAL_FBITS = 8;

/**
* What's the first non-fractional bit
Expand Down Expand Up @@ -53,13 +51,13 @@ library RealMath {
}

// Return the final result.
return uint216(realResult / REAL_ONE);
return realResult;
}

/**
* Create a real from a rational fraction.
*/
function fraction(uint216 numerator, uint216 denominator) internal pure returns (uint256) {
function fraction(uint248 numerator, uint248 denominator) internal pure returns (uint256) {
return div(uint256(numerator) * REAL_ONE, uint256(denominator) * REAL_ONE);
}

Expand All @@ -69,7 +67,7 @@ library RealMath {
function mul(uint256 realA, uint256 realB) private pure returns (uint256) {
// When multiplying fixed point in x.y and z.w formats we get (x+z).(y+w) format.
// So we just have to clip off the extra REAL_FBITS fractional bits.
return uint256((uint256(realA) * uint256(realB)) >> REAL_FBITS);
return ((realA * realB) >> REAL_FBITS);
}

/**
Expand Down
16 changes: 9 additions & 7 deletions contracts/votingMachines/GenesisProtocolLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import "openzeppelin-solidity/contracts/utils/Address.sol";
* @title GenesisProtocol implementation -an organization's voting machine scheme.
*/
contract GenesisProtocolLogic is IntVoteInterface {
using SafeMath for uint;
using Math for uint;
using RealMath for uint216;
using SafeMath for uint256;
using Math for uint256;
using RealMath for uint248;
using RealMath for uint256;
using Address for address;

Expand Down Expand Up @@ -117,6 +117,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
event StateChange(bytes32 indexed _proposalId, ProposalState _proposalState);
event GPExecuteProposal(bytes32 indexed _proposalId, ExecutionState _executionState);
event ExpirationCallBounty(bytes32 indexed _proposalId, address indexed _beneficiary, uint256 _amount);
event ConfidenceLevelChange(bytes32 indexed _proposalId, uint256 _confidenceThreshold);

mapping(bytes32=>Parameters) public parameters; // A mapping from hashes to parameters
mapping(bytes32=>Proposal) public proposals; // Mapping from the ID of the proposal to the proposal itself.
Expand Down Expand Up @@ -284,7 +285,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
queuedVotePeriodLimit: _params[1],
boostedVotePeriodLimit: _params[2],
preBoostedVotePeriodLimit: _params[3],
thresholdConst:uint216(_params[4]).fraction(uint216(1000)),
thresholdConst:uint248(_params[4]).fraction(uint248(1000)),
limitExponentValue:limitExponent,
quietEndingPeriod: _params[5],
proposingRepReward: _params[6],
Expand Down Expand Up @@ -432,7 +433,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
* This threshold is dynamically set and it depend on the number of boosted proposal.
* @param _organizationId the organization identifier
* @param _paramsHash the organization parameters hash
* @return uint256 organization's score threshold.
* @return uint256 organization's score threshold as real number.
*/
function threshold(bytes32 _paramsHash, bytes32 _organizationId) public view returns(uint256) {
uint256 power = orgBoostedProposalsCnt[_organizationId];
Expand Down Expand Up @@ -550,6 +551,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
proposal.state = ProposalState.Queued;
} else if (proposal.confidenceThreshold > proposalScore) {
proposal.confidenceThreshold = confidenceThreshold;
emit ConfidenceLevelChange(_proposalId, confidenceThreshold);
}
}
}
Expand Down Expand Up @@ -715,12 +717,12 @@ contract GenesisProtocolLogic is IntVoteInterface {
* @dev _score return the proposal score (Confidence level)
* For dual choice proposal S = (S+)/(S-)
* @param _proposalId the ID of the proposal
* @return uint256 proposal score.
* @return uint256 proposal score as real number.
*/
function _score(bytes32 _proposalId) internal view returns(uint256) {
Proposal storage proposal = proposals[_proposalId];
//proposal.stakes[NO] cannot be zero as the dao downstake > 0 for each proposal.
return proposal.stakes[YES]/proposal.stakes[NO];
return uint248(proposal.stakes[YES]).fraction(uint248(proposal.stakes[NO]));
}

/**
Expand Down
Loading