diff --git a/Cargo.lock b/Cargo.lock index f71a8602bc..5b73e81c23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3088,7 +3088,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "async-trait", "fp-storage", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "async-trait", "fp-consensus", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "async-trait", "ethereum", @@ -3146,7 +3146,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fc-db", "fc-storage", @@ -3169,7 +3169,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "ethereum-types", @@ -3224,7 +3224,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "ethereum-types", @@ -3239,7 +3239,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "ethereum-types", @@ -3429,7 +3429,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "hex", "impl-serde", @@ -3448,7 +3448,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "parity-scale-codec", @@ -3459,7 +3459,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "ethereum-types", @@ -3471,7 +3471,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "environmental", "evm", @@ -3487,7 +3487,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "ethereum", "ethereum-types", @@ -3503,7 +3503,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "frame-support", "parity-scale-codec", @@ -3515,7 +3515,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "parity-scale-codec", "serde", @@ -8587,7 +8587,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "environmental", "ethereum", @@ -8643,7 +8643,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "cumulus-primitives-storage-weight-reclaim", "environmental", @@ -8667,7 +8667,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "frame-support", "frame-system", @@ -8762,7 +8762,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", ] @@ -8770,7 +8770,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "sp-core", @@ -8902,7 +8902,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "frame-support", @@ -8978,7 +8978,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "num", @@ -9222,7 +9222,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "tiny-keccak", @@ -9231,7 +9231,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "ripemd", @@ -9241,7 +9241,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-storage-cleaner" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "fp-evm", "frame-support", @@ -11979,7 +11979,7 @@ dependencies = [ [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "derive_more", "environmental", @@ -12008,7 +12008,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#58543e9aa0a2c85719aac34c8bad6dfcd962dae2" dependencies = [ "case", "num_enum 0.7.3", diff --git a/test/contracts/src/SelfDestruct.sol b/test/contracts/src/SelfDestruct.sol new file mode 100644 index 0000000000..eddc583c5c --- /dev/null +++ b/test/contracts/src/SelfDestruct.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity ^0.8.24; + +contract SelfDestructable { + constructor() { + selfdestruct(payable(address(0))); + } +} + +contract SelfDestructAfterCreate2 { + uint constant SALT = 1; + + address public deployed1; + address public deployed2; + + function step1() public { + bytes memory bytecode = type(SelfDestructable).creationCode; + address contractAddress; + uint contractSize; + assembly { + contractAddress := create2(0, add(bytecode, 32), mload(bytecode), SALT) + contractSize := extcodesize(contractAddress) + } + require(contractSize == 0, "Contract size should be zero"); + deployed1 = contractAddress; + } + + + function step2() public { + bytes memory bytecode = type(SelfDestructable).creationCode; + address contractAddress; + uint contractSize; + assembly { + contractAddress := create2(0, add(bytecode, 32), mload(bytecode), SALT) + contractSize := extcodesize(contractAddress) + } + require(contractSize == 0, "Contract size should be zero"); + deployed2 = contractAddress; + require(deployed1 == deployed2, "Addresses not equal"); + } + + function cannotRecreateInTheSameCall() public { + bytes memory bytecode = type(SelfDestructable).creationCode; + address contractAddress1; + address contractAddress2; + assembly { + contractAddress1 := create2(0, add(bytecode, 32), mload(bytecode), SALT) + contractAddress2 := create2(0, add(bytecode, 32), mload(bytecode), SALT) + } + require(contractAddress1 != address(0), "First address must not be null"); + require(contractAddress2 == address(0), "Second address must be null"); + } +} \ No newline at end of file diff --git a/test/suites/dev/moonbase/test-contract/test-self-destruct.ts b/test/suites/dev/moonbase/test-contract/test-self-destruct.ts new file mode 100644 index 0000000000..8fb4d768f8 --- /dev/null +++ b/test/suites/dev/moonbase/test-contract/test-self-destruct.ts @@ -0,0 +1,82 @@ +import { describeSuite, expect } from "@moonwall/cli"; +import { createEthersTransaction } from "@moonwall/util"; +import { encodeFunctionData } from "viem"; + +describeSuite({ + id: "D010613", + title: "Test self-destruct contract", + foundationMethods: "dev", + testCases: ({ context, it }) => { + it({ + id: "T01", + title: "SELFDESTRUCT must reset contract account", + test: async function () { + const { contractAddress, abi } = await context.deployContract!("SelfDestructAfterCreate2"); + + const block = await context.createBlock([ + await createEthersTransaction(context, { + to: contractAddress, + data: encodeFunctionData({ + abi, + functionName: "step1", + args: [], + }), + gasLimit: 100_000n, + nonce: 1, + }), + await createEthersTransaction(context, { + to: contractAddress, + data: encodeFunctionData({ + abi, + functionName: "step2", + args: [], + }), + gasLimit: 100_000n, + nonce: 2, + }), + await createEthersTransaction(context, { + to: contractAddress, + data: encodeFunctionData({ + abi, + functionName: "cannotRecreateInTheSameCall", + args: [], + }), + gasLimit: 100_000n, + nonce: 3, + }), + ]); + + for (const result of block.result) { + const receipt = await context + .viem("public") + .getTransactionReceipt({ hash: result.hash as `0x${string}` }); + + expect(receipt.status).toBe("success"); + } + + const deployedAddress = await context.readContract!({ + contractName: "SelfDestructAfterCreate2", + contractAddress: contractAddress, + functionName: "deployed1", + args: [], + rawTxOnly: true, + }); + + const deletedAccount = await context.polkadotJs().query.system.account(deployedAddress); + expect(deletedAccount.toJSON()).toEqual( + expect.objectContaining({ + nonce: 0, + consumers: 0, + providers: 0, + sufficients: 0, + data: expect.objectContaining({ + free: 0, + reserved: 0, + frozen: 0, + }), + }) + ); + }, + }); + }, +});