Skip to content

Commit 39f1f7f

Browse files
authored
Merge pull request #1044 from liquity/fix-high-fraction-liquidation-security-advisory
Fix high fraction liquidation security advisory
2 parents e38edf3 + 7fea84a commit 39f1f7f

18 files changed

+1311
-1082
lines changed

packages/contracts/contracts/Dependencies/LiquitySafeMath128.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/contracts/contracts/Interfaces/IStabilityPool.sol

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ interface IStabilityPool {
5050
event CommunityIssuanceAddressChanged(address _newCommunityIssuanceAddress);
5151

5252
event P_Updated(uint _P);
53-
event S_Updated(uint _S, uint128 _epoch, uint128 _scale);
54-
event G_Updated(uint _G, uint128 _epoch, uint128 _scale);
55-
event EpochUpdated(uint128 _currentEpoch);
56-
event ScaleUpdated(uint128 _currentScale);
53+
event S_Updated(uint _S, uint _scale);
54+
event G_Updated(uint _G, uint _scale);
55+
event ScaleUpdated(uint _currentScale);
5756

5857
event FrontEndRegistered(address indexed _frontEnd, uint _kickbackRate);
5958
event FrontEndTagSet(address indexed _depositor, address indexed _frontEnd);
@@ -159,6 +158,13 @@ interface IStabilityPool {
159158
*/
160159
function getTotalLUSDDeposits() external view returns (uint);
161160

161+
/*
162+
* Returns the max amount of LUSD held in the pool that can be used for liquidations.
163+
* It makes sure that at least 1 LUSD remains.
164+
* If the max amount is used, it makes sure it won’t revert by underflow due to the accumulated offset error.
165+
*/
166+
function getMaxAmountToOffset() external view returns (uint);
167+
162168
/*
163169
* Calculates the ETH gain earned by the deposit since its last snapshots were taken.
164170
*/

packages/contracts/contracts/StabilityPool.sol

Lines changed: 87 additions & 92 deletions
Large diffs are not rendered by default.

packages/contracts/contracts/TestContracts/LiquitySafeMath128Tester.sol

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/contracts/contracts/TestContracts/StabilityPoolTester.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ contract StabilityPoolTester is StabilityPool {
1010
ETH = ETH.add(msg.value);
1111
}
1212

13-
function setCurrentScale(uint128 _currentScale) external {
13+
function setCurrentScale(uint _currentScale) external {
1414
currentScale = _currentScale;
1515
}
1616

packages/contracts/contracts/TroveManager.sol

Lines changed: 41 additions & 41 deletions
Large diffs are not rendered by default.

packages/contracts/hardhat.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = {
5454
{
5555
version: "0.6.11",
5656
settings: {
57+
evmVersion: "istanbul",
5758
optimizer: {
5859
enabled: true,
5960
runs: 100

packages/contracts/test/GasCompensationTest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ contract('Gas compensation tests', async accounts => {
356356
// D, E each provide LUSD to SP
357357
await stabilityPool.provideToSP(A_totalDebt, ZERO_ADDRESS, { from: dennis, gasPrice: GAS_PRICE })
358358
await stabilityPool.provideToSP(B_totalDebt.add(C_totalDebt), ZERO_ADDRESS, { from: erin, gasPrice: GAS_PRICE })
359+
// whale deposits LUSD so all debt can be offset
360+
await stabilityPool.provideToSP(dec(1, 18), ZERO_ADDRESS, { from: whale })
359361

360362
const LUSDinSP_0 = await stabilityPool.getTotalLUSDDeposits()
361363

@@ -448,8 +450,10 @@ contract('Gas compensation tests', async accounts => {
448450
const LUSDinSP_C = await stabilityPool.getTotalLUSDDeposits()
449451
assert.isTrue(LUSDinSP_C.lt(LUSDinSP_B))
450452

451-
// Check ETH in SP has not changed due to the lquidation of C
453+
// Check ETH in SP has not changed due to the liquidation of C
452454
const ETHinSP_C = await stabilityPool.getETH()
455+
console.log('ETHinSP_C.toString(): ', ETHinSP_C.toString())
456+
console.log('aliceColl.sub(_0pt5percent_aliceColl).add(bobColl).sub(_0pt5percent_bobColl).add(carolColl).sub(_0pt5percent_carolColl).toString(): ', aliceColl.sub(_0pt5percent_aliceColl).add(bobColl).sub(_0pt5percent_bobColl).add(carolColl).sub(_0pt5percent_carolColl).toString())
453457
assert.equal(ETHinSP_C.toString(), aliceColl.sub(_0pt5percent_aliceColl).add(bobColl).sub(_0pt5percent_bobColl).add(carolColl).sub(_0pt5percent_carolColl)) // (1+2+3 ETH) * 0.995
454458
})
455459

packages/contracts/test/LiquitySafeMath128Test.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)