Gas Cost of Keccak-256 and SHA-256 in an Ethereum Smart Contract
Main Article Content
Abstract
Smart contracts often store a hash of a record instead of the record, and Ethereum offers Keccak-256 as an opcode and SHA-256 as a precompiled contract. A Hardhat experiment on a course-evaluation contract compared their gas cost in 18 scenarios (2 algorithms, 3 functions, 3 input lengths) of 10 transactions each, and reported Keccak-256 as cheaper by 0.44–2.66%. We re-analyze the reported mean, minimum, maximum, and standard deviation. All 18 scenarios are reproduced exactly by nine repeated transactions at the minimum and one first transaction at the maximum, so the means mix two regimes. For the 850-character submit and verify functions the repeated transactions sit at the EIP-7623 calldata floor (56,030 gas) under both algorithms, which turns a first-transaction gap of 2,518–2,521 gas into a reported mean gap of 252. The first-transaction gaps follow 455 + 76.4w gas for w input words, within 8 gas, about 12 times the cost-schedule difference of 6 gas per word. Keccak-256 stays cheaper, by 0.4–4.1% of first-transaction gas, but the size of the gap is not a property of the hash functions alone. Per-transaction logs and the contract source are needed to confirm the reconstruction.
Downloads
Article Details
Section

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
How to Cite
References
[1] V. Buterin, “Ethereum white paper: A next-generation smart contract and decentralized application platform,” 2014. [Online]. Available: https://ethereum.org/en/whitepaper/
[2] G. Wood, “Ethereum: A secure decentralised generalised transaction ledger,” Shanghai version efc5f9a, Feb. 2025. [Online]. Available: https://ethereum.github.io/yellowpaper/paper.pdf
[3] National Institute of Standards and Technology, “Secure hash standard (SHS),” Federal Information Processing Standards Publication 180-4, Aug. 2015, doi: 10.6028/NIST.FIPS.180-4.
[4] G. Bertoni, J. Daemen, M. Peeters, and G. Van Assche, “On the indifferentiability of the sponge construction,” in Advances in Cryptology – EUROCRYPT 2008, Lecture Notes in Computer Science, vol. 4965. Berlin, Germany: Springer, 2008, pp. 181–197, doi: 10.1007/978-3-540-78967-3_11.
[5] National Institute of Standards and Technology, “SHA-3 standard: Permutation-based hash and extendable-output functions,” Federal Information Processing Standards Publication 202, Aug. 2015, doi: 10.6028/NIST.FIPS.202.
[6] A. Alammary, S. Alhazmi, M. Almasri, and S. Gillani, “Blockchain-based applications in education: A systematic review,” Appl. Sci., vol. 9, no. 12, Art. no. 2400, Jun. 2019, doi: 10.3390/app9122400.
[7] T. Chen, X. Li, X. Luo, and X. Zhang, “Under-optimized smart contracts devour your money,” in Proc. IEEE 24th Int. Conf. Softw. Anal., Evol. Reengineering (SANER), 2017, pp. 442–446, doi: 10.1109/SANER.2017.7884650.
[8] T. Chen, Z. Li, H. Zhou, J. Chen, X. Luo, X. Li, and X. Zhang, “Towards saving money in using smart contracts,” in Proc. 40th Int. Conf. Softw. Eng.: New Ideas Emerg. Results (ICSE-NIER), 2018, pp. 81–84, doi: 10.1145/3183399.3183420.
[9] N. Grech, M. Kong, A. Jurisevic, L. Brent, B. Scholz, and Y. Smaragdakis, “MadMax: Surviving out-of-gas conditions in Ethereum smart contracts,” Proc. ACM Program. Lang., vol. 2, no. OOPSLA, pp. 1–27, 2018, doi: 10.1145/3276486.
[10] E. Albert, J. Correas, P. Gordillo, G. Román-Díez, and A. Rubio, “GASOL: Gas analysis and optimization for Ethereum smart contracts,” arXiv:1912.11929, 2019.
[11] N. Atzei, M. Bartoletti, and T. Cimoli, “A survey of attacks on Ethereum smart contracts (SoK),” in Principles of Security and Trust, Lecture Notes in Computer Science. Berlin, Germany: Springer, 2017, pp. 164–186, doi: 10.1007/978-3-662-54455-6_8.
[12] J. S. G. Sinaga, N. Sitorus, and S. L. Samosir, “Analisis kinerja algoritma hash pada keamanan data: Perbandingan antara SHA-256, SHA-3, dan Blake2” (in Indonesian), Jurnal Quancom: Quantum Computer Jurnal, vol. 2, no. 2, pp. 9–16, Dec. 2024, doi: 10.62375/jqc.v2i2.432.
[13] A. Georges, D. Buytaert, and L. Eeckhout, “Statistically rigorous Java performance evaluation,” in Proc. 22nd Annu. ACM SIGPLAN Conf. Object-Oriented Program. Syst. Lang. Appl. (OOPSLA), 2007, pp. 57–76, doi: 10.1145/1297027.1297033.
[14] “Solidity 0.8.26 documentation.” [Online]. Available: https://docs.soliditylang.org/en/v0.8.26/ (accessed Oct. 12, 2026).
[15] “Hardhat Network reference,” Hardhat 2 documentation. [Online]. Available: https://v2.hardhat.org/hardhat-network/docs/reference (accessed Oct. 12, 2026).
[16] V. Buterin and M. Swende, “EIP-2929: Gas cost increases for state access opcodes,” Ethereum Improvement Proposals, Sep. 2020. [Online]. Available: https://eips.ethereum.org/EIPS/eip-2929
[17] T. Wahrstätter and V. Buterin, “EIP-7623: Increase calldata cost,” Ethereum Improvement Proposals, Feb. 2024. [Online]. Available: https://eips.ethereum.org/EIPS/eip-7623
[18] T. Beiko, “EIP-7600: Hardfork Meta - Pectra,” Ethereum Improvement Proposals, Jan. 2024. [Online]. Available: https://eips.ethereum.org/EIPS/eip-7600
[19] V. Buterin, “EIP-150: Gas cost changes for IO-heavy operations,” Ethereum Improvement Proposals, Sep. 2016. [Online]. Available: https://eips.ethereum.org/EIPS/eip-150