Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wesley and mike #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"editor.minimap.enabled": false
}
4 changes: 2 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.11;

// This is a useless import, but it forces EIP20.sol to be compiled. We need its build file for
// the test pipeline.
import "tokens/eip20/EIP20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract Migrations {
address public owner;
Expand All @@ -12,7 +12,7 @@ contract Migrations {
if (msg.sender == owner) _;
}

function Migrations() public {
constructor() public {
owner = msg.sender;
}

Expand Down
20 changes: 9 additions & 11 deletions contracts/PLCRFactory.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
pragma solidity ^0.4.20;

import "tokens/eip20/EIP20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "./PLCRVoting.sol";
import "./ProxyFactory.sol";

contract PLCRFactory {

event newPLCR(address creator, EIP20 token, PLCRVoting plcr);

event newPLCR(address creator, ERC20 token, PLCRVoting plcr);
ProxyFactory public proxyFactory;
PLCRVoting public canonizedPLCR;

/// @dev constructor deploys a new canonical PLCRVoting contract and a proxyFactory.
constructor() {
constructor() public{
canonizedPLCR = new PLCRVoting();
proxyFactory = new ProxyFactory();
}
Expand All @@ -22,7 +21,7 @@ contract PLCRFactory {
supplied by the user.
@param _token an EIP20 token to be consumed by the new PLCR contract
*/
function newPLCRBYOToken(EIP20 _token) public returns (PLCRVoting) {
function newPLCRBYOToken(ERC20 _token) public returns (PLCRVoting) {
PLCRVoting plcr = PLCRVoting(proxyFactory.createProxy(canonizedPLCR, ""));
plcr.init(_token);

Expand All @@ -40,22 +39,21 @@ contract PLCRFactory {
@param _symbol the symbol of the new EIP20 token
*/
function newPLCRWithToken(
uint _supply,
string _name,
string _symbol,
uint8 _decimals,
string _symbol
) public returns (PLCRVoting) {
uint _supply
) public returns (bool) {
// Create a new token and give all the tokens to the PLCR creator
EIP20 token = new EIP20(_supply, _name, _decimals, _symbol);
ERC20 token = new ERC20(_name, _symbol, _decimals, _supply);
token.transfer(msg.sender, _supply);

// Create and initialize a new PLCR contract
PLCRVoting plcr = PLCRVoting(proxyFactory.createProxy(canonizedPLCR, ""));
plcr.init(token);

emit newPLCR(msg.sender, token, plcr);

return plcr;
return true;
}
}

14 changes: 7 additions & 7 deletions contracts/PLCRVoting.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pragma solidity ^0.4.8;
import "tokens/eip20/EIP20Interface.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "dll/DLL.sol";
import "attrstore/AttributeStore.sol";
import "zeppelin/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
@title Partial-Lock-Commit-Reveal Voting scheme with ERC20 tokens
Expand Down Expand Up @@ -52,7 +52,7 @@ contract PLCRVoting {
mapping(address => DLL.Data) dllMap;
AttributeStore.Data store;

EIP20Interface public token;
ERC20 public token;

/**
@dev Initializer. Can only be called once.
Expand All @@ -61,7 +61,7 @@ contract PLCRVoting {
function init(address _token) public {
require(_token != address(0) && address(token) == address(0));

token = EIP20Interface(_token);
token = ERC20(_token);
pollNonce = INITIAL_POLL_NONCE;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ contract PLCRVoting {
require(revealPeriodActive(_pollID));
require(pollMap[_pollID].didCommit[msg.sender]); // make sure user has committed a vote for this poll
require(!pollMap[_pollID].didReveal[msg.sender]); // prevent user from revealing multiple times
require(keccak256(_voteOption, _salt) == getCommitHash(msg.sender, _pollID)); // compare resultant hash from inputs to original commitHash
require(keccak256(abi.encodePacked(_voteOption, _salt)) == getCommitHash(msg.sender, _pollID)); // compare resultant hash from inputs to original commitHash

uint numTokens = getNumTokens(msg.sender, _pollID);

Expand Down Expand Up @@ -254,7 +254,7 @@ contract PLCRVoting {
require(pollMap[_pollID].didReveal[_voter]);

uint winningChoice = isPassed(_pollID) ? 1 : 0;
bytes32 winnerHash = keccak256(winningChoice, _salt);
bytes32 winnerHash = keccak256(abi.encodePacked(winningChoice, _salt));
bytes32 commitHash = getCommitHash(_voter, _pollID);

require(winnerHash == commitHash);
Expand Down Expand Up @@ -484,6 +484,6 @@ contract PLCRVoting {
@return UUID Hash which is deterministic from _user and _pollID
*/
function attrUUID(address _user, uint _pollID) public pure returns (bytes32 UUID) {
return keccak256(_user, _pollID);
return keccak256(abi.encodePacked(_user, _pollID));
}
}
4 changes: 2 additions & 2 deletions contracts/ProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract ProxyFactory {
proxyAddresses[i] = createProxyImpl(_target, _data);
}

ProxiesDeployed(proxyAddresses, _target);
emit ProxiesDeployed(proxyAddresses, _target);
}

function createProxy(address _target, bytes _data)
Expand All @@ -54,7 +54,7 @@ contract ProxyFactory {
{
proxyContract = createProxyImpl(_target, _data);

ProxyDeployed(proxyContract, _target);
emit ProxyDeployed(proxyContract, _target);
}

function createProxyImpl(address _target, bytes _data)
Expand Down
4 changes: 1 addition & 3 deletions ethpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
"plcr"
],
"dependencies": {
"tokens": "1.0.0",
"dll": "1.0.4",
"attrstore": "1.0.0",
"zeppelin": "1.3.0"
"attrstore": "1.0.1"
},
"license": "Apache 2.0"
}
Loading