-
-
Save IllIllI000/e7d44c6bf21155c5cc076d3ace69d47f to your computer and use it in GitHub Desktop.
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
diff --git a/test/votingEscrowTest.ts b/test/votingEscrowTest.ts | |
index 7d3163d..5063bb4 100644 | |
--- a/test/votingEscrowTest.ts | |
+++ b/test/votingEscrowTest.ts | |
@@ -115,6 +115,103 @@ describe("VotingEscrow Tests", function () { | |
await restoreSnapshot(provider); | |
}); | |
+ | |
+ | |
+ // to run: | |
+ // rm -Rf 2022-08-fiatdao || true && git clone https://github.com/code-423n4/2022-08-fiatdao && cd 2022-08-fiatdao && npm install && npm run build && wget https://gist.githubusercontent.com/IllIllI000/e7d44c6bf21155c5cc076d3ace69d47f/raw/9a8e4b24c0b7abc1ba532431169ab36e4755d50e/veFDT_mit_1wVs2w.diff && git apply veFDT_mit_1wVs2w.diff && npx hardhat test --config hardhat.config.test.ts test/votingEscrowTest.ts | |
+ | |
+ | |
+ | |
+ describe("IllIllI Mitigation tests", async () => { | |
+ it("IllIllI - Verify that the penalty ensures locking for one week is better than locking for two, then quitLocking after one", async () => { | |
+ await provider.send("evm_setAutomine", [false]); | |
+ await provider.send("evm_setIntervalMining", [0]); | |
+ await provider.send("evm_mine", []); | |
+ | |
+ let blockAnticipated = await getBlock() + 1; | |
+ let timeStartup = await getTimestamp(); | |
+ let timeStart = (Math.trunc(timeStartup / WEEK) * WEEK) + WEEK + WEEK; // give us room to go backwards by adding another week | |
+ let timeActuallyLockedFrom = timeStart; | |
+ //timeStart += 284680 | |
+ timeStart = timeActuallyLockedFrom + 0; | |
+ //timeStart = timeActuallyLockedFrom + 1; | |
+ //timeStart = timeActuallyLockedFrom - 1; | |
+ //timeStart = timeActuallyLockedFrom - WEEK + 1; | |
+ //timeStart = timeActuallyLockedFrom + WEEK - 1; | |
+ | |
+ await provider.send("evm_setNextBlockTimestamp", [ timeStart ]); | |
+ | |
+ // alice creates a lock for 2 weeks | |
+ //let amountToLock = BigNumber.from("10"); | |
+ let amountToLock = BigNumber.from("1000000000000000000000"); | |
+ let txAlice = await ve.connect(alice).createLock(amountToLock, (2 * WEEK) + timeStart); | |
+ // bob creates the same one, but for 1 week | |
+ let txBob = await ve.connect(bob).createLock(amountToLock, (1 * WEEK) + timeStart); | |
+ await provider.send("evm_mine", []); | |
+ let respAlice = await txAlice.wait(); | |
+ let respBob = await txBob.wait(); | |
+ // verify they both got in the block we expected | |
+ expect(respBob.blockNumber).to.equal(respAlice.blockNumber); | |
+ expect(respBob.blockNumber).to.equal(blockAnticipated); | |
+ console.log("mined:",respAlice.blockNumber, respBob.blockNumber, blockAnticipated); | |
+ let unlockTimeAlice = (await ve.connect(alice).lockEnd(alice.address)).toNumber(); | |
+ console.log("alice wanted unlocktime:", (2*WEEK)+timeStart, "got:", unlockTimeAlice); | |
+ let unlockTimeBob = (await ve.connect(bob).lockEnd(bob.address)).toNumber(); | |
+ console.log("bob wanted unlocktime:", (1*WEEK)+timeStart, "got:", unlockTimeBob); | |
+ if (timeActuallyLockedFrom < timeStart) { | |
+ // ends up locking one week less than expected, matching bob | |
+ expect(unlockTimeAlice).to.equal(1*WEEK + timeActuallyLockedFrom); | |
+ } else { | |
+ expect(unlockTimeAlice).to.equal(2*WEEK + timeActuallyLockedFrom); | |
+ } | |
+ console.log("alice unlock - bob unlock vs week:", (unlockTimeAlice - unlockTimeBob), WEEK); | |
+ expect(unlockTimeAlice - unlockTimeBob).to.equal(WEEK); | |
+ console.log("bob votes:", (await ve.balanceOf(bob.address)).toString()); | |
+ // half alice's duration passes (bob's full duration) | |
+ await provider.send("evm_setNextBlockTimestamp", [ unlockTimeBob ]); | |
+ // alice quits | |
+ txAlice = await ve.connect(alice).quitLock(); | |
+ await provider.send("evm_mine", []); | |
+ respAlice = await txAlice.wait(); | |
+ let blockBeforeQuit = respAlice.blockNumber - 1; | |
+ let tsQuit = (await ethers.provider.getBlock(respAlice.blockNumber)).timestamp; | |
+ console.log("mined:",respAlice.blockNumber, "ts:", tsQuit, "vs", timeStart + WEEK); | |
+ console.log("quit after secs:", tsQuit - timeActuallyLockedFrom, WEEK); | |
+ if (timeActuallyLockedFrom < timeStart) { | |
+ expect(tsQuit - timeActuallyLockedFrom).to.equal(0); | |
+ } else { | |
+ expect(tsQuit - timeActuallyLockedFrom).to.equal(WEEK); | |
+ } | |
+ let votes = await ve.balanceOfAt(alice.address, blockBeforeQuit) | |
+ let votesAlice2 = await ve.balanceOfAt(alice.address, blockAnticipated) | |
+ let votesAlice3 = await ve.balanceOfAt(alice.address, blockAnticipated+1) | |
+ let votesBob = await ve.balanceOfAt(bob.address, blockBeforeQuit) | |
+ let votesBob2 = await ve.balanceOfAt(bob.address, blockAnticipated) | |
+ let penalty = (await fdtMock.balanceOf(ve.address)).sub(amountToLock); // exclude bob's tokens since he's still locked | |
+ | |
+ await provider.send("evm_mine", []); | |
+ await provider.send("evm_mine", []); | |
+ await provider.send("evm_mine", []); | |
+ let data = [] | |
+ console.log("alice votes at block and start:", votes.toString(), votesAlice2.toString(), "penalty:", penalty.toString()); | |
+ console.log("bob votes at block and start:", votesBob.toString(), votesBob2.toString()); | |
+ console.log("alice bob starting vote diff:", votesAlice2.sub(votesBob2).toString()); | |
+ console.log("bob votes now:", (await ve.balanceOf(bob.address)).toString()); | |
+ console.log("alice votes at block - penalty:", votes.sub(penalty).toString()); | |
+ console.log("alice votes at start - penalty:", votesAlice2.sub(penalty).toString()); | |
+ console.log("diff between penalty and bob's starting votes:", votesBob2.sub(penalty).toString()); | |
+ console.log("alice net votes vs bob's:", votesAlice2.sub(penalty).toString(), votesBob2.toString()); | |
+ let diff = votesAlice2.sub(penalty).sub(votesBob2); | |
+ console.log("difference:", diff.toString()) | |
+ if (!votesAlice2.eq(BigNumber.from(0))) { | |
+ expect(diff).to.below(0); | |
+ expect(votesAlice2.sub(penalty)).to.below(votesBob2); | |
+ } else { | |
+ expect(diff).to.equal(0); | |
+ } | |
+ }); | |
+ }) | |
+/** | |
describe("Deployment", async () => { | |
it("Initialized properly", async () => { | |
expect(await ve.owner()).to.equal(admin.address); | |
@@ -856,5 +953,5 @@ describe("VotingEscrow Tests", function () { | |
await ve.connect(alice).quitLock(); | |
expect(await fdtMock.balanceOf(alice.address)).to.equal(aliceBalBefore); | |
}); | |
- }); | |
+ });/**/ | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment