From b3a81eaa9a0b5828a131196a44035f3d4837eba5 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:34:33 +1000 Subject: [PATCH 1/3] add safety notes about docs fields in soroban-spec-rust --- soroban-spec-rust/src/lib.rs | 5 +++++ soroban-spec-rust/src/trait.rs | 5 +++++ soroban-spec-rust/src/types.rs | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/soroban-spec-rust/src/lib.rs b/soroban-spec-rust/src/lib.rs index 536e4062a..bac07ee45 100644 --- a/soroban-spec-rust/src/lib.rs +++ b/soroban-spec-rust/src/lib.rs @@ -14,6 +14,11 @@ use soroban_spec::read::{from_wasm, FromWasmError}; use types::{generate_enum, generate_error_enum, generate_event, generate_struct, generate_union}; +// IMPORTANT: The "docs" fields of spec entries are not output in Rust token +// streams as rustdocs, because rustdocs can contain rust code, and that code +// will be executed. Generated code may be generated on untrusted wasms +// containing untrusted spec docs. + #[derive(thiserror::Error, Debug)] pub enum GenerateFromFileError { #[error("reading file: {0}")] diff --git a/soroban-spec-rust/src/trait.rs b/soroban-spec-rust/src/trait.rs index c65993d37..063b907b5 100644 --- a/soroban-spec-rust/src/trait.rs +++ b/soroban-spec-rust/src/trait.rs @@ -5,6 +5,11 @@ use stellar_xdr::ScSpecFunctionV0; use super::types::generate_type_ident; +// IMPORTANT: The "docs" fields of spec entries are not output in Rust token +// streams as rustdocs, because rustdocs can contain rust code, and that code +// will be executed. Generated code may be generated on untrusted wasms +// containing untrusted spec docs. + /// Constructs a token stream containing a single trait that has a function for /// every function spec. pub fn generate_trait(name: &str, specs: &[&ScSpecFunctionV0]) -> TokenStream { diff --git a/soroban-spec-rust/src/types.rs b/soroban-spec-rust/src/types.rs index 8ce65eacc..8c1ff7225 100644 --- a/soroban-spec-rust/src/types.rs +++ b/soroban-spec-rust/src/types.rs @@ -8,8 +8,9 @@ use stellar_xdr::{ }; // IMPORTANT: The "docs" fields of spec entries are not output in Rust token -// streams as rustdocs, because rustdocs are evaluated and execute code by -// default in Rust projects. +// streams as rustdocs, because rustdocs can contain rust code, and that code +// will be executed. Generated code may be generated on untrusted wasms +// containing untrusted spec docs. // TODO: Replace the unwrap()s in this code with returning Result. // TODO: Create Idents in a way that we can get a Result back and return it too From d231e16689c0d3510635eab5f8d1b418706ad361 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:43:38 +1000 Subject: [PATCH 2/3] clarify safety notes and organize imports --- soroban-spec-rust/src/lib.rs | 4 ++-- soroban-spec-rust/src/trait.rs | 4 ++-- soroban-spec-rust/src/types.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/soroban-spec-rust/src/lib.rs b/soroban-spec-rust/src/lib.rs index bac07ee45..1d72a43ed 100644 --- a/soroban-spec-rust/src/lib.rs +++ b/soroban-spec-rust/src/lib.rs @@ -15,8 +15,8 @@ use soroban_spec::read::{from_wasm, FromWasmError}; use types::{generate_enum, generate_error_enum, generate_event, generate_struct, generate_union}; // IMPORTANT: The "docs" fields of spec entries are not output in Rust token -// streams as rustdocs, because rustdocs can contain rust code, and that code -// will be executed. Generated code may be generated on untrusted wasms +// streams as rustdocs, because rustdocs can contain Rust code, and that code +// will be executed. Generated code may be generated from untrusted Wasm // containing untrusted spec docs. #[derive(thiserror::Error, Debug)] diff --git a/soroban-spec-rust/src/trait.rs b/soroban-spec-rust/src/trait.rs index 063b907b5..dad73e25a 100644 --- a/soroban-spec-rust/src/trait.rs +++ b/soroban-spec-rust/src/trait.rs @@ -6,8 +6,8 @@ use stellar_xdr::ScSpecFunctionV0; use super::types::generate_type_ident; // IMPORTANT: The "docs" fields of spec entries are not output in Rust token -// streams as rustdocs, because rustdocs can contain rust code, and that code -// will be executed. Generated code may be generated on untrusted wasms +// streams as rustdocs, because rustdocs can contain Rust code, and that code +// will be executed. Generated code may be generated from untrusted Wasm // containing untrusted spec docs. /// Constructs a token stream containing a single trait that has a function for diff --git a/soroban-spec-rust/src/types.rs b/soroban-spec-rust/src/types.rs index 8c1ff7225..9bf6f8afc 100644 --- a/soroban-spec-rust/src/types.rs +++ b/soroban-spec-rust/src/types.rs @@ -1,15 +1,15 @@ -use ::stellar_xdr::curr::ScSpecEventParamLocationV0; use proc_macro2::{Literal, TokenStream}; use quote::{format_ident, quote}; use stellar_xdr::curr as stellar_xdr; +use stellar_xdr::curr::ScSpecEventParamLocationV0; use stellar_xdr::{ ScSpecEventV0, ScSpecTypeDef, ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0, }; // IMPORTANT: The "docs" fields of spec entries are not output in Rust token -// streams as rustdocs, because rustdocs can contain rust code, and that code -// will be executed. Generated code may be generated on untrusted wasms +// streams as rustdocs, because rustdocs can contain Rust code, and that code +// will be executed. Generated code may be generated from untrusted Wasm // containing untrusted spec docs. // TODO: Replace the unwrap()s in this code with returning Result. From c47d4b0f0a917d3d538a64b7751a2ddc5195b639 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:47:59 +1000 Subject: [PATCH 3/3] add safety notes field import and reorder imports --- soroban-spec-rust/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soroban-spec-rust/src/types.rs b/soroban-spec-rust/src/types.rs index 9bf6f8afc..7ad6959c2 100644 --- a/soroban-spec-rust/src/types.rs +++ b/soroban-spec-rust/src/types.rs @@ -1,7 +1,7 @@ +use ::stellar_xdr::curr::ScSpecEventParamLocationV0; use proc_macro2::{Literal, TokenStream}; use quote::{format_ident, quote}; use stellar_xdr::curr as stellar_xdr; -use stellar_xdr::curr::ScSpecEventParamLocationV0; use stellar_xdr::{ ScSpecEventV0, ScSpecTypeDef, ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0,