same contract using create2 after calling selfdestruct?
                  
                  
                  
                  
                  
                  The below is a Foundry test:
                  
                  
                  
                  
                  
                  // SPDX-License-Identifier: UNLICENSED
                  
                  
                  pragma solidity ^0.8.13;
                  
                  
                  
                  
                  
                  import "forge-std/Test.sol";
                  
                  
                  
                  
                  
                  contract Factory {
                  
                  
                      event WalletCreated(address wallet);
                  
                  
                  
                  
                  
                      function deployWallet() external returns (address) {
                  
                  
                          uint256 salt = 0x123456789; // Specify a unique salt value for create2
                  
                  
                  
                  
                  
                          address walletAddress;
                  
                  
                          bytes memory bytecode = type(Wallet).creationCode;
                  
                  
                          assembly {
                  
                  
                              // Bytecode of the Wallet contract
                  
                  
                              
                  
                  
                  
                  
                  
                              // Calculate the address using the create2 opcode
                  
                  
                              walletAddress := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
                  
                  
                              if iszero(extcodesize(walletAddress)) {
                  
                  
                                  revert(0, 0)
                  
                  
                              }
                  
                  
                          }
                  
                  
                  
                  
                  
                          emit WalletCreated(walletAddress);
                  
                  
                          return walletAddress;
                  
                  
                      }
                  
                  
                  }
                  
                  
                  
                  
                  
                  contract Wallet {
                  
                  
                      constructor() {
                  
                  
                      }
                  
                  
                  
                  
                  
                      function destroyMe() public {
                  
                  
                          selfdestruct(payable(address(msg.sender)));
                  
                  
                      }
                  
                  
                  }
                  
                  
                  
                  
                  
                  contract MetamorphicTest is Test {
                  
                  
                      Factory public factory;
                  
                  
                      address public wallet1;
                  
                  
                      address public wallet2;
                  
                  
                  
                  
                  
                  
                  
                  
                      function _getCodeHash(address _account) private view returns (bytes32 codeHash){
                  
                  
                          assembly { 
                  
                  
                              codeHash := extcodehash(_account)
                  
                  
                          }
                  
                  
                      }
                  
                  
                  
                  
                  
                      function setUp() public {
                  
                  
                          factory = new Factory();
                  
                  
                      }
                  
                  
                  
                  
                  
                      function testMeta() public {
                  
                  
                          wallet1 = factory.deployWallet();
                  
                  
                          console.log(address(wallet1));
                  
                  
                          Wallet(wallet1).destroyMe();
                  
                  
                  
                  
                  
                          wallet2 = factory.deployWallet();
                  
                  
                          console.log(address(wallet2));
                  
                  
                          assertEq(wallet1, wallet2);
                  
                  
                      }
                  
                  
                  }
                  
                  
                
Foundry doesn't selfdestruct the contracts
You can do it here too
Обсуждают сегодня