Skip to content

Commit

Permalink
Added whitelisting mechanism to KYC crowdsale.
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Nov 6, 2017
1 parent 87726e4 commit 9f114b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion contracts/CrowdsaleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ contract CrowdsaleBase is Haltable {
assignTokens(receiver, tokenAmount);

// Pocket the money, or fail the crowdsale if we for some reason cannot send the money to our multisig
require(multisigWallet.send(weiAmount) == true);
if(!multisigWallet.send(weiAmount)) throw;

// Tell us invest was success
Invested(receiver, weiAmount, tokenAmount, customerId);
Expand Down
41 changes: 27 additions & 14 deletions contracts/KYCCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,39 @@ contract KYCCrowdsale is AllocatedCrowdsaleMixin, KYCPayloadDeserializer {
*/
function buyWithKYCData(bytes dataframe, uint8 v, bytes32 r, bytes32 s) public payable returns(uint tokenAmount) {

bytes32 hash = sha256(dataframe);
uint _tokenAmount;
uint multiplier = 10 ** 18;

// Check that the KYC data is signed by our server
require(ecrecover(hash, v, r, s) == signerAddress);
// Perform signature check for normal addresses
// (not deployment accounts, etc.)
if(earlyParticipantWhitelist[msg.sender]) {
// For test purchases use this faux customer id
_tokenAmount = investInternal(msg.sender, 0x1000);

var (whitelistedAddress, customerId, minETH, maxETH) = getKYCPayload(dataframe);
} else {

// Only whitelisted address can participate the transaction
require(whitelistedAddress == msg.sender);
bytes32 hash = sha256(dataframe);

uint _tokenAmount = investInternal(msg.sender, customerId);
var (whitelistedAddress, customerId, minETH, maxETH) = getKYCPayload(dataframe);

uint multiplier = 10 ** 18;
// Check that the KYC data is signed by our server
require(ecrecover(hash, v, r, s) == signerAddress);

// Only whitelisted address can participate the transaction
require(whitelistedAddress == msg.sender);

_tokenAmount = investInternal(msg.sender, customerId);

}

// We assume there is no serious min and max fluctuations for the customer, unless
// especially set in the server side per customer manual override.
// Otherwise the customer can reuse old data payload with different min or max value
// to work around the per customer cap.
require(investedAmountOf[whitelistedAddress] >= minETH * multiplier / 10000);
require(investedAmountOf[whitelistedAddress] <= maxETH * multiplier / 10000);
if(!earlyParticipantWhitelist[msg.sender]) {
// We assume there is no serious min and max fluctuations for the customer, unless
// especially set in the server side per customer manual override.
// Otherwise the customer can reuse old data payload with different min or max value
// to work around the per customer cap.
require(investedAmountOf[msg.sender] >= minETH * multiplier / 10000);
require(investedAmountOf[msg.sender] <= maxETH * multiplier / 10000);
}

return _tokenAmount;
}
Expand Down
5 changes: 2 additions & 3 deletions contracts/KYCPayloadDeserializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ contract KYCPayloadDeserializer {
* TODO: Some sort of compiler issue (?) with memory keyword. Tested with solc 0.4.16 and solc 0.4.18.
* If used, makes KYCCrowdsale to set itself to a bad state getState() returns 5 (Failure). Overrides some memory?
*/

/*
function broken_getKYCPayload(bytes dataframe) public constant returns(address whitelistedAddress, uint128 customerId, uint32 minEth, uint32 maxEth) {
KYCPayload memory payload = deserializeKYCPayload(dataframe);
payload.whitelistedAddress = dataframe.sliceAddress(0);
payload.customerId = uint128(dataframe.slice16(20));
payload.minETH = uint32(dataframe.slice4(36));
payload.maxETH = uint32(dataframe.slice4(40));
return (payload.whitelistedAddress, payload.customerId, payload.minETH, payload.maxETH);
}
}*/

/**
* Same as above, does not seem to cause any issue.
Expand All @@ -77,5 +77,4 @@ contract KYCPayloadDeserializer {
return (_whitelistedAddress, _customerId, _minETH, _maxETH);
}


}

0 comments on commit 9f114b1

Please sign in to comment.