@@ -5,6 +5,7 @@ import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
5
5
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol " ;
6
6
import "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol " ;
7
7
import "zeppelin-solidity/contracts/math/SafeMath.sol " ;
8
+ import "./external/SafeMathUint256.sol " ;
8
9
import "./lib/Set.sol " ;
9
10
10
11
@@ -68,14 +69,17 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
68
69
*/
69
70
function issue (uint quantity ) public returns (bool success ) {
70
71
// Transfers the sender's components to the contract
72
+ // Since the component length is defined ahead of time, this is not
73
+ // an unbounded loop
71
74
for (uint i = 0 ; i < components.length ; i++ ) {
72
75
address currentComponent = components[i];
73
76
uint currentUnits = units[i];
74
77
75
78
// Transfer value is defined as the currentUnits (in GWei)
76
79
// multiplied by quantity in Wei divided by the units of gWei.
77
80
// We do this to allow fractional units to be defined
78
- uint transferValue = currentUnits.mul (quantity).div (10 ** 9 );
81
+ // uint transferValue = currentUnits.mul(quantity).div(10**9);
82
+ uint transferValue = SafeMathUint256.fxpMul (currentUnits, quantity, 10 ** 9 );
79
83
80
84
// Protect against the case that the gWei divisor results in a value that is
81
85
// 0 and the user is able to generate Sets without sending a balance
@@ -104,6 +108,8 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
104
108
*/
105
109
function redeem (uint quantity ) public returns (bool success ) {
106
110
// Check that the sender has sufficient components
111
+ // Since the component length is defined ahead of time, this is not
112
+ // an unbounded loop
107
113
require (balances[msg .sender ] >= quantity);
108
114
109
115
// To prevent re-entrancy attacks, decrement the user's Set balance
@@ -117,7 +123,8 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
117
123
uint currentUnits = units[i];
118
124
119
125
// The transaction will fail if any of the components fail to transfer
120
- uint transferValue = currentUnits.mul (quantity).div (10 ** 9 );
126
+ // uint transferValue = currentUnits.mul(quantity).div(10**9);
127
+ uint transferValue = SafeMathUint256.fxpMul (currentUnits, quantity, 10 ** 9 );
121
128
122
129
// Protect against the case that the gWei divisor results in a value that is
123
130
// 0 and the user is able to generate Sets without sending a balance
0 commit comments