You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Built-in" functions such as sha3 and selfdestruct can be hidden by functions and events with the same name. This can alter the functionality of contracts in non-obvious ways.
pragma solidity ^0.4.2;
contract FakingItsOwnDeath {
function selfdestruct(address x) internal constant {}
}
contract SelfDestructive is FakingItsOwnDeath {
function die() public {
selfdestruct(address(0x0));
}
}
At a glance, SelfDestructive.die appears to destroy the contract. But in fact, it's actually calling FakingItsOwnDeath.selfdestruct rather than the built-in version of selfdestruct and so the contract doesn't die.
It is also to possible to create functions/events called this and now.
(Tested using version 0.4.2+commit.af6afb04.mod.Emscripten.clang of the online Solidity compiler.)
The text was updated successfully, but these errors were encountered:
codywatts
changed the title
Functions and events can hide special variables and functions
Local functions and events can hide "special" variables and functions
Oct 20, 2016
"Built-in" functions such as
sha3
andselfdestruct
can be hidden by functions and events with the same name. This can alter the functionality of contracts in non-obvious ways.Consider the following contract:
At a glance,
SelfDestructive.die
appears to destroy the contract. But in fact, it's actually callingFakingItsOwnDeath.selfdestruct
rather than the built-in version ofselfdestruct
and so the contract doesn't die.It is also to possible to create functions/events called
this
andnow
.(Tested using version
0.4.2+commit.af6afb04.mod.Emscripten.clang
of the online Solidity compiler.)The text was updated successfully, but these errors were encountered: