[types] Add committed_hash() to Transaction and remove CryptoHash trait#18590
Merged
ibalajiarun merged 5 commits intomainfrom Feb 10, 2026
Merged
[types] Add committed_hash() to Transaction and remove CryptoHash trait#18590ibalajiarun merged 5 commits intomainfrom
ibalajiarun merged 5 commits intomainfrom
Conversation
cff8abf to
e651ed1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
grao1991
approved these changes
Feb 9, 2026
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Introduce a committed_hash() method on Transaction that provides the hash used when a transaction is committed to the ledger. For UserTransaction, this leverages the existing cache in SignedTransaction. Update all call sites to use committed_hash() instead of hash() directly, providing clearer semantics and preparing for future enforcement. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove BCSCryptoHash derive from Transaction enum to prevent accidental use of .hash() method. All hash computation now goes through the unified compute_transaction_hash() helper function. This enforces at compile-time that committed_hash() is the only way to get a Transaction's hash, preventing mistakes where .hash() was called directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests to verify: 1. committed_hash() returns the same value as CryptoHash::hash() 2. SignedTransaction caches the committed_hash correctly Uses conditional BCSCryptoHash derive (test/fuzzing only) so tests can compare committed_hash() against the real CryptoHash implementation. This ensures our manual implementation stays in sync with the trait. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
8944f81 to
de17cb8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Contributor
✅ Forge suite
|
Contributor
✅ Forge suite
|
Contributor
✅ Forge suite
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a
committed_hash()method onTransactionand removes theCryptoHashtrait implementation in production to enforce its usage at compile-time.Changes
Add
committed_hash()method toTransactionUserTransaction, delegates toSignedTransaction::committed_hash()which uses cachingRemove
BCSCryptoHashderive fromTransaction(production only).hash()method in production codecommitted_hash()is the only way to get a Transaction's hashConditional
BCSCryptoHashderive for testingTransactionderivesBCSCryptoHashcommitted_hash()matchesCryptoHash::hash()CryptoHashbehavior changes, tests will fail, alerting us to update our implementationUpdate all call sites (25+ locations across the codebase)
Architecture
Benefits
.hash()onTransactionis a compile error in productioncompute_transaction_hash()is the only place that knows how to hashUserTransactionstill benefits fromSignedTransaction'sOnceCellcacheCryptoHashtrait behaviorTest plan
cargo checkpasses for all affected cratescommitted_hash()matchesCryptoHash::hash()Generated with Claude Code