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.
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.