Encode contract spec XDR at const evaluation time - #1965
Draft
leighmcculloch wants to merge 1 commit into
Draft
Conversation
This was referenced Jul 29, 2026
leighmcculloch
force-pushed
the
handcode-spec-refs-in-derives
branch
3 times, most recently
from
August 7, 2026 16:49
1537072 to
7fc76f9
Compare
leighmcculloch
force-pushed
the
handcode-spec-refs-in-derives
branch
from
August 7, 2026 17:10
7fc76f9 to
230b718
Compare
This was referenced Aug 8, 2026
leighmcculloch
commented
Aug 9, 2026
| /// | ||
| /// A const implementation is needed because the marker is built while the | ||
| /// generated code compiles; `sha2` is not usable in a const context. | ||
| const fn sha256(input: &[u8]) -> [u8; 32] { |
Member
Author
There was a problem hiding this comment.
TODO: Find a way to do the sha256 marker generation in a const context without writing our own sha256 impl.
This was referenced Aug 10, 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.
Note
Part of a stack of PRs that must merge in this order.
A first group of PRs deliver const-encoded contract specs, so that contract specs are produced at compile time instead of at proc-macro execution time. This provides the foundation for the capability to construct the specs from information that is not known at proc-macro execution and only known at compile time, like the fully qualified name of a type:
A second group of PRs deliver fully qualified type names in contract specs. Instead of a type having the name
Contextit will have the namesoroban_sdk::auth::Context. Qualified type names make it possible to uniquely identify types in the spec, even when they have the same name. This resolves several problems with contract specs the type identify problem (#1570), type aliases limitations (#1857), and optimise spec shaking data section size (#1978):What
Change when and where contract spec XDR is encoded. Before, the proc-macro encoded the spec and embedded the resulting bytes as an opaque literal in the generated code. After, the proc-macro constructs a
ScSpecEntryViewover static data and the encoding happens at const evaluation time while the generated code compiles, using the new const XDR encoding support.Example
Why
The spec stops being an opaque blob and becomes a value: readable in
cargo expand, referenceable by other generated code, and no longer only inspectable by decoding bytes back out of a built wasm. It is also the foundation for connecting type IDs across types in a future change.All 43 test contracts'
contractspecv0sections are byte-identical tomain, so nothing downstream observes a difference. 42 of the 43 whole wasm binaries are identical as well; in the one that differs, two internal non-exported functions swap emission order — the export, type, data and metadata sections are all byte-identical.