Is it possible to use bcrypt hash function in a ethereum smart contract? Or only keccak is available?

Searching I got to this question, where the OP apparently assumes it's possible, but there is no confirmation or sample code that indicates such.

1 Answer 1


The cryptographic functions available in solidity are the following:

keccak256(bytes memory) returns (bytes32)
sha256(bytes memory) returns (bytes32)
ripemd160(bytes memory) returns (bytes20)

So, bcrypt is not available in Solidity. Mathematical and Cryptographic Functions from Solidity docs.

It seems that the OP of the other question is using bcrypt function to encrypt/decrypt something stored in a smart cotnract, but not using the function within a smart contract.

  • Thanks alberto, is there by anychance a "external" lib that implements it? Something that I could import into the smart contract, but doesn't rely on offchain solution? (Sorry if this doesn't make sense, I'm still a begginer in solidity/smart contracts) Commented Mar 18, 2021 at 16:27
  • @Justcurious One possiblity it is that Ethereum core developers implement the bcrypt function in the same way that some cryptographic functions are implemented. In something called precompiled contracts, here you can see them: github.com/ethereum/go-ethereum/blob/master/core/vm/…. This code is from the Ethereum Go implementation, and you can see address 0x02 is for sha256hash and address 0x03 for ripemd160hash. This is similar to some type of "external" lib as you said. Hope it helps.
    – alberto
    Commented Mar 18, 2021 at 17:08
  • 1
    @Justcurious Just to clarify. What I wrote above is only an alternative, but maybe we won't see in the future. Anyway, I recommend you to read about precompiled contracts and how they work.
    – alberto
    Commented Mar 18, 2021 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.