In the repo, trying to implement and test upgradable proxy contract.
-
UpgradeableProxy.sol
-
TradingCenter.sol: version 1 contract with exchange function to transfer USDT or USDC
-
TradingCenterV2.sol: version 2 contract with malicious empty function to rub all users' money
-
TradingCenterTest.t.sol
- user1, user2 approve to proxy contract
- upgrade version 1 contract to version 2
- Initialize TradingCenterV2
- empty users' account
-
FiatTokenV3.sol:
- mimick to upgrade USDC contract
- with new whitelist function that both mint() and transfer() require msg.sender who is in the whitelist to call
- require to preserve the same slots as FiatTokenV2_1 at first
-
FiatTokenV3Test.t.sol:
- set users as leaf to implement merkle tree function and get root and proof
- fork the ethereum mainnet
- get admin address through ADMIN_SLOT
- upgrade the proxy pointer from V2_1 to V3
- check contract version()
- test mint() and transfer()
- USDC proxy contract on etherscan
- USDC FiatTokenV2_1 contract
Environment: foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup
forge init [project name]
forge install openzeppelin/openzeppelin-contracts --no-commit
forge install dmfxyz/murky --no-commit
forge remappings > remappings.txt
git clone https://github.com/Rita94105/proxy.git
cd proxy
forge test --mc TradingCenter
- test result
forge test --mc FiatTokenV3
- test result