Template hash hardening (breaking change) - #143
Merged
someone235 merged 4 commits intoJul 12, 2026
Conversation
Include fixed-width prefix and suffix lengths when validating template hashes in readInputStateWithTemplate and validateOutputStateWithTemplate. This changes the template hash format and breaks existing tests until Rust-side hash calculations and fixtures are updated.
Exposes templateHash(prefix, suffix), allowing contracts to reconstruct the canonical length-bound template hash from revealed template parts. Supports cases where a template hash is not committed directly, but is contained in a higher-level commitment such as a route table or a hash over several template hashes. The contract can open that commitment, reconstruct the individual template hash, and use it for state validation. Documents the builtin, updates template-related examples to use the canonical hash and camelCase naming, and adds an execution test proving that the prefix/suffix boundary affects the result.
- introduced a shared length-bound template hash helper - exposed the canonical hash through CompiledContract - migrated chess contracts and tests to templateHash - refreshed chess size snapshots and editor highlighting
- locked Rust and Sil hashing to shared canonical vectors - verified templateHash against both *WithTemplate builtins at runtime
someone235
approved these changes
Jul 12, 2026
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.
This PR changes the canonical template hash from:
H(prefix || suffix)to:
H(i64le(prefix.length) || prefix || i64le(suffix.length) || suffix)Lengths are encoded as fixed-width 8-byte little-endian integers.
This is a breaking change for contracts using
readInputStateWithTemplateorvalidateOutputStateWithTemplate. Existing template hashes must be recalculated.The new
templateHash(prefix, suffix)builtin exposes the canonical calculation to Silverscript contracts. Rust callers can usetemplate::template_hash(prefix, suffix)orCompiledContract::template_hash().