Keccak256 Error – Fix Undeclared Identifier Keccak256 Error in Browser-Solidity

hash-algorithmkeccakremixsha3

I try to use sha3/keccak functions inside a Solidity contract, but I get a weird error:

Untitled:5:13: Error: Undeclared identifier.

bytes32 d=keccak256(0x616263);

The contract :

pragma solidity ^0.4.0;

contract C {

    bytes32 d=keccak256(0x616263);

    bytes32 a=sha3(uint256(1));
}

Best Answer

the keccak256() is an alias for the sha3 function to avoid any confusion with the sha-3 standard (The opcode is still called SHA3.) this alias was adopted this month so the old compiler don't recognize it. so use sha3 instead.

The available hashing functions are sha3, sha256, ripemd160:

pragma solidity ^0.4.0;

contract C { 

    function hashingsha3 (string s)   returns  (bytes32 hash){
        return sha3(s);//<=========
    }

    function hashingsha256 (string s)   returns  (bytes32 hash){
        return sha256(s); //<=========
    }

    function ripemd160 (string s)   returns  (bytes20 hash){
        return ripemd160(s); //<=========
    }
}