As titled. I'm learning to build a DApp and I'm wondering if it's worth it to add the extra RIPEMD layer over keccak for a shorter hash to reduce storage costs.

1 Answer 1


From purely a cost perspective, all that matters is the number of slots (32 bytes) used. The storage costs on Ethereum are on a per-byte basis.

Ethereum's Keccack-256, as the name implies, is 256 bits, or 32 bytes.

The number of bytes for the RIPEMD hash depends on the algorithm chosen. If you use RIPEMD-128 or RIPEMD-160, you will use 16 bytes and 20 bytes, respectively. If you go with RIPEMD-256, the size of the hash will be 32 bytes, which is the same as Keccack-256. If you go with RIPEMD-320, you the size will be 40 bytes, which will be more expensive.

(Update based on Ismael's comment) The actual cost of the hashing algorithms above vary. However, slot sizes are 32 bytes so anything smaller will still take up 32 bytes. Because of this, Keccack-256, RIPEMD-128/160/256 will all cost the same and all take up one slot. RIPEMD-320 will take up two slots and cost more.

As a note, the number of 0s in the hash could make it cheaper than expected.

Disclaimer: the answer deals only with the cost of the hashing algorithm. There is no concern for security of the algorithms listed. Do not use this answer for security purposes.

  • 1
    The minimum storage unit is a slot (which is 32 bytes) so storing a hash in a single slot will cost the same for 16, 20 or 32 bytes hashes.
    – Ismael
    Mar 30, 2020 at 19:46
  • 1
    You are correct. I will update the answer now. Mar 30, 2020 at 19:55
  • 1
    If I'm reading this right, it costs the same amount to store hashes for both 32 bytes (Keccak) and 20 bytes (output of final RIPEMD160 layer). However, it is more expensive overall to apply another RIPEMD over Keccak due to gas costs? Mar 31, 2020 at 0:41
  • That is correct. Mar 31, 2020 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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