From 065602ddb5edaff0c1f0182dbf0b1cdb7174080f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 26 Jan 2022 14:31:14 +0100 Subject: [PATCH 1/6] added a bound check where spread has to be a valid number between 0 and 1 --- packages/protocol/contracts/stability/Exchange.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/protocol/contracts/stability/Exchange.sol b/packages/protocol/contracts/stability/Exchange.sol index 074c838222b..f8a56b8b642 100644 --- a/packages/protocol/contracts/stability/Exchange.sol +++ b/packages/protocol/contracts/stability/Exchange.sol @@ -296,6 +296,7 @@ contract Exchange is */ function setSpread(uint256 newSpread) public onlyOwner { spread = FixidityLib.wrap(newSpread); + require(FixidityLib.lt(spread, FixidityLib.fixed1()), "value of spread must be smaller than 1"); emit SpreadSet(newSpread); } From b9e0f1612b3130402ab8a78eee90ecb3b9a4556c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 27 Jan 2022 17:54:19 +0100 Subject: [PATCH 2/6] added a test for the bound check --- packages/protocol/test/stability/exchange.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/exchange.ts b/packages/protocol/test/stability/exchange.ts index dce03c8e37e..3748b98a466 100644 --- a/packages/protocol/test/stability/exchange.ts +++ b/packages/protocol/test/stability/exchange.ts @@ -296,7 +296,6 @@ contract('Exchange', (accounts: string[]) => { describe('#setSpread', () => { const newSpread = toFixed(6 / 1000) - it('should set the spread', async () => { await exchange.setSpread(newSpread) @@ -305,6 +304,10 @@ contract('Exchange', (accounts: string[]) => { assert.isTrue(actualSpread.eq(newSpread)) }) + it('the spread should always be less than 1', async () => { + assert.isTrue(fixed1.gt(newSpread)) + }) + it('should emit a SpreadSet event', async () => { const tx = await exchange.setSpread(newSpread) assert(tx.logs.length === 1, 'Did not receive event') From 36a0385f748db4f27433e6a4261e6efecb3a4992 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 27 Jan 2022 18:47:57 +0100 Subject: [PATCH 3/6] changed the logical operator helper function from lt to lte --- packages/protocol/contracts/stability/Exchange.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/Exchange.sol b/packages/protocol/contracts/stability/Exchange.sol index f8a56b8b642..9e1268c3e75 100644 --- a/packages/protocol/contracts/stability/Exchange.sol +++ b/packages/protocol/contracts/stability/Exchange.sol @@ -296,7 +296,10 @@ contract Exchange is */ function setSpread(uint256 newSpread) public onlyOwner { spread = FixidityLib.wrap(newSpread); - require(FixidityLib.lt(spread, FixidityLib.fixed1()), "value of spread must be smaller than 1"); + require( + FixidityLib.lte(spread, FixidityLib.fixed1()), + "the value of spread must be less than or equal to 1" + ); emit SpreadSet(newSpread); } From 24759264089af94be57ac17c454680cf28216830 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 27 Jan 2022 19:13:13 +0100 Subject: [PATCH 4/6] updated the logical operator so spread is no <= 1 --- packages/protocol/test/stability/exchange.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/test/stability/exchange.ts b/packages/protocol/test/stability/exchange.ts index 3748b98a466..e24906e055b 100644 --- a/packages/protocol/test/stability/exchange.ts +++ b/packages/protocol/test/stability/exchange.ts @@ -304,8 +304,8 @@ contract('Exchange', (accounts: string[]) => { assert.isTrue(actualSpread.eq(newSpread)) }) - it('the spread should always be less than 1', async () => { - assert.isTrue(fixed1.gt(newSpread)) + it('the spread should always be less than or equal to 1', async () => { + assert.isTrue(fixed1.gte(newSpread)) }) it('should emit a SpreadSet event', async () => { From d0c7ebb159c077dd5c467fa4ea0efb1464c40d3a Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 27 Jan 2022 19:15:05 +0100 Subject: [PATCH 5/6] edge case to make sure that transaction reverts if spread is > 1 --- packages/protocol/test/stability/exchange.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/protocol/test/stability/exchange.ts b/packages/protocol/test/stability/exchange.ts index e24906e055b..cc335f14d1b 100644 --- a/packages/protocol/test/stability/exchange.ts +++ b/packages/protocol/test/stability/exchange.ts @@ -306,6 +306,7 @@ contract('Exchange', (accounts: string[]) => { it('the spread should always be less than or equal to 1', async () => { assert.isTrue(fixed1.gte(newSpread)) + await assertRevert(exchange.setSpread(toFixed(1001 / 1000))) }) it('should emit a SpreadSet event', async () => { From c945669bebe84f7afa24656a4484ba5fdd1ff1d5 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 31 Jan 2022 16:31:37 +0100 Subject: [PATCH 6/6] removing the unnecessary test-case --- packages/protocol/test/stability/exchange.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/protocol/test/stability/exchange.ts b/packages/protocol/test/stability/exchange.ts index cc335f14d1b..de340307265 100644 --- a/packages/protocol/test/stability/exchange.ts +++ b/packages/protocol/test/stability/exchange.ts @@ -305,7 +305,6 @@ contract('Exchange', (accounts: string[]) => { }) it('the spread should always be less than or equal to 1', async () => { - assert.isTrue(fixed1.gte(newSpread)) await assertRevert(exchange.setSpread(toFixed(1001 / 1000))) })