forked from compound-finance/compound-protocol
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from CreamFi/handle_erc777
contracts/, tests/: handle erc777
- Loading branch information
Showing
7 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { | ||
etherMantissa | ||
} = require('../Utils/Ethereum'); | ||
|
||
const { | ||
makeCToken, | ||
makeComptroller, | ||
makeEvilAccount | ||
} = require('../Utils/Compound'); | ||
|
||
const collateralFactor = 0.5, underlyingPrice = 1, mintAmount = 2, borrowAmount = 1; | ||
|
||
describe('Attack', function () { | ||
let root, accounts; | ||
let comptroller; | ||
let cEth, cEvil; | ||
let evilAccount; | ||
|
||
beforeEach(async () => { | ||
[root, ...accounts] = saddle.accounts; | ||
comptroller = await makeComptroller(); | ||
cEth = await makeCToken({comptroller, kind: 'cether', supportMarket: true, collateralFactor}); | ||
cEvil = await makeCToken({comptroller, kind: 'cevil', supportMarket: true, collateralFactor, underlyingPrice}); | ||
evilAccount = await makeEvilAccount({crEth: cEth, crEvil: cEvil, borrowAmount: etherMantissa(borrowAmount)}); | ||
}); | ||
|
||
it('reentry borrow attack', async () => { | ||
await send(cEvil.underlying, 'allocateTo', [accounts[0], etherMantissa(100)]); | ||
await send(cEvil.underlying, 'approve', [cEvil._address, etherMantissa(100)], {from: accounts[0]}); | ||
await send(cEvil, 'mint', [etherMantissa(100)], {from: accounts[0]}); | ||
|
||
// Actually, this attack will emit a Failure event with value (3: COMPTROLLER_REJECTION, 6: BORROW_COMPTROLLER_REJECTION, 4: INSUFFICIENT_LIQUIDITY). | ||
// However, somehow it failed to parse the event. | ||
await send(evilAccount, 'attack', [], {value: etherMantissa(mintAmount)}); | ||
|
||
// The attack should have no effect. | ||
({1: liquidity, 2: shortfall} = await call(comptroller, 'getAccountLiquidity', [evilAccount._address])); | ||
expect(liquidity).toEqualNumber(0); | ||
expect(shortfall).toEqualNumber(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters