Permalink
Browse files

Merge pull request #15 from holiman/master

Added back precision-loss guards
  • Loading branch information...
yudilevi committed Jun 19, 2017
2 parents bc9f836 + 2961405 commit 5d651ea1d22b962a35d3acb375575530912dff20
Showing with 10 additions and 2 deletions.
  1. +10 −2 solidity/contracts/BancorFormula.sol
@@ -52,7 +52,11 @@ contract BancorFormula is IBancorFormula, SafeMath {
var resN = power(baseN, _reserveBalance, _reserveRatio, 100);
temp = safeMul(_supply, resN) / FIXED_ONE;
return safeSub(temp, _supply);
var result = safeSub(temp, _supply);
//From the result, we deduct the minimal increment, which is a
// function of S and precision.
return safeSub(result, _supply/0x100000000);
}
/**
@@ -96,7 +100,11 @@ contract BancorFormula is IBancorFormula, SafeMath {
temp1 = safeMul(_reserveBalance, resN);
temp2 = safeMul(_reserveBalance, FIXED_ONE);
return safeSub(temp1, temp2) / resN;
var result = safeSub(temp1, temp2) / resN;
//From the result, we deduct the minimal increment, which is a
// function of R and precision.
return safeSub(result, _reserveBalance/0x100000000);
}
/**

0 comments on commit 5d651ea

Please sign in to comment.