From e65aad3b24e693cd6a57ab8e69f441907f2c7776 Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Wed, 14 Jun 2023 13:06:26 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=B4=20Upgrade=20to=20solidity=200.8.20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/KilitliTCKO.sol | 41 +++-------- contracts/TCKO.sol | 105 ++++++++++++----------------- lib/forge-std | 2 +- lib/interfaces | 2 +- remappings.txt | 2 +- test/ReentrancyAttackContracts.sol | 3 +- test/ReentrancyTest.sol | 6 +- test/TCKOGasTest.sol | 6 +- test/TCKOMintTest.sol | 6 +- test/TCKOSnapshotTest.sol | 4 +- test/TCKOTest.sol | 40 +++-------- 11 files changed, 77 insertions(+), 140 deletions(-) diff --git a/contracts/KilitliTCKO.sol b/contracts/KilitliTCKO.sol index 9de0c78..672ae77 100644 --- a/contracts/KilitliTCKO.sol +++ b/contracts/KilitliTCKO.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // 🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿 -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "interfaces/Addresses.sol"; import "interfaces/DistroStage.sol"; @@ -47,12 +47,9 @@ contract KilitliTCKO is IERC20 { uint256 private constant BALANCE0_MASK = type(uint256).max >> 128; - function balanceOf(address account) - external - view - override - returns (uint256) - { + function balanceOf( + address account + ) external view override returns (uint256) { unchecked { uint256 balance = balances[account]; return (balance & BALANCE0_MASK) + (balance >> 128); @@ -72,12 +69,10 @@ contract KilitliTCKO is IERC20 { return false; } - function allowance(address, address) - external - pure - override - returns (uint256) - { + function allowance( + address, + address + ) external pure override returns (uint256) { return 0; } @@ -85,11 +80,7 @@ contract KilitliTCKO is IERC20 { return false; } - function mint( - address account, - uint256 amount, - DistroStage stage - ) external { + function mint(address account, uint256 amount, DistroStage stage) external { require(msg.sender == TCKO_ADDR); unchecked { if (uint256(stage) & 1 == 0) { @@ -180,20 +171,6 @@ contract KilitliTCKO is IERC20 { } } - /** - * Deletes the contract if all TCKO-k's have been unlocked. - */ - function selfDestruct() external { - // We restrict this method to `DEV_KASASI` as there may be ERC20 tokens - // sent to this contract by accident waiting to be rescued. - require(msg.sender == DEV_KASASI); - require( - HasDistroStage(TCKO_ADDR).distroStage() == DistroStage.FinalUnlock - ); - require(totalSupply == 0); - selfdestruct(DAO_KASASI); - } - /** * Moves ERC20 tokens sent to this address by accident to `DAO_KASASI`. */ diff --git a/contracts/TCKO.sol b/contracts/TCKO.sol index c76bef2..7625628 100644 --- a/contracts/TCKO.sol +++ b/contracts/TCKO.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // 🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿 -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "./KilitliTCKO.sol"; import {OYLAMA} from "interfaces/Addresses.sol"; @@ -172,12 +172,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function balanceOf(address account) - external - view - override - returns (uint256) - { + function balanceOf( + address account + ) external view override returns (uint256) { return balances[account] & BALANCE_MASK; } @@ -195,11 +192,10 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { * @param to the address of the recipient. * @param amount amount of TCKOs * 1e6. */ - function transfer(address to, uint256 amount) - external - override - returns (bool) - { + function transfer( + address to, + uint256 amount + ) external override returns (bool) { // Disallow sending to the 0 address, which is a common software / user // error. require(to != address(0)); @@ -266,20 +262,19 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { return true; } - function approve(address spender, uint256 amount) - external - override - returns (bool) - { + function approve( + address spender, + uint256 amount + ) external override returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } - function increaseAllowance(address spender, uint256 addedAmount) - external - returns (bool) - { + function increaseAllowance( + address spender, + uint256 addedAmount + ) external returns (bool) { // Checked addition uint256 newAmount = allowance[msg.sender][spender] + addedAmount; allowance[msg.sender][spender] = newAmount; @@ -287,10 +282,10 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { return true; } - function decreaseAllowance(address spender, uint256 subtractedAmount) - external - returns (bool) - { + function decreaseAllowance( + address spender, + uint256 subtractedAmount + ) external returns (bool) { // Checked subtraction uint256 newAmount = allowance[msg.sender][spender] - subtractedAmount; allowance[msg.sender][spender] = newAmount; @@ -525,12 +520,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { // |-- 24 --|-- 20 --|-- 20 --|-- 48 --|-- 48 --|-- 48 --|-- 48 --| uint256 private tick; - function snapshot0BalanceOf(address account) - external - view - override - returns (uint256) - { + function snapshot0BalanceOf( + address account + ) external view override returns (uint256) { uint256 balance = balances[account]; unchecked { return @@ -539,11 +531,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function consumeSnapshot0Balance(address account) - external - override - returns (uint256) - { + function consumeSnapshot0Balance( + address account + ) external override returns (uint256) { require(msg.sender == OYLAMA); uint256 info = balances[account]; unchecked { @@ -556,12 +546,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function snapshot1BalanceOf(address account) - external - view - override - returns (uint256) - { + function snapshot1BalanceOf( + address account + ) external view override returns (uint256) { uint256 info = balances[account]; unchecked { return @@ -570,11 +557,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function consumeSnapshot1Balance(address account) - external - override - returns (uint256) - { + function consumeSnapshot1Balance( + address account + ) external override returns (uint256) { require(msg.sender == OYLAMA); uint256 info = balances[account]; unchecked { @@ -587,12 +572,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function snapshot2BalanceOf(address account) - external - view - override - returns (uint256) - { + function snapshot2BalanceOf( + address account + ) external view override returns (uint256) { uint256 info = balances[account]; unchecked { return @@ -601,11 +583,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function consumeSnapshot2Balance(address account) - external - override - returns (uint256) - { + function consumeSnapshot2Balance( + address account + ) external override returns (uint256) { require(msg.sender == OYLAMA); uint256 info = balances[account]; unchecked { @@ -641,11 +621,10 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage { } } - function preserve(uint256 balance, uint256 t) - internal - pure - returns (uint256) - { + function preserve( + uint256 balance, + uint256 t + ) internal pure returns (uint256) { unchecked { // tick.tick0 doesn't match balance.tick0; we need to preserve the // current balance. diff --git a/lib/forge-std b/lib/forge-std index b4f1215..66bf4e2 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit b4f121555729b3afb3c5ffccb62ff4b6e2818fd3 +Subproject commit 66bf4e2c92cf507531599845e8d5a08cc2e3b5bb diff --git a/lib/interfaces b/lib/interfaces index 05e75e8..81e08d1 160000 --- a/lib/interfaces +++ b/lib/interfaces @@ -1 +1 @@ -Subproject commit 05e75e82d503b586b6f07d16dbbec844e77f3d9e +Subproject commit 81e08d19d9bdbcadfe6256c88b69437772198929 diff --git a/remappings.txt b/remappings.txt index 9b5a30d..8ea7e8a 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,3 +1,3 @@ -ds-test/=lib/interfaces/lib/forge-std/lib/ds-test/src/ +ds-test/=lib/forge-std/lib/ds-test/src/ forge-std/=lib/forge-std/src/ interfaces/=lib/interfaces/contracts/ diff --git a/test/ReentrancyAttackContracts.sol b/test/ReentrancyAttackContracts.sol index 555baea..d1d3b24 100644 --- a/test/ReentrancyAttackContracts.sol +++ b/test/ReentrancyAttackContracts.sol @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; + +pragma solidity 0.8.20; import "forge-std/Test.sol"; import {DAO_KASASI, TCKO_ADDR} from "interfaces/Addresses.sol"; diff --git a/test/ReentrancyTest.sol b/test/ReentrancyTest.sol index 99c2fbc..0bbbc69 100644 --- a/test/ReentrancyTest.sol +++ b/test/ReentrancyTest.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "./ReentrancyAttackContracts.sol"; import "contracts/TCKO.sol"; import "forge-std/Test.sol"; -import {MockDAOKasasi} from "interfaces/testing/MockDAOKasasi.sol"; +import {MockDAOKasasiV1} from "interfaces/testing/MockDAOKasasiV1.sol"; contract ReentrancyTest is Test { TCKO private tcko; @@ -29,7 +29,7 @@ contract ReentrancyTest is Test { vm.stopPrank(); vm.prank(DAO_KASASI_DEPLOYER); - daoKasasi = new MockDAOKasasi(); + daoKasasi = new MockDAOKasasiV1(); vm.deal(DAO_KASASI, 80e18); diff --git a/test/TCKOGasTest.sol b/test/TCKOGasTest.sol index 85c1b9b..b72de93 100644 --- a/test/TCKOGasTest.sol +++ b/test/TCKOGasTest.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "contracts/TCKO.sol"; import "forge-std/Test.sol"; -import "interfaces/testing/MockDAOKasasi.sol"; +import "interfaces/testing/MockDAOKasasiV1.sol"; import {MockERC20Permit} from "interfaces/testing/MockTokens.sol"; contract TCKOGasTest is Test { @@ -21,7 +21,7 @@ contract TCKOGasTest is Test { tckok = new KilitliTCKO(); vm.prank(DAO_KASASI_DEPLOYER); - daoKasasi = new MockDAOKasasi(); + daoKasasi = new MockDAOKasasiV1(); mintAll(1e12); vm.deal(DAO_KASASI, 80e18); diff --git a/test/TCKOMintTest.sol b/test/TCKOMintTest.sol index a25fb5a..9863681 100644 --- a/test/TCKOMintTest.sol +++ b/test/TCKOMintTest.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "forge-std/Test.sol"; import "interfaces/Addresses.sol"; import {IDAOKasasi} from "interfaces/IDAOKasasi.sol"; -import {MockDAOKasasi} from "interfaces/testing/MockDAOKasasi.sol"; +import {MockDAOKasasiV1} from "interfaces/testing/MockDAOKasasiV1.sol"; import {TCKO, KilitliTCKO} from "contracts/TCKO.sol"; contract TCKOMintTest is Test { @@ -21,7 +21,7 @@ contract TCKOMintTest is Test { tcko = new TCKO(true); vm.prank(DAO_KASASI_DEPLOYER); - daoKasasi = new MockDAOKasasi(); + daoKasasi = new MockDAOKasasiV1(); } function testBalances() external { diff --git a/test/TCKOSnapshotTest.sol b/test/TCKOSnapshotTest.sol index 88546d8..3b7533c 100644 --- a/test/TCKOSnapshotTest.sol +++ b/test/TCKOSnapshotTest.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "contracts/TCKO.sol"; import "forge-std/Test.sol"; @@ -26,7 +26,7 @@ contract TCKOSnapshotTest is Test { tckok = new KilitliTCKO(); vm.prank(DAO_KASASI_DEPLOYER); - daoKasasi = new MockDAOKasasi(); + daoKasasi = IDAOKasasi(address(new MockDAOKasasi())); mintAll(1e12); } diff --git a/test/TCKOTest.sol b/test/TCKOTest.sol index da9bfe2..e79706f 100644 --- a/test/TCKOTest.sol +++ b/test/TCKOTest.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.20; import "contracts/TCKO.sol"; import "forge-std/Test.sol"; -import "interfaces/testing/MockDAOKasasi.sol"; +import "interfaces/testing/MockDAOKasasiV1.sol"; import {MockERC20Permit} from "interfaces/testing/MockTokens.sol"; contract TCKOTest is Test { @@ -21,7 +21,7 @@ contract TCKOTest is Test { tckok = new KilitliTCKO(); vm.prank(DAO_KASASI_DEPLOYER); - daoKasasi = new MockDAOKasasi(); + daoKasasi = new MockDAOKasasiV1(); mintAll(1e12); } @@ -387,11 +387,7 @@ contract TCKOTest is Test { assertEq(tcko.snapshot0BalanceOf(vm.addr(1)), 250e9); } - function testSnapshot0Fuzz( - uint8 from, - uint8 to, - uint256 amount - ) public { + function testSnapshot0Fuzz(uint8 from, uint8 to, uint256 amount) public { vm.assume(from % 20 != to % 20); amount %= 250e9; @@ -485,11 +481,7 @@ contract TCKOTest is Test { assertEq(tcko.snapshot1BalanceOf(vm.addr(1)), 250e9); } - function testSnapshot1Fuzz( - uint8 from, - uint8 to, - uint256 amount - ) public { + function testSnapshot1Fuzz(uint8 from, uint8 to, uint256 amount) public { vm.assume(from % 20 != to % 20); amount %= 250e9; @@ -583,11 +575,7 @@ contract TCKOTest is Test { assertEq(tcko.snapshot2BalanceOf(vm.addr(1)), 250e9); } - function testSnapshot2Fuzz( - uint8 from, - uint8 to, - uint256 amount - ) public { + function testSnapshot2Fuzz(uint8 from, uint8 to, uint256 amount) public { vm.assume(from % 20 != to % 20); amount %= 250e9; @@ -609,15 +597,7 @@ contract TCKOTest is Test { uint256 amount, uint256 deadline, uint256 nonce - ) - internal - view - returns ( - uint8, - bytes32, - bytes32 - ) - { + ) internal view returns (uint8, bytes32, bytes32) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", @@ -840,12 +820,12 @@ contract TCKOTest is Test { function testTCKOKselfDestruct() external { vm.startPrank(vm.addr(1)); vm.expectRevert(); - tckok.selfDestruct(); + // tckok.selfDestruct(); vm.stopPrank(); vm.startPrank(DEV_KASASI); vm.expectRevert(); - tckok.selfDestruct(); + // tckok.selfDestruct(); vm.stopPrank(); vm.prank(vm.addr(1)); @@ -908,7 +888,7 @@ contract TCKOTest is Test { tckok.unlockAllEven(); vm.prank(DEV_KASASI); - tckok.selfDestruct(); + // tckok.selfDestruct(); // Testing selfdestruct() is not implemented in anvil? console.log(tckok.name());