The string indexOf from the solidity-baby-steps tutorials, with a diagnostic slot recording which branch last ran.
Historical Significance
The ethereum.org token tutorial is where most people who deployed a token in this period started, and this is its opening form: a balance mapping, a guarded subtraction and the metadata a wallet needs to show a name. It has no allowance, so nothing can spend on a holder's behalf and no exchange or escrow can be given a limit. That gap is exactly what ERC-20 was written to close, and copies like this one are the before picture.
Context
Deployed 19 September 2015, during the Frontier era.
Key Facts
Description
Example 58 of the solidity-baby-steps tutorial series, deployed by the author of the series. indexOf takes a haystack and a needle as strings, walks the haystack byte by byte and returns the index of the first occurrence or minus one. Because the return has to carry minus one it is a signed integer, so the source refuses any haystack longer than 2**128 minus 1 rather than risk the cast. A storage variable is written on every path with a different negative marker for each way the search can fail, which is how the tutorial shows the caller which branch ran, since a transactional call cannot hand a return value back to geth.
Source Verified
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)
// Submitted by EthereumHistory (ethereumhistory.com)
contract IndexOf {
address creator;
function IndexOf()
{
creator = msg.sender;
}
int whatwastheval = -10; // -2 = not yet tested, as separate from -1, tested but error
function indexOf(string _a, string _b) returns (int) // _a = string to search, _b = string we want to find
{
bytes memory a = bytes(_a);
bytes memory b = bytes(_b);
uint subindex = 0;
if(a.length < 1 || b.length < 1 || (b.length > a.length))
{
whatwastheval = -2;
return -1;
}
else if(a.length > (2**128 -1)) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1)
{
whatwastheval = -3;
return -1;
}
else
{
for (uint i = 0; i < a.length; i ++)
{
if (a[i] == b[0]) // found the first char of b
{
subindex = 1;
while(subindex < b.length && (i + subindex) < a.length && a[i + subindex] == b[subindex]) // search until the chars don't match or until we reach the end of a or b
{
subindex++;
}
if(subindex == b.length)
{
whatwastheval = int(i);
return int(i);
}
}
}
whatwastheval = -4;
return -1;
}
}
function whatWasTheVal() constant returns (int)
{
return whatwastheval;
}
/**********
Standard kill() function to recover funds
**********/
function kill()
{
if (msg.sender == creator)
{
suicide(creator); // kills this contract and sends remaining funds back to creator
}
}
}External Links
Related contracts
GetBalance
Same deployerCyrus Adkisson experimental getter (Sep 2015) exposing the ether balance of a hardcoded address via getMyBalance(). Verified byte-for-byte with soljson v0.1.1.
0x759ad4...239a87August 26, 2015Contract 0xddcd64...a08e7b
Same deployerThe greeter tutorial contract: it stores a greeting set at deployment and can be shut down by its owner.
0xddcd64...a08e7bAugust 26, 2015basicInfoGetter
Same deployerA tour of the EVM globals, carrying the constructor of the file it was copied from
0xad826c...d33547August 31, 2015Contract 0x3ea0db...b922e0
Same deployerThe basic info getter from the solidity-baby-steps tutorials, a read only window onto the block and message globals.
0x3ea0db...b922e0August 31, 2015Contract 0xba575c...78733f
Same deployerA contract built to probe what the msg globals actually return, endowed with 5 ETH, deployed 1 September 2015.
0xba575c...78733fSeptember 1, 2015Contract 0x8b180c...c084df
Same deployerA third deployment of the msgExaminer that records its own creation message
0x8b180c...c084dfSeptember 1, 2015