A tutorial contract that detects whether a caller is a contract or an externally owned account.
Key Facts
Description
A tutorial contract from Cyrus Adkisson's solidity-baby-steps series (contract #70) that demonstrates how to detect whether the caller is a smart contract or an externally owned account (EOA). Uses EXTCODESIZE to check if an address has code deployed.
Deployed on September 13, 2015. This pattern later became important for security considerations, as contracts and EOAs behave differently in certain contexts.
Source Verified
Exact creation bytecode match. Author Cyrus Adkisson published source at https://github.com/cyrusadkisson/solidity-baby-steps/blob/master/contracts/70_contract_detector.sol. Batch-matched against 357 deploy TXs from deployer 0xcf684dfb8304729355b58315e8019b1aa2ad1bac.
Heuristic Analysis
The following characteristics were detected through bytecode analysis and may not be accurate.
Frontier Era
The initial release of Ethereum. A bare-bones implementation for technical users.
Bytecode Overview
Verified Source Available
Source verified through compiler archaeology and exact bytecode matching.
View Verification ProofShow source code (Solidity)
// Given an address hash, detect whether it's a contract-type address or a normal one
/***
* _ _ ___ ______ _ _ _____ _ _ _____
* | | | |/ _ \ | ___ \ \ | |_ _| \ | | __ \
* | | | / /_\ \| |_/ / \| | | | | \| | | \/
* | |/\| | _ || /| . ` | | | | . ` | | __
* \ /\ / | | || |\ \| |\ |_| |_| |\ | |_\ \
* \/ \/\_| |_/\_| \_\_| \_/\___/\_| \_/\____/
*
* This contract DOES NOT WORK. It is not currently possible to
* determine whether an address hash is a contract or normal address
* from Solidity. - fivedogit 9/14/2015
*/
contract ContractDetector {
address creator;
string contract_or_normal = "not checked";
function ContractDetector()
{
creator = msg.sender;
}
function testContractOrNormal(address inc_addr)
{
if(inc_addr.call())
contract_or_normal = "normal";
else
contract_or_normal = "contract";
}
function getContractOrNormal(address inc_addr) constant returns (string)
{
return contract_or_normal;
}
/**********
Standard kill() function to recover funds
**********/
function kill()
{
if (msg.sender == creator)
{
suicide(creator); // kills this contract and sends remaining funds back to creator
}
}
}