From 6d068b63313b7ad409d7e3ddfe1d9ec0dc53d565 Mon Sep 17 00:00:00 2001 From: William Entriken Date: Tue, 3 Dec 2019 20:39:24 -0500 Subject: [PATCH] Reduce usage of the word "kill" --- docs/contracts/function-modifiers.rst | 2 +- docs/contracts/inheritance.rst | 56 ++++++++++++------------- docs/examples/micropayment.rst | 2 +- docs/metadata.rst | 4 +- docs/style-guide.rst | 4 +- docs/using-the-compiler.rst | 4 +- test/contracts/Wallet.cpp | 2 +- test/tools/ossfuzz/config/solidity.dict | 1 + 8 files changed, 38 insertions(+), 37 deletions(-) diff --git a/docs/contracts/function-modifiers.rst b/docs/contracts/function-modifiers.rst index ad2804302..785be74e9 100644 --- a/docs/contracts/function-modifiers.rst +++ b/docs/contracts/function-modifiers.rst @@ -39,7 +39,7 @@ if they are marked ``virtual``. For details, please see } } - contract mortal is owned { + contract retrievable is owned { // This contract inherits the `onlyOwner` modifier from // `owned` and applies it to the `close` function, which // causes that calls to `close` only have an effect if diff --git a/docs/contracts/inheritance.rst b/docs/contracts/inheritance.rst index ee766e474..cc5534a06 100644 --- a/docs/contracts/inheritance.rst +++ b/docs/contracts/inheritance.rst @@ -51,10 +51,10 @@ Details are given in the following example. // contracts can access all non-private members including // internal functions and state variables. These cannot be // accessed externally via `this`, though. - contract Mortal is Owned { + contract Temporary is Owned { // The keyword `virtual` means that the function can change // its behaviour in derived classes ("overriding"). - function kill() virtual public { + function shutdown() virtual public { if (msg.sender == owner) selfdestruct(owner); } } @@ -76,9 +76,9 @@ Details are given in the following example. // Multiple inheritance is possible. Note that `owned` is - // also a base class of `mortal`, yet there is only a single + // also a base class of `Temporary`, yet there is only a single // instance of `owned` (as for virtual inheritance in C++). - contract Named is Owned, Mortal { + contract Named is Owned, Temporary { constructor(bytes32 name) public { Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); NameReg(config.lookup(1)).register(name); @@ -92,13 +92,13 @@ Details are given in the following example. // If you want the function to override, you need to use the // `override` keyword. You need to specify the `virtual` keyword again // if you want this function to be overridden again. - function kill() public virtual override { + function shutdown() public virtual override { if (msg.sender == owner) { Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); NameReg(config.lookup(1)).unregister(); // It is still possible to call a specific // overridden function. - Mortal.kill(); + Temporary.shutdown(); } } } @@ -107,21 +107,21 @@ Details are given in the following example. // If a constructor takes an argument, it needs to be // provided in the header (or modifier-invocation-style at // the constructor of the derived contract (see below)). - contract PriceFeed is Owned, Mortal, Named("GoldFeed") { + contract PriceFeed is Owned, Temporary, Named("GoldFeed") { function updateInfo(uint newInfo) public { if (msg.sender == owner) info = newInfo; } // Here, we only specify `override` and not `virtual`. // This means that contracts deriving from `PriceFeed` - // cannot change the behaviour of `kill` anymore. - function kill() public override(Mortal, Named) { Named.kill(); } + // cannot change the behaviour of `shutdown` anymore. + function shutdown() public override(Temporary, Named) { Named.shutdown(); } function get() public view returns(uint r) { return info; } uint info; } -Note that above, we call ``mortal.kill()`` to "forward" the +Note that above, we call ``Temporary.shutdown()`` to "forward" the destruction request. The way this is done is problematic, as seen in the following example:: @@ -132,27 +132,27 @@ seen in the following example:: address payable owner; } - contract mortal is owned { - function kill() public virtual { + contract Temporary is owned { + function shutdown() public virtual { if (msg.sender == owner) selfdestruct(owner); } } - contract Base1 is mortal { - function kill() public virtual override { /* do cleanup 1 */ mortal.kill(); } + contract Base1 is Temporary { + function shutdown() public virtual override { /* do cleanup 1 */ Temporary.shutdown(); } } - contract Base2 is mortal { - function kill() public virtual override { /* do cleanup 2 */ mortal.kill(); } + contract Base2 is Temporary { + function shutdown() public virtual override { /* do cleanup 2 */ Temporary.shutdown(); } } contract Final is Base1, Base2 { - function kill() public override(Base1, Base2) { Base2.kill(); } + function shutdown() public override(Base1, Base2) { Base2.shutdown(); } } -A call to ``Final.kill()`` will call ``Base2.kill`` because we specify it +A call to ``Final.shutdown()`` will call ``Base2.shutdown`` because we specify it explicitly in the final override, but this function will bypass -``Base1.kill``. The way around this is to use ``super``:: +``Base1.shutdown``. The way around this is to use ``super``:: pragma solidity >=0.4.22 <0.7.0; @@ -161,31 +161,31 @@ explicitly in the final override, but this function will bypass address payable owner; } - contract mortal is owned { - function kill() virtual public { + contract Temporary is owned { + function shutdown() virtual public { if (msg.sender == owner) selfdestruct(owner); } } - contract Base1 is mortal { - function kill() public virtual override { /* do cleanup 1 */ super.kill(); } + contract Base1 is Temporary { + function shutdown() public virtual override { /* do cleanup 1 */ super.shutdown(); } } - contract Base2 is mortal { - function kill() public virtual override { /* do cleanup 2 */ super.kill(); } + contract Base2 is Temporary { + function shutdown() public virtual override { /* do cleanup 2 */ super.shutdown(); } } contract Final is Base1, Base2 { - function kill() public override(Base1, Base2) { super.kill(); } + function shutdown() public override(Base1, Base2) { super.shutdown(); } } If ``Base2`` calls a function of ``super``, it does not simply call this function on one of its base contracts. Rather, it calls this function on the next base contract in the final -inheritance graph, so it will call ``Base1.kill()`` (note that +inheritance graph, so it will call ``Base1.shutdown()`` (note that the final inheritance sequence is -- starting with the most -derived contract: Final, Base2, Base1, mortal, owned). +derived contract: Final, Base2, Base1, Temporary, owned). The actual function that is called when using super is not known in the context of the class where it is used, although its type is known. This is similar for ordinary diff --git a/docs/examples/micropayment.rst b/docs/examples/micropayment.rst index f675586dd..fe310f37a 100644 --- a/docs/examples/micropayment.rst +++ b/docs/examples/micropayment.rst @@ -164,7 +164,7 @@ The full contract } /// destroy the contract and reclaim the leftover funds. - function kill() public { + function shutdown() public { require(msg.sender == owner); selfdestruct(msg.sender); } diff --git a/docs/metadata.rst b/docs/metadata.rst index f7d16b23a..3660ce69a 100644 --- a/docs/metadata.rst +++ b/docs/metadata.rst @@ -56,11 +56,11 @@ explanatory purposes. // Swarm URL is recommended "urls": [ "bzzr://56ab..." ] }, - "mortal": { + "retrievable": { // Required: keccak256 hash of the source file "keccak256": "0x234...", // Required (unless "url" is used): literal contents of the source file - "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" + "content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }" } }, // Required: Compiler settings diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 84602542f..11ddaef07 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -584,7 +584,7 @@ Yes:: return balanceOf[from]; } - function kill() public onlyowner { + function shutdown() public onlyowner { selfdestruct(owner); } @@ -594,7 +594,7 @@ No:: return balanceOf[from]; } - function kill() onlyowner public { + function shutdown() onlyowner public { selfdestruct(owner); } diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index f323d0c61..30b00bae0 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -180,12 +180,12 @@ Input Description // `--allow-paths `. ] }, - "mortal": + "retrievable": { // Optional: keccak256 hash of the source file "keccak256": "0x234...", // Required (unless "urls" is used): literal contents of the source file - "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" + "content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }" } }, // Optional diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 25b81d4d9..b71e6555c 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -378,7 +378,7 @@ contract Wallet is multisig, multiowned, daylimit { multiowned.changeOwner(_from, _to); } // destroys the contract sending everything to `_to`. - function kill(address payable _to) onlymanyowners(keccak256(msg.data)) external { + function shutdown(address payable _to) onlymanyowners(keccak256(msg.data)) external { selfdestruct(_to); } diff --git a/test/tools/ossfuzz/config/solidity.dict b/test/tools/ossfuzz/config/solidity.dict index 5ff5318e4..9fe773870 100644 --- a/test/tools/ossfuzz/config/solidity.dict +++ b/test/tools/ossfuzz/config/solidity.dict @@ -41,6 +41,7 @@ ".delegatecall(" ".gas(" ".kill(" +".shutdown(" ".length" ".pop();" ".push("