Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
05917c7
shake by the version in wasm meta, not an env var
leighmcculloch Sep 5, 2026
b3fe016
bump sdk pins to the restacked 2043 head
leighmcculloch Sep 23, 2026
b1009bf
bump sdk pins to the 2043 v2 vector head
leighmcculloch Sep 23, 2026
9e8a3be
bump sdk pins to the v3 rename head
leighmcculloch Sep 23, 2026
c64c508
bump sdk pins to the shared vector head
leighmcculloch Sep 23, 2026
0b49511
bump sdk pins to the restacked 2043 tip
leighmcculloch Sep 23, 2026
e4bce5c
bump sdk pins to the 2043 tip after the make fix
leighmcculloch Sep 23, 2026
d9cc591
bump sdk pins to the 2043 head on main
leighmcculloch Sep 24, 2026
0b8d685
bump sdk pins to the 2043 head with semver
leighmcculloch Sep 24, 2026
257f7e8
bump sdk pins to the 2043 head with the fuzz fix
leighmcculloch Sep 24, 2026
a71859b
bump sdk pins to the 2043 head
leighmcculloch Sep 24, 2026
aeb5af8
bump sdk pins to the latest 2043 head
leighmcculloch Sep 24, 2026
573f09d
bump sdk pins to the 2043 v3 rename head
leighmcculloch Sep 24, 2026
823914f
bump sdk pins to the 2043 test match head
leighmcculloch Sep 24, 2026
9d2f714
merge the 2674 branch with main
leighmcculloch Sep 24, 2026
877f5a0
bump sdk pins to the 2043 head on the sorted specs
leighmcculloch Sep 24, 2026
6cd797a
bump sdk pins to the 2043 head with the examples fix
leighmcculloch Sep 24, 2026
a45a467
bump sdk pins to the 2043 head with nist tests
leighmcculloch Sep 24, 2026
b41ecc9
bump sdk pins to the 2043 head with the table fix
leighmcculloch Sep 24, 2026
3686495
merge the 2674 pin bump
leighmcculloch Sep 24, 2026
fc50c30
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
08c6774
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
61ca5bc
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
fb24536
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
6eddba8
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
c83bcaa
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
557899e
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
ff6ba40
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
20a9872
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
9c48197
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
2615d6b
merge the 2674 pin bump
leighmcculloch Sep 25, 2026
9f3bba9
merge patch-xdr-and-spec-crates into reduce-spec-markers-on-build
leighmcculloch Sep 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,32 @@ version = "28.0.2"
[workspace.dependencies.soroban-spec]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

[workspace.dependencies.soroban-spec-rust]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

[workspace.dependencies.soroban-sdk]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

[workspace.dependencies.soroban-token-sdk]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

[workspace.dependencies.stellar-asset-spec]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

[workspace.dependencies.soroban-ledger-snapshot]
version = "28.0.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "421b87d67c8789963f522e4a1cdfcaa9f8440752"
rev = "69a2976ef96b683c8190ba607fae06e3310a341e"

# Dependencies from the rs-stellar-rpc-client repo:
[workspace.dependencies.soroban-rpc]
Expand Down
12 changes: 9 additions & 3 deletions cmd/crates/soroban-test/tests/it/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn filter_and_dedup_spec_removes_duplicates() {
.unwrap(),
});

// Build markers for the struct so it passes the filter
// Build markers for the struct so it passes the version 2 filter
let mut markers = std::collections::HashSet::new();
markers.insert(soroban_spec::shaking::generate_marker_for_entry(
&used_struct,
Expand All @@ -527,7 +527,8 @@ fn filter_and_dedup_spec_removes_duplicates() {
used_struct.clone(),
];

let result_xdr = filter_and_dedup_spec(entries, &markers).unwrap();
let result_xdr =
filter_and_dedup_spec(entries, &markers, soroban_spec::shaking::Version::V2).unwrap();

// Parse back the entries from the XDR
let result_entries: Vec<ScSpecEntry> =
Expand Down Expand Up @@ -556,8 +557,13 @@ fn build_with_spec_shaking_has_feature_meta() {

let version = soroban_spec::shaking::spec_shaking_version_for_meta(&meta);

// The fixture builds against a published soroban-sdk, which records
// version 2. The workspace's `[patch.crates-io]` does not reach a contract
// built in a temp dir, so this covers the version 2 rules end to end, and
// the SDK's own test contract covers version 3.
assert_eq!(
version, 2,
version,
soroban_spec::shaking::Version::V2,
"contractmeta should indicate spec shaking version 2"
);
}
Expand Down
41 changes: 25 additions & 16 deletions cmd/soroban-cli/src/commands/contract/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ impl Cmd {
}

// Set env var to inform the SDK that this CLI supports spec
// optimization using markers. Current and new SDK versions no
// optimization. The var says only that this CLI shakes; which
// rules it shakes a given contract by comes from the version that
// contract records in its meta. Current and new SDK versions no
// longer read this var, relying on the CLI version below
// instead, but it must keep being set for past SDK versions that
// require it.
Expand Down Expand Up @@ -532,14 +534,17 @@ impl Cmd {

/// Filters unused types and events from the contract spec.
///
/// This removes:
/// - Type definitions that are not referenced by any function
/// - Events that don't have corresponding markers in the WASM data section
/// (events that are defined but never published)
/// The contract records which spec shaking version it was built with, and
/// that version says which entries carry a marker and so what a missing
/// marker means. Read it and shake by its rules rather than the newest
/// known: a version 2 contract marks every used type, so markers alone say
/// what is used, while a version 3 contract marks only the events it
/// publishes and the errors it panics with, and every other type is
/// settled by following the references to it.
///
/// The SDK embeds markers in the data section for types/events that are
/// actually used. These markers survive dead code elimination, so we can
/// detect which spec entries are truly needed.
/// A version this CLI does not recognise reads as version 1, and a
/// version 1 contract carries no markers at all, so in both cases there is
/// nothing to shake by and the spec is left alone.
fn filter_spec(target_file_path: &PathBuf) -> Result<(), Error> {
use soroban_spec_tools::contract::Spec;
use soroban_spec_tools::wasm::replace_custom_section;
Expand All @@ -549,17 +554,19 @@ impl Cmd {
// Parse the spec from the wasm
let spec = Spec::new(&wasm_bytes)?;

// Check if the contract meta indicates spec shaking v2 is enabled.
if soroban_spec::shaking::spec_shaking_version_for_meta(&spec.meta) != 2 {
// Read the version the contract was built with, which selects the
// rules below. Nothing to shake by at version 1, so leave it alone.
let version = soroban_spec::shaking::spec_shaking_version_for_meta(&spec.meta);
if version == soroban_spec::shaking::Version::V1 {
return Ok(());
}

// Extract markers from the WASM data section
let markers = soroban_spec::shaking::find_all(&wasm_bytes);

// Filter spec entries (types, events) based on markers, and
// Filter spec entries (types, events) by that version's rules, and
// deduplicate any exact duplicate entries.
let filtered_xdr = filter_and_dedup_spec(spec.spec.clone(), &markers)?;
let filtered_xdr = filter_and_dedup_spec(spec.spec.clone(), &markers, version)?;

// Replace the contractspecv0 section with the filtered version
let new_wasm = replace_custom_section(&wasm_bytes, "contractspecv0", &filtered_xdr)
Expand Down Expand Up @@ -955,23 +962,25 @@ fn check_overflow_checks(doc: &toml_edit::DocumentMut, profile: &str) -> Result<
}
}

/// Filters spec entries based on markers and deduplicates exact duplicates.
/// Filters spec entries down to those the contract needs, by the rules of the
/// spec shaking version it was built with, and deduplicates exact duplicates.
///
/// Functions are always kept. Other entries (types, events) are kept only if a
/// matching marker exists. Exact duplicate entries (identical XDR) are collapsed
/// Which entries survive is decided by `soroban_spec::shaking::filter` for the
/// given version. Exact duplicate entries (identical XDR) are then collapsed
/// to a single occurrence.
#[allow(clippy::implicit_hasher)]
pub fn filter_and_dedup_spec(
entries: Vec<stellar_xdr::ScSpecEntry>,
markers: &HashSet<soroban_spec::shaking::Marker>,
version: soroban_spec::shaking::Version,
) -> Result<Vec<u8>, Error> {
let mut seen = HashSet::new();
let mut filtered_xdr = Vec::new();
let mut writer = Limited::new(
Cursor::new(&mut filtered_xdr),
Limits::depth(XDR_DEPTH_LIMIT),
);
for entry in soroban_spec::shaking::filter(entries, markers) {
for entry in soroban_spec::shaking::filter(entries, markers, version) {
let entry_xdr = entry.to_xdr(Limits::depth(XDR_DEPTH_LIMIT))?;
if seen.insert(entry_xdr) {
entry.write_xdr(&mut writer)?;
Expand Down
Loading