From 8cdb5d005abab607937c3bd5d5d43a2566871204 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sun, 28 Jan 2018 04:08:09 -0200 Subject: [PATCH] fix constructor and signed message header --- contracts/status/SNTPreSigned.sol | 6 +-- contracts/token/MiniMeTokenFactory.sol | 2 + contracts/token/MiniMeTokenPreSigned.sol | 64 +++++++++++------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/contracts/status/SNTPreSigned.sol b/contracts/status/SNTPreSigned.sol index e11257c..6e7962e 100644 --- a/contracts/status/SNTPreSigned.sol +++ b/contracts/status/SNTPreSigned.sol @@ -9,9 +9,9 @@ import "../token/MiniMeTokenPreSignedFactory.sol"; contract SNTPreSigned is MiniMeTokenPreSigned { // @dev SNT constructor just parametrizes the MiniMeIrrevocableVestedToken constructor - function SNTPreSigned(address _oldToken) - MiniMeToken( - new MiniMeTokenPreSignedFactory(), + function SNTPreSigned(address _newFactory, address _oldToken) + MiniMeTokenPreSigned( + _newFactory, _oldToken, // parent token block.number, // snapshot block "Status Network Token", // Token name diff --git a/contracts/token/MiniMeTokenFactory.sol b/contracts/token/MiniMeTokenFactory.sol index 4e79ead..a7643fc 100644 --- a/contracts/token/MiniMeTokenFactory.sol +++ b/contracts/token/MiniMeTokenFactory.sol @@ -11,6 +11,8 @@ import "./MiniMeToken.sol"; /// same class contract MiniMeTokenFactory { + + /// @notice Update the DApp by creating a new token with new functionalities /// the msg.sender becomes the controller of this clone token /// @param _parentToken Address of the token being cloned diff --git a/contracts/token/MiniMeTokenPreSigned.sol b/contracts/token/MiniMeTokenPreSigned.sol index cd84592..0725625 100644 --- a/contracts/token/MiniMeTokenPreSigned.sol +++ b/contracts/token/MiniMeTokenPreSigned.sol @@ -9,6 +9,28 @@ import "./MiniMeToken.sol"; */ contract MiniMeTokenPreSigned is MiniMeToken { + function MiniMeTokenPreSigned( + address _tokenFactory, + address _parentToken, + uint _parentSnapShotBlock, + string _tokenName, + uint8 _decimalUnits, + string _tokenSymbol, + bool _transfersEnabled + ) MiniMeToken( + _tokenFactory, + _parentToken, + _parentSnapShotBlock, + _tokenName, + _decimalUnits, + _tokenSymbol, + _transfersEnabled + ) + public + { + + } + mapping (address => uint256) public nonce; /** @@ -34,8 +56,9 @@ contract MiniMeTokenPreSigned is MiniMeToken { { uint256 _gas = msg.gas; //"a9059cbb": "transfer(address,uint256)", - bytes32 txHash = keccak256(byte(0x19), byte(0), address(this), bytes4(0xa9059cbb), _to, _value, _gasPrice, _nonce); - address recovered = ecrecover(txHash, _sigV, _sigR, _sigS); + bytes32 txHash = keccak256(address(this), bytes4(0xa9059cbb), _to, _value, _gasPrice, _nonce); + bytes32 signedMsg = keccak256("\x19Ethereum Signed Message:\n32", txHash); + address recovered = ecrecover(signedMsg, _sigV, _sigR, _sigS); require(recovered > 0x0); require(nonce[recovered] == _nonce); nonce[recovered]++; @@ -72,8 +95,9 @@ contract MiniMeTokenPreSigned is MiniMeToken { uint256 _gas = msg.gas; require(transfersEnabled); //"cae9ca51": "approveAndCall(address,uint256,bytes)" - bytes32 txHash = keccak256(byte(0x19), byte(0), address(this), bytes4(0xcae9ca51), _spender, _amount, _extraData, _gasPrice, _nonce); - address recovered = ecrecover(txHash, _sigV, _sigR, _sigS); + bytes32 txHash = keccak256(address(this), bytes4(0xcae9ca51), _spender, _amount, _extraData, _gasPrice, _nonce); + bytes32 signedMsg = keccak256("\x19Ethereum Signed Message:\n32", txHash); + address recovered = ecrecover(signedMsg, _sigV, _sigR, _sigS); require(recovered > 0x0); require(nonce[recovered] == _nonce); nonce[recovered]++; @@ -97,38 +121,6 @@ contract MiniMeTokenPreSigned is MiniMeToken { } - /** - * @notice Include batches of presigned `approveAndCall(address,uint256,bytes)` - * @param _sigV Signature V - * @param _sigR Signature R - * @param _sigS Signature S - * @param _spender The address of the recipient - * @param _amount The amount of tokens to be transferred - * @param _extraData option data to send to contract - * @param _gasPrice How much tokens willing to pay per gas - * @param _nonce Presigned transaction number. - */ - function approveAndCallPreSigned( - uint8[] _sigV, - bytes32[] _sigR, - bytes32[] _sigS, - address[] _spender, - uint256[] _amount, - bytes[] _extraData, - uint256[] _gasPrice, - uint256[] _nonce - ) - public - { - uint len = _sigR.length; - require(len == _sigS.length && len == _sigV.length); - for (uint i = 0; i < len; i++) { - approveAndCallPreSigned(_sigV[i], _sigR[i], _sigS[i], _spender[i], _amount[i], _extraData[i], _gasPrice[i], _nonce[i]); - } - } - - - /** * @notice Include batches of presigned `transfer(address,uint256)` * @param _sigV Signature V